Class: Oakdex::Battle::InBattlePokemon
- Inherits:
-
Object
- Object
- Oakdex::Battle::InBattlePokemon
- Extended by:
- Forwardable
- Defined in:
- lib/oakdex/battle/in_battle_pokemon.rb
Overview
Represents detailed pokemon instance that is part of a Trainer’s Team
Constant Summary collapse
- OTHER_STATS =
%i[accuracy evasion critical_hit]
- ALL_STATS =
Oakdex::Pokemon::BATTLE_STATS + OTHER_STATS
- STATUS_CONDITIONS =
{ 'poison' => StatusConditions::Poison, 'burn' => StatusConditions::Burn, 'freeze' => StatusConditions::Freeze, 'paralysis' => StatusConditions::Paralysis, 'badly_poisoned' => StatusConditions::BadlyPoisoned, 'sleep' => StatusConditions::Sleep }
- STAGE_MULTIPLIERS =
{ -6 => Rational(2, 8), -5 => Rational(2, 7), -4 => Rational(2, 6), -3 => Rational(2, 5), -2 => Rational(2, 4), -1 => Rational(2, 3), 0 => Rational(2, 2), 1 => Rational(3, 2), 2 => Rational(4, 2), 3 => Rational(5, 2), 4 => Rational(6, 2), 5 => Rational(7, 2), 6 => Rational(8, 2) }
- STAGE_MULTIPLIERS_CRITICAL_HIT =
{ 0 => Rational(1, 24), 1 => Rational(1, 8), 2 => Rational(1, 2), 3 => Rational(1, 1) }
- STAGE_MULTIPLIERS_ACC_EVA =
{ -6 => Rational(3, 9), -5 => Rational(3, 8), -4 => Rational(3, 7), -3 => Rational(3, 6), -2 => Rational(3, 5), -1 => Rational(3, 4), 0 => Rational(3, 3), 1 => Rational(4, 3), 2 => Rational(5, 3), 3 => Rational(6, 3), 4 => Rational(7, 3), 5 => Rational(8, 3), 6 => Rational(9, 3) }
Instance Attribute Summary collapse
-
#pokemon ⇒ Object
readonly
Returns the value of attribute pokemon.
-
#status_conditions ⇒ Object
readonly
Returns the value of attribute status_conditions.
Instance Method Summary collapse
- #accuracy ⇒ Object
- #add_status_condition(condition_name) ⇒ Object
- #change_stat_by(stat, change_by) ⇒ Object
- #critical_hit_prob ⇒ Object
- #evasion ⇒ Object
- #id ⇒ Object
-
#initialize(pokemon, options = {}) ⇒ InBattlePokemon
constructor
A new instance of InBattlePokemon.
- #remove_status_condition(condition) ⇒ Object
- #reset_stats ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(pokemon, options = {}) ⇒ InBattlePokemon
Returns a new instance of InBattlePokemon.
68 69 70 71 72 73 74 75 76 |
# File 'lib/oakdex/battle/in_battle_pokemon.rb', line 68 def initialize(pokemon, = {}) @pokemon = pokemon @status_conditions = [:status_conditions] || [] if @pokemon.primary_status_condition add_status_condition(@pokemon.primary_status_condition) end @pokemon.enable_battle_mode reset_stats end |
Instance Attribute Details
#pokemon ⇒ Object (readonly)
Returns the value of attribute pokemon.
66 67 68 |
# File 'lib/oakdex/battle/in_battle_pokemon.rb', line 66 def pokemon @pokemon end |
#status_conditions ⇒ Object (readonly)
Returns the value of attribute status_conditions.
66 67 68 |
# File 'lib/oakdex/battle/in_battle_pokemon.rb', line 66 def status_conditions @status_conditions end |
Instance Method Details
#accuracy ⇒ Object
107 108 109 |
# File 'lib/oakdex/battle/in_battle_pokemon.rb', line 107 def accuracy stage(:accuracy) end |
#add_status_condition(condition_name) ⇒ Object
91 92 93 94 |
# File 'lib/oakdex/battle/in_battle_pokemon.rb', line 91 def add_status_condition(condition_name) @status_conditions << status_condition(condition_name) @pokemon.primary_status_condition = condition_name end |
#change_stat_by(stat, change_by) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/oakdex/battle/in_battle_pokemon.rb', line 78 def change_stat_by(stat, change_by) modifiers = stage_multipliers(stat) stat_before = @stat_modifiers[stat] min_value = modifiers.keys.first max_value = modifiers.keys.last @stat_modifiers[stat] = if change_by < 0 [stat_before + change_by, min_value].max else [stat_before + change_by, max_value].min end stat_before != @stat_modifiers[stat] end |
#critical_hit_prob ⇒ Object
115 116 117 |
# File 'lib/oakdex/battle/in_battle_pokemon.rb', line 115 def critical_hit_prob stage(:critical_hit) end |
#evasion ⇒ Object
111 112 113 |
# File 'lib/oakdex/battle/in_battle_pokemon.rb', line 111 def evasion stage(:evasion) end |
#id ⇒ Object
119 120 121 |
# File 'lib/oakdex/battle/in_battle_pokemon.rb', line 119 def id @id ||= SecureRandom.uuid end |
#remove_status_condition(condition) ⇒ Object
96 97 98 99 |
# File 'lib/oakdex/battle/in_battle_pokemon.rb', line 96 def remove_status_condition(condition) @status_conditions = @status_conditions.reject { |s| s == condition } @pokemon.primary_status_condition = nil if @status_conditions.empty? end |
#reset_stats ⇒ Object
101 102 103 104 105 |
# File 'lib/oakdex/battle/in_battle_pokemon.rb', line 101 def reset_stats @stat_modifiers = (ALL_STATS - %i[hp]).map do |stat| [stat, 0] end.to_h end |
#to_h ⇒ Object
130 131 132 133 134 135 |
# File 'lib/oakdex/battle/in_battle_pokemon.rb', line 130 def to_h { id: id, pokemon: @pokemon.to_h } end |