Class: Oakdex::Battle::Action
- Inherits:
-
Object
- Object
- Oakdex::Battle::Action
- Extended by:
- Forwardable
- Defined in:
- lib/oakdex/battle/action.rb
Overview
Represents one Action. One turn has many actions.
Constant Summary collapse
- RECALL_PRIORITY =
7
- ITEM_PRIORITY =
6
Instance Attribute Summary collapse
-
#damage ⇒ Object
readonly
Returns the value of attribute damage.
-
#trainer ⇒ Object
readonly
Returns the value of attribute trainer.
-
#turn ⇒ Object
Returns the value of attribute turn.
Instance Method Summary collapse
- #execute ⇒ Object
- #hitting? ⇒ Boolean
- #hitting_probability ⇒ Object
-
#initialize(trainer, attributes) ⇒ Action
constructor
A new instance of Action.
- #item_id ⇒ Object
- #move ⇒ Object
- #pokemon ⇒ Object
- #pokemon_id ⇒ Object
- #pokemon_position ⇒ Object
- #priority ⇒ Object
- #target ⇒ Object
- #target_id ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(trainer, attributes) ⇒ Action
Returns a new instance of Action.
17 18 19 20 |
# File 'lib/oakdex/battle/action.rb', line 17 def initialize(trainer, attributes) @trainer = trainer @attributes = attributes end |
Instance Attribute Details
#damage ⇒ Object (readonly)
Returns the value of attribute damage.
14 15 16 |
# File 'lib/oakdex/battle/action.rb', line 14 def damage @damage end |
#trainer ⇒ Object (readonly)
Returns the value of attribute trainer.
14 15 16 |
# File 'lib/oakdex/battle/action.rb', line 14 def trainer @trainer end |
#turn ⇒ Object
Returns the value of attribute turn.
15 16 17 |
# File 'lib/oakdex/battle/action.rb', line 15 def turn @turn end |
Instance Method Details
#execute ⇒ Object
66 67 68 69 70 71 |
# File 'lib/oakdex/battle/action.rb', line 66 def execute return execute_growth if growth? return execute_recall if recall? return execute_use_item if item? targets.each { |t| MoveExecution.new(self, t).execute } end |
#hitting? ⇒ Boolean
61 62 63 64 |
# File 'lib/oakdex/battle/action.rb', line 61 def hitting? @hitting = rand(1..1000) <= hitting_probability ? 1 : 0 @hitting == 1 end |
#hitting_probability ⇒ Object
57 58 59 |
# File 'lib/oakdex/battle/action.rb', line 57 def hitting_probability ((move.accuracy / 100.0) * (pokemon.accuracy / target.evasion)) * 1000 end |
#item_id ⇒ Object
73 74 75 |
# File 'lib/oakdex/battle/action.rb', line 73 def item_id @attributes['item_id'] end |
#move ⇒ Object
51 52 53 54 55 |
# File 'lib/oakdex/battle/action.rb', line 51 def move return unless @attributes['move'] @move ||= pokemon.moves.find { |m| m.name == @attributes['move'] } @move ||= Oakdex::Pokemon::Move.create(@attributes['move']) end |
#pokemon ⇒ Object
26 27 28 29 |
# File 'lib/oakdex/battle/action.rb', line 26 def pokemon return pokemon_by_team_position if item? recall? ? pokemon_by_position : battle.pokemon_by_id(pokemon_id) end |
#pokemon_id ⇒ Object
31 32 33 |
# File 'lib/oakdex/battle/action.rb', line 31 def pokemon_id move? ? @attributes['pokemon'] : nil end |
#pokemon_position ⇒ Object
35 36 37 |
# File 'lib/oakdex/battle/action.rb', line 35 def pokemon_position recall? ? @attributes['pokemon'] : nil end |
#priority ⇒ Object
22 23 24 |
# File 'lib/oakdex/battle/action.rb', line 22 def priority move&.priority || (recall? ? RECALL_PRIORITY : ITEM_PRIORITY) end |
#target ⇒ Object
39 40 41 |
# File 'lib/oakdex/battle/action.rb', line 39 def target recall? ? battle.pokemon_by_id(@attributes['target']) : targets end |
#target_id ⇒ Object
43 44 45 |
# File 'lib/oakdex/battle/action.rb', line 43 def target_id recall? ? @attributes['target'] : nil end |
#type ⇒ Object
47 48 49 |
# File 'lib/oakdex/battle/action.rb', line 47 def type @attributes['action'] end |