Class: Battle::Effects::EffectsHandler

Inherits:
Object
  • Object
show all
Defined in:
scripts/01600 Alpha 25 Battle Engine/04000 Effects/00001 EffectsHandler.rb

Overview

Class responsive of handling the effects active on something (terrain, pokemon, bank position)

Instance Method Summary collapse

Constructor Details

#initializeEffectsHandler

Create a new effect handler



7
8
9
10
11
# File 'scripts/01600 Alpha 25 Battle Engine/04000 Effects/00001 EffectsHandler.rb', line 7

def initialize
  # List of all the effects
  # @type [Array<Battle::Effects::EffectBase>]
  @effects = []
end

Instance Method Details

#add(effect)

Add an effect

Parameters:



32
33
34
# File 'scripts/01600 Alpha 25 Battle Engine/04000 Effects/00001 EffectsHandler.rb', line 32

def add(effect)
  @effects.push(effect)
end

#delete_specific_dead_effect(name)

Delete specific dead effect

Parameters:

  • name (Symbol)


89
90
91
92
93
94
95
# File 'scripts/01600 Alpha 25 Battle Engine/04000 Effects/00001 EffectsHandler.rb', line 89

def delete_specific_dead_effect(name)
  deleted_effect = @effects.select { |effect| effect.dead? && effect.name == name }
  return if deleted_effect.empty?

  @effects.reject! { |effect| effect.dead? && effect.name == name }
  deleted_effect.each(&:on_delete)
end

#deleted_dead_effects

Delete all the effect that should be deleted



79
80
81
82
83
84
85
# File 'scripts/01600 Alpha 25 Battle Engine/04000 Effects/00001 EffectsHandler.rb', line 79

def deleted_dead_effects
  deleted_effect = @effects.select(&:dead?)
  return if deleted_effect.empty?

  @effects.reject!(&:dead?)
  deleted_effect.each(&:on_delete)
end

#each(&block) {|effect| ... }

Note:

automatically calls deleted_dead_effects if a block is given

Call something on all effects

Parameters:

  • block (Proc)

    block that is called for the each process

Yield Parameters:



71
72
73
74
75
76
# File 'scripts/01600 Alpha 25 Battle Engine/04000 Effects/00001 EffectsHandler.rb', line 71

def each(&block)
  return @effects.each unless block_given?

  @effects.each(&block)
  deleted_dead_effects
end

#get(name = nil, &block) {|effect| ... } ⇒ EffectBase?

Get an effect using its name or a block

Parameters:

  • name (Symbol, nil) (defaults to: nil)

    name of the effect. Ignored if a block is given.

  • block (Proc, nil)

    (optional) block testing each effect

Yield Parameters:

Returns:



50
51
52
53
54
# File 'scripts/01600 Alpha 25 Battle Engine/04000 Effects/00001 EffectsHandler.rb', line 50

def get(name = nil, &block)
  return @effects.find(&block) if block

  return @effects.find { |e| e.name == name }
end

#get_all(name = nil, &block) {|effect| ... } ⇒ Array<EffectBase>, Array<NilClass>

Get every effects responding to a name or a block

Parameters:

  • name (Symbol, nil) (defaults to: nil)

    name of the effects. Ignored if a block is given.

  • block (Proc, nil)

    (optional) block testing each effect

Yield Parameters:

Returns:



61
62
63
64
65
# File 'scripts/01600 Alpha 25 Battle Engine/04000 Effects/00001 EffectsHandler.rb', line 61

def get_all(name = nil, &block)
  return @effects.find(&block) if block

  return @effects.find_all { |e| e.name == name }
end

#has?(name = nil, &block) {|effect| ... } ⇒ Boolean

Tell if an effect is present

Parameters:

  • name (Symbol, nil) (defaults to: nil)

    name of the effect. Ignored if a block is given.

  • block (Proc, nil)

    (optional) block testing each effect

Yield Parameters:

Returns:

  • (Boolean)

    if the effect is present



24
25
26
27
28
# File 'scripts/01600 Alpha 25 Battle Engine/04000 Effects/00001 EffectsHandler.rb', line 24

def has?(name = nil, &block)
  return @effects.any?(&block) if block

  return @effects.any? { |e| e.name == name }
end

#replace(effect, &block)

Replace the effects matching the block by the new one

Parameters:



39
40
41
42
43
# File 'scripts/01600 Alpha 25 Battle Engine/04000 Effects/00001 EffectsHandler.rb', line 39

def replace(effect, &block)
  @effects.find_all(&block).each(&:kill)
  deleted_dead_effects
  add(effect)
end

#update_counter

Update the counter of all effects



14
15
16
17
# File 'scripts/01600 Alpha 25 Battle Engine/04000 Effects/00001 EffectsHandler.rb', line 14

def update_counter
  @effects.each(&:update_counter)
  deleted_dead_effects
end