=begin #=============================================================================== Title: Action Speed Formula Author: Hime Date: Mar 22, 2014 URL: http://www.himeworks.com/2014/03/22/action-speed-formulas/ -------------------------------------------------------------------------------- ** Change log Mar 22, 2014 - Initial release -------------------------------------------------------------------------------- ** Terms of Use * Free to use in non-commercial projects * Contact me for commercial use * No real support. The script is provided as-is * Will do bug fixes, but no compatibility patches * Features may be requested but no guarantees, especially if it is non-trivial * Credits to Hime Works in your project * Preserve this header -------------------------------------------------------------------------------- ** Description This script allows you to specify action speed formulas for your database objects. An action speed formula allows you to use a formula to calculate a battler's action speed. For example, suppose you had a "Haste" state that doubles your action speed. In the default battle system, action speed determines who will act first. Battlers with higher action speeds can perform their actions before battlers with lower action speeds. The default speed calculations considers three things: - the battler's agi, using the formula (agi + rand(5 + agi / 4)) - the skill/item's invocation speed, if a skill/item is used - any "atk speed" features, if the skill used is the "attack" skill The formulas provided by this script first calculates the base speed from above and then passes it to custom formulas that you define. -------------------------------------------------------------------------------- ** Installation In the script editor, place this script below Materials and above Main -------------------------------------------------------------------------------- ** Usage To specify an action speed formula, note-tag an object with FORMULA Where the formula is any valid formula that evaluates to a number. The following formula variables are supported: speed - the current speed, after any modifiers a - the current battler p - game party t - game troop s - game switches v - game variables The following database objects support speed formulas: Actors, Classes, Items, Skills, Weapons, Armors, Enemies, States -------------------------------------------------------------------------------- ** Example To implement a "haste" state that doubles your action speed, you would notetag the state with speed * 2 #=============================================================================== =end $imported = {} if $imported.nil? $imported[:TH_ActionSpeedFormula] = true #=============================================================================== # ** Configuration #=============================================================================== module TH module Action_Speed_Formula Ext_Regex = /(.*?)<\/speed[-_ ]formula>/im end end #=============================================================================== # ** Rest of script #=============================================================================== module RPG class BaseItem def speed_formula load_notetag_action_speed_formula unless @speed_formula return @speed_formula end def load_notetag_action_speed_formula @speed_formula = "" res = self.note.match(TH::Action_Speed_Formula::Ext_Regex) if res @speed_formula = res[1] end end def eval_speed_formula(speed, p=$game_party, t=$game_troop, s=$game_switches, v=$game_variables) eval(self.speed_formula) end end end class Game_Action alias :th_action_speed_modifiers_speed :speed def speed speed = th_action_speed_modifiers_speed speed = item.eval_speed_formula(speed) if item && !item.speed_formula.empty? speed = subject.apply_speed_modifiers(speed) speed end end class Game_Battler < Game_BattlerBase def speed_modifier_objects states end def apply_speed_modifiers(speed) speed_modifier_objects.each do |obj| speed = obj.eval_speed_formula(speed) unless obj.speed_formula.empty? end return speed end end class Game_Actor < Game_Battler alias :th_action_speed_modifiers_speed_modifier_objects :speed_modifier_objects def speed_modifier_objects th_action_speed_modifiers_speed_modifier_objects + [actor] + [self.class] + equips.compact end end class Game_Enemy < Game_Battler alias :th_action_speed_modifiers_speed_modifier_objects :speed_modifier_objects def speed_modifier_objects th_action_speed_modifiers_speed_modifier_objects + [enemy] end end