-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy patheffect_functions.asm
11191 lines (9960 loc) · 229 KB
/
effect_functions.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
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Poison50PercentEffect:
ldtx de, PoisonCheckText
call TossCoin_BankB
ret nc
PoisonEffect:
lb bc, CNF_SLP_PRZ, POISONED
jr QueueStatusCondition
DoublePoisonEffect:
lb bc, CNF_SLP_PRZ, DOUBLE_POISONED
jr QueueStatusCondition
Paralysis50PercentEffect:
ldtx de, ParalysisCheckText
call TossCoin_BankB
ret nc
ParalysisEffect:
lb bc, PSN_DBLPSN, PARALYZED
jr QueueStatusCondition
Confusion50PercentEffect:
ldtx de, ConfusionCheckText
call TossCoin_BankB
ret nc
ConfusionEffect:
lb bc, PSN_DBLPSN, CONFUSED
jr QueueStatusCondition
Sleep50PercentEffect:
ldtx de, SleepCheckText
call TossCoin_BankB
ret nc
SleepEffect:
lb bc, PSN_DBLPSN, ASLEEP
jr QueueStatusCondition
QueueStatusCondition:
ldh a, [hWhoseTurn]
ld hl, wWhoseTurn
cp [hl]
jr nz, .can_induce_status
ld a, [wTempNonTurnDuelistCardID]
cp CLEFAIRY_DOLL
jr z, .cant_induce_status
cp MYSTERIOUS_FOSSIL
jr z, .cant_induce_status
; Snorlax's Thick Skinned prevents it from being statused...
cp SNORLAX
jr nz, .can_induce_status
call SwapTurn
xor a ; PLAY_AREA_ARENA
; ...unless already so, or if affected by Muk's Toxic Gas
call CheckIsIncapableOfUsingPkmnPower
call SwapTurn
jr c, .can_induce_status
.cant_induce_status
ld a, c
ld [wNoEffectFromWhichStatus], a
call SetNoEffectFromStatus
or a
ret
.can_induce_status
ld hl, wStatusConditionQueueIndex
push hl
ld e, [hl]
ld d, $0
ld hl, wStatusConditionQueue
add hl, de
call SwapTurn
ldh a, [hWhoseTurn]
ld [hli], a
call SwapTurn
ld [hl], b ; mask of status conditions not to discard on the target
inc hl
ld [hl], c ; status condition to inflict to the target
pop hl
; advance wStatusConditionQueueIndex
inc [hl]
inc [hl]
inc [hl]
scf
ret
TossCoin_BankB:
call TossCoin
ret
TossCoinATimes_BankB:
call TossCoinATimes
ret
CommentedOut_2c086:
ret
Serial_TossZeroCoins:
xor a
jr Serial_TossCoinATimes
Serial_TossCoin:
ld a, $1
Serial_TossCoinATimes:
push de
push af
ld a, OPPACTION_TOSS_COIN_A_TIMES
call SetOppAction_SerialSendDuelData
pop af
pop de
call SerialSend8Bytes
call TossCoinATimes
ret
SetNoEffectFromStatus:
ld a, EFFECT_FAILED_NO_EFFECT
ld [wEffectFailed], a
ret
SetWasUnsuccessful:
ld a, EFFECT_FAILED_UNSUCCESSFUL
ld [wEffectFailed], a
ret
Func_2c0a8:
ldh a, [hTemp_ffa0]
push af
ldh a, [hWhoseTurn]
ldh [hTemp_ffa0], a
ld a, OPPACTION_6B30
call SetOppAction_SerialSendDuelData
bank1call PlayDeckShuffleAnimation
ld c, a
pop af
ldh [hTemp_ffa0], a
ld a, c
ret
ShuffleCardsInDeck:
call ExchangeRNG
bank1call PlayDeckShuffleAnimation
call ShuffleDeck
ret
; return carry if Player is the Turn Duelist
IsPlayerTurn:
ld a, DUELVARS_DUELIST_TYPE
call GetTurnDuelistVariable
cp DUELIST_TYPE_PLAYER
jr z, .player
or a
ret
.player
scf
ret
; Stores information about the attack damage for AI purposes
; taking into account poison damage between turns.
; if target poisoned
; [wAIMinDamage] <- [wDamage]
; [wAIMaxDamage] <- [wDamage]
; else
; [wAIMinDamage] <- [wDamage] + d
; [wAIMaxDamage] <- [wDamage] + e
; [wDamage] <- [wDamage] + a
UpdateExpectedAIDamage_AccountForPoison:
push af
ld a, DUELVARS_ARENA_CARD_STATUS
call GetNonTurnDuelistVariable
and POISONED | DOUBLE_POISONED
jr z, UpdateExpectedAIDamage.skip_push_af
pop af
ld a, [wDamage]
ld [wAIMinDamage], a
ld [wAIMaxDamage], a
ret
; Sets some variables for AI use
; [wAIMinDamage] <- [wDamage] + d
; [wAIMaxDamage] <- [wDamage] + e
; [wDamage] <- [wDamage] + a
UpdateExpectedAIDamage:
push af
.skip_push_af
ld hl, wDamage
ld a, [hl]
add d
ld [wAIMinDamage], a
ld a, [hl]
add e
ld [wAIMaxDamage], a
pop af
add [hl]
ld [hl], a
ret
; Stores information about the attack damage for AI purposes
; [wDamage] <- a (average amount of damage)
; [wAIMinDamage] <- d (minimum)
; [wAIMaxDamage] <- e (maximum)
SetExpectedAIDamage:
ld [wDamage], a
xor a
ld [wDamage + 1], a
ld a, d
ld [wAIMinDamage], a
ld a, e
ld [wAIMaxDamage], a
ret
DrawPlayAreaScreenToShowChanges:
ldh [hTempPlayAreaLocation_ff9d], a
bank1call SetupPlayAreaScreen
bank1call PrintPlayAreaCardList_EnableLCD
bank1call InitAndPrintPlayAreaCardInformationAndLocation_WithTextBox
ret
; deal damage to all the turn holder's benched Pokemon
; input: a = amount of damage to deal to each Pokemon
DealDamageToAllBenchedPokemon:
ld e, a
ld d, $00
ld a, DUELVARS_NUMBER_OF_POKEMON_IN_PLAY_AREA
call GetTurnDuelistVariable
ld c, a
ld b, PLAY_AREA_ARENA
jr .skip_to_bench
.loop
push bc
call DealDamageToPlayAreaPokemon_RegularAnim
pop bc
.skip_to_bench
inc b
dec c
jr nz, .loop
ret
PlayAttackAnimationOverAttackingPokemon:
ld [wLoadedAttackAnimation], a
ldh a, [hTempPlayAreaLocation_ff9d]
ld b, a
ld c, $0 ; neither WEAKNESS nor RESISTANCE
ldh a, [hWhoseTurn]
ld h, a
bank1call PlayAttackAnimation
bank1call WaitAttackAnimation
ret
; apply a status condition of type 1 identified by register a to the target
ApplySubstatus1ToDefendingCard:
push af
ld a, DUELVARS_ARENA_CARD_SUBSTATUS1
call GetTurnDuelistVariable
pop af
ld [hli], a
ret
; apply a status condition of type 2 identified by register a to the target,
; unless prevented by wNoDamageOrEffect
ApplySubstatus2ToDefendingCard:
push af
call CheckNoDamageOrEffect
jr c, .no_damage_orEffect
ld a, DUELVARS_ARENA_CARD_SUBSTATUS2
call GetNonTurnDuelistVariable
pop af
ld [hl], a
ld l, DUELVARS_ARENA_CARD_LAST_TURN_SUBSTATUS2
ld [hl], a
ret
.no_damage_orEffect
pop af
push hl
bank1call DrawDuelMainScene
pop hl
ld a, l
or h
call nz, DrawWideTextBox_PrintText
ret
; overwrites in wDamage, wAIMinDamage and wAIMaxDamage
; with the value in a.
SetDefiniteDamage:
ld [wDamage], a
ld [wAIMinDamage], a
ld [wAIMaxDamage], a
xor a
ld [wDamage + 1], a
ret
; overwrites wAIMinDamage and wAIMaxDamage
; with value in wDamage.
SetDefiniteAIDamage:
ld a, [wDamage]
ld [wAIMinDamage], a
ld [wAIMaxDamage], a
ret
; returns in a some random occupied Play Area location
; in Turn Duelist's Play Area.
PickRandomPlayAreaCard:
ld a, DUELVARS_NUMBER_OF_POKEMON_IN_PLAY_AREA
call GetTurnDuelistVariable
call Random
or a
ret
; outputs in hl the next position
; in hTempList to place a new card,
; and increments hCurSelectionItem.
GetNextPositionInTempList:
push de
ld hl, hCurSelectionItem
ld a, [hl]
inc [hl]
ld e, a
ld d, $00
ld hl, hTempList
add hl, de
pop de
ret
; creates in wDuelTempList list of attached Fire Energy cards
; that are attached to the Turn Duelist's Arena card.
CreateListOfFireEnergyAttachedToArena:
ld a, TYPE_ENERGY_FIRE
; fallthrough
; creates in wDuelTempList a list of cards that
; are in the Arena of the same type as input a.
; this is called to list Energy cards of a specific type
; that are attached to the Arena Pokemon.
; input:
; a = TYPE_ENERGY_* constant
; output:
; a = number of cards in list;
; wDuelTempList filled with cards, terminated by $ff
CreateListOfEnergyAttachedToArena:
ld b, a
ld c, 0
ld de, wDuelTempList
ld a, DUELVARS_CARD_LOCATIONS
call GetTurnDuelistVariable
.loop
ld a, [hl]
cp CARD_LOCATION_ARENA
jr nz, .next
push de
ld a, l
call GetCardIDFromDeckIndex
call GetCardType
pop de
cp b
jr nz, .next ; is same as input type?
ld a, l
ld [de], a
inc de
inc c
.next
inc l
ld a, l
cp DECK_SIZE
jr c, .loop
ld a, $ff
ld [de], a
ld a, c
ret
; prints the text "<X> devolved to <Y>!" with
; the proper card names and levels.
; input:
; d = deck index of the lower stage card
; e = deck index of card that was devolved
PrintDevolvedCardNameAndLevelText:
push de
ld a, e
call LoadCardDataToBuffer1_FromDeckIndex
ld bc, wTxRam2
ld hl, wLoadedCard1Name
ld a, [hli]
ld [bc], a
inc bc
ld a, [hl]
ld [bc], a
inc bc ; wTxRam2_b
xor a
ld [bc], a
inc bc
ld [bc], a
ld a, d
call LoadCardDataToBuffer1_FromDeckIndex
ld a, 18
call CopyCardNameAndLevel
ld [hl], $00
ldtx hl, PokemonDevolvedToText
call DrawWideTextBox_WaitForInput
pop de
ret
HandleSwitchDefendingPokemonEffect:
ld e, a
cp $ff
ret z
; check Defending Pokemon's HP
ld a, DUELVARS_ARENA_CARD_HP
call GetNonTurnDuelistVariable
or a
jr nz, .switch
; if 0, handle Destiny Bond first
push de
bank1call HandleDestinyBondSubstatus
pop de
.switch
call HandleNoDamageOrEffect
ret c
; attack was successful, switch Defending Pokemon
call SwapTurn
call SwapArenaWithBenchPokemon
call SwapTurn
xor a
ld [wccc5], a
ld [wDuelDisplayedScreen], a
inc a
ld [wDefendingWasForcedToSwitch], a
ret
; returns carry if Defending has No Damage or Effect
; if so, print its appropriate text.
HandleNoDamageOrEffect:
call CheckNoDamageOrEffect
ret nc
ld a, l
or h
call nz, DrawWideTextBox_PrintText
scf
ret
; applies HP recovery on Pokemon after an attack
; with HP recovery effect, and handles its animation.
; input:
; d = damage effectiveness
; e = HP amount to recover
ApplyAndAnimateHPRecovery:
push de
ld hl, wccbd
ld [hl], e
inc hl
ld [hl], d
; get Arena card's damage
ld e, PLAY_AREA_ARENA
call GetCardDamageAndMaxHP
pop de
or a
ret z ; return if no damage
; load correct animation
push de
ld a, ATK_ANIM_HEAL
ld [wLoadedAttackAnimation], a
lb bc, PLAY_AREA_ARENA, $1 ; arrow
bank1call PlayAttackAnimation
; compare HP to be restored with max HP
; if HP to be restored would cause HP to
; be larger than max HP, cap it accordingly
ld e, PLAY_AREA_ARENA
call GetCardDamageAndMaxHP
ld b, $00
pop de
ld a, DUELVARS_ARENA_CARD_HP
call GetTurnDuelistVariable
add e
ld e, a
ld a, 0
adc d
ld d, a
; de = damage dealt + current HP
; bc = max HP of card
call CompareDEtoBC
jr c, .skip_cap
; cap de to value in bc
ld e, c
ld d, b
.skip_cap
ld [hl], e ; apply new HP to arena card
bank1call WaitAttackAnimation
ret
; returns carry if Play Area has no damage counters.
CheckIfPlayAreaHasAnyDamage:
ld a, DUELVARS_NUMBER_OF_POKEMON_IN_PLAY_AREA
call GetTurnDuelistVariable
ld d, a
ld e, PLAY_AREA_ARENA
.loop_play_area
call GetCardDamageAndMaxHP
or a
ret nz ; found damage
inc e
dec d
jr nz, .loop_play_area
; no damage found
scf
ret
; makes a list in wDuelTempList with the deck indices
; of Trainer cards found in Turn Duelist's Discard Pile.
; returns carry set if no Trainer cards found, and loads
; corresponding text to notify this.
CreateTrainerCardListFromDiscardPile:
; get number of cards in Discard Pile
; and have hl point to the end of the
; Discard Pile list in wOpponentDeckCards.
ld a, DUELVARS_NUMBER_OF_CARDS_IN_DISCARD_PILE
call GetTurnDuelistVariable
ld b, a
add DUELVARS_DECK_CARDS
ld l, a
ld de, wDuelTempList
inc b
jr .next_card
.check_trainer
ld a, [hl]
call LoadCardDataToBuffer2_FromDeckIndex
ld a, [wLoadedCard2Type]
cp TYPE_TRAINER
jr nz, .next_card
ld a, [hl]
ld [de], a
inc de
.next_card
dec l
dec b
jr nz, .check_trainer
ld a, $ff ; terminating byte
ld [de], a
ld a, [wDuelTempList]
cp $ff
jr z, .no_trainers
or a
ret
.no_trainers
ldtx hl, ThereAreNoTrainerCardsInDiscardPileText
scf
ret
; makes a list in wDuelTempList with the deck indices
; of all basic energy cards found in Turn Duelist's Discard Pile.
CreateEnergyCardListFromDiscardPile_OnlyBasic:
ld c, $01
jr CreateEnergyCardListFromDiscardPile
; makes a list in wDuelTempList with the deck indices
; of all energy cards (including Double Colorless)
; found in Turn Duelist's Discard Pile.
CreateEnergyCardListFromDiscardPile_AllEnergy:
ld c, $00
; fallthrough
; makes a list in wDuelTempList with the deck indices
; of energy cards found in Turn Duelist's Discard Pile.
; if (c == 0), all energy cards are allowed;
; if (c != 0), double colorless energy cards are not included.
; returns carry if no energy cards were found.
CreateEnergyCardListFromDiscardPile:
; get number of cards in Discard Pile
; and have hl point to the end of the
; Discard Pile list in wOpponentDeckCards.
ld a, DUELVARS_NUMBER_OF_CARDS_IN_DISCARD_PILE
call GetTurnDuelistVariable
ld b, a
add DUELVARS_DECK_CARDS
ld l, a
ld de, wDuelTempList
inc b
jr .next_card
.check_energy
ld a, [hl]
call LoadCardDataToBuffer2_FromDeckIndex
ld a, [wLoadedCard2Type]
and TYPE_ENERGY
jr z, .next_card
; if (c != $00), then we dismiss Double Colorless
; energy cards found.
ld a, c
or a
jr z, .copy
ld a, [wLoadedCard2Type]
cp TYPE_ENERGY_DOUBLE_COLORLESS
jr nc, .next_card
.copy
ld a, [hl]
ld [de], a
inc de
; goes through Discard Pile list
; in wOpponentDeckCards in descending order.
.next_card
dec l
dec b
jr nz, .check_energy
; terminating byte on wDuelTempList
ld a, $ff
ld [de], a
; check if any energy card was found
; by checking whether the first byte
; in wDuelTempList is $ff.
; if none were found, return carry.
ld a, [wDuelTempList]
cp $ff
jr z, .set_carry
or a
ret
.set_carry
scf
ret
; returns carry if Deck is empty
CheckIfDeckIsEmpty:
ld a, DUELVARS_NUMBER_OF_CARDS_NOT_IN_DECK
call GetTurnDuelistVariable
ldtx hl, NoCardsLeftInTheDeckText
cp DECK_SIZE
ccf
ret
; searches through Deck in wDuelTempList looking for
; a certain card or cards, and prints text depending
; on whether at least one was found.
; if none were found, asks the Player whether to look
; in the Deck anyway, and returns carry if No is selected.
; uses SEARCHEFFECT_* as input which determines what to search for:
; SEARCHEFFECT_CARD_ID = search for card ID in e
; SEARCHEFFECT_NIDORAN = search for either NidoranM or NidoranF
; SEARCHEFFECT_BASIC_FIGHTING = search for any Basic Fighting Pokemon
; SEARCHEFFECT_BASIC_ENERGY = search for any Basic Energy
; SEARCHEFFECT_POKEMON = search for any Pokemon card
; input:
; d = SEARCHEFFECT_* constant
; e = (optional) card ID to search for in deck
; hl = text to print if Deck has card(s)
; output:
; carry set if refused to look at deck
LookForCardsInDeck:
push hl
push bc
ld a, [wDuelTempList]
cp $ff
jr z, .none_in_deck
ld a, d
ld hl, .search_table
call JumpToFunctionInTable
jr c, .none_in_deck
pop bc
pop hl
call DrawWideTextBox_WaitForInput
or a
ret
.none_in_deck
pop hl
call LoadTxRam2
pop hl
ldtx hl, ThereIsNoInTheDeckText
call DrawWideTextBox_WaitForInput
ldtx hl, WouldYouLikeToCheckTheDeckText
call YesOrNoMenuWithText_SetCursorToYes
ret
.search_table
dw .SearchDeckForCardID
dw .SearchDeckForNidoran
dw .SearchDeckForBasicFighting
dw .SearchDeckForBasicEnergy
dw .SearchDeckForPokemon
.set_carry
scf
ret
; returns carry if no card with
; same card ID as e is found in Deck
.SearchDeckForCardID
ld hl, wDuelTempList
.loop_deck_e
ld a, [hli]
cp $ff
jr z, .set_carry
push de
call GetCardIDFromDeckIndex
ld a, e
pop de
cp e
jr nz, .loop_deck_e
or a
ret
; returns carry if no NidoranM or NidoranF card is found in Deck
.SearchDeckForNidoran
ld hl, wDuelTempList
.loop_deck_nidoran
ld a, [hli]
cp $ff
jr z, .set_carry
call GetCardIDFromDeckIndex
ld a, e
cp NIDORANF
jr z, .found_nidoran
cp NIDORANM
jr nz, .loop_deck_nidoran
.found_nidoran
or a
ret
; returns carry if no Basic Fighting Pokemon is found in Deck
.SearchDeckForBasicFighting
ld hl, wDuelTempList
.loop_deck_fighting
ld a, [hli]
cp $ff
jr z, .set_carry
call LoadCardDataToBuffer2_FromDeckIndex
ld a, [wLoadedCard2Type]
cp TYPE_PKMN_FIGHTING
jr nz, .loop_deck_fighting
ld a, [wLoadedCard2Stage]
or a ; BASIC
jr nz, .loop_deck_fighting
ret
; returns carry if no Basic Energy cards are found in Deck
.SearchDeckForBasicEnergy
ld hl, wDuelTempList
.loop_deck_energy
ld a, [hli]
cp $ff
jr z, .set_carry
call GetCardIDFromDeckIndex
call GetCardType
cp TYPE_ENERGY_DOUBLE_COLORLESS
jr z, .loop_deck_energy
and TYPE_ENERGY
jr z, .loop_deck_energy
or a
ret
; returns carry if no Pokemon cards are found in Deck
.SearchDeckForPokemon
ld hl, wDuelTempList
.loop_deck_pkmn
ld a, [hli]
cp $ff
jr z, .set_carry
call GetCardIDFromDeckIndex
call GetCardType
cp TYPE_ENERGY
jr nc, .loop_deck_pkmn
or a
ret
; handles the Player selection of attack
; to use, i.e. Amnesia or Metronome on.
; returns carry if none selected.
; outputs:
; d = card index of defending card
; e = attack index selected
HandleDefendingPokemonAttackSelection:
bank1call DrawDuelMainScene
call SwapTurn
xor a
ldh [hCurSelectionItem], a
.start
bank1call PrintAndLoadAttacksToDuelTempList
push af
ldh a, [hCurSelectionItem]
ld hl, .menu_parameters
call InitializeMenuParameters
pop af
ld [wNumMenuItems], a
call EnableLCD
.loop_input
call DoFrame
ldh a, [hKeysPressed]
bit B_BUTTON_F, a
jr nz, .set_carry
and START
jr nz, .open_atk_page
call HandleMenuInput
jr nc, .loop_input
cp -1
jr z, .loop_input
; an attack was selected
ldh a, [hCurMenuItem]
add a
ld e, a
ld d, $00
ld hl, wDuelTempList
add hl, de
ld d, [hl]
inc hl
ld e, [hl]
call SwapTurn
or a
ret
.set_carry
call SwapTurn
scf
ret
.open_atk_page
ldh a, [hCurMenuItem]
ldh [hCurSelectionItem], a
ld a, DUELVARS_ARENA_CARD
call GetTurnDuelistVariable
call LoadCardDataToBuffer1_FromDeckIndex
bank1call OpenAttackPage
call SwapTurn
bank1call DrawDuelMainScene
call SwapTurn
jr .start
.menu_parameters
db 1, 13 ; cursor x, cursor y
db 2 ; y displacement between items
db 2 ; number of items
db SYM_CURSOR_R ; cursor tile number
db SYM_SPACE ; tile behind cursor
dw NULL ; function pointer if non-0
; loads in hl the pointer to attack's name.
; input:
; d = deck index of card
; e = attack index (0 = first attack, 1 = second attack)
GetAttackName:
ld a, d
call LoadCardDataToBuffer1_FromDeckIndex
ld hl, wLoadedCard1Atk1Name
inc e
dec e
jr z, .load_name
ld hl, wLoadedCard1Atk2Name
.load_name
ld a, [hli]
ld h, [hl]
ld l, a
ret
; returns carry if Defending Pokemon
; doesn't have an attack.
CheckIfDefendingPokemonHasAnyAttack:
call SwapTurn
ld a, DUELVARS_ARENA_CARD
call GetTurnDuelistVariable
call LoadCardDataToBuffer2_FromDeckIndex
ld a, [wLoadedCard2Atk1Category]
cp POKEMON_POWER
jr nz, .has_attack
ld hl, wLoadedCard2Atk2Name
ld a, [hli]
or [hl]
jr nz, .has_attack
call SwapTurn
scf
ret
.has_attack
call SwapTurn
or a
ret
; overwrites HP and Stage data of the card that was
; devolved in the Play Area to the values of new card.
; if the damage exceeds HP of pre-evolution,
; then HP is set to zero.
; input:
; a = card index of pre-evolved card
UpdateDevolvedCardHPAndStage:
push bc
push de
push af
ldh a, [hTempPlayAreaLocation_ff9d]
ld e, a
call GetCardDamageAndMaxHP
ld b, a ; store damage
ld a, e
add DUELVARS_ARENA_CARD
call GetTurnDuelistVariable
pop af
ld [hl], a
call LoadCardDataToBuffer2_FromDeckIndex
ld a, e
add DUELVARS_ARENA_CARD_HP
ld l, a
ld a, [wLoadedCard2HP]
sub b ; subtract damage from new HP
jr nc, .got_hp
; damage exceeds HP
xor a ; 0 HP
.got_hp
ld [hl], a
ld a, e
; overwrite card stage
add DUELVARS_ARENA_CARD_STAGE
ld l, a
ld a, [wLoadedCard2Stage]
ld [hl], a
pop de
pop bc
ret
; reset various status after devolving card.
ResetDevolvedCardStatus:
; if it's Arena card, clear status conditions
ldh a, [hTempPlayAreaLocation_ff9d]
or a
jr nz, .skip_clear_status
call ClearAllStatusConditions
.skip_clear_status
; reset changed color status
ldh a, [hTempPlayAreaLocation_ff9d]
add DUELVARS_ARENA_CARD_CHANGED_TYPE
call GetTurnDuelistVariable
ld [hl], $00
; reset C2 flags
ldh a, [hTempPlayAreaLocation_ff9d]
add DUELVARS_ARENA_CARD_FLAGS
ld l, a
ld [hl], $00
ret
; prompts the Player with a Yes/No question
; whether to quit the screen, even though
; they can select more cards from list.
; [hCurSelectionItem] holds number of cards
; that were already selected by the Player.
; input:
; - a = total number of cards that can be selected
; output:
; - carry set if "No" was selected
AskWhetherToQuitSelectingCards:
ld hl, hCurSelectionItem
sub [hl]
ld l, a
ld h, $00
call LoadTxRam3
ldtx hl, YouCanSelectMoreCardsQuitText
call YesOrNoMenuWithText
ret
; handles the selection of a forced switch by link/AI opponent or by the player.
; outputs the Play Area location of the chosen bench card in hTempPlayAreaLocation_ff9d.
DuelistSelectForcedSwitch:
ld a, DUELVARS_DUELIST_TYPE
call GetNonTurnDuelistVariable
cp DUELIST_TYPE_LINK_OPP
jr z, .link_opp
cp DUELIST_TYPE_PLAYER
jr z, .player
; AI opponent
call SwapTurn
bank1call AIDoAction_ForcedSwitch
call SwapTurn
ld a, [wPlayerAttackingAttackIndex]
ld e, a
ld a, [wPlayerAttackingCardIndex]