Class: Battle::Logic::AbilityChangeHandler

Inherits:
ChangeHandlerBase show all
Includes:
Hooks
Defined in:
scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01010 AbilityChangeHandler.rb

Overview

Handler responsive of answering properly ability changes requests

Constant Summary collapse

CANT_OVERWRITE_ABILITIES =
%i[battle_bond comatose disguise multitype power_construct rks_system schooling shields_down stance_change zen_mode]
RECEIVER_CANT_COPY_ABILITIES =
%i[receiver power_of_alchemy trace forecast flower_gift multitype illusion wonder_guard zen_mode imposter
stance_change power_construct schooling comatose shields_down disguise rks_system battle_bond]
SKILL_BLOCKING_ABILITIES =

Case of a move that fail if the target has this ability

{
  entrainment: %i[truant],
  role_play: %i[flower_gift forecast illusion imposter power_of_alchemy receiver trace wonder_guard],
  simple_beam: %i[simple truant],
  skill_swap: %i[illusion wonder_guard]
}
ABILITY_BLOCKING_ABILITIES =

Case of a ability that fail

{
  mummy: %i[mummy],
  wandering_spirit: %i[wandering_spirit],
  trace: %i[flower_gift forecast illusion imposter multitype stance_change trace zen_mode receiver power_of_alchemy],
  receiver: RECEIVER_CANT_COPY_ABILITIES,
  power_of_alchemy: RECEIVER_CANT_COPY_ABILITIES
}
USER_BLOCKING_ABILITIES =

Case of a move that fail if the launcher has this ability

{
  # TODO: Case management of an attack failure if the user has such an ability
  entrainment: %i[disguise forecast flower_gift illusion imposter power_construct power_of_alchemy receiver trace zen_mode],
  role_play: CANT_OVERWRITE_ABILITIES + %i[receiver power_of_alchemy]
}

Instance Attribute Summary

Attributes inherited from ChangeHandlerBase

#logic, #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_ability_prevention_hook(reason) {|handler, target, ability_symbol, launcher, skill| ... }

Function that registers a ability_change_prevention hook

Parameters:

  • reason (String)

    reason of the ability_change_prevention registration

Yield Parameters:

Yield Returns:

  • (:prevent, nil)

    :prevent if the ability cannot be changed



67
68
69
70
71
72
73
74
75
76
77
78
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01010 AbilityChangeHandler.rb', line 67

def register_ability_prevention_hook(reason)
  Hooks.register(AbilityChangeHandler, :ability_change_prevention, reason) do |hook_binding|
    result = yield(
      self,
      hook_binding.local_variable_get(:target),
      hook_binding.local_variable_get(:ability_symbol),
      hook_binding.local_variable_get(:launcher),
      hook_binding.local_variable_get(:skill)
    )
    force_return(false) if result == :prevent
  end
end

Instance Method Details

#can_change_ability?(target, ability_symbol, launcher = nil, skill = nil) ⇒ Boolean

Function that tell if this is possible to change the ability of a Pokemon

Parameters:

Returns:

  • (Boolean)


49
50
51
52
53
54
55
56
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01010 AbilityChangeHandler.rb', line 49

def can_change_ability?(target, ability_symbol, launcher = nil, skill = nil)
  log_data("# can_change_ability?(#{target}, #{ability_symbol}, #{launcher}, #{skill})")
  exec_hooks(AbilityChangeHandler, :ability_change_prevention, binding)
  return true
rescue Hooks::ForceReturn => e
  log_data("# FR: can_change_ability? #{e.data} from #{e.hook_name} (#{e.reason})")
  return e.data
end

#change_ability(target, ability_symbol, launcher = nil, skill = nil)

Function that change the ability of a Pokemon

Parameters:



38
39
40
41
42
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01010 AbilityChangeHandler.rb', line 38

def change_ability(target, ability_symbol, launcher = nil, skill = nil)
  return unless can_change_ability?(target, ability_symbol, launcher, skill)

  target.ability = (ability_symbol == :none ? 0 : data_ability(ability_symbol).id) || 0
end