Class: Oakdex::Battle::Turn

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

Overview

Represents one Turn within the battle

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(battle, actions) ⇒ Turn

Returns a new instance of Turn.



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

def initialize(battle, actions)
  @battle = battle
  @actions = actions
end

Instance Attribute Details

#battleObject (readonly)

Returns the value of attribute battle.



10
11
12
# File 'lib/oakdex/battle/turn.rb', line 10

def battle
  @battle
end

Instance Method Details

#executeObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/oakdex/battle/turn.rb', line 17

def execute
  execute_status_conditions(:before_turn)

  @actions.each { |a| a.turn = self }
  ordered_actions.each do |action|
    next unless valid_target?(action)
    next if action.pokemon && action.pokemon.fainted?
    action.execute
  end

  execute_status_conditions(:after_turn)
end