1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
|
require 'active_record/diff'
class Revision < ApplicationRecord
include ActiveRecord::Diff
diff :species_id, :nickname, :level, :hp, :attack, :defense,
:special_attack, :special_defense, :speed, :coolness, :beauty, :cuteness,
:smartness, :toughness, :sheen, :item_id, :move_1_id, :move_2_id,
:move_3_id, :move_4_id, :move_1_pp_bonuses, :move_2_pp_bonuses,
:move_3_pp_bonuses, :move_4_pp_bonuses, :cool_ribbons, :beauty_ribbons,
:cute_ribbons, :smart_ribbons, :tough_ribbons, :champion_ribbon,
:winning_ribbon, :victory_ribbon, :artist_ribbon, :effort_ribbon,
:marine_ribbon, :land_ribbon, :sky_ribbon, :country_ribbon,
:national_ribbon, :earth_ribbon, :world_ribbon
belongs_to :pokemon
acts_as_sequenced scope: :pokemon_id
after_create :cache_pokemon_current
belongs_to :species
validates :nickname, presence: true
validates :experience, presence: true,
numericality: { greater_than_or_equal_to: 1, only_integer: true }
validates :level, presence: true,
numericality: { greater_than_or_equal_to: 1, only_integer: true }
validates :hp, presence: true,
numericality: { greater_than_or_equal_to: 1, only_integer: true }
validates :attack, presence: true,
numericality: { greater_than_or_equal_to: 1, only_integer: true }
validates :defense, presence: true,
numericality: { greater_than_or_equal_to: 1, only_integer: true }
validates :special_attack, presence: true,
numericality: { greater_than_or_equal_to: 1, only_integer: true }
validates :special_defense, presence: true,
numericality: { greater_than_or_equal_to: 1, only_integer: true }
validates :speed, presence: true,
numericality: { greater_than_or_equal_to: 1, only_integer: true }
validates :coolness, presence: true,
numericality: {
greater_than_or_equal_to: 0,
less_than_or_equal_to: 10,
only_integer: true }
validates :beauty, presence: true,
numericality: {
greater_than_or_equal_to: 0,
less_than_or_equal_to: 10,
only_integer: true }
validates :cuteness, presence: true,
numericality: {
greater_than_or_equal_to: 0,
less_than_or_equal_to: 10,
only_integer: true }
validates :smartness, presence: true,
numericality: {
greater_than_or_equal_to: 0,
less_than_or_equal_to: 10,
only_integer: true }
validates :toughness, presence: true,
numericality: {
greater_than_or_equal_to: 0,
less_than_or_equal_to: 10,
only_integer: true }
validates :sheen, presence: true,
numericality: {
greater_than_or_equal_to: 0,
less_than_or_equal_to: 10,
only_integer: true }
belongs_to :item, optional: true
belongs_to :move_1, class_name: "Move"
belongs_to :move_2, class_name: "Move", optional: true
belongs_to :move_3, class_name: "Move", optional: true
belongs_to :move_4, class_name: "Move", optional: true
validates :move_1_pp_bonuses, presence: true,
numericality: {
greater_than_or_equal_to: 0,
less_than_or_equal_to: 3,
only_integer: true}
validates :move_2_pp_bonuses, presence: true,
numericality: {
greater_than_or_equal_to: 0,
less_than_or_equal_to: 3,
only_integer: true}
validates :move_3_pp_bonuses, presence: true,
numericality: {
greater_than_or_equal_to: 0,
less_than_or_equal_to: 3,
only_integer: true}
validates :move_4_pp_bonuses, presence: true,
numericality: {
greater_than_or_equal_to: 0,
less_than_or_equal_to: 3,
only_integer: true}
validates :cool_ribbons, presence: true,
numericality: {
greater_than_or_equal_to: 0,
less_than_or_equal_to: 4,
only_integer: true}
validates :beauty_ribbons, presence: true,
numericality: {
greater_than_or_equal_to: 0,
less_than_or_equal_to: 4,
only_integer: true}
validates :cute_ribbons, presence: true,
numericality: {
greater_than_or_equal_to: 0,
less_than_or_equal_to: 4,
only_integer: true}
validates :smart_ribbons, presence: true,
numericality: {
greater_than_or_equal_to: 0,
less_than_or_equal_to: 4,
only_integer: true}
validates :tough_ribbons, presence: true,
numericality: {
greater_than_or_equal_to: 0,
less_than_or_equal_to: 4,
only_integer: true}
def icon_path
form = ""
if species_id == 201
# Handle Unown form
form = "-#{pokemon.unown_letter}"
elsif species_id == 386
# Handle Deoxys forms
if pokemon.trainer.firered?
form = "-attack"
elsif pokemon.trainer.leafgreen?
form = "-defense"
elsif pokemon.trainer.emerald?
form = "-speed"
end
end
"icons/#{species_id}#{form}.png"
end
def sprite_path
shininess = "normal"
if pokemon.shiny
shininess = "shiny"
end
game = "ruby-sapphire"
unless pokemon.trainer.nil?
if (pokemon.trainer.firered? or pokemon.trainer.leafgreen?) and (species_id <= 151 or species_id == 216 or species_id == 386)
game = "firered-leafgreen"
elsif pokemon.trainer.emerald?
game = "emerald"
end
end
form = ""
if species_id == 201
# Handle Unown forms
form = "-#{pokemon.unown_letter}"
elsif species_id == 386
# Handle Deoxys forms
if pokemon.trainer.firered?
form = "-attack"
elsif pokemon.trainer.leafgreen?
form = "-defense"
elsif pokemon.trainer.emerald?
form = "-speed"
end
end
if game == "emerald"
"sprites/emerald/#{shininess}/#{species_id}#{form}.gif"
else
"sprites/#{game}/#{shininess}/#{species_id}#{form}.png"
end
end
def ability
if pokemon.second_ability
species.ability_2
else
species.ability_1
end
end
def move_1_pp
move_1.pp * (5 + move_1_pp_bonuses) / 5
end
def move_2_pp
move_2.pp * (5 + move_2_pp_bonuses) / 5
end
def move_3_pp
move_3.pp * (5 + move_3_pp_bonuses) / 5
end
def move_4_pp
move_4.pp * (5 + move_4_pp_bonuses) / 5
end
def ribbons
result = []
if cool_ribbons >= 1
result << {
filename: "cool-ribbon.png",
name: "Cool Ribbon",
description: "Cool Contest Normal Rank Winner!"
}
end
if cool_ribbons >= 2
result << {
filename: "cool-ribbon-super.png",
name: "Cool Ribbon Super",
description: "Cool Contest Super Rank Winner!"
}
end
if cool_ribbons >= 3
result << {
filename: "cool-ribbon-hyper.png",
name: "Cool Ribbon Hyper",
description: "Cool Contest Hyper Rank Winner!"
}
end
if cool_ribbons == 4
result << {
filename: "cool-ribbon-master.png",
name: "Cool Ribbon Master",
description: "Cool Contest Master Rank Winner!"
}
end
if beauty_ribbons >= 1
result << {
filename: "beauty-ribbon.png",
name: "Beauty Ribbon",
description: "Beauty Contest Normal Rank Winner!"
}
end
if beauty_ribbons >= 2
result << {
filename: "beauty-ribbon-super.png",
name: "Beauty Ribbon Super",
description: "Beauty Contest Super Rank Winner!"
}
end
if beauty_ribbons >= 3
result << {
filename: "beauty-ribbon-hyper.png",
name: "Beauty Ribbon Hyper",
description: "Beauty Contest Hyper Rank Winner!"
}
end
if beauty_ribbons == 4
result << {
filename: "beauty-ribbon-master.png",
name: "Beauty Ribbon Master",
description: "Beauty Contest Master Rank Winner!"
}
end
if cute_ribbons >= 1
result << {
filename: "cute-ribbon.png",
name: "Cute Ribbon",
description: "Cute Contest Normal Rank Winner!"
}
end
if cute_ribbons >= 2
result << {
filename: "cute-ribbon-super.png",
name: "Cute Ribbon Super",
description: "Cute Contest Super Rank Winner!"
}
end
if cute_ribbons >= 3
result << {
filename: "cute-ribbon-hyper.png",
name: "Cute Ribbon Hyper",
description: "Cute Contest Hyper Rank Winner!"
}
end
if cute_ribbons == 4
result << {
filename: "cute-ribbon-master.png",
name: "Cute Ribbon Master",
description: "Cute Contest Master Rank Winner!"
}
end
if smart_ribbons >= 1
result << {
filename: "smart-ribbon.png",
name: "Smart Ribbon",
description: "Smart Contest Normal Rank Winner!"
}
end
if smart_ribbons >= 2
result << {
filename: "smart-ribbon-super.png",
name: "Smart Ribbon Super",
description: "Smart Contest Super Rank Winner!"
}
end
if smart_ribbons >= 3
result << {
filename: "smart-ribbon-hyper.png",
name: "Smart Ribbon Hyper",
description: "Smart Contest Hyper Rank Winner!"
}
end
if smart_ribbons == 4
result << {
filename: "smart-ribbon-master.png",
name: "Smart Ribbon Master",
description: "Smart Contest Master Rank Winner!"
}
end
if tough_ribbons >= 1
result << {
filename: "tough-ribbon.png",
name: "Tough Ribbon",
description: "Tough Contest Normal Rank Winner!"
}
end
if tough_ribbons >= 2
result << {
filename: "tough-ribbon-super.png",
name: "Tough Ribbon Super",
description: "Tough Contest Super Rank Winner!"
}
end
if tough_ribbons >= 3
result << {
filename: "tough-ribbon-hyper.png",
name: "Tough Ribbon Hyper",
description: "Tough Contest Hyper Rank Winner!"
}
end
if tough_ribbons == 4
result << {
filename: "tough-ribbon-master.png",
name: "Tough Ribbon Master",
description: "Tough Contest Master Rank Winner!"
}
end
if champion_ribbon
result << {
filename: "champion-ribbon.png",
name: "Champion Ribbon",
description: "Champion-beating, Hall of Fame Member Ribbon"
}
end
if winning_ribbon
result << {
filename: "winning-ribbon.png",
name: "Winning Ribbon",
description: "Ribbon for clearing LV50 at the Battle Tower."
}
end
if victory_ribbon
result << {
filename: "victory-ribbon.png",
name: "Victory Ribbon",
description: "Won for clearing LV100 at the Battle Tower."
}
end
if artist_ribbon
result << {
filename: "artist-ribbon.png",
name: "Artist Ribbon",
description: "Ribbon for being chosen as a super sketch model."
}
end
if effort_ribbon
result << {
filename: "effort-ribbon.png",
name: "Effort Ribbon",
description: "Ribbon awarded for being a hard worker."
}
end
if marine_ribbon
result << {
filename: "marine-ribbon.png",
name: "Marine Ribbon",
description: pokemon.gift_ribbon_description(:marine_ribbon)
}
end
if land_ribbon
result << {
filename: "land-ribbon.png",
name: "Land Ribbon",
description: pokemon.gift_ribbon_description(:land_ribbon)
}
end
if sky_ribbon
result << {
filename: "sky-ribbon.png",
name: "Sky Ribbon",
description: pokemon.gift_ribbon_description(:sky_ribbon)
}
end
if country_ribbon
result << {
filename: "country-ribbon.png",
name: "Country Ribbon",
description: pokemon.gift_ribbon_description(:country_ribbon)
}
end
if national_ribbon
result << {
filename: "national-ribbon.png",
name: "National Ribbon",
description: pokemon.gift_ribbon_description(:national_ribbon)
}
end
if earth_ribbon
result << {
filename: "earth-ribbon.png",
name: "Earth Ribbon",
description: pokemon.gift_ribbon_description(:earth_ribbon)
}
end
if world_ribbon
result << {
filename: "world-ribbon.png",
name: "World Ribbon",
description: pokemon.gift_ribbon_description(:world_ribbon)
}
end
result
end
private
def cache_pokemon_current
self.pokemon.current_id = self.id
self.pokemon.save!
end
end
|