=begin
#==============================================================================#
# AMN Element Variables
# Version 1.01
# Author: AMoonlessNight
# Date: 19 Nov 2019
# Latest: 19 Nov 2019
#==============================================================================#
# UPDATE LOG
#------------------------------------------------------------------------------#
# 19 Nov 2019 - created the script
#==============================================================================#
# TERMS OF USE
#------------------------------------------------------------------------------#
# - Please credit AMoonlessNight or A-Moonless-Night
# - Free for non-commercial use; contact for commercial use
# - If you would like to edit/adjust this script, please make edits as a new
# script (do not edit this script directly), and make sure you provide proper
# credit
# - I'd love to see your game if you end up using one of my scripts
#==============================================================================#
This script makes it so that element rates can be tied to a game variable set
via notetags in the item's note field.
You can use notetags in the following note fields:
Actor
Class
Weapon
Armour
State
Enemy
<ElementRateVariable x y>
where x is the ID of the element and y is the ID of the variable
OR
where x is the name of the element and y is the ID of the variable
<ElementRateVariable 3 20>
would set element 3 to be the value of game variable 20
<ElementRateVariable Ice 3>
would set the element called Ice in the database to be the value of
game variable 3
Variables should be set to an integer, e.g. 20 for 20%, 100 for 100%, 5 for 5%
NOTE: You will need to set your variables to the correct amounts at the start,
or else you may have issues with elements not working or returning zero values,
(because the automatic value for variables is 0).
=end
module AMN_ElementVars
VARS_REGEX = /<ElementRateVariable\s+(\d+|.+)\s+(\d+)>/i
end
class RPG::BaseItem
attr_accessor :element_rate_vars
def load_element_vars_notetags
@element_rate_vars = {}
self.note.split(/[\r\n]+/).each { |line|
case line
when AMN_ElementVars::VARS_REGEX
ele, var = $1, $2
is_integer = ele.split("").all?{|i| i =~ /\d/}
ele = is_integer ? ele.to_i : $data_system.elements.index(ele)
@element_rate_vars[ele] = var.to_i unless ele.nil?
end
}
end
end
module DataManager
class <<self; alias :amn_elevars_datamgr_loaddbase :load_database; end
def self.load_database
amn_elevars_datamgr_loaddbase
load_element_vars_notetags
end
def self.load_element_vars_notetags
groups = [$data_actors, $data_classes, $data_weapons, $data_armors,
$data_enemies, $data_states]
for group in groups
for obj in group
next if obj.nil?
obj.load_element_vars_notetags
end
end
end
end
class Game_BattlerBase
def objects_element_rate_vars(element)
feature_objects.inject(1.0) { |r, obj|
r *= ($game_variables[obj.element_rate_vars[element]].to_f / 100.0) }
end
end
class Game_Battler < Game_BattlerBase
alias amn_elevars_gamebattler_itemelerate item_element_rate
def item_element_rate(user, item)
rate = amn_elevars_gamebattler_itemelerate(user, item)
if item.damage.element_id < 0
result = user.atk_elements.empty? ? 1.0 : objects_element_rate_vars(user.atk_elements)
else
result = objects_element_rate_vars(item.damage.element_id)
end
return rate * result
end
end