Class: Oakdex::Battle::MoveExecution

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

Overview

Represents one Action. One turn has many actions.

Constant Summary collapse

RECALL_PRIORITY =
6

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action, target) ⇒ MoveExecution

Returns a new instance of MoveExecution.



16
17
18
19
# File 'lib/oakdex/battle/move_execution.rb', line 16

def initialize(action, target)
  @action = action
  @target = target
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



14
15
16
# File 'lib/oakdex/battle/move_execution.rb', line 14

def action
  @action
end

#targetObject (readonly)

Returns the value of attribute target.



14
15
16
# File 'lib/oakdex/battle/move_execution.rb', line 14

def target
  @target
end

Instance Method Details

#executeObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/oakdex/battle/move_execution.rb', line 30

def execute
  return if prevented_by_status_condition?
  pokemon.change_pp_by(move.name, -1)
  if hitting?
    add_uses_move_log
    execute_damage
    execute_stat_modifiers
    execute_status_conditions
    execute_status_condition_callbacks
  else
    add_move_does_not_hit_log
  end

  battle.remove_fainted
end

#hitting?Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/oakdex/battle/move_execution.rb', line 25

def hitting?
  @hitting = rand(1..1000) <= hitting_probability ? 1 : 0
  @hitting == 1
end

#hitting_probabilityObject



21
22
23
# File 'lib/oakdex/battle/move_execution.rb', line 21

def hitting_probability
  ((move.accuracy / 100.0) * (pokemon.accuracy / target.evasion)) * 1000
end