Class: Battle::Logic::FTerrainChangeHandler

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

Overview

Handler responsive of answering properly terrain changes requests

Constant Summary collapse

FTERRAIN_SYM_TO_MSG =

Weather thingies copiepasted, I don't think this is really useful right now

{
  none: {
    electric_terrain: 227,
    grassy_terrain: 223,
    misty_terrain: 225,
    psychic_terrain: 347
  },
  electric_terrain: 226,
  grassy_terrain: 222,
  misty_terrain: 224,
  psychic_terrain: 346
}

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_fterrain_prevention_hook(reason) {|handler, fterrain_type, last_fterrain| ... }

Function that registers a fterrain_prevetion hook

Parameters:

  • reason (String)

    reason of the fterrain_prevetion registration

Yield Parameters:

  • handler (FTerrainChangeHandler)
  • fterrain_type (Symbol)

    :none, :electric_terrain, :grassy_terrain, :misty_terrain, :psychic_terrain

  • last_fterrain (Symbol)

    :none, :electric_terrain, :grassy_terrain, :misty_terrain, :psychic_terrain

Yield Returns:

  • (:prevent, nil)

    :prevent if the status cannot be applied



79
80
81
82
83
84
85
86
87
88
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01012 FTerrainChangeHandler.rb', line 79

def register_fterrain_prevention_hook(reason)
  Hooks.register(FTerrainChangeHandler, :fterrain_prevention, reason) do |hook_binding|
    result = yield(
      self,
      hook_binding.local_variable_get(:fterrain_type),
      hook_binding.local_variable_get(:last_fterrain)
    )
    force_return(false) if result == :prevent
  end
end

.register_post_fterrain_change_hook(reason) {|handler, fterrain_type, last_fterrain| ... }

Function that registers a post_fterrain_handler hook

Parameters:

  • reason (String)

    reason of the post_fterrain_handler registration

Yield Parameters:

  • handler (FTerrainChangeHandler)
  • fterrain_type (Symbol)

    :none, :electric_terrain, :grassy_terrain, :misty_terrain, :psychic_terrain

  • last_fterrain (Symbol)

    :none, :electric_terrain, :grassy_terrain, :misty_terrain, :psychic_terrain



95
96
97
98
99
100
101
102
103
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01012 FTerrainChangeHandler.rb', line 95

def register_post_fterrain_change_hook(reason)
  Hooks.register(FTerrainChangeHandler, :post_fterrain_change, reason) do |hook_binding|
    yield(
      self,
      hook_binding.local_variable_get(:fterrain_type),
      hook_binding.local_variable_get(:last_fterrain)
    )
  end
end

Instance Method Details

#fterrain_appliable?(fterrain_type) ⇒ Boolean

Function telling if a terrain can be applyied

Parameters:

  • fterrain_type (Symbol)

    :none, :electric_terrain, :grassy_terrain, :misty_terrain, :psychic_terrain

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
32
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01012 FTerrainChangeHandler.rb', line 23

def fterrain_appliable?(fterrain_type)
  log_data("# fterrain_appliable?(#{fterrain_type})")
  reset_prevention_reason
  last_fterrain = @logic.field_terrain || :none
  exec_hooks(FTerrainChangeHandler, :fterrain_prevention, binding)
  return true
rescue Hooks::ForceReturn => e
  log_data("# FR: fterrain_appliable? #{e.data} from #{e.hook_name} (#{e.reason})")
  return e.data
end

#fterrain_change(fterrain_type)

Function that actually change the terrain

Parameters:

  • fterrain_type (Symbol)

    :none, :electric_terrain, :grassy_terrain, :misty_terrain, :psychic_terrain



36
37
38
39
40
41
42
43
44
45
46
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01012 FTerrainChangeHandler.rb', line 36

def fterrain_change(fterrain_type)
  log_data("# fterrain_change(#{fterrain_type})")
  last_fterrain = @logic.field_terrain || :none
  @logic.field_terrain = fterrain_type
  @logic.field_terrain_effect # <= This will force the field terrain effect to be initialized to the right value
  show_fterrain_message(last_fterrain, fterrain_type)
  exec_hooks(FTerrainChangeHandler, :post_fterrain_change, binding)
rescue Hooks::ForceReturn => e
  log_data("# FR: fterrain_change #{e.data} from #{e.hook_name} (#{e.reason})")
  return e.data
end

#fterrain_change_with_process(fterrain_type)

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

Parameters:

  • fterrain_type (Symbol)

    :none, :electric_terrain, :grassy_terrain, :misty_terrain, :psychic_terrain



50
51
52
53
54
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/01012 FTerrainChangeHandler.rb', line 50

def fterrain_change_with_process(fterrain_type)
  return process_prevention_reason unless fterrain_appliable?(fterrain_type)

  fterrain_change(fterrain_type)
end