-
Notifications
You must be signed in to change notification settings - Fork 210
/
Copy pathwonder_trade.asm
589 lines (504 loc) · 11.2 KB
/
wonder_trade.asm
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
WonderTrade::
xor a
ldh [hScriptVar], a
ld hl, .Text_WonderTradeQuestion
call PrintText
call YesNoBox
ret c
ld hl, .Text_WonderTradePrompt
call PrintText
ld b, PARTYMENUACTION_GIVE_MON
farcall SelectTradeOrDayCareMon
ret c
ld a, MON_IS_EGG
call GetPartyParamLocation
bit MON_IS_EGG_F, [hl]
jr z, .not_egg
ld a, EGG
ld [wCurPartySpecies], a
.not_egg
ld hl, wPartyMonNicknames
ld bc, MON_NAME_LENGTH
call Trade_GetAttributeOfCurrentPartymon
ld de, wStringBuffer1
call CopyTradeName
ld hl, .Text_WonderTradeConfirm
call PrintText
call YesNoBox
ret c
ld hl, .Text_WonderTradeSetup
call PrintText
call DoWonderTrade
ld hl, .Text_WonderTradeReady
call PrintText
call DisableSpriteUpdates
predef TradeAnimation
jmp ReturnToMapWithSpeechTextbox
.Text_WonderTradeQuestion:
text_far WonderTradeQuestionText
text_end
.Text_WonderTradePrompt:
text_far WonderTradePromptText
text_end
;.Text_WonderTradeCantTradeEgg:
; text_far WonderTradeCantTradeEggText
; text_end
.Text_WonderTradeConfirm:
text_far WonderTradeConfirmText
text_end
.Text_WonderTradeSetup:
text_far WonderTradeSetupText
text_end
.Text_WonderTradeReady:
text_far WonderTradeReadyText
text_end
DoWonderTrade:
ld a, 1
ldh [hScriptVar], a
ld a, [wCurPartySpecies]
ld [wPlayerTrademonSpecies], a
; If you've beaten the Elite Four...
eventflagcheck EVENT_BEAT_ELITE_FOUR
jr z, .random_trademon
; ...and haven't gotten the GS Ball Pichu yet...
eventflagcheck EVENT_GOT_GS_BALL_FROM_POKECOM_CENTER
jr nz, .random_trademon
; ...then receive a spiky-eared Pichu holding a GS Ball
call GetGSBallPichu
jmp .compute_trademon_stats
.random_trademon
ld a, NUM_POKEMON
call RandomRange
inc a
ld [wOTTrademonSpecies], a
call CheckValidLevel
and a
jr nz, .random_trademon
ld a, [wPlayerTrademonSpecies]
ld b, a
ld a, [wOTTrademonSpecies]
cp b
jr z, .random_trademon
ld a, [wPlayerTrademonSpecies]
ld de, wPlayerTrademonSpeciesName
call GetTradeMonName
call CopyTradeName
ld a, [wOTTrademonSpecies]
ld de, wOTTrademonSpeciesName
call GetTradeMonName
call CopyTradeName
ld hl, wPartyMonOTs
ld bc, NAME_LENGTH
call Trade_GetAttributeOfCurrentPartymon
ld de, wPlayerTrademonOTName
call CopyTradeOT
ld hl, wPlayerName
ld de, wPlayerTrademonSenderName
call CopyTradeOT
ld hl, wPartyMon1ID
ld bc, PARTYMON_STRUCT_LENGTH
call Trade_GetAttributeOfCurrentPartymon
ld de, wPlayerTrademonID
call Trade_CopyTwoBytes
ld hl, wPartyMon1DVs
ld bc, PARTYMON_STRUCT_LENGTH
call Trade_GetAttributeOfCurrentPartymon
ld de, wPlayerTrademonDVs
call Trade_CopyThreeBytes
ld hl, wPartyMon1Personality
ld bc, PARTYMON_STRUCT_LENGTH
call Trade_GetAttributeOfCurrentPartymon
ld de, wPlayerTrademonPersonality
call Trade_CopyTwoBytes
ld hl, wPartyMon1Species
ld bc, PARTYMON_STRUCT_LENGTH
call Trade_GetAttributeOfCurrentPartymon
ld b, h
ld c, l
call GetCaughtGender
ld [wPlayerTrademonCaughtData], a
xor a
ld [wOTTrademonCaughtData], a
ld hl, wPartyMon1Level
ld bc, PARTYMON_STRUCT_LENGTH
call Trade_GetAttributeOfCurrentPartymon
ld a, [hl]
ld [wCurPartyLevel], a
ld a, [wOTTrademonSpecies]
ld [wCurPartySpecies], a
xor a
ld [wMonType], a
ld [wPokemonWithdrawDepositParameter], a
predef RemoveMonFromParty
call GetWonderTradeOTForm
ld [wCurForm], a
predef TryAddMonToParty
ld a, [wOTTrademonSpecies]
cp MAGIKARP
jr nz, .not_first_magikarp
ld a, [wFirstMagikarpSeen]
and a
jr nz, .not_first_magikarp
ld a, [wCurForm]
ld [wFirstMagikarpSeen], a
.not_first_magikarp
ld a, [wOTTrademonSpecies]
ld de, wOTTrademonNickname
call GetTradeMonName
call CopyTradeName
ld hl, wPartyMonNicknames
ld bc, MON_NAME_LENGTH
call Trade_GetAttributeOfLastPartymon
ld hl, wOTTrademonNickname
call CopyTradeName
call Random
ld [wBuffer1], a
call Random
ld [wBuffer1 + 1], a
ld hl, wBuffer1
ld de, wOTTrademonID
call Trade_CopyTwoBytes
ld hl, wPartyMon1ID
ld bc, PARTYMON_STRUCT_LENGTH
call Trade_GetAttributeOfLastPartymon
ld hl, wOTTrademonID
call Trade_CopyTwoBytes
call GetWonderTradeOTName
push hl
ld de, wOTTrademonOTName
call CopyTradeOT
pop hl
ld de, wOTTrademonSenderName
call CopyTradeOT
ld hl, wPartyMonOTs
ld bc, NAME_LENGTH
call Trade_GetAttributeOfLastPartymon
ld hl, wOTTrademonOTName
call CopyTradeOT
call GetWonderTradeOTGender
ld b, a
; Random Ball
; 2/3 chance of Poké Ball, 1/3 chance of other
.random_ball
ld a, PREMIER_BALL * 2 - 2
call RandomRange
cp PREMIER_BALL - 2
jr nc, .poke_ball
cp MASTER_BALL - 2
jr z, .random_ball
cp SAFARI_BALL - 2
jr z, .random_ball
inc a
inc a
jr .got_ball
.poke_ball
ld a, POKE_BALL
.got_ball
ld c, a
farcall SetGiftPartyMonCaughtData
; Random DVs
call Random
ld [wBuffer1], a
call Random
ld [wBuffer1 + 1], a
call Random
ld [wBuffer1 + 2], a
ld hl, wBuffer1
ld de, wOTTrademonDVs
call Trade_CopyThreeBytes
ld hl, wPartyMon1DVs
ld bc, PARTYMON_STRUCT_LENGTH
call Trade_GetAttributeOfLastPartymon
ld hl, wOTTrademonDVs
call Trade_CopyThreeBytes
; Random nature
ld a, NUM_NATURES
call RandomRange
ld b, a
; Random ability
ld a, 3
call RandomRange
inc a
rept 5
add a
endr
add b
ld b, a
; Random shininess (1 in 1,024)
call Random
and a
jr nz, .not_shiny
call Random
cp $40
jr nc, .not_shiny
ld a, b
or SHINY_MASK
ld b, a
.not_shiny
ld a, b
ld [wBuffer1], a
; Random gender (50-50)
call Random
and GENDER_MASK
ld b, a
; Egg for Egg
ld a, [wPlayerTrademonSpecies]
inc a ; cp EGG
jr nz, .not_egg
dec a ; ld a, EGG
ld [wOTTrademonSpecies], a
push bc
ld hl, wPartyMonNicknames
ld bc, MON_NAME_LENGTH
call Trade_GetAttributeOfLastPartymon
ld hl, .EggString
call CopyTradeName
pop bc
ld a, b
or IS_EGG_MASK
ld b, a
.not_egg
; Form
ld a, [wCurForm]
add b
ld [wBuffer1 + 1], a
ld hl, wBuffer1
ld de, wOTTrademonPersonality
call Trade_CopyTwoBytes
ld hl, wPartyMon1Personality
ld bc, PARTYMON_STRUCT_LENGTH
call Trade_GetAttributeOfLastPartymon
ld hl, wOTTrademonPersonality
call Trade_CopyTwoBytes
ld hl, wPartyMon1Item
ld bc, PARTYMON_STRUCT_LENGTH
call Trade_GetAttributeOfLastPartymon
call GetWonderTradeHeldItem
ld [de], a
.compute_trademon_stats
push hl
push de
push bc
push af
ld a, [wCurPartyMon]
push af
ld a, [wPartyCount]
dec a
ld [wCurPartyMon], a
farcall ComputeNPCTrademonStats
farcall GivePokerusToWonderTradeMon
pop af
ld [wCurPartyMon], a
jmp PopAFBCDEHL
.EggString:
rawchar "Egg@@@@@@@@"
GetGSBallPichu:
ld a, 2
ldh [hScriptVar], a
ld a, PICHU
ld [wOTTrademonSpecies], a
ld a, [wPlayerTrademonSpecies]
ld de, wPlayerTrademonSpeciesName
call GetTradeMonName
call CopyTradeName
ld a, [wOTTrademonSpecies]
ld de, wOTTrademonSpeciesName
call GetTradeMonName
call CopyTradeName
ld hl, wPartyMonOTs
ld bc, NAME_LENGTH
call Trade_GetAttributeOfCurrentPartymon
ld de, wPlayerTrademonOTName
call CopyTradeOT
ld hl, wPlayerName
ld de, wPlayerTrademonSenderName
call CopyTradeOT
ld hl, wPartyMon1ID
ld bc, PARTYMON_STRUCT_LENGTH
call Trade_GetAttributeOfCurrentPartymon
ld de, wPlayerTrademonID
call Trade_CopyTwoBytes
ld hl, wPartyMon1DVs
ld bc, PARTYMON_STRUCT_LENGTH
call Trade_GetAttributeOfCurrentPartymon
ld de, wPlayerTrademonDVs
call Trade_CopyThreeBytes
ld hl, wPartyMon1Personality
ld bc, PARTYMON_STRUCT_LENGTH
call Trade_GetAttributeOfCurrentPartymon
ld de, wPlayerTrademonPersonality
call Trade_CopyTwoBytes
ld hl, wPartyMon1Species
ld bc, PARTYMON_STRUCT_LENGTH
call Trade_GetAttributeOfCurrentPartymon
ld b, h
ld c, l
call GetCaughtGender
ld [wPlayerTrademonCaughtData], a
ld [wOTTrademonCaughtData], a
ld hl, wPartyMon1Level
ld bc, PARTYMON_STRUCT_LENGTH
call Trade_GetAttributeOfCurrentPartymon
ld a, 30
ld [wCurPartyLevel], a
ld a, [wOTTrademonSpecies]
ld [wCurPartySpecies], a
xor a
ld [wMonType], a
ld [wPokemonWithdrawDepositParameter], a
predef RemoveMonFromParty
predef TryAddMonToParty
ld b, MALE
ld a, [wPlayerGender]
and a
jr z, .male_ot_pikachu
ld b, FEMALE
.male_ot_pikachu
ld c, ULTRA_BALL
farcall SetGiftPartyMonCaughtData
ld a, [wOTTrademonSpecies]
ld de, wOTTrademonNickname
call GetTradeMonName
call CopyTradeName
ld hl, wPartyMonNicknames
ld bc, MON_NAME_LENGTH
call Trade_GetAttributeOfLastPartymon
ld hl, wOTTrademonNickname
call CopyTradeName
ld hl, wPlayerID
ld de, wOTTrademonID
call Trade_CopyTwoBytes
ld hl, wPartyMon1ID
ld bc, PARTYMON_STRUCT_LENGTH
call Trade_GetAttributeOfLastPartymon
ld hl, wOTTrademonID
call Trade_CopyTwoBytes
ld hl, wPlayerName
push hl
ld de, wOTTrademonOTName
call CopyTradeOT
pop hl
ld de, wOTTrademonSenderName
call CopyTradeOT
ld hl, wPartyMonOTs
ld bc, NAME_LENGTH
call Trade_GetAttributeOfLastPartymon
ld hl, wOTTrademonOTName
call CopyTradeOT
ld a, $ff
ld [wOTTrademonDVs], a
ld [wOTTrademonDVs + 1], a
ld [wOTTrademonDVs + 2], a
ld hl, wPartyMon1DVs
ld bc, PARTYMON_STRUCT_LENGTH
call Trade_GetAttributeOfLastPartymon
ld hl, wOTTrademonDVs
call Trade_CopyThreeBytes
ld a, HIDDEN_ABILITY | QUIRKY
ld [wOTTrademonPersonality], a
ld a, FEMALE | 2 ; spiky-eared variant
ld [wOTTrademonPersonality + 1], a
ld hl, wPartyMon1Personality
ld bc, PARTYMON_STRUCT_LENGTH
call Trade_GetAttributeOfLastPartymon
ld hl, wOTTrademonPersonality
call Trade_CopyTwoBytes
ld hl, wPartyMon1Item
ld bc, PARTYMON_STRUCT_LENGTH
call Trade_GetAttributeOfLastPartymon
xor a
ld [de], a
ret
GetWonderTradeOTName:
; pick from WonderTradeOTNames1 if [wOTTrademonID] is even,
; WonderTradeOTNames2 if odd, using [wOTTrademonID+1] as the index.
ld hl, wOTTrademonID
ld a, [hli]
and 1
ld a, [hl]
ld hl, WonderTradeOTNames1
jr z, .ok
ld hl, WonderTradeOTNames2
.ok
lb bc, 0, PLAYER_NAME_LENGTH
rst AddNTimes
ret
INCLUDE "data/events/wonder_trade/ot_names.asm"
GetWonderTradeOTGender:
; pick from .WonderTradeOTGenders1 if [wOTTrademonID] is even,
; WonderTradeOTGenders2 if odd, using [wOTTrademonID+1] as the index.
ld hl, wOTTrademonID
ld a, [hli]
and 1
ld a, [hl]
ld hl, WonderTradeOTGenders1
jr z, .ok
ld hl, WonderTradeOTGenders2
.ok
ld c, a
ld d, BANK(WonderTradeOTGenders1) ; aka BANK(WonderTradeOTGenders2)
ld b, CHECK_FLAG
predef FlagPredef
ld a, c
and a
ret z ; MALE
ld a, FEMALE
ret
INCLUDE "data/events/wonder_trade/ot_genders.asm"
GetWonderTradeOTForm:
; pick randomly from [1, N] for [wOTTrademonSpecies], or default to 1
ld a, [wOTTrademonSpecies]
ld hl, ValidVariantRanges
ld de, 2
call IsInArray
ld a, 1
jr nc, .ok
inc hl
ld a, [hl]
.ok
call RandomRange
inc a
ret
INCLUDE "data/pokemon/valid_variants.asm"
GetWonderTradeHeldItem:
; Returns a level-scaled item reward
ld a, [wOTTrademonSpecies]
inc a ; cp EGG
ret z
push de
ld hl, wPartyMon1Level
ld bc, PARTYMON_STRUCT_LENGTH
call Trade_GetAttributeOfLastPartymon
ld a, [de]
ld b, a
ld a, BANK(WonderTradeBaseItems)
ld hl, WonderTradeBaseItems
ld de, WonderTradeRareItems
farcall GetScaledItemReward
pop de
ret
INCLUDE "data/events/wonder_trade/held_items.asm"
CheckValidLevel:
; Don't receive Pokémon outside a valid level range.
; Legendaries and other banned Pokémon have a "valid" range of 255 to 255.
ld hl, wPartyMon1Level
ld bc, PARTYMON_STRUCT_LENGTH
call Trade_GetAttributeOfCurrentPartymon
ld a, [hl]
ld d, a
ld a, [wOTTrademonSpecies]
ld hl, ValidPokemonLevels
ld b, 0
ld c, a
add hl, bc
add hl, bc
ld a, [hli]
dec a
cp d
ret nc
ld a, [hl]
cp d
ret c
xor a
ret
INCLUDE "data/pokemon/valid_levels.asm"