Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pret
GitHub Repository: pret/pokered
Path: blob/master/engine/battle/move_effects/heal.asm
1271 views
1
HealEffect_:
2
ldh a, [hWhoseTurn]
3
and a
4
ld de, wBattleMonHP
5
ld hl, wBattleMonMaxHP
6
ld a, [wPlayerMoveNum]
7
jr z, .healEffect
8
ld de, wEnemyMonHP
9
ld hl, wEnemyMonMaxHP
10
ld a, [wEnemyMoveNum]
11
.healEffect
12
ld b, a
13
ld a, [de]
14
cp [hl] ; most significant bytes comparison is ignored
15
; causes the move to miss if max HP is 255 or 511 points higher than the current HP
16
inc de
17
inc hl
18
ld a, [de]
19
sbc [hl]
20
jp z, .failed ; no effect if user's HP is already at its maximum
21
ld a, b
22
cp REST
23
jr nz, .healHP
24
push hl
25
push de
26
push af
27
ld c, 50
28
call DelayFrames
29
ld hl, wBattleMonStatus
30
ldh a, [hWhoseTurn]
31
and a
32
jr z, .restEffect
33
ld hl, wEnemyMonStatus
34
.restEffect
35
ld a, [hl]
36
and a
37
ld [hl], 2 ; clear status and set number of turns asleep to 2
38
ld hl, StartedSleepingEffect ; if mon didn't have an status
39
jr z, .printRestText
40
ld hl, FellAsleepBecameHealthyText ; if mon had an status
41
.printRestText
42
call PrintText
43
pop af
44
pop de
45
pop hl
46
.healHP
47
ld a, [hld]
48
ld [wHPBarMaxHP], a
49
ld c, a
50
ld a, [hl]
51
ld [wHPBarMaxHP+1], a
52
ld b, a
53
jr z, .gotHPAmountToHeal
54
; Recover and Softboiled only heal for half the mon's max HP
55
srl b
56
rr c
57
.gotHPAmountToHeal
58
; update HP
59
ld a, [de]
60
ld [wHPBarOldHP], a
61
add c
62
ld [de], a
63
ld [wHPBarNewHP], a
64
dec de
65
ld a, [de]
66
ld [wHPBarOldHP+1], a
67
adc b
68
ld [de], a
69
ld [wHPBarNewHP+1], a
70
inc hl
71
inc de
72
ld a, [de]
73
dec de
74
sub [hl]
75
dec hl
76
ld a, [de]
77
sbc [hl]
78
jr c, .playAnim
79
; copy max HP to current HP if an overflow occurred
80
ld a, [hli]
81
ld [de], a
82
ld [wHPBarNewHP+1], a
83
inc de
84
ld a, [hl]
85
ld [de], a
86
ld [wHPBarNewHP], a
87
.playAnim
88
ld hl, PlayCurrentMoveAnimation
89
call EffectCallBattleCore
90
ldh a, [hWhoseTurn]
91
and a
92
hlcoord 10, 9
93
ld a, $1
94
jr z, .updateHPBar
95
hlcoord 2, 2
96
xor a
97
.updateHPBar
98
ld [wHPBarType], a
99
predef UpdateHPBar2
100
ld hl, DrawHUDsAndHPBars
101
call EffectCallBattleCore
102
ld hl, RegainedHealthText
103
jp PrintText
104
.failed
105
ld c, 50
106
call DelayFrames
107
ld hl, PrintButItFailedText_
108
jp EffectCallBattleCore
109
110
StartedSleepingEffect:
111
text_far _StartedSleepingEffect
112
text_end
113
114
FellAsleepBecameHealthyText:
115
text_far _FellAsleepBecameHealthyText
116
text_end
117
118
RegainedHealthText:
119
text_far _RegainedHealthText
120
text_end
121
122