Class: Battle::Logic::StatusChangeHandler

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

Overview

Handler responsive of answering properly status changes requests

Constant Summary collapse

STATUS_APPLY_METHODS =

List of method to call in order to apply the status on the Pokemon

{
  poison: :status_poison,
  toxic: :status_toxic,
  confusion: :status_confuse,
  sleep: :status_sleep,
  freeze: :status_frozen,
  paralysis: :status_paralyze,
  burn: :status_burn,
  cure: :cure,
  flinch: :apply_flinch
}
STATUS_APPLY_MESSAGE =

List of message ID when applying a status

{ poison: 234, toxic: 237, confusion: 345, sleep: 306, freeze: 288, paralysis: 273, burn: 255 }
STATUS_APPLY_ANIMATION =

List of animation ID when applying a status

{ poison: 470, toxic: 477, confusion: 475, sleep: 473, freeze: 474, paralysis: 471, burn: 472, flinch: 476 }

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_post_status_change_hook(reason) {|handler, status, target, launcher, skill| ... }

Function that registers a post_status_change hook

Parameters:

  • reason (String)

    reason of the post_status_change registration

Yield Parameters:



129
130
131
132
133
134
135
136
137
138
139
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01003 StatusChangeHandler.rb', line 129

def register_post_status_change_hook(reason)
  Hooks.register(StatusChangeHandler, :post_status_change, reason) do |hook_binding|
    yield(
      self,
      hook_binding.local_variable_get(:status),
      hook_binding.local_variable_get(:target),
      hook_binding.local_variable_get(:launcher),
      hook_binding.local_variable_get(:skill)
    )
  end
end

.register_status_prevention_hook(reason) {|handler, status, target, launcher, skill| ... }

Function that registers a status_prevention hook

Parameters:

  • reason (String)

    reason of the status_prevention registration

Yield Parameters:

Yield Returns:

  • (:prevent, nil)

    :prevent if the status cannot be applied



109
110
111
112
113
114
115
116
117
118
119
120
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01003 StatusChangeHandler.rb', line 109

def register_status_prevention_hook(reason)
  Hooks.register(StatusChangeHandler, :status_prevention, reason) do |hook_binding|
    result = yield(
      self,
      hook_binding.local_variable_get(:status),
      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

#status_appliable?(status, target, launcher = nil, skill = nil) ⇒ Boolean

Note:

Thing that prevents the status from being applyied should be defined using :status_prevention Hook.

Function telling if a status can be applyied

Parameters:

  • status (Symbol)

    :poison, :toxic, :confusion, :sleep, :freeze, :paralysis, :burn, :flinch

  • target (PFM::PokemonBattler)
  • launcher (PFM::PokemonBattler, nil) (defaults to: nil)

    Potential launcher of a move

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

    Potential move used

Returns:

  • (Boolean)


30
31
32
33
34
35
36
37
38
39
40
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01003 StatusChangeHandler.rb', line 30

def status_appliable?(status, target, launcher = nil, skill = nil)
  return false if target.hp <= 0

  reset_prevention_reason
  exec_hooks(StatusChangeHandler, :status_prevention, binding) if status != :cure
  return true
rescue Hooks::ForceReturn => e
  log_data("# status = #{status}; target = #{target}; launcher = #{launcher}; skill = #{skill}")
  log_data("# FR: status_appliable? #{e.data} from #{e.hook_name} (#{e.reason})")
  return e.data
end

#status_change(status, target, launcher = nil, skill = nil, message_overwrite: nil)

Function that actually change the status

Parameters:

  • status (Symbol)

    :poison, :toxic, :confusion, :sleep, :freeze, :paralysis, :burn, :flinch, :cure, :confuse_cure

  • target (PFM::PokemonBattler)
  • launcher (PFM::PokemonBattler, nil) (defaults to: nil)

    Potential launcher of a move

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

    Potential move used

  • message_overwrite (Integer) (defaults to: nil)

    Index of the message to use if file 19 to apply the status (if there's specific reason)



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01003 StatusChangeHandler.rb', line 48

def status_change(status, target, launcher = nil, skill = nil, message_overwrite: nil)
  log_data("# status_change(#{status}, #{target}, #{launcher}, #{skill})")
  if status == :cure
    message_overwrite ||= cure_message_id(target)
    target.send(STATUS_APPLY_METHODS[status])
  elsif status == :confuse_cure
    target.effects.get(:confusion)&.kill
    target.effects.delete_specific_dead_effect(:confusion)
  else
    message_overwrite ||= STATUS_APPLY_MESSAGE[status]
    target.send(STATUS_APPLY_METHODS[status], true)
    @scene.visual.show_rmxp_animation(target, STATUS_APPLY_ANIMATION[status])
  end
  @scene.display_message_and_wait(parse_text_with_pokemon(19, message_overwrite, target)) if message_overwrite
  exec_hooks(StatusChangeHandler, :post_status_change, binding)
rescue Hooks::ForceReturn => e
  log_data("# FR: status_change #{e.data} from #{e.hook_name} (#{e.reason})")
  return e.data
ensure
  @scene.visual.refresh_info_bar(target)
end

#status_change_with_process(status, target, launcher = nil, skill = nil, message_overwrite: nil)

Function that test if the change is possible and perform the change if so

Parameters:

  • status (Symbol)

    :poison, :toxic, :confusion, :sleep, :freeze, :paralysis, :burn, :flinch, :cure

  • target (PFM::PokemonBattler)
  • launcher (PFM::PokemonBattler, nil) (defaults to: nil)

    Potential launcher of a move

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

    Potential move used



75
76
77
78
79
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01003 StatusChangeHandler.rb', line 75

def status_change_with_process(status, target, launcher = nil, skill = nil, message_overwrite: nil)
  return process_prevention_reason unless status_appliable?(status, target, launcher, skill)

  status_change(status, target, launcher, skill, message_overwrite: message_overwrite)
end