Class: Battle::Logic::StatChangeHandler
- Inherits:
-
ChangeHandlerBase
- Object
- ChangeHandlerBase
- Battle::Logic::StatChangeHandler
- Includes:
- Hooks
- Defined in:
- scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01001 StatChangeHandler.rb
Overview
Handler responsive of answering properly statistic changes requests
Constant Summary collapse
- TEXT_POS =
Position of text for Attack depending on the power
{ atk: atk = [0, 27, 48, 69, 153, 174, 132, 111, 90], dfe: atk.map { |i| i + 3 }, ats: atk.map { |i| i + 6 }, dfs: atk.map { |i| i + 9 }, spd: atk.map { |i| i + 12 }, acc: atk.map { |i| i + 15 }, eva: atk.map { |i| i + 18 } }
- ANIMATION =
ID of the animation depending on the stat
{ atk: 478, dfe: 480, spd: 482, dfs: 486, ats: 484, eva: 488, acc: 490 }
- STAT_INDEX =
Index of the stages depending on the stat to change
{ atk: Configs.stats.atk_stage_index, dfe: Configs.stats.dfe_stage_index, ats: Configs.stats.ats_stage_index, dfs: Configs.stats.dfs_stage_index, spd: Configs.stats.spd_stage_index, acc: Configs.stats.acc_stage_index, eva: Configs.stats.eva_stage_index }
- ALL_STATS =
Array containing all the possible stats
%i[atk dfe spd dfs ats eva acc]
- ATTACK_STATS =
Array containing all the attack kind stat
%i[atk ats]
- DEFENSE_STATS =
Array containing all the defense kind stat
%i[dfe dfs]
- PHYSICAL_STATS =
Array containing the physical stats
%i[atk dfe]
- SPECIAL_STATS =
Array containing the special stats
%i[ats dfs]
Instance Attribute Summary
Attributes inherited from ChangeHandlerBase
Class Method Summary collapse
-
.register_stat_change_hook(reason) {|handler, stat, power, target, launcher, skill| ... }
Function that register a stat_change hook.
-
.register_stat_change_post_event_hook(reason) {|handler, stat, power, target, launcher, skill| ... }
Function that register a stat_change_post_event hook.
-
.register_stat_decrease_prevention_hook(reason) {|handler, stat, target, launcher, skill| ... }
Function that registers a stat_decrease_prevention hook.
-
.register_stat_increase_prevention_hook(reason) {|handler, stat, target, launcher, skill| ... }
Function that registers a stat_increase_prevention hook.
Instance Method Summary collapse
-
#stat_change(stat, power, target, launcher = nil, skill = nil, no_message: false)
Function that actually change a stat.
-
#stat_change_with_process(stat, power, target, launcher = nil, skill = nil, no_message: false)
Function that test if the change is possible and perform the change if so.
-
#stat_decreasable?(stat, target, launcher = nil, skill = nil) ⇒ Boolean
Function telling if a stat can be decreased.
-
#stat_increasable?(stat, target, launcher = nil, skill = nil) ⇒ Boolean
Function telling if a stat can be increased.
-
#stat_text_index(amount, power) ⇒ Integer
Get the text index in the TEXT_POS array depending on amount & power.
Methods included from Hooks
#exec_hooks, #force_return, included, register, remove, remove_without_name
Methods inherited from ChangeHandlerBase
#initialize, #prevent_change, #process_prevention_reason, #reset_prevention_reason
Constructor Details
This class inherits a constructor from Battle::Logic::ChangeHandlerBase
Class Method Details
.register_stat_change_hook(reason) {|handler, stat, power, target, launcher, skill| ... }
Function that register a stat_change hook
213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01001 StatChangeHandler.rb', line 213 def register_stat_change_hook(reason) Hooks.register(StatChangeHandler, :stat_change, reason) do |hook_binding| result = yield( self, hook_binding.local_variable_get(:stat), hook_binding.local_variable_get(:power), hook_binding.local_variable_get(:target), hook_binding.local_variable_get(:launcher), hook_binding.local_variable_get(:skill) ) hook_binding.local_variable_set(:power, result) if result.is_a?(Integer) end end |
.register_stat_change_post_event_hook(reason) {|handler, stat, power, target, launcher, skill| ... }
Function that register a stat_change_post_event hook
191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01001 StatChangeHandler.rb', line 191 def register_stat_change_post_event_hook(reason) Hooks.register(StatChangeHandler, :stat_change_post_event, reason) do |hook_binding| yield( self, hook_binding.local_variable_get(:stat), hook_binding.local_variable_get(:power), hook_binding.local_variable_get(:target), hook_binding.local_variable_get(:launcher), hook_binding.local_variable_get(:skill) ) end end |
.register_stat_decrease_prevention_hook(reason) {|handler, stat, target, launcher, skill| ... }
Function that registers a stat_decrease_prevention hook
170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01001 StatChangeHandler.rb', line 170 def register_stat_decrease_prevention_hook(reason) Hooks.register(StatChangeHandler, :stat_decrease_prevention, reason) do |hook_binding| result = yield( self, hook_binding.local_variable_get(:stat), hook_binding.local_variable_get(:target), hook_binding.local_variable_get(:launcher), hook_binding.local_variable_get(:skill) ) force_return(false) if result == :prevent end end |
.register_stat_increase_prevention_hook(reason) {|handler, stat, target, launcher, skill| ... }
Function that registers a stat_increase_prevention hook
149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01001 StatChangeHandler.rb', line 149 def register_stat_increase_prevention_hook(reason) Hooks.register(StatChangeHandler, :stat_increase_prevention, reason) do |hook_binding| result = yield( self, hook_binding.local_variable_get(:stat), hook_binding.local_variable_get(:target), hook_binding.local_variable_get(:launcher), hook_binding.local_variable_get(:skill) ) force_return(false) if result == :prevent end end |
Instance Method Details
#stat_change(stat, power, target, launcher = nil, skill = nil, no_message: false)
Function that actually change a stat
84 85 86 87 88 89 90 91 92 93 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01001 StatChangeHandler.rb', line 84 def stat_change(stat, power, target, launcher = nil, skill = nil, no_message: false) log_data("# stat_change(#{stat}, #{power}, #{target}, #{launcher}, #{skill})") exec_hooks(StatChangeHandler, :stat_change, binding) amount = target.change_stat(STAT_INDEX[stat], power) show_stat_change_text_and_animation(stat, power, amount, target, ) exec_hooks(StatChangeHandler, :stat_change_post_event, binding) rescue Hooks::ForceReturn => e log_data("# FR: stat_change #{e.data} from #{e.hook_name} (#{e.reason})") return e.data end |
#stat_change_with_process(stat, power, target, launcher = nil, skill = nil, no_message: false)
Function that test if the change is possible and perform the change if so
102 103 104 105 106 107 108 109 110 111 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01001 StatChangeHandler.rb', line 102 def stat_change_with_process(stat, power, target, launcher = nil, skill = nil, no_message: false) if power < 0 result = stat_decreasable?(stat, target, launcher, skill) else result = stat_increasable?(stat, target, launcher, skill) end return process_prevention_reason unless result stat_change(stat, power, target, launcher, skill, no_message: ) end |
#stat_decreasable?(stat, target, launcher = nil, skill = nil) ⇒ Boolean
Thing that prevents the stat from decreasing should be defined using :stat_decrease_prevention Hook.
Function telling if a stat can be decreased
65 66 67 68 69 70 71 72 73 74 75 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01001 StatChangeHandler.rb', line 65 def stat_decreasable?(stat, target, launcher = nil, skill = nil) return false if target.hp <= 0 reset_prevention_reason exec_hooks(StatChangeHandler, :stat_decrease_prevention, binding) return true rescue Hooks::ForceReturn => e log_data("# stat = #{stat}; target = #{target}; launcher = #{launcher}; skill = #{skill}") log_data("# FR: stat_decreasable? #{e.data} from #{e.hook_name} (#{e.reason})") return e.data end |
#stat_increasable?(stat, target, launcher = nil, skill = nil) ⇒ Boolean
Thing that prevents the stat from increasoing should be defined using :stat_increase_prevention Hook.
Function telling if a stat can be increased
46 47 48 49 50 51 52 53 54 55 56 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01001 StatChangeHandler.rb', line 46 def stat_increasable?(stat, target, launcher = nil, skill = nil) return false if target.hp <= 0 reset_prevention_reason exec_hooks(StatChangeHandler, :stat_increase_prevention, binding) return true rescue Hooks::ForceReturn => e log_data("# stat = #{stat}; target = #{target}; launcher = #{launcher}; skill = #{skill}") log_data("# FR: stat_increasable? #{e.data} from #{e.hook_name} (#{e.reason})") return e.data end |
#stat_text_index(amount, power) ⇒ Integer
Get the text index in the TEXT_POS array depending on amount & power
117 118 119 120 121 122 123 124 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01001 StatChangeHandler.rb', line 117 def stat_text_index(amount, power) if amount != 0 return -3 if power < -2 return (power > 2 ? 3 : power) end return (power > 0 ? 4 : 5) end |