-
Notifications
You must be signed in to change notification settings - Fork 996
/
effects.asm
1499 lines (1405 loc) · 30.5 KB
/
effects.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
JumpMoveEffect:
call _JumpMoveEffect
ld b, $1
ret
_JumpMoveEffect:
ldh a, [hWhoseTurn]
and a
ld a, [wPlayerMoveEffect]
jr z, .next1
ld a, [wEnemyMoveEffect]
.next1
dec a ; subtract 1, there is no special effect for 00
add a ; x2, 16bit pointers
ld hl, MoveEffectPointerTable
ld b, 0
ld c, a
add hl, bc
ld a, [hli]
ld h, [hl]
ld l, a
jp hl ; jump to special effect handler
INCLUDE "data/moves/effects_pointers.asm"
SleepEffect:
ld de, wEnemyMonStatus
ld bc, wEnemyBattleStatus2
ldh a, [hWhoseTurn]
and a
jp z, .sleepEffect
ld de, wBattleMonStatus
ld bc, wPlayerBattleStatus2
.sleepEffect
ld a, [bc]
bit NEEDS_TO_RECHARGE, a ; does the target need to recharge? (hyper beam)
res NEEDS_TO_RECHARGE, a ; target no longer needs to recharge
ld [bc], a
jr nz, .setSleepCounter ; if the target had to recharge, all hit tests will be skipped
; including the event where the target already has another status
ld a, [de]
ld b, a
and $7
jr z, .notAlreadySleeping ; can't affect a mon that is already asleep
ld hl, AlreadyAsleepText
jp PrintText
.notAlreadySleeping
ld a, b
and a
jr nz, .didntAffect ; can't affect a mon that is already statused
push de
call MoveHitTest ; apply accuracy tests
pop de
ld a, [wMoveMissed]
and a
jr nz, .didntAffect
.setSleepCounter
; set target's sleep counter to a random number between 1 and 7
call BattleRandom
and $7
jr z, .setSleepCounter
ld [de], a
call PlayCurrentMoveAnimation2
ld hl, FellAsleepText
jp PrintText
.didntAffect
jp PrintDidntAffectText
FellAsleepText:
text_far _FellAsleepText
text_end
AlreadyAsleepText:
text_far _AlreadyAsleepText
text_end
PoisonEffect:
ld hl, wEnemyMonStatus
ld de, wPlayerMoveEffect
ldh a, [hWhoseTurn]
and a
jr z, .poisonEffect
ld hl, wBattleMonStatus
ld de, wEnemyMoveEffect
.poisonEffect
call CheckTargetSubstitute
jr nz, .noEffect ; can't poison a substitute target
ld a, [hli]
ld b, a
and a
jr nz, .noEffect ; miss if target is already statused
ld a, [hli]
cp POISON ; can't poison a poison-type target
jr z, .noEffect
ld a, [hld]
cp POISON ; can't poison a poison-type target
jr z, .noEffect
ld a, [de]
cp POISON_SIDE_EFFECT1
ld b, 20 percent + 1 ; chance of poisoning
jr z, .sideEffectTest
cp POISON_SIDE_EFFECT2
ld b, 40 percent + 1 ; chance of poisoning
jr z, .sideEffectTest
push hl
push de
call MoveHitTest ; apply accuracy tests
pop de
pop hl
ld a, [wMoveMissed]
and a
jr nz, .didntAffect
jr .inflictPoison
.sideEffectTest
call BattleRandom
cp b ; was side effect successful?
ret nc
.inflictPoison
dec hl
set PSN, [hl]
push de
dec de
ldh a, [hWhoseTurn]
and a
ld b, SHAKE_SCREEN_ANIM
ld hl, wPlayerBattleStatus3
ld a, [de]
ld de, wPlayerToxicCounter
jr nz, .ok
ld b, ENEMY_HUD_SHAKE_ANIM
ld hl, wEnemyBattleStatus3
ld de, wEnemyToxicCounter
.ok
cp TOXIC
jr nz, .normalPoison ; done if move is not Toxic
set BADLY_POISONED, [hl] ; else set Toxic battstatus
xor a
ld [de], a
ld hl, BadlyPoisonedText
jr .continue
.normalPoison
ld hl, PoisonedText
.continue
pop de
ld a, [de]
cp POISON_EFFECT
jr z, .regularPoisonEffect
ld a, b
call PlayBattleAnimation2
jp PrintText
.regularPoisonEffect
call PlayCurrentMoveAnimation2
jp PrintText
.noEffect
ld a, [de]
cp POISON_EFFECT
ret nz
.didntAffect
ld c, 50
call DelayFrames
jp PrintDidntAffectText
PoisonedText:
text_far _PoisonedText
text_end
BadlyPoisonedText:
text_far _BadlyPoisonedText
text_end
DrainHPEffect:
jpfar DrainHPEffect_
ExplodeEffect:
ld hl, wBattleMonHP
ld de, wPlayerBattleStatus2
ldh a, [hWhoseTurn]
and a
jr z, .faintUser
ld hl, wEnemyMonHP
ld de, wEnemyBattleStatus2
.faintUser
xor a
ld [hli], a ; set the mon's HP to 0
ld [hli], a
inc hl
ld [hl], a ; set mon's status to 0
ld a, [de]
res SEEDED, a ; clear mon's leech seed status
ld [de], a
ret
FreezeBurnParalyzeEffect:
xor a
ld [wAnimationType], a
call CheckTargetSubstitute
ret nz ; return if they have a substitute, can't effect them
ldh a, [hWhoseTurn]
and a
jp nz, .opponentAttacker
ld a, [wEnemyMonStatus]
and a
jp nz, CheckDefrost ; can't inflict status if opponent is already statused
ld a, [wPlayerMoveType]
ld b, a
ld a, [wEnemyMonType1]
cp b ; do target type 1 and move type match?
ret z ; return if they match (an ice move can't freeze an ice-type, body slam can't paralyze a normal-type, etc.)
ld a, [wEnemyMonType2]
cp b ; do target type 2 and move type match?
ret z ; return if they match
ld a, [wPlayerMoveEffect]
cp PARALYZE_SIDE_EFFECT1 + 1
ld b, 10 percent + 1
jr c, .regular_effectiveness
; extra effectiveness
ld b, 30 percent + 1
assert PARALYZE_SIDE_EFFECT2 - PARALYZE_SIDE_EFFECT1 == BURN_SIDE_EFFECT2 - BURN_SIDE_EFFECT1
assert PARALYZE_SIDE_EFFECT2 - PARALYZE_SIDE_EFFECT1 == FREEZE_SIDE_EFFECT2 - FREEZE_SIDE_EFFECT1
sub PARALYZE_SIDE_EFFECT2 - PARALYZE_SIDE_EFFECT1 ; treat extra effective as regular from now on
.regular_effectiveness
push af
call BattleRandom ; get random 8bit value for probability test
cp b
pop bc
ret nc ; do nothing if random value is >= 1A or 4D [no status applied]
ld a, b ; what type of effect is this?
cp BURN_SIDE_EFFECT1
jr z, .burn1
cp FREEZE_SIDE_EFFECT1
jr z, .freeze1
; .paralyze1
ld a, 1 << PAR
ld [wEnemyMonStatus], a
call QuarterSpeedDueToParalysis ; quarter speed of affected mon
ld a, ENEMY_HUD_SHAKE_ANIM
call PlayBattleAnimation
jp PrintMayNotAttackText ; print paralysis text
.burn1
ld a, 1 << BRN
ld [wEnemyMonStatus], a
call HalveAttackDueToBurn ; halve attack of affected mon
ld a, ENEMY_HUD_SHAKE_ANIM
call PlayBattleAnimation
ld hl, BurnedText
jp PrintText
.freeze1
call ClearHyperBeam ; resets hyper beam (recharge) condition from target
ld a, 1 << FRZ
ld [wEnemyMonStatus], a
ld a, ENEMY_HUD_SHAKE_ANIM
call PlayBattleAnimation
ld hl, FrozenText
jp PrintText
.opponentAttacker
ld a, [wBattleMonStatus] ; mostly same as above with addresses swapped for opponent
and a
jp nz, CheckDefrost
ld a, [wEnemyMoveType]
ld b, a
ld a, [wBattleMonType1]
cp b
ret z
ld a, [wBattleMonType2]
cp b
ret z
ld a, [wEnemyMoveEffect]
cp PARALYZE_SIDE_EFFECT1 + 1
ld b, 10 percent + 1
jr c, .regular_effectiveness2
; extra effectiveness
ld b, 30 percent + 1
sub BURN_SIDE_EFFECT2 - BURN_SIDE_EFFECT1 ; treat extra effective as regular from now on
.regular_effectiveness2
push af
call BattleRandom
cp b
pop bc
ret nc
ld a, b
cp BURN_SIDE_EFFECT1
jr z, .burn2
cp FREEZE_SIDE_EFFECT1
jr z, .freeze2
; .paralyze2
ld a, 1 << PAR
ld [wBattleMonStatus], a
call QuarterSpeedDueToParalysis
jp PrintMayNotAttackText
.burn2
ld a, 1 << BRN
ld [wBattleMonStatus], a
call HalveAttackDueToBurn
ld hl, BurnedText
jp PrintText
.freeze2
; hyper beam bits aren't reseted for opponent's side
ld a, 1 << FRZ
ld [wBattleMonStatus], a
ld hl, FrozenText
jp PrintText
BurnedText:
text_far _BurnedText
text_end
FrozenText:
text_far _FrozenText
text_end
CheckDefrost:
; any fire-type move that has a chance inflict burn (all but Fire Spin) will defrost a frozen target
and 1 << FRZ ; are they frozen?
ret z ; return if so
ldh a, [hWhoseTurn]
and a
jr nz, .opponent
;player [attacker]
ld a, [wPlayerMoveType]
sub FIRE
ret nz ; return if type of move used isn't fire
ld [wEnemyMonStatus], a ; set opponent status to 00 ["defrost" a frozen monster]
ld hl, wEnemyMon1Status
ld a, [wEnemyMonPartyPos]
ld bc, wEnemyMon2 - wEnemyMon1
call AddNTimes
xor a
ld [hl], a ; clear status in roster
ld hl, FireDefrostedText
jr .common
.opponent
ld a, [wEnemyMoveType] ; same as above with addresses swapped
sub FIRE
ret nz
ld [wBattleMonStatus], a
ld hl, wPartyMon1Status
ld a, [wPlayerMonNumber]
ld bc, wPartyMon2 - wPartyMon1
call AddNTimes
xor a
ld [hl], a
ld hl, FireDefrostedText
.common
jp PrintText
FireDefrostedText:
text_far _FireDefrostedText
text_end
StatModifierUpEffect:
ld hl, wPlayerMonStatMods
ld de, wPlayerMoveEffect
ldh a, [hWhoseTurn]
and a
jr z, .statModifierUpEffect
ld hl, wEnemyMonStatMods
ld de, wEnemyMoveEffect
.statModifierUpEffect
ld a, [de]
sub ATTACK_UP1_EFFECT
cp EVASION_UP1_EFFECT + $3 - ATTACK_UP1_EFFECT ; covers all +1 effects
jr c, .incrementStatMod
sub ATTACK_UP2_EFFECT - ATTACK_UP1_EFFECT ; map +2 effects to equivalent +1 effect
.incrementStatMod
ld c, a
ld b, $0
add hl, bc
ld b, [hl]
inc b ; increment corresponding stat mod
ld a, $d
cp b ; can't raise stat past +6 ($d or 13)
jp c, PrintNothingHappenedText
ld a, [de]
cp ATTACK_UP1_EFFECT + $8 ; is it a +2 effect?
jr c, .ok
inc b ; if so, increment stat mod again
ld a, $d
cp b ; unless it's already +6
jr nc, .ok
ld b, a
.ok
ld [hl], b
ld a, c
cp $4
jr nc, UpdateStatDone ; jump if mod affected is evasion/accuracy
push hl
ld hl, wBattleMonAttack + 1
ld de, wPlayerMonUnmodifiedAttack
ldh a, [hWhoseTurn]
and a
jr z, .pointToStats
ld hl, wEnemyMonAttack + 1
ld de, wEnemyMonUnmodifiedAttack
.pointToStats
push bc
sla c
ld b, $0
add hl, bc ; hl = modified stat
ld a, c
add e
ld e, a
jr nc, .checkIf999
inc d ; de = unmodified (original) stat
.checkIf999
pop bc
; check if stat is already 999
ld a, [hld]
sub LOW(MAX_STAT_VALUE)
jr nz, .recalculateStat
ld a, [hl]
sbc HIGH(MAX_STAT_VALUE)
jp z, RestoreOriginalStatModifier
.recalculateStat ; recalculate affected stat
; paralysis and burn penalties, as well as badge boosts are ignored
push hl
push bc
ld hl, StatModifierRatios
dec b
sla b
ld c, b
ld b, $0
add hl, bc
pop bc
xor a
ldh [hMultiplicand], a
ld a, [de]
ldh [hMultiplicand + 1], a
inc de
ld a, [de]
ldh [hMultiplicand + 2], a
ld a, [hli]
ldh [hMultiplier], a
call Multiply
ld a, [hl]
ldh [hDivisor], a
ld b, $4
call Divide
pop hl
; cap at MAX_STAT_VALUE (999)
ldh a, [hProduct + 3]
sub LOW(MAX_STAT_VALUE)
ldh a, [hProduct + 2]
sbc HIGH(MAX_STAT_VALUE)
jp c, UpdateStat
ld a, HIGH(MAX_STAT_VALUE)
ldh [hMultiplicand + 1], a
ld a, LOW(MAX_STAT_VALUE)
ldh [hMultiplicand + 2], a
UpdateStat:
ldh a, [hProduct + 2]
ld [hli], a
ldh a, [hProduct + 3]
ld [hl], a
pop hl
UpdateStatDone:
ld b, c
inc b
call PrintStatText
ld hl, wPlayerBattleStatus2
ld de, wPlayerMoveNum
ld bc, wPlayerMonMinimized
ldh a, [hWhoseTurn]
and a
jr z, .playerTurn
ld hl, wEnemyBattleStatus2
ld de, wEnemyMoveNum
ld bc, wEnemyMonMinimized
.playerTurn
ld a, [de]
cp MINIMIZE
jr nz, .notMinimize
; if a substitute is up, slide off the substitute and show the mon pic before
; playing the minimize animation
bit HAS_SUBSTITUTE_UP, [hl]
push af
push bc
ld hl, HideSubstituteShowMonAnim
ld b, BANK(HideSubstituteShowMonAnim)
push de
call nz, Bankswitch
pop de
.notMinimize
call PlayCurrentMoveAnimation
ld a, [de]
cp MINIMIZE
jr nz, .applyBadgeBoostsAndStatusPenalties
pop bc
ld a, $1
ld [bc], a
ld hl, ReshowSubstituteAnim
ld b, BANK(ReshowSubstituteAnim)
pop af
call nz, Bankswitch
.applyBadgeBoostsAndStatusPenalties
ldh a, [hWhoseTurn]
and a
call z, ApplyBadgeStatBoosts ; whenever the player uses a stat-up move, badge boosts get reapplied again to every stat,
; even to those not affected by the stat-up move (will be boosted further)
ld hl, MonsStatsRoseText
call PrintText
; these shouldn't be here
call QuarterSpeedDueToParalysis ; apply speed penalty to the player whose turn is not, if it's paralyzed
jp HalveAttackDueToBurn ; apply attack penalty to the player whose turn is not, if it's burned
RestoreOriginalStatModifier:
pop hl
dec [hl]
PrintNothingHappenedText:
ld hl, NothingHappenedText
jp PrintText
MonsStatsRoseText:
text_far _MonsStatsRoseText
text_asm
ld hl, GreatlyRoseText
ldh a, [hWhoseTurn]
and a
ld a, [wPlayerMoveEffect]
jr z, .playerTurn
ld a, [wEnemyMoveEffect]
.playerTurn
cp ATTACK_DOWN1_EFFECT
ret nc
ld hl, RoseText
ret
GreatlyRoseText:
text_pause
text_far _GreatlyRoseText
; fallthrough
RoseText:
text_far _RoseText
text_end
StatModifierDownEffect:
ld hl, wEnemyMonStatMods
ld de, wPlayerMoveEffect
ld bc, wEnemyBattleStatus1
ldh a, [hWhoseTurn]
and a
jr z, .statModifierDownEffect
ld hl, wPlayerMonStatMods
ld de, wEnemyMoveEffect
ld bc, wPlayerBattleStatus1
ld a, [wLinkState]
cp LINK_STATE_BATTLING
jr z, .statModifierDownEffect
call BattleRandom
cp 25 percent + 1 ; chance to miss by in regular battle
jp c, MoveMissed
.statModifierDownEffect
call CheckTargetSubstitute ; can't hit through substitute
jp nz, MoveMissed
ld a, [de]
cp ATTACK_DOWN_SIDE_EFFECT
jr c, .nonSideEffect
call BattleRandom
cp 33 percent + 1 ; chance for side effects
jp nc, CantLowerAnymore
ld a, [de]
sub ATTACK_DOWN_SIDE_EFFECT ; map each stat to 0-3
jr .decrementStatMod
.nonSideEffect ; non-side effects only
push hl
push de
push bc
call MoveHitTest ; apply accuracy tests
pop bc
pop de
pop hl
ld a, [wMoveMissed]
and a
jp nz, MoveMissed
ld a, [bc]
bit INVULNERABLE, a ; fly/dig
jp nz, MoveMissed
ld a, [de]
sub ATTACK_DOWN1_EFFECT
cp EVASION_DOWN1_EFFECT + $3 - ATTACK_DOWN1_EFFECT ; covers all -1 effects
jr c, .decrementStatMod
sub ATTACK_DOWN2_EFFECT - ATTACK_DOWN1_EFFECT ; map -2 effects to corresponding -1 effect
.decrementStatMod
ld c, a
ld b, $0
add hl, bc
ld b, [hl]
dec b ; dec corresponding stat mod
jp z, CantLowerAnymore ; if stat mod is 1 (-6), can't lower anymore
ld a, [de]
cp ATTACK_DOWN2_EFFECT - $16 ; $24
jr c, .ok
cp EVASION_DOWN2_EFFECT + $5 ; $44
jr nc, .ok
dec b ; stat down 2 effects only (dec mod again)
jr nz, .ok
inc b ; increment mod to 1 (-6) if it would become 0 (-7)
.ok
ld [hl], b ; save modified mod
ld a, c
cp $4
jr nc, UpdateLoweredStatDone ; jump for evasion/accuracy
push hl
push de
ld hl, wEnemyMonAttack + 1
ld de, wEnemyMonUnmodifiedAttack
ldh a, [hWhoseTurn]
and a
jr z, .pointToStat
ld hl, wBattleMonAttack + 1
ld de, wPlayerMonUnmodifiedAttack
.pointToStat
push bc
sla c
ld b, $0
add hl, bc ; hl = modified stat
ld a, c
add e
ld e, a
jr nc, .noCarry
inc d ; de = unmodified stat
.noCarry
pop bc
ld a, [hld]
sub $1 ; can't lower stat below 1 (-6)
jr nz, .recalculateStat
ld a, [hl]
and a
jp z, CantLowerAnymore_Pop
.recalculateStat
; recalculate affected stat
; paralysis and burn penalties, as well as badge boosts are ignored
push hl
push bc
ld hl, StatModifierRatios
dec b
sla b
ld c, b
ld b, $0
add hl, bc
pop bc
xor a
ldh [hMultiplicand], a
ld a, [de]
ldh [hMultiplicand + 1], a
inc de
ld a, [de]
ldh [hMultiplicand + 2], a
ld a, [hli]
ldh [hMultiplier], a
call Multiply
ld a, [hl]
ldh [hDivisor], a
ld b, $4
call Divide
pop hl
ldh a, [hProduct + 3]
ld b, a
ldh a, [hProduct + 2]
or b
jp nz, UpdateLoweredStat
ldh [hMultiplicand + 1], a
ld a, $1
ldh [hMultiplicand + 2], a
UpdateLoweredStat:
ldh a, [hProduct + 2]
ld [hli], a
ldh a, [hProduct + 3]
ld [hl], a
pop de
pop hl
UpdateLoweredStatDone:
ld b, c
inc b
push de
call PrintStatText
pop de
ld a, [de]
cp $44
jr nc, .ApplyBadgeBoostsAndStatusPenalties
call PlayCurrentMoveAnimation2
.ApplyBadgeBoostsAndStatusPenalties
ldh a, [hWhoseTurn]
and a
call nz, ApplyBadgeStatBoosts ; whenever the player uses a stat-down move, badge boosts get reapplied again to every stat,
; even to those not affected by the stat-up move (will be boosted further)
ld hl, MonsStatsFellText
call PrintText
; These where probably added given that a stat-down move affecting speed or attack will override
; the stat penalties from paralysis and burn respectively.
; But they are always called regardless of the stat affected by the stat-down move.
call QuarterSpeedDueToParalysis
jp HalveAttackDueToBurn
CantLowerAnymore_Pop:
pop de
pop hl
inc [hl]
CantLowerAnymore:
ld a, [de]
cp ATTACK_DOWN_SIDE_EFFECT
ret nc
ld hl, NothingHappenedText
jp PrintText
MoveMissed:
ld a, [de]
cp $44
ret nc
jp ConditionalPrintButItFailed
MonsStatsFellText:
text_far _MonsStatsFellText
text_asm
ld hl, FellText
ldh a, [hWhoseTurn]
and a
ld a, [wPlayerMoveEffect]
jr z, .playerTurn
ld a, [wEnemyMoveEffect]
.playerTurn
; check if the move's effect decreases a stat by 2
cp BIDE_EFFECT
ret c
cp ATTACK_DOWN_SIDE_EFFECT
ret nc
ld hl, GreatlyFellText
ret
GreatlyFellText:
text_pause
text_far _GreatlyFellText
; fallthrough
FellText:
text_far _FellText
text_end
PrintStatText:
ld hl, StatModTextStrings
ld c, "@"
.findStatName_outer
dec b
jr z, .foundStatName
.findStatName_inner
ld a, [hli]
cp c
jr z, .findStatName_outer
jr .findStatName_inner
.foundStatName
ld de, wStringBuffer
ld bc, $a
jp CopyData
INCLUDE "data/battle/stat_mod_names.asm"
INCLUDE "data/battle/stat_modifiers.asm"
BideEffect:
ld hl, wPlayerBattleStatus1
ld de, wPlayerBideAccumulatedDamage
ld bc, wPlayerNumAttacksLeft
ldh a, [hWhoseTurn]
and a
jr z, .bideEffect
ld hl, wEnemyBattleStatus1
ld de, wEnemyBideAccumulatedDamage
ld bc, wEnemyNumAttacksLeft
.bideEffect
set STORING_ENERGY, [hl] ; mon is now using bide
xor a
ld [de], a
inc de
ld [de], a
ld [wPlayerMoveEffect], a
ld [wEnemyMoveEffect], a
call BattleRandom
and $1
inc a
inc a
ld [bc], a ; set Bide counter to 2 or 3 at random
ldh a, [hWhoseTurn]
add XSTATITEM_ANIM
jp PlayBattleAnimation2
ThrashPetalDanceEffect:
ld hl, wPlayerBattleStatus1
ld de, wPlayerNumAttacksLeft
ldh a, [hWhoseTurn]
and a
jr z, .thrashPetalDanceEffect
ld hl, wEnemyBattleStatus1
ld de, wEnemyNumAttacksLeft
.thrashPetalDanceEffect
set THRASHING_ABOUT, [hl] ; mon is now using thrash/petal dance
call BattleRandom
and $1
inc a
inc a
ld [de], a ; set thrash/petal dance counter to 2 or 3 at random
ldh a, [hWhoseTurn]
add SHRINKING_SQUARE_ANIM
jp PlayBattleAnimation2
SwitchAndTeleportEffect:
ldh a, [hWhoseTurn]
and a
jr nz, .handleEnemy
ld a, [wIsInBattle]
dec a
jr nz, .notWildBattle1
ld a, [wCurEnemyLevel]
ld b, a
ld a, [wBattleMonLevel]
cp b ; is the player's level greater than the enemy's level?
jr nc, .playerMoveWasSuccessful ; if so, teleport will always succeed
add b
ld c, a
inc c ; c = playerLevel + enemyLevel + 1
.rejectionSampleLoop1
call BattleRandom
cp c ; get a random number between 0 and c
jr nc, .rejectionSampleLoop1
srl b
srl b ; b = enemyLevel / 4
cp b ; is rand[0, playerLevel + enemyLevel] >= (enemyLevel / 4)?
jr nc, .playerMoveWasSuccessful ; if so, allow teleporting
ld c, 50
call DelayFrames
ld a, [wPlayerMoveNum]
cp TELEPORT
jp nz, PrintDidntAffectText
jp PrintButItFailedText_
.playerMoveWasSuccessful
call ReadPlayerMonCurHPAndStatus
xor a
ld [wAnimationType], a
inc a
ld [wEscapedFromBattle], a
ld a, [wPlayerMoveNum]
jr .playAnimAndPrintText
.notWildBattle1
ld c, 50
call DelayFrames
ld hl, IsUnaffectedText
ld a, [wPlayerMoveNum]
cp TELEPORT
jp nz, PrintText
jp PrintButItFailedText_
.handleEnemy
ld a, [wIsInBattle]
dec a
jr nz, .notWildBattle2
ld a, [wBattleMonLevel]
ld b, a
ld a, [wCurEnemyLevel]
cp b
jr nc, .enemyMoveWasSuccessful
add b
ld c, a
inc c
.rejectionSampleLoop2
call BattleRandom
cp c
jr nc, .rejectionSampleLoop2
srl b
srl b
cp b
jr nc, .enemyMoveWasSuccessful
ld c, 50
call DelayFrames
ld a, [wEnemyMoveNum]
cp TELEPORT
jp nz, PrintDidntAffectText
jp PrintButItFailedText_
.enemyMoveWasSuccessful
call ReadPlayerMonCurHPAndStatus
xor a
ld [wAnimationType], a
inc a
ld [wEscapedFromBattle], a
ld a, [wEnemyMoveNum]
jr .playAnimAndPrintText
.notWildBattle2
ld c, 50
call DelayFrames
ld hl, IsUnaffectedText
ld a, [wEnemyMoveNum]
cp TELEPORT
jp nz, PrintText
jp ConditionalPrintButItFailed
.playAnimAndPrintText
push af
call PlayBattleAnimation
ld c, 20
call DelayFrames
pop af
ld hl, RanFromBattleText
cp TELEPORT
jr z, .printText
ld hl, RanAwayScaredText
cp ROAR
jr z, .printText
ld hl, WasBlownAwayText
.printText
jp PrintText
RanFromBattleText:
text_far _RanFromBattleText
text_end
RanAwayScaredText:
text_far _RanAwayScaredText
text_end
WasBlownAwayText:
text_far _WasBlownAwayText
text_end
TwoToFiveAttacksEffect:
ld hl, wPlayerBattleStatus1
ld de, wPlayerNumAttacksLeft
ld bc, wPlayerNumHits
ldh a, [hWhoseTurn]
and a
jr z, .twoToFiveAttacksEffect
ld hl, wEnemyBattleStatus1
ld de, wEnemyNumAttacksLeft
ld bc, wEnemyNumHits
.twoToFiveAttacksEffect
bit ATTACKING_MULTIPLE_TIMES, [hl] ; is mon attacking multiple times?
ret nz
set ATTACKING_MULTIPLE_TIMES, [hl] ; mon is now attacking multiple times
ld hl, wPlayerMoveEffect
ldh a, [hWhoseTurn]
and a
jr z, .setNumberOfHits
ld hl, wEnemyMoveEffect
.setNumberOfHits
ld a, [hl]
cp TWINEEDLE_EFFECT
jr z, .twineedle
cp ATTACK_TWICE_EFFECT
ld a, $2 ; number of hits it's always 2 for ATTACK_TWICE_EFFECT
jr z, .saveNumberOfHits
; for TWO_TO_FIVE_ATTACKS_EFFECT 3/8 chance for 2 and 3 hits, and 1/8 chance for 4 and 5 hits
call BattleRandom
and $3
cp $2
jr c, .gotNumHits
; if the number of hits was greater than 2, re-roll again for a lower chance
call BattleRandom
and $3
.gotNumHits
inc a
inc a
.saveNumberOfHits
ld [de], a
ld [bc], a
ret
.twineedle
ld a, POISON_SIDE_EFFECT1
ld [hl], a ; set Twineedle's effect to poison effect
jr .saveNumberOfHits
FlinchSideEffect:
call CheckTargetSubstitute
ret nz
ld hl, wEnemyBattleStatus1
ld de, wPlayerMoveEffect
ldh a, [hWhoseTurn]
and a
jr z, .flinchSideEffect
ld hl, wPlayerBattleStatus1
ld de, wEnemyMoveEffect
.flinchSideEffect
ld a, [de]
cp FLINCH_SIDE_EFFECT1
ld b, 10 percent + 1 ; chance of flinch (FLINCH_SIDE_EFFECT1)
jr z, .gotEffectChance
ld b, 30 percent + 1 ; chance of flinch otherwise
.gotEffectChance
call BattleRandom
cp b
ret nc
set FLINCHED, [hl] ; set mon's status to flinching
call ClearHyperBeam
ret
OneHitKOEffect:
jpfar OneHitKOEffect_
ChargeEffect:
ld hl, wPlayerBattleStatus1
ld de, wPlayerMoveEffect