class Oakdex::Battle::InBattlePokemon
Represents detailed pokemon instance that is part of a Trainer's Team
Constants
- ALL_STATS
- OTHER_STATS
- STAGE_MULTIPLIERS
- STAGE_MULTIPLIERS_ACC_EVA
- STAGE_MULTIPLIERS_CRITICAL_HIT
- STATUS_CONDITIONS
Attributes
pokemon[R]
status_conditions[R]
Public Class Methods
new(pokemon, options = {})
click to toggle source
# File lib/oakdex/battle/in_battle_pokemon.rb, line 68 def initialize(pokemon, options = {}) @pokemon = pokemon @status_conditions = options[:status_conditions] || [] if @pokemon.primary_status_condition add_status_condition(@pokemon.primary_status_condition) end @pokemon.enable_battle_mode reset_stats end
Public Instance Methods
accuracy()
click to toggle source
# File lib/oakdex/battle/in_battle_pokemon.rb, line 107 def accuracy stage(:accuracy) end
add_status_condition(condition_name)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# File lib/oakdex/battle/in_battle_pokemon.rb, line 115 def critical_hit_prob stage(:critical_hit) end
evasion()
click to toggle source
# File lib/oakdex/battle/in_battle_pokemon.rb, line 111 def evasion stage(:evasion) end
id()
click to toggle source
# File lib/oakdex/battle/in_battle_pokemon.rb, line 119 def id @id ||= SecureRandom.uuid end
remove_status_condition(condition)
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# File lib/oakdex/battle/in_battle_pokemon.rb, line 130 def to_h { id: id, pokemon: @pokemon.for_game } end
Private Instance Methods
stage(stat)
click to toggle source
# File lib/oakdex/battle/in_battle_pokemon.rb, line 149 def stage(stat) multipliers = stage_multipliers(stat) multipliers[@stat_modifiers[stat] || 0] end
stage_multipliers(stat)
click to toggle source
# File lib/oakdex/battle/in_battle_pokemon.rb, line 154 def stage_multipliers(stat) case stat when :evasion, :accuracy STAGE_MULTIPLIERS_ACC_EVA when :critical_hit STAGE_MULTIPLIERS_CRITICAL_HIT else STAGE_MULTIPLIERS end end
status_condition(condition_name)
click to toggle source
# File lib/oakdex/battle/in_battle_pokemon.rb, line 145 def status_condition(condition_name) STATUS_CONDITIONS[condition_name].new(self) end
status_condition_modifier(stat)
click to toggle source
# File lib/oakdex/battle/in_battle_pokemon.rb, line 139 def status_condition_modifier(stat) status_conditions.reduce(1.0) do |modifier, condition| condition.stat_modifier(stat) * modifier end end