Class: Battle::Logic::FleeHandler
- Inherits:
-
ChangeHandlerBase
- Object
- ChangeHandlerBase
- Battle::Logic::FleeHandler
- Includes:
- Hooks
- Defined in:
- scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01008 FleeHandler.rb
Overview
Handler responsive of processing flee attempt
Instance Attribute Summary
Attributes inherited from ChangeHandlerBase
Class Method Summary collapse
-
.register_flee_block_hook(reason) {|handler| ... }
Function that registers a flee_block hook.
-
.register_flee_passthrough_hook(reason) {|handler, pokemon| ... }
Function that registers a flee_passthrough hook.
Instance Method Summary collapse
-
#attempt(index) ⇒ Symbol
Try to flee.
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_flee_block_hook(reason) {|handler| ... }
Function that registers a flee_block hook
55 56 57 58 59 60 61 62 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01008 FleeHandler.rb', line 55 def register_flee_block_hook(reason) Hooks.register(FleeHandler, :flee_block, reason) do result = yield( self ) force_return(:blocked) if result == :prevent end end |
.register_flee_passthrough_hook(reason) {|handler, pokemon| ... }
Function that registers a flee_passthrough hook
69 70 71 72 73 74 75 76 77 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01008 FleeHandler.rb', line 69 def register_flee_passthrough_hook(reason) Hooks.register(FleeHandler, :flee_passthrough, reason) do |hook_binding| result = yield( self, logic.battler(0, hook_binding.local_variable_get(:index)) ) force_return(:success) if result == :success end end |
Instance Method Details
#attempt(index) ⇒ Symbol
Note:
flee_block hooks are called to test if the flee is blocked for other reason than switch blocked
Try to flee
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01008 FleeHandler.rb', line 11 def attempt(index) log_data("# flee#attempt(#{index})") exec_hooks(FleeHandler, :flee_block, binding) exec_hooks(FleeHandler, :flee_passthrough, binding) switch_handler = @logic.switch_handler unless switch_handler.can_switch?(@logic.battler(0, index), reason: :flee) switch_handler.process_prevention_reason return :failure end value = flee_value(index) @logic.battle_info.flee_attempt_count += 1 result = @logic.generic_rng.rand(256) < value ? :success : :failure @scene.(parse_text(18, result == :success ? 75 : 76)) return result rescue Hooks::ForceReturn => e log_data("# FR: flee#attempt #{e.data} from #{e.hook_name} (#{e.reason})") process_prevention_reason return e.data end |