class Oakdex::Pokemon::ExperienceGainCalculator

Calculates the experience a pokemon gains after a defeat bulbapedia.bulbagarden.net/wiki/Experience#Experience_gain_in_battle

Public Class Methods

calculate(fainted, winner, options = {}) click to toggle source
# File lib/oakdex/pokemon/experience_gain_calculator.rb, line 6
def self.calculate(fainted, winner, options = {})
  new(fainted, winner, options).calculate
end
new(fainted, winner, options = {}) click to toggle source
# File lib/oakdex/pokemon/experience_gain_calculator.rb, line 10
def initialize(fainted, winner, options = {})
  @options = options
  @fainted = fainted
  @winner = winner
end

Public Instance Methods

calculate() click to toggle source
# File lib/oakdex/pokemon/experience_gain_calculator.rb, line 16
def calculate
  (flat? ? flat_formula : scaled_formula).to_i
end

Private Instance Methods

a() click to toggle source
# File lib/oakdex/pokemon/experience_gain_calculator.rb, line 34
def a
  @fainted.wild? ? 1.0 : 1.5
end
b() click to toggle source
# File lib/oakdex/pokemon/experience_gain_calculator.rb, line 38
def b
  @fainted.species.base_exp_yield
end
e() click to toggle source
# File lib/oakdex/pokemon/experience_gain_calculator.rb, line 50
def e
  @winner.item_id == 'Lucky Egg' ? 1.5 : 1.0
end
f() click to toggle source
# File lib/oakdex/pokemon/experience_gain_calculator.rb, line 59
def f
  @winner.amie_level(:affection) >= 2 ? 1.2 : 1.0
end
flat?() click to toggle source
# File lib/oakdex/pokemon/experience_gain_calculator.rb, line 22
def flat?
  @options[:flat]
end
flat_formula() click to toggle source
# File lib/oakdex/pokemon/experience_gain_calculator.rb, line 30
def flat_formula
  (a * t * b * e * l * p * f * v) / (7 * s)
end
l() click to toggle source
# File lib/oakdex/pokemon/experience_gain_calculator.rb, line 42
def l
  @fainted.level
end
lp() click to toggle source
# File lib/oakdex/pokemon/experience_gain_calculator.rb, line 46
def lp
  @winner.level
end
p() click to toggle source
# File lib/oakdex/pokemon/experience_gain_calculator.rb, line 54
def p
  # TODO: Integrate Point Power
  1
end
s() click to toggle source
# File lib/oakdex/pokemon/experience_gain_calculator.rb, line 67
def s
  @options[:winner_using_exp_share] ? 2 : 1
end
scaled_formula() click to toggle source
# File lib/oakdex/pokemon/experience_gain_calculator.rb, line 26
def scaled_formula
  (((a * b * l) / (5 * s)) * ((2 * l + 10)**2.5 / (l + lp + 10)**2.5) + 1) * t * e * p
end
t() click to toggle source
# File lib/oakdex/pokemon/experience_gain_calculator.rb, line 63
def t
  @winner.traded? ? 1.5 : 1.0
end
v() click to toggle source
# File lib/oakdex/pokemon/experience_gain_calculator.rb, line 71
def v
  # TODO: 1.2 if the winning Pokemon is at or past
  # the level where it would be able to evolve,
  # but it has not
  1
end