Class: Oakdex::Battle::ActiveInBattlePokemon

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/oakdex/battle/active_in_battle_pokemon.rb

Overview

Represents a pokemon that is actively fighting in battle

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pokemon, side, position = 0) ⇒ ActiveInBattlePokemon

Returns a new instance of ActiveInBattlePokemon.



14
15
16
17
18
# File 'lib/oakdex/battle/active_in_battle_pokemon.rb', line 14

def initialize(pokemon, side, position = 0)
  @pokemon = pokemon
  @side = side
  @position = position
end

Instance Attribute Details

#pokemonObject (readonly)

Returns the value of attribute pokemon.



12
13
14
# File 'lib/oakdex/battle/active_in_battle_pokemon.rb', line 12

def pokemon
  @pokemon
end

#positionObject (readonly)

Returns the value of attribute position.



12
13
14
# File 'lib/oakdex/battle/active_in_battle_pokemon.rb', line 12

def position
  @position
end

#sideObject (readonly)

Returns the value of attribute side.



12
13
14
# File 'lib/oakdex/battle/active_in_battle_pokemon.rb', line 12

def side
  @side
end

Instance Method Details

#action_added?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/oakdex/battle/active_in_battle_pokemon.rb', line 20

def action_added?
  actions.any? { |a| a.pokemon_id == id }
end

#to_hObject



40
41
42
# File 'lib/oakdex/battle/active_in_battle_pokemon.rb', line 40

def to_h
  @pokemon.to_h
end

#valid_move_actionsObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/oakdex/battle/active_in_battle_pokemon.rb', line 24

def valid_move_actions
  return [] if action_added?
  moves = moves_with_pp
  moves = [struggle_move] if moves_with_pp.empty?
  moves.flat_map do |move|
    targets_in_battle(move).map do |target|
      {
        'action' => 'move',
        'pokemon' => pokemon.id,
        'move' => move.name,
        'target' => target
      }
    end
  end
end