Class: Battle::Logic::SwitchHandler

Inherits:
ChangeHandlerBase show all
Includes:
Hooks
Defined in:
docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb

Overview

Handler responsive of processing switch events that happens during switch

Instance Attribute Summary

Attributes inherited from ChangeHandlerBase

#logic, #pre_checked_effects, #scene

Class Method Summary collapse

Instance Method Summary collapse

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

Parameters:

  • reason (String)

    reason of the pre_switch_event hook

Yield Parameters:



1271
1272
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 1271

def register_pre_switch_event_hook(reason)
end

.register_switch_event_hook(reason) {|handler, who, with| ... }

Register a switch event

Parameters:

  • reason (String)

    reason of the switch_event hook

Yield Parameters:



1278
1279
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 1278

def register_switch_event_hook(reason)
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?

Parameters:

  • reason (String)

    reason of the switch_passthrough hook

Yield Parameters:

Yield Returns:

  • (:passthrough, nil)

    if :passthrough, can_switch? will return true without checking switch_prevention



1255
1256
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 1255

def register_switch_passthrough_hook(reason)
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?

Parameters:

  • reason (String)

    reason of the switch_prevention hook

Yield Parameters:

Yield Returns:

  • (:prevent, nil)

    if :prevent, can_switch? will return false



1264
1265
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 1264

def register_switch_prevention_hook(reason)
end

Instance Method Details

#can_switch?(pokemon, skill = nil, reason: :switch) ⇒ Boolean

Test if the switch is possible

Parameters:

  • pokemon (PFM::PokemonBattler)

    pokemon to switch

  • skill (Battle::Move, nil) (defaults to: nil)

    potential move

  • reason (Symbol) (defaults to: :switch)

    the reason why the SwitchHandler is called (:switch or :flee)

Returns:

  • (Boolean)

    if it can switch or not



1233
1234
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 1233

def can_switch?(pokemon, skill = nil, reason: :switch)
end

#execute_pre_switch_events(who, with)

Note:

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

Parameters:



1239
1240
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 1239

def execute_pre_switch_events(who, with)
end

#execute_switch_events(who, with)

Note:

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

Parameters:



1245
1246
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 1245

def execute_switch_events(who, with)
end