oakdex-pokemon 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d21644d03a3d35efce1f5dec4bcba277d5d87395
4
- data.tar.gz: aa47c97fd2fc60ea0bf4c94e6d49bfb9beaea7b6
3
+ metadata.gz: f76d4ae970dc1d103c9ce5a2fd9301e19786e067
4
+ data.tar.gz: 716c84b59d44cb3d5a95ec70a7601431aebf4d49
5
5
  SHA512:
6
- metadata.gz: 6a86f5126133eeda5e15bf68ef74aa555b3022c48984c9e35014668cad92ebfb8bdf9a8f87fe63de9184215848800fc106e23415e449acfdcee92ed363517a0d
7
- data.tar.gz: 4d15acde748b58cde382e363567037ac53ab8ee653ed3cc9a7c823cc19b920fbe362c10b0eab7d835b4160f238da3f61b9068272060007fcd043b7511f8b4224
6
+ metadata.gz: 052e9a4a83ba05746908ef6f56dc12d9dfc1d322e044d4584232238ef0a03c568dcca022e2df50acbaf5c47ef7cda8032e79155fd74aec2132e60bcac44f3d20
7
+ data.tar.gz: a8be7b269365758dbfa5faa6a02c5da440f6ee253a370daacfb501738656cb348912bf5875e11fb0fe86a30a97c35a3e426614125dc0517f7d2e1d9c4162f8a9
data/README.md CHANGED
@@ -77,9 +77,9 @@ end
77
77
  pikachu.level # => 13
78
78
  pikachu.exp # => 2197
79
79
 
80
- # Calculate exp from won battles
80
+ # Calculate exp and ev from won battles
81
81
  fainted_opponent = bulbasaur
82
- pikachu.gain_exp_from_battle(fainted_opponent, using_exp_share: false, flat: false)
82
+ pikachu.grow_from_battle(fainted_opponent, using_exp_share: false, flat: false)
83
83
 
84
84
  # Evolution by level
85
85
  charmander = Oakdex::Pokemon.create('Charmander', level: 15)
@@ -152,6 +152,24 @@ end
152
152
  charmander.hp # => 40
153
153
  charmander.usable_item?('Potion') # => false
154
154
 
155
+ # Increase pp by PP Up
156
+ exeggcute = Oakdex::Pokemon.create('Exeggcute', level: 12)
157
+ exeggcute.usable_item?('PP Up') # => true
158
+ exeggcute.use_item('PP Up')
159
+ # Exeggcute can increase pp of a mvoe
160
+ while exeggcute.growth_event? do
161
+ e = exeggcute.growth_event
162
+ if e.read_only?
163
+ puts e.message
164
+ e.execute
165
+ else
166
+ puts e.message
167
+ puts e.possible_actions # => name of moves
168
+ e.execute(e.possible_actions.first)
169
+ end
170
+ end
171
+ exeggcute.moves.first.max_pp # => Changed
172
+
155
173
 
156
174
  charmander = Oakdex::Pokemon.create('Charmander', level: 15, primary_status_condition: 'poison')
157
175
  charmander.usable_item?('Antidote') # => true
@@ -168,6 +186,15 @@ charmander.primary_status_condition # => nil
168
186
  charmander.usable_item?('Antidote') # => false
