Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pret
GitHub Repository: pret/pokered
Path: blob/master/engine/battle/move_effects/substitute.asm
1271 views
1
SubstituteEffect_:
2
ld c, 50
3
call DelayFrames
4
ld hl, wBattleMonMaxHP
5
ld de, wPlayerSubstituteHP
6
ld bc, wPlayerBattleStatus2
7
ldh a, [hWhoseTurn]
8
and a
9
jr z, .notEnemy
10
ld hl, wEnemyMonMaxHP
11
ld de, wEnemySubstituteHP
12
ld bc, wEnemyBattleStatus2
13
.notEnemy
14
ld a, [bc]
15
bit HAS_SUBSTITUTE_UP, a ; user already has substitute?
16
jr nz, .alreadyHasSubstitute
17
; quarter health to remove from user
18
; assumes max HP is 1023 or lower
19
push bc
20
ld a, [hli]
21
ld b, [hl]
22
srl a
23
rr b
24
srl a
25
rr b ; max hp / 4
26
push de
27
ld de, wBattleMonHP - wBattleMonMaxHP
28
add hl, de ; point hl to current HP low byte
29
pop de
30
ld a, b
31
ld [de], a ; save copy of HP to subtract in wPlayerSubstituteHP/wEnemySubstituteHP
32
ld a, [hld]
33
; subtract [max hp / 4] to current HP
34
sub b
35
ld d, a
36
ld a, [hl]
37
sbc 0
38
pop bc
39
jr c, .notEnoughHP ; underflow means user would be left with negative health
40
; bug: since it only branches on carry, it will possibly leave user with 0 HP
41
.userHasZeroOrMoreHP
42
ldi [hl], a ; save resulting HP after subtraction into current HP
43
ld [hl], d
44
ld h, b
45
ld l, c
46
set HAS_SUBSTITUTE_UP, [hl]
47
ld a, [wOptions]
48
bit BIT_BATTLE_ANIMATION, a
49
ld hl, PlayCurrentMoveAnimation
50
ld b, BANK(PlayCurrentMoveAnimation)
51
jr z, .animationEnabled
52
ld hl, AnimationSubstitute
53
ld b, BANK(AnimationSubstitute)
54
.animationEnabled
55
call Bankswitch ; jump to routine depending on animation setting
56
ld hl, SubstituteText
57
call PrintText
58
jpfar DrawHUDsAndHPBars
59
.alreadyHasSubstitute
60
ld hl, HasSubstituteText
61
jr .printText
62
.notEnoughHP
63
ld hl, TooWeakSubstituteText
64
.printText
65
jp PrintText
66
67
SubstituteText:
68
text_far _SubstituteText
69
text_end
70
71
HasSubstituteText:
72
text_far _HasSubstituteText
73
text_end
74
75
TooWeakSubstituteText:
76
text_far _TooWeakSubstituteText
77
text_end
78
79