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
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
|
/*
* Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Header include
#include "ItemEffect.h"
// Pokemod includes
#include "Item.h"
#include "MapWildList.h"
#include "Pokemod.h"
const QStringList ItemEffect::EffectStr = QStringList() << "HP Cure" << "Revive" << "Cure Status" << "Level Boost" << "Stat Boost" << "Flinch" << "Go First" << "Keep Alive" << "Modify Stat (Battle Only)" << "Shield (Battle Only)" << "Run (Battle Only)" << "PP Boost" << "Type Boost" << "PP Restore" << "Experience Share" << "Fishing Rod" << "Repel" << "Escape" << "TM" << "HM" << "Map" << "Ball" << "Itemfinder" << "Bike" << "Scope" << "Coin" << "Coin Case" << "Berry" << "Acorn";
const QStringList ItemEffect::RelativeStr = QStringList() << "Absolute" << "Relative";
const QStringList ItemEffect::EscapeStr = QStringList() << "Anywhere" << "Dungeon";
const QStringList ItemEffect::RepelStr = QStringList() << "First" << "Max" << "All";
const QStringList ItemEffect::AmountStr = QStringList() << "All" << "One";
const QStringList ItemEffect::SpecialPhysicalStr = QStringList() << "Special" << "Physical";
const QStringList ItemEffect::BallTypeStr = QStringList() << "Regular" << "Master" << "Level" << "Love" << "Area" << "Time" << "Battle" << "Friend" << "Stat" << "Type" << "Weight";
const QStringList ItemEffect::BerryTypeStr = QStringList() << "HP Cure" << "Status Cure";
ItemEffect::ItemEffect(const ItemEffect& effect) :
Object("ItemEffect", effect.parent(), effect.id())
{
*this = effect;
}
ItemEffect::ItemEffect(const Item* parent, const int id) :
Object("ItemEffect", parent, id),
m_overworld(false),
m_battle(false),
m_held(false),
m_effect(INT_MAX),
m_value1(INT_MAX),
m_value2(INT_MAX),
m_value3(INT_MAX),
m_value4(1, 1)
{
}
ItemEffect::ItemEffect(const ItemEffect& effect, const Item* parent, const int id) :
Object("ItemEffect", parent, id)
{
*this = effect;
}
ItemEffect::ItemEffect(const QDomElement& xml, const Item* parent, const int id) :
Object("ItemEffect", parent, id)
{
load(xml, id);
}
void ItemEffect::validate()
{
TEST(setOverworld, overworld);
TEST(setEffect, effect);
TEST(setValue1, value1);
TEST(setValue2, value2);
TEST(setValue3, value3);
TEST(setValue4, value4);
}
void ItemEffect::load(const QDomElement& xml, int id)
{
LOAD_ID();
LOAD(bool, overworld);
LOAD(bool, battle);
LOAD(bool, held);
LOAD(int, effect);
LOAD(int, value1);
LOAD(int, value2);
LOAD(int, value3);
LOAD(Fraction, value4);
}
QDomElement ItemEffect::save() const
{
SAVE_CREATE();
SAVE(bool, overworld);
SAVE(bool, battle);
SAVE(bool, held);
SAVE(int, effect);
SAVE(int, value1);
SAVE(int, value2);
SAVE(int, value3);
SAVE(Fraction, value4);
return xml;
}
void ItemEffect::setOverworld(const bool overworld)
{
switch (m_effect)
{
case E_Revive:
case E_LevelBoost:
case E_StatBoost:
case E_PPBoost:
case E_Fish:
case E_Repel:
case E_Escape:
case E_TM:
case E_HM:
case E_Map:
case E_Itemfinder:
case E_Bike:
case E_Scope:
case E_Coin:
case E_CoinCase:
case E_Acorn:
case E_Evolution:
if (!overworld)
{
emit(error("Overworld mismatch"));
return;
}
break;
case E_Flinch:
case E_First:
case E_KeepAlive:
case E_ModifyStatBattle:
case E_ShieldBattle:
case E_RunBattle:
case E_TypeBoost:
case E_ExpShare:
case E_Ball:
case E_Berry:
if (overworld)
{
emit(error("Overworld mismatch"));
return;
}
break;
}
m_overworld = overworld;
emit(changed());
}
void ItemEffect::setBattle(const bool battle)
{
m_battle = battle;
emit(changed());
}
void ItemEffect::setHeld(const bool held)
{
m_held = held;
emit(changed());
}
void ItemEffect::setEffect(const int effect)
{
if (E_End <= effect)
{
emit(error(bounds("effect")));
return;
}
switch (effect)
{
case E_Revive:
case E_LevelBoost:
case E_StatBoost:
case E_PPBoost:
case E_Fish:
case E_Repel:
case E_Escape:
case E_TM:
case E_HM:
case E_Map:
case E_Itemfinder:
case E_Bike:
case E_Scope:
case E_Coin:
case E_CoinCase:
case E_Acorn:
case E_Evolution:
m_overworld = true;
break;
case E_Flinch:
case E_First:
case E_KeepAlive:
case E_ModifyStatBattle:
case E_ShieldBattle:
case E_RunBattle:
case E_TypeBoost:
case E_ExpShare:
case E_Ball:
case E_Berry:
m_overworld = false;
break;
}
m_effect = effect;
m_value1 = 0;
m_value2 = INT_MAX;
m_value3 = INT_MAX;
m_value4.set(1, 1);
emit(changed());
}
void ItemEffect::setValue1(const int value1)
{
switch (m_effect)
{
case E_HPCure:
case E_Revive:
if ((m_value4 != R_Absolute) || !value1)
{
emit(error(bounds("value1")));
return;
}
break;
case E_LevelBoost:
case E_ShieldBattle:
case E_PPBoost:
case E_Repel:
if (!value1)
{
emit(error(bounds("value1")));
return;
}
break;
case E_StatBoost:
case E_Acorn:
if ((value1 < 0) || (65536 <= value1))
{
emit(error(bounds("value1")));
return;
}
break;
case E_ModifyStatBattle:
if ((value1 < -12) || (12 < value1))
{
emit(error(bounds("value1")));
return;
}
break;
case E_Fish:
case E_Coin:
case E_CoinCase:
break;
case E_Ball:
switch (m_value2)
{
case B_Regular:
if (256 <= value1)
{
emit(error(bounds("value1")));
return;
}
break;
case B_Level:
if (static_cast<const Pokemod*>(pokemod())->rules()->maxLevel() < value1)
{
emit(error(bounds("value1")));
return;
}
break;
case B_Master:
case B_Love:
case B_Area:
case B_Time:
case B_Battle:
case B_Friend:
case B_Stat:
case B_Type:
case B_Weight:
break;
default:
emit(error(bounds("value1")));
return;
}
break;
default:
emit(warning(unused("value1")));
return;
}
m_value1 = value1;
emit(changed());
}
void ItemEffect::setValue2(const int value2)
{
switch (m_effect)
{
case E_HPCure:
case E_Revive:
if (R_End <= value2)
{
emit(error(bounds("value2")));
return;
}
break;
case E_CureStatus:
if (Pokemod::STS_End <= value2)
{
emit(error(bounds("value2")));
return;
}
break;
case E_StatBoost:
if ((value2 <= 0) || (65536 <= value2))
{
emit(error(bounds("value2")));
return;
}
break;
case E_ModifyStatBattle:
if (Pokemod::ST_End_Battle <= value2)
{
emit(error(bounds("value2")));
return;
}
break;
case E_ShieldBattle:
if (SP_End <= value2)
{
emit(error(bounds("value2")));
return;
}
break;
case E_TypeBoost:
if (static_cast<const Pokemod*>(pokemod())->typeIndex(value2) == INT_MAX)
{
emit(error(bounds("value2")));
return;
}
break;
case E_PPRestore:
if (A_End <= value2)
{
emit(error(bounds("value2")));
return;
}
break;
case E_Repel:
if (RP_End <= value2)
{
emit(error(bounds("value2")));
return;
}
break;
case E_Escape:
if (ES_End <= value2)
{
emit(error(bounds("value2")));
return;
}
break;
case E_TM:
case E_HM:
if (static_cast<const Pokemod*>(pokemod())->moveIndex(value2) == INT_MAX)
{
emit(error(bounds("value2")));
return;
}
break;
case E_Ball:
if (B_End <= value2)
{
emit(error(bounds("value2")));
return;
}
break;
case E_Scope:
break;
case E_Berry:
if (B2_End <= value2)
{
emit(error(bounds("value2")));
return;
}
break;
case E_Coin:
case E_CoinCase:
if (value2 <= 0)
{
emit(error(bounds("value2")));
return;
}
break;
case E_Acorn:
if (static_cast<const Pokemod*>(pokemod())->itemIndex(value2) == INT_MAX)
{
emit(error(bounds("value2")));
return;
}
break;
default:
emit(warning(unused("value2")));
return;
}
m_value2 = value2;
emit(changed());
}
void ItemEffect::setValue3(const int value3)
{
switch (m_effect)
{
case E_StatBoost:
if ((static_cast<const Pokemod*>(pokemod())->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= value3)
{
emit(error(bounds("value3")));
return;
}
break;
case E_Ball:
switch (m_value2)
{
case B_Level:
case B_Friend:
case B_Weight:
break;
case B_Area:
if (MapWildList::End <= value3)
{
emit(error(bounds("value3")));
return;
}
break;
case B_Time:
if (static_cast<const Pokemod*>(pokemod())->timeIndex(value3) == INT_MAX)
{
emit(error(bounds("value3")));
return;
}
break;
case B_Stat:
if ((static_cast<const Pokemod*>(pokemod())->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= value3)
{
emit(error(bounds("value3")));
return;
}
break;
case B_Type:
if (static_cast<const Pokemod*>(pokemod())->typeIndex(value3) == INT_MAX)
{
emit(error(bounds("value3")));
return;
}
break;
case B_Regular:
case B_Master:
case B_Love:
case B_Battle:
emit(warning(unused("value3")));
return;
}
break;
case E_Berry:
switch (m_value2)
{
case B2_HPCure:
if (Pokemod::REL_End <= value3)
{
emit(error(bounds("value3")));
return;
}
break;
case B2_StatusCure:
if (Pokemod::STS_End <= value3)
{
emit(error(bounds("value3")));
return;
}
break;
default:
emit(warning(unused("value3")));
return;
}
break;
default:
emit(warning(unused("value3")));
return;
}
m_value3 = value3;
emit(changed());
}
void ItemEffect::setValue4(const Fraction& value4)
{
if ((E_TypeBoost == m_effect) || (E_PPBoost == m_effect))
{
if (value4 < 1)
{
emit(error(bounds("value4")));
return;
}
}
else if (1 < value4)
{
emit(error(bounds("value4")));
return;
}
switch (m_effect)
{
case E_CureStatus:
case E_LevelBoost:
case E_StatBoost:
case E_ModifyStatBattle:
case E_Fish:
case E_Escape:
case E_TM:
case E_HM:
case E_Map:
case E_Itemfinder:
case E_Bike:
case E_Scope:
case E_Coin:
case E_CoinCase:
case E_Acorn:
case E_Evolution:
{
emit(warning(unused("value4")));
return;
}
case E_Ball:
if (m_value2 == B_Master)
{
emit(warning(unused("value4")));
return;
}
break;
case E_Berry:
if (m_value2 != B2_HPCure)
{
emit(warning(unused("value4")));
return;
}
break;
}
m_value4 = value4;
emit(changed());
}
bool ItemEffect::overworld() const
{
return m_overworld;
}
bool ItemEffect::battle() const
{
return m_battle;
}
bool ItemEffect::held() const
{
return m_held;
}
int ItemEffect::effect() const
{
return m_effect;
}
int ItemEffect::value1() const
{
return m_value1;
}
int ItemEffect::value2() const
{
return m_value2;
}
int ItemEffect::value3() const
{
return m_value3;
}
Fraction ItemEffect::value4() const
{
return m_value4;
}
ItemEffect& ItemEffect::operator=(const ItemEffect& rhs)
{
if (this == &rhs)
return *this;
COPY(overworld);
COPY(battle);
COPY(held);
COPY(effect);
COPY(value1);
COPY(value2);
COPY(value3);
COPY(value4);
return *this;
}
|