169
187
  ```
170
188
 
189
+ ### Import and export Pokemon
190
+
191
+ ```ruby
192
+ squirtle = Oakdex::Pokemon.create('Squirtle', level: 12)
193
+ json = squirtle.to_json
194
+ # Might throw Oakdex::Pokemon::InvalidPokemon
195
+ identical_squirtle = Oakdex::Pokemon.from_json(json)
196
+ ```
197
+
171
198
 
172
199
  ## Contributing
173
200
 
@@ -1,4 +1,5 @@
1
1
  require 'forwardable'
2
+ require 'json'
2
3
  require 'oakdex/pokedex'
3
4
 
4
5
  require 'oakdex/pokemon/stat'
@@ -8,6 +9,7 @@ require 'oakdex/pokemon/experience_gain_calculator'
8
9
  require 'oakdex/pokemon/evolution_matcher'
9
10
  require 'oakdex/pokemon/use_item_service'
10
11
  require 'oakdex/pokemon/growth_events'
12
+ require 'oakdex/pokemon/import'
11
13
 
12
14
  module Oakdex
13
15
  # Represents detailed pokemon instance
@@ -29,6 +31,7 @@ module Oakdex
29
31
  @species_id = species_id
30
32
  @attributes = attributes
31
33
  @attributes[:growth_events] ||= []
34
+ species
32
35
  end
33
36
 
34
37
  def species
@@ -143,6 +146,16 @@ module Oakdex
143
146
  @attributes[:exp] += exp_to_add
144
147
  end
145
148
 
149
+ def add_ev(stat, ev_to_add)
150
+ @attributes[:ev] = @attributes[:ev].map do |k, v|
151
+ [k, k.to_s == stat ? [v + ev_to_add, 255].min : v]
152
+ end.to_h
153
+ end
154
+
155
+ def ev_max?(stat)
156
+ @attributes[:ev][stat].to_i >= 255
157
+ end
158
+
146
159
  def learn_new_move(move_id, replaced_move_id = nil)
147
160
  new_move = Move.create(move_id)
148
161
  if replaced_move_id.nil?
@@ -181,9 +194,10 @@ module Oakdex
181
194
  gain_exp(gained_exp)
182
195
  end
183
196
 
184
- def gain_exp_from_battle(fainted, options = {})
197
+ def grow_from_battle(fainted, options = {})
185
198
  exp = ExperienceGainCalculator.calculate(fainted, self, options)
186
199
  gain_exp(exp)
200
+ gain_ev_from_battle(fainted) unless options[:using_exp_share]
187
201
  end
188
202
 
189
203
  def growth_event?
@@ -222,8 +236,31 @@ module Oakdex
222
236
  species
223
237
  end
224
238
 
239
+ def to_json
240
+ JSON.dump(to_h)
241
+ end
242
+
243
+ def self.from_json(json)
244
+ Import.new(json).import!
245
+ end
246
+
225
247
  private
226
248
 
249
+ def to_h
250
+ @attributes.dup.tap do |attributes|
251
+ attributes[:species_id] = species.name
252
+ attributes[:moves] = attributes[:moves].map(&:to_h)
253
+ attributes[:growth_events] = attributes[:growth_events].map(&:to_h)
254
+ end
255
+ end
256
+
257
+ def gain_ev_from_battle(fainted)
258
+ fainted.species.ev_yield.each do |stat, value|
259
+ next if value.zero?
260
+ add_growth_event(GrowthEvents::GainedEv, stat: stat, value: value)
261
+ end
262
+ end
263
+
227
264
  def initial_stat(stat)
228
265
  Stat.initial_stat(stat,
229
266
  level: level,
@@ -8,6 +8,7 @@ end
8
8
 
9
9
  require 'oakdex/pokemon/growth_events/base'
10
10
  require 'oakdex/pokemon/growth_events/gained_exp'
11
+ require 'oakdex/pokemon/growth_events/gained_ev'
11
12
  require 'oakdex/pokemon/growth_events/learn_move'
12
13
  require 'oakdex/pokemon/growth_events/level_up'
13
14
  require 'oakdex/pokemon/growth_events/forgot_and_learned_move'
@@ -18,3 +19,7 @@ require 'oakdex/pokemon/growth_events/evolution'
18
19
  require 'oakdex/pokemon/growth_events/add_hp'
19
20
  require 'oakdex/pokemon/growth_events/revive'
20
21
  require 'oakdex/pokemon/growth_events/remove_status_condition'
22
+ require 'oakdex/pokemon/growth_events/increase_max_pp'
23
+ require 'oakdex/pokemon/growth_events/increase_move_max_pp'
24
+ require 'oakdex/pokemon/growth_events/increase_pp'
25
+ require 'oakdex/pokemon/growth_events/increase_move_pp'
@@ -25,6 +25,13 @@ class Oakdex::Pokemon
25
25
  remove_event
26
26
  end
27
27
 
28
+ def to_h
29
+ {
30
+ name: self.class.name,
31
+ options: @options
32
+ }
33
+ end
34
+
28
35
  private
29
36
 
30
37
  def remove_event
@@ -0,0 +1,17 @@
1
+ require 'forwardable'
2
+
3
+ class Oakdex::Pokemon
4
+ module GrowthEvents
5
+ # When pokemon gains ev
6
+ class GainedEv < Base
7
+ def message
8
+ "#{@pokemon.name} got stronger in #{@options[:stat]}."
9
+ end
10
+
11
+ def execute
12
+ @pokemon.add_ev(@options[:stat], @options[:value])
13
+ remove_event
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ require 'forwardable'
2
+
3
+ class Oakdex::Pokemon
4
+ module GrowthEvents
5
+ # When pokemon increases max pp for a move
6
+ class IncreaseMaxPp < Base
7
+ def message
8
+ "Please choose a move of #{@pokemon.name} that should increase its Max PP."
9
+ end
10
+
11
+ def possible_actions
12
+ @options[:moves].keys
13
+ end
14
+
15
+ def execute(action)
16
+ @pokemon.add_growth_event(GrowthEvents::IncreaseMoveMaxPp,
17
+ move_id: action,
18
+ change_by: @options[:moves][action])
19
+ remove_event
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,18 @@
1
+ require 'forwardable'
2
+
3
+ class Oakdex::Pokemon
4
+ module GrowthEvents
5
+ # When picked move for increasing max pp
6
+ class IncreaseMoveMaxPp < Base
7
+ def message
8
+ "#{@pokemon.name} increased Max PP for #{@options[:move_id]}."
9
+ end
10
+
11
+ def execute
12
+ move = @pokemon.moves.find { |m| m.name == @options[:move_id] }
13
+ move.add_max_pp(@options[:change_by])
14
+ remove_event
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ require 'forwardable'
2
+
3
+ class Oakdex::Pokemon
4
+ module GrowthEvents
5
+ # When picked move for increasing pp
6
+ class IncreaseMovePp < Base
7
+ def message
8
+ "#{@pokemon.name} increased PP for #{@options[:move_id]}."
9
+ end
10
+
11
+ def execute
12
+ move = @pokemon.moves.find { |m| m.name == @options[:move_id] }
13
+ move.add_pp(@options[:change_by])
14
+ remove_event
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ require 'forwardable'
2
+
3
+ class Oakdex::Pokemon
4
+ module GrowthEvents
5
+ # When pokemon increases pp for a move
6
+ class IncreasePp < Base
7
+ def message
8
+ "Please choose a move of #{@pokemon.name} that should increase its PP."
9
+ end
10
+
11
+ def possible_actions
12
+ @options[:moves].keys
13
+ end
14
+
15
+ def execute(action)
16
+ @pokemon.add_growth_event(GrowthEvents::IncreaseMovePp,
17
+ move_id: action,
18
+ change_by: @options[:moves][action])
19
+ remove_event
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,60 @@
1
+ require 'json-schema'
2
+ require 'json'
3
+ require 'oakdex/pokemon/invalid_pokemon'
4
+
5
+ module Oakdex
6
+ class Pokemon
7
+ # Imports and validates pokemon
8
+ class Import
9
+ SCHEMA_PATH = './lib/oakdex/pokemon/schema.json'.freeze
10
+
11
+ def self.schema
12
+ @schema ||= File.read(File.expand_path(SCHEMA_PATH))
13
+ end
14
+
15
+ def initialize(data)
16
+ @data = data.is_a?(Hash) ? data : JSON.parse(data)
17
+ end
18
+
19
+ def import!
20
+ JSON::Validator.validate!(self.class.schema, @data)
21
+ pok = Oakdex::Pokemon.new(@data['species_id'], attributes)
22
+ apply_growth_events(pok)
23
+ pok
24
+ rescue JSON::Schema::ValidationError => e
25
+ raise Oakdex::Pokemon::InvalidPokemon, e.message
26
+ rescue Oakdex::Pokedex::NotFound => e
27
+ raise Oakdex::Pokemon::InvalidPokemon, e.message
28
+ end
29
+
30
+ private
31
+
32
+ def attributes
33
+ @data.map do |k, v|
34
+ next if k == 'species_id' || k == 'growth_events'
35
+ if k == 'moves'
36
+ [:moves, moves]
37
+ else
38
+ [k.to_sym, v]
39
+ end
40
+ end.compact.to_h
41
+ end
42
+
43
+ def moves
44
+ (@data['moves'] || []).map do |move_data|
45
+ move_type = Oakdex::Pokedex::Move.find!(move_data['move_id'])
46
+ Move.new(move_type, move_data['pp'], move_data['max_pp'])
47
+ end
48
+ end
49
+
50
+ def apply_growth_events(pok)
51
+ (@data['growth_events'] || []).each do |growth_event_data|
52
+ klass = Object.const_get(growth_event_data['name'])
53
+ pok.add_growth_event(klass, growth_event_data['options'].map do |k, v|
54
+ [k.to_sym, v]
55
+ end.to_h)
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,7 @@
1
+ module Oakdex
2
+ class Pokemon
3
+ # Exception if pokemon is invalid
4
+ class InvalidPokemon < StandardError
5
+ end
6
+ end
7
+ end
@@ -11,7 +11,7 @@ module Oakdex
11
11
 
12
12
  extend Forwardable
13
13
 
14
- attr_reader :max_pp
14
+ attr_reader :max_pp, :move_type
15
15
  attr_accessor :pp
16
16
 
17
17
  def_delegators :@move_type, :target, :priority, :accuracy,
@@ -39,6 +39,24 @@ module Oakdex
39
39
  @move_type.names['en']
40
40
  end
41
41
 
42
+ def max_pp_at_max?
43
+ @max_pp >= @move_type.max_pp
44
+ end
45
+
46
+ def pp_max?
47
+ @pp >= @max_pp
48
+ end
49
+
50
+ def add_max_pp(change_by)
51
+ old = max_pp
52
+ @max_pp = [max_pp + change_by, @move_type.max_pp].min
53
+ @pp += @max_pp - old
54
+ end
55
+
56
+ def add_pp(change_by)
57
+ @pp = [@pp + change_by, @max_pp].min
58
+ end
59
+
42
60
  def type_id
43
61
  @move_type.type
44
62
  end
@@ -46,6 +64,14 @@ module Oakdex
46
64
  def type
47
65
  Oakdex::Pokedex::Type.find!(type_id)
48
66
  end
67
+
68
+ def to_h
69
+ {
70
+ move_id: @move_type.name,
71
+ pp: @pp,
72
+ max_pp: @max_pp
73
+ }
74
+ end
49
75
  end
50
76
  end
51
77
  end
@@ -0,0 +1,237 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema#",
3
+ "type": "object",
4
+ "title": "Pokemon",
5
+ "definitions": {
6
+ "ev_stats": {
7
+ "type": "object",
8
+ "properties": {
9
+ "hp": {
10
+ "type": "integer",
11
+ "minimum": 0,
12
+ "maximum": 255
13
+ },
14
+ "atk": {
15
+ "type": "integer",
16
+ "minimum": 0,
17
+ "maximum": 255
18
+ },
19
+ "def": {
20
+ "type": "integer",
21
+ "minimum": 0,
22
+ "maximum": 255
23
+ },
24
+ "sp_atk": {
25
+ "type": "integer",
26
+ "minimum": 0,
27
+ "maximum": 255
28
+ },
29
+ "sp_def": {
30
+ "type": "integer",
31
+ "minimum": 0,
32
+ "maximum": 255
33
+ },
34
+ "speed": {
35
+ "type": "integer",
36
+ "minimum": 0,
37
+ "maximum": 255
38
+ }
39
+ },
40
+ "required": [
41
+ "hp",
42
+ "atk",
43
+ "def",
44
+ "sp_atk",
45
+ "sp_def",
46
+ "speed"
47
+ ],
48
+ "additionalProperties": false
49
+ },
50
+ "iv_stats": {
51
+ "type": "object",
52
+ "properties": {
53
+ "hp": {
54
+ "type": "integer",
55
+ "minimum": 0,
56
+ "maximum": 31
57
+ },
58
+ "atk": {
59
+ "type": "integer",
60
+ "minimum": 0,
61
+ "maximum": 31
62
+ },
63
+ "def": {
64
+ "type": "integer",
65
+ "minimum": 0,
66
+ "maximum": 31
67
+ },
68
+ "sp_atk": {
69
+ "type": "integer",
70
+ "minimum": 0,
71
+ "maximum": 31
72
+ },
73
+ "sp_def": {
74
+ "type": "integer",
75
+ "minimum": 0,
76
+ "maximum": 31
77
+ },
78
+ "speed": {
79
+ "type": "integer",
80
+ "minimum": 0,
81
+ "maximum": 31
82
+ }
83
+ },
84
+ "required": [
85
+ "hp",
86
+ "atk",
87
+ "def",
88
+ "sp_atk",
89
+ "sp_def",
90
+ "speed"
91
+ ],
92
+ "additionalProperties": false
93
+ }
94
+ },
95
+ "properties": {
96
+ "species_id": {
97
+ "type": "string"
98
+ },
99
+ "exp": {
100
+ "type": "integer",
101
+ "minimum": 0,
102
+ "maximum": 1640000
103
+ },
104
+ "gender": {
105
+ "type": "string",
106
+ "enum": [
107
+ "male",
108
+ "female",
109
+ "neuter"
110
+ ]
111
+ },
112
+ "ability_id": {
113
+ "type": "string"
114
+ },
115
+ "item_id": {
116
+ "type": ["string", "null"]
117
+ },
118
+ "nature_id": {
119
+ "type": "string"
120
+ },
121
+ "hp": {
122
+ "type": "integer",
123
+ "minimum": 0,
124
+ "maximum": 10000000
125
+ },
126
+ "friendship": {
127
+ "type": "integer",
128
+ "minimum": 0,
129
+ "maximum": 255
130
+ },
131
+ "original_trainer": {
132
+ "type": ["string", "null"]
133
+ },
134
+ "ev": {
135
+ "$ref": "#/definitions/ev_stats"
136
+ },
137
+ "iv": {
138
+ "$ref": "#/definitions/iv_stats"
139
+ },
140
+ "primary_status_condition": {
141
+ "type": ["string", "null"],
142
+ "enum": [
143
+ "poison",
144
+ "bad_poison",
145
+ "paralysis",
146
+ "sleep",
147
+ "freeze",
148
+ "burn",
149
+ null
150
+ ]
151
+ },
152
+ "wild": {
153
+ "type": ["boolean", "null"]
154
+ },
155
+ "moves": {
156
+ "type": "array",
157
+ "minItems": 1,
158
+ "items": {
159
+ "type": "object",
160
+ "properties": {
161
+ "move_id": {
162
+ "type": "string"
163
+ },
164
+ "pp": {
165
+ "type": "integer",
166
+ "minimum": 0,
167
+ "maximum": 50
168
+ },
169
+ "max_pp": {
170
+ "type": "integer",
171
+ "minimum": 0,
172
+ "maximum": 50
173
+ }
174
+ },
175
+ "required": [
176
+ "move_id",
177
+ "pp",
178
+ "max_pp"
179
+ ],
180
+ "additionalProperties": false
181
+ }
182
+ },
183
+ "amie": {
184
+ "type": ["object", "null"],
185
+ "properties": {
186
+ "affection": {
187
+ "type": "integer",
188
+ "minimum": 0,
189
+ "maximum": 255
190
+ },
191
+ "fullness": {
192
+ "type": "integer",
193
+ "minimum": 0,
194
+ "maximum": 255
195
+ },
196
+ "enjoyment": {
197
+ "type": "integer",
198
+ "minimum": 0,
199
+ "maximum": 255
200
+ }
201
+ },
202
+ "additionalProperties": false
203
+ },
204
+ "growth_events": {
205
+ "type": "array",
206
+ "items": {
207
+ "type": "object",
208
+ "properties": {
209
+ "name": {
210
+ "type": "string"
211
+ },
212
+ "options": {
213
+ "type": "object"
214
+ }
215
+ },
216
+ "required": [
217
+ "name",
218
+ "options"
219
+ ],
220
+ "additionalProperties": false
221
+ }
222
+ }
223
+ },
224
+ "required": [
225
+ "species_id",
226
+ "exp",
227
+ "ability_id",
228
+ "gender",
229
+ "nature_id",
230
+ "hp",
231
+ "iv",
232
+ "ev",
233
+ "moves",
234
+ "friendship"
235
+ ],
236
+ "additionalProperties": false
237
+ }
@@ -31,7 +31,7 @@ module Oakdex
31
31
  def effect_usable?
32
32
  @item.effects.any? do |effect|
33
33
  condition_applies?(effect) && target_applies?(effect) &&
34
- pokemon_changes_apply?(effect)
34
+ pokemon_changes_apply?(effect) && move_changes_apply?(effect)
35
35
  end
36
36
  end
37
37
 
@@ -56,22 +56,51 @@ module Oakdex
56
56
  end
57
57
  end
58
58
 
59
+ def move_changes_apply?(effect)
60
+ move_changes = effect['move_changes'] || []
61
+ return true if move_changes.empty?
62
+ move_changes.any? do |change|
63
+ move_change_applies?(change)
64
+ end
65
+ end
66
+
59
67
  def pokemon_change_applies?(change)
60
68
  !pokemon_field_max?(change) &&
61
- (!@pokemon.fainted? || (@pokemon.fainted? && change['revive']))
69
+ (independent_fainted?(change) ||
70
+ !@pokemon.fainted? ||
71
+ (@pokemon.fainted? && change['revive']))
72
+ end
73
+
74
+ def move_change_applies?(change)
75
+ !move_field_max?(change)
76
+ end
77
+
78
+ def move_field_max?(change)
79
+ case change['field']
80
+ when 'max_pp' then @pokemon.moves.all?(&:max_pp_at_max?)
81
+ when 'pp' then @pokemon.moves.all?(&:pp_max?)
82
+ end
62
83
  end
63
84
 
64
85
  def pokemon_field_max?(change)
65
86
  case change['field']
66
87
  when 'current_hp' then @pokemon.current_hp >= @pokemon.hp
88
+ when 'level' then @pokemon.level >= 100
89
+ when /^ev_/ then @pokemon.ev_max?(change['field'].sub('ev_', '').to_sym)
67
90
  when 'status_condition' then !change['conditions']
68
91
  .include?(@pokemon.primary_status_condition)
69
92
  end
70
93
  end
71
94
 
95
+ def independent_fainted?(change)
96
+ %w[level max_pp].include?(change['field']) ||
97
+ change['field'].start_with?('ev_')
98
+ end
99
+
72
100
  def execute_effects
73
101
  @item.effects.each do |effect|
74
102
  execute_pokemon_changes(effect)
103
+ execute_move_changes(effect)
75
104
  end
76
105
  end
77
106
 
@@ -81,17 +110,91 @@ module Oakdex
81
110
  end
82
111
  end
83
112
 
113
+ def execute_move_changes(effect)
114
+ (effect['move_changes'] || []).each do |change|
115
+ execute_move_change(change, effect) if move_change_applies?(change)
116
+ end
117
+ end
118
+
84
119
  def execute_pokemon_change(change)
85
120
  case change['field']
86
121
  when 'current_hp' then execute_current_hp_change(change)
87
122
  when 'status_condition' then execute_remove_status_condition(change)
123
+ when 'level' then execute_level_up(change)
124
+ when /^ev_/ then execute_ev_change(change)
125
+ end
126
+ end
127
+
128
+ def execute_move_change(change, effect)
129
+ case change['field']
130
+ when 'max_pp' then execute_add_max_pp(change)
131
+ when 'pp' then execute_add_pp(change, effect)
88
132
  end
89
133
  end
90
134
 
135
+ def execute_level_up(_change)
136
+ @pokemon.increment_level
137
+ end
138
+
139
+ def execute_ev_change(change)
140
+ stat = change['field'].sub('ev_', '').to_sym
141
+ @pokemon.add_ev(stat, change['change_by'])
142
+ end
143
+
91
144
  def execute_remove_status_condition(_change)
92
145
  @pokemon.add_growth_event(GrowthEvents::RemoveStatusCondition)
93
146
  end
94
147
 
148
+ def execute_add_max_pp(change)
149
+ moves = @pokemon.moves.map do |move|
150
+ next if move.max_pp_at_max?
151
+ [move.name, change_for_move(move, change)]
152
+ end.compact.to_h
153
+ @pokemon.add_growth_event(GrowthEvents::IncreaseMaxPp, moves: moves)
154
+ end
155
+
156
+ def execute_add_pp(change, effect)
157
+ if effect['target'] == 'Single Pokemon > All Moves'
158
+ @pokemon.moves.each do |move|
159
+ next if move.pp_max?
160
+ @pokemon.add_growth_event(
161
+ GrowthEvents::IncreaseMovePp,
162
+ move_id: move.name,
163
+ change_by: pp_change_for_move(move, change)
164
+ )
165
+ end
166
+ else
167
+ moves = @pokemon.moves.map do |move|
168
+ next if move.pp_max?
169
+ [move.name, pp_change_for_move(move, change)]
170
+ end.compact.to_h
171
+ @pokemon.add_growth_event(GrowthEvents::IncreasePp, moves: moves)
172
+ end
173
+ end
174
+
175
+ def pp_change_for_move(move, change)
176
+ if change['change_by_percent']
177
+ (move.max_pp.to_f * (change['change_by_percent'].to_f / 100)).to_i
178
+ else
179
+ change['change_by']
180
+ end
181
+ end
182
+
183
+ def change_for_move(move, change)
184
+ increase_by = if change['change_by_percent']
185
+ (move.move_type.pp.to_f *
186
+ (change['change_by_percent'].to_f / 100)).to_i
187
+ else
188
+ change['change_by']
189
+ end
190
+
191
+ if change['change_by_max'] && increase_by > change['change_by_max']
192
+ change['change_by_max']
193
+ else
194
+ increase_by
195
+ end
196
+ end
197
+
95
198
  def execute_current_hp_change(change)
96
199
  change_by = change['change_by']
97
200
  if change['change_by_percent']
@@ -1,5 +1,5 @@
1
1
  module Oakdex
2
2
  class Pokemon
3
- VERSION = '0.0.6'
3
+ VERSION = '0.0.7'
4
4
  end
5
5
  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.6
4
+ version: 0.0.7
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-27 00:00:00.000000000 Z
11
+ date: 2019-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oakdex-pokedex
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.4.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: json-schema
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.5.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 2.5.2
27
41
  description: Pokémon Instance Representer, based on oakdex-pokedex
28
42
  email: jalyna.schroeder@gmail.com
29
43
  executables: []
@@ -43,13 +57,21 @@ files:
43
57
  - lib/oakdex/pokemon/growth_events/did_not_learn_move.rb
44
58
  - lib/oakdex/pokemon/growth_events/evolution.rb
45
59
  - lib/oakdex/pokemon/growth_events/forgot_and_learned_move.rb
60
+ - lib/oakdex/pokemon/growth_events/gained_ev.rb
46
61
  - lib/oakdex/pokemon/growth_events/gained_exp.rb
62
+ - lib/oakdex/pokemon/growth_events/increase_max_pp.rb
63
+ - lib/oakdex/pokemon/growth_events/increase_move_max_pp.rb
64
+ - lib/oakdex/pokemon/growth_events/increase_move_pp.rb
65
+ - lib/oakdex/pokemon/growth_events/increase_pp.rb
47
66
  - lib/oakdex/pokemon/growth_events/learn_move.rb
48
67
  - lib/oakdex/pokemon/growth_events/level_up.rb
49
68
  - lib/oakdex/pokemon/growth_events/remove_status_condition.rb
50
69
  - lib/oakdex/pokemon/growth_events/revive.rb
51
70
  - lib/oakdex/pokemon/growth_events/skipped_evolution.rb
71
+ - lib/oakdex/pokemon/import.rb
72
+ - lib/oakdex/pokemon/invalid_pokemon.rb
52
73
  - lib/oakdex/pokemon/move.rb
74
+ - lib/oakdex/pokemon/schema.json
53
75
  - lib/oakdex/pokemon/stat.rb
54
76
  - lib/oakdex/pokemon/use_item_service.rb
55
77
  - lib/oakdex/pokemon/version.rb