Class: Oakdex::Battle::ActiveInBattlePokemon
- Inherits:
-
Object
- Object
- Oakdex::Battle::ActiveInBattlePokemon
- 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
-
#pokemon ⇒ Object
readonly
Returns the value of attribute pokemon.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
-
#side ⇒ Object
readonly
Returns the value of attribute side.
Instance Method Summary collapse
- #action_added? ⇒ Boolean
-
#initialize(pokemon, side, position = 0) ⇒ ActiveInBattlePokemon
constructor
A new instance of ActiveInBattlePokemon.
- #to_h ⇒ Object
- #valid_move_actions ⇒ Object
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
#pokemon ⇒ Object (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 |
#position ⇒ Object (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 |
#side ⇒ Object (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
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_h ⇒ Object
40 41 42 |
# File 'lib/oakdex/battle/active_in_battle_pokemon.rb', line 40 def to_h @pokemon.to_h end |
#valid_move_actions ⇒ Object
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 |