Class: Battle::Logic::SwitchHandler
- Inherits:
-
ChangeHandlerBase
- Object
- ChangeHandlerBase
- Battle::Logic::SwitchHandler
- Includes:
- Hooks
- Defined in:
- scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01005 SwitchHandler.rb
Overview
Handler responsive of processing switch events that happens during switch
Instance Attribute Summary
Attributes inherited from ChangeHandlerBase
Class Method Summary collapse
-
.register_pre_switch_event_hook(reason) {|handler, who, with| ... }
Register a pre switch event.
-
.register_switch_event_hook(reason) {|handler, who, with| ... }
Register a switch event.
-
.register_switch_passthrough_hook(reason) {|handler, pokemon, skill, reason| ... }
Register a switch passthrough.
-
.register_switch_prevention_hook(reason) {|handler, pokemon, skill, reason| ... }
Register a switch prevention hook.
Instance Method Summary collapse
-
#can_switch?(pokemon, skill = nil, reason: :switch) ⇒ Boolean
Test if the switch is possible.
-
#execute_pre_switch_events(who, with)
Execute the events before the pokemon switch out.
-
#execute_switch_events(who, with)
Perform the switch between two Pokemon.
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_pre_switch_event_hook(reason) {|handler, who, with| ... }
Register a pre switch event
88 89 90 91 92 93 94 95 96 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01005 SwitchHandler.rb', line 88 def register_pre_switch_event_hook(reason) Hooks.register(SwitchHandler, :pre_switch_event, reason) do |hook_binding| yield( self, hook_binding.local_variable_get(:who), hook_binding.local_variable_get(:with) ) end end |
.register_switch_event_hook(reason) {|handler, who, with| ... }
Register a switch event
103 104 105 106 107 108 109 110 111 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01005 SwitchHandler.rb', line 103 def register_switch_event_hook(reason) Hooks.register(SwitchHandler, :switch_event, reason) do |hook_binding| yield( self, hook_binding.local_variable_get(:who), hook_binding.local_variable_get(:with) ) end end |
.register_switch_passthrough_hook(reason) {|handler, pokemon, skill, reason| ... }
Register a switch passthrough. If the block returns :passthrough, it will say that Pokemon can switch in can_switch?
52 53 54 55 56 57 58 59 60 61 62 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01005 SwitchHandler.rb', line 52 def register_switch_passthrough_hook(reason) Hooks.register(SwitchHandler, :switch_passthrough, reason) do |hook_binding| result = yield( self, hook_binding.local_variable_get(:pokemon), hook_binding.local_variable_get(:skill), hook_binding.local_variable_get(:reason) ) force_return(true) if result == :passthrough end end |
.register_switch_prevention_hook(reason) {|handler, pokemon, skill, reason| ... }
Register a switch prevention hook. If the block returns :prevent, it will say that Pokemon cannot switch in can_switch?
71 72 73 74 75 76 77 78 79 80 81 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01005 SwitchHandler.rb', line 71 def register_switch_prevention_hook(reason) Hooks.register(SwitchHandler, :switch_prevention, reason) do |hook_binding| result = yield( self, hook_binding.local_variable_get(:pokemon), hook_binding.local_variable_get(:skill), hook_binding.local_variable_get(:reason) ) force_return(false) if result == :prevent end end |
Instance Method Details
#can_switch?(pokemon, skill = nil, reason: :switch) ⇒ Boolean
Test if the switch is possible
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01005 SwitchHandler.rb', line 12 def can_switch?(pokemon, skill = nil, reason: :switch) log_data("# can_switch?(#{pokemon}, #{skill})") return false if pokemon.hp <= 0 reset_prevention_reason exec_hooks(SwitchHandler, :switch_passthrough, binding) exec_hooks(SwitchHandler, :switch_prevention, binding) return true rescue Hooks::ForceReturn => e log_data("# FR: can_switch? #{e.data} from #{e.hook_name} (#{e.reason})") return e.data end |
#execute_pre_switch_events(who, with)
In the event we're starting the battle who & with should be identic, this help to process effect like Intimidate
Execute the events before the pokemon switch out
29 30 31 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01005 SwitchHandler.rb', line 29 def execute_pre_switch_events(who, with) exec_hooks(SwitchHandler, :pre_switch_event, binding) end |
#execute_switch_events(who, with)
In the event we're starting the battle who & with should be identic, this help to process effect like Intimidate
Perform the switch between two Pokemon
37 38 39 40 41 42 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01005 SwitchHandler.rb', line 37 def execute_switch_events(who, with) if with != who with.turn_count = 0 end exec_hooks(SwitchHandler, :switch_event, binding) end |