oakdex-pokemon 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -0
- data/lib/oakdex/pokemon.rb +1 -0
- data/lib/oakdex/pokemon/experience_gain_calculator.rb +79 -0
- data/lib/oakdex/pokemon/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d56143befcd254ccac067dfdb99833ebdd08e865
|
4
|
+
data.tar.gz: c001f5809aa83482bfc53faaac4f5a2058b12825
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91c81951efe0bc65b3c238a50c855ce221fa5914ac33be1f85a6702745f9eb3a31d8d2bcec9d59c2bc9320900ab36dbcdc1b416daea359dcfdc2d86269af58b3
|
7
|
+
data.tar.gz: 8d712bf555aba6ffcf69d08386348c8137a5d8e5803766fa22bcdaa4fa6562da636b12360f180010d7d7bb3c643036ee2ff8eda49ab7c9137fe15c80bce885a7
|
data/README.md
CHANGED
@@ -59,6 +59,20 @@ pikachu.change_pp_by('Thunder Shock', -1)
|
|
59
59
|
pikachu.moves.map { |p| "#{p.name} #{p.pp}" } # => ["Quick Attack 30", "Tail Whip 30", "Growl 40", "Thunder Shock 29"]
|
60
60
|
```
|
61
61
|
|
62
|
+
|
63
|
+
### Exp Gain Calculation
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
fainted = Oakdex::Pokemon.create('Pikachu', level: 10)
|
67
|
+
winner = Oakdex::Pokemon.create('Bulbasaur', level: 12)
|
68
|
+
|
69
|
+
Oakdex::Pokemon::ExperienceGainCalculator.calculate(fainted, winner) # => 269
|
70
|
+
Oakdex::Pokemon::ExperienceGainCalculator.calculate(fainted, winner, flat: true) # => 225
|
71
|
+
Oakdex::Pokemon::ExperienceGainCalculator.calculate(fainted, winner, winner_using_exp_share: true) # => 135
|
72
|
+
```
|
73
|
+
|
74
|
+
|
75
|
+
|
62
76
|
## Contributing
|
63
77
|
|
64
78
|
I would be happy if you want to add your contribution to the project. In order to contribute, you just have to fork this repository.
|
data/lib/oakdex/pokemon.rb
CHANGED
@@ -0,0 +1,79 @@
|
|
1
|
+
module Oakdex
|
2
|
+
class Pokemon
|
3
|
+
# Calculates the experience a pokemon gains after a defeat
|
4
|
+
# https://bulbapedia.bulbagarden.net/wiki/Experience#Experience_gain_in_battle
|
5
|
+
class ExperienceGainCalculator
|
6
|
+
def self.calculate(fainted, winner, options = {})
|
7
|
+
new(fainted, winner, options).calculate
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(fainted, winner, options = {})
|
11
|
+
@options = options
|
12
|
+
@fainted = fainted
|
13
|
+
@winner = winner
|
14
|
+
end
|
15
|
+
|
16
|
+
def calculate
|
17
|
+
(flat? ? flat_formula : scaled_formula).to_i
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def flat?
|
23
|
+
@options[:flat]
|
24
|
+
end
|
25
|
+
|
26
|
+
def scaled_formula
|
27
|
+
(((a * b * l) / (5 * s)) * ((2 * l + 10)**2.5 / (l + lp + 10)**2.5) + 1) * t * e * p
|
28
|
+
end
|
29
|
+
|
30
|
+
def flat_formula
|
31
|
+
(a * t * b * e * l * p * f * v) / (7 * s)
|
32
|
+
end
|
33
|
+
|
34
|
+
def a
|
35
|
+
@fainted.wild? ? 1.0 : 1.5
|
36
|
+
end
|
37
|
+
|
38
|
+
def b
|
39
|
+
@fainted.species.base_exp_yield
|
40
|
+
end
|
41
|
+
|
42
|
+
def l
|
43
|
+
@fainted.level
|
44
|
+
end
|
45
|
+
|
46
|
+
def lp
|
47
|
+
@winner.level
|
48
|
+
end
|
49
|
+
|
50
|
+
def e
|
51
|
+
@winner.item_id == 'Lucky Egg' ? 1.5 : 1.0
|
52
|
+
end
|
53
|
+
|
54
|
+
def p
|
55
|
+
# TODO: Integrate Point Power
|
56
|
+
1
|
57
|
+
end
|
58
|
+
|
59
|
+
def f
|
60
|
+
@winner.amie_level(:affection) >= 2 ? 1.2 : 1.0
|
61
|
+
end
|
62
|
+
|
63
|
+
def t
|
64
|
+
@winner.traded? ? 1.5 : 1.0
|
65
|
+
end
|
66
|
+
|
67
|
+
def s
|
68
|
+
@options[:winner_using_exp_share] ? 2 : 1
|
69
|
+
end
|
70
|
+
|
71
|
+
def v
|
72
|
+
# TODO: 1.2 if the winning Pokemon is at or past
|
73
|
+
# the level where it would be able to evolve,
|
74
|
+
# but it has not
|
75
|
+
1
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oakdex-pokemon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jalyna Schroeder
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oakdex-pokedex
|
@@ -33,6 +33,7 @@ files:
|
|
33
33
|
- README.md
|
34
34
|
- lib/oakdex.rb
|
35
35
|
- lib/oakdex/pokemon.rb
|
36
|
+
- lib/oakdex/pokemon/experience_gain_calculator.rb
|
36
37
|
- lib/oakdex/pokemon/factory.rb
|
37
38
|
- lib/oakdex/pokemon/move.rb
|
38
39
|
- lib/oakdex/pokemon/stat.rb
|