class Oakdex::Battle::Damage
Calculates damage
Public Class Methods
new(turn, action)
click to toggle source
# File lib/oakdex/battle/damage.rb, line 11 def initialize(turn, action) @turn = turn @action = action end
Public Instance Methods
critical?()
click to toggle source
# File lib/oakdex/battle/damage.rb, line 20 def critical? @critical ||= rand(1..1000) <= pokemon.critical_hit_prob * 1000 ? 1 : 0 @critical == 1 end
damage()
click to toggle source
# File lib/oakdex/battle/damage.rb, line 16 def damage (simple_damage * modifier).to_i end
effective?()
click to toggle source
# File lib/oakdex/battle/damage.rb, line 25 def effective? type_modifier > 1.0 end
ineffective?()
click to toggle source
# File lib/oakdex/battle/damage.rb, line 29 def ineffective? type_modifier < 1.0 end
Private Instance Methods
burn_modifier()
click to toggle source
# File lib/oakdex/battle/damage.rb, line 77 def burn_modifier 1.0 # TODO: 0.5 if attack is burning and physical move end
critical_hit_modifier()
click to toggle source
# File lib/oakdex/battle/damage.rb, line 55 def critical_hit_modifier if critical? 1.5 else 1.0 end end
def_and_atk()
click to toggle source
# File lib/oakdex/battle/damage.rb, line 85 def def_and_atk if move.category == 'special' (pokemon.sp_atk.to_f / target.sp_def.to_f) else (pokemon.atk.to_f / target.def.to_f) end end
modifier()
click to toggle source
# File lib/oakdex/battle/damage.rb, line 35 def modifier target_modifier * weather_modifier * critical_hit_modifier * random_modifier * stab_modifier * type_modifier * burn_modifier * status_condition_modifier * other_modifiers end
other_modifiers()
click to toggle source
# File lib/oakdex/battle/damage.rb, line 81 def other_modifiers 1.0 # TODO: See other https://bulbapedia.bulbagarden.net/wiki/Damage end
random_modifier()
click to toggle source
# File lib/oakdex/battle/damage.rb, line 63 def random_modifier @random_modifier ||= rand(850..1000) / 1000.0 end
simple_damage()
click to toggle source
# File lib/oakdex/battle/damage.rb, line 93 def simple_damage (((2 * pokemon.level) / 5.0 + 2) * move.power * def_and_atk) / 50 + 2 end
stab_modifier()
click to toggle source
# File lib/oakdex/battle/damage.rb, line 67 def stab_modifier pokemon.types.include?(move.type_id) ? 1.5 : 1.0 end
status_condition_modifier()
click to toggle source
# File lib/oakdex/battle/damage.rb, line 41 def status_condition_modifier pokemon.status_conditions.reduce(1.0) do |modifier, condition| modifier * condition.damage_modifier(@action) end end
target_modifier()
click to toggle source
# File lib/oakdex/battle/damage.rb, line 47 def target_modifier 1.0 # TODO: 0.75 if move has more than one target end
type_modifier()
click to toggle source
# File lib/oakdex/battle/damage.rb, line 71 def type_modifier target.types.reduce(1.0) do |factor, type| factor * move.type.effectivness[type] end end
weather_modifier()
click to toggle source
# File lib/oakdex/battle/damage.rb, line 51 def weather_modifier 1.0 # TODO: 1.5 water at rain or fire at harsh sunlight, 0.5 vice versa end