Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pret
GitHub Repository: pret/pokered
Path: blob/master/engine/events/poison.asm
1271 views
1
ApplyOutOfBattlePoisonDamage:
2
ld a, [wStatusFlags5]
3
ASSERT BIT_SCRIPTED_MOVEMENT_STATE == 7
4
add a ; overflows scripted movement state bit into carry flag
5
jp c, .noBlackOut ; no black out if joypad states are being simulated
6
ld a, [wPartyCount]
7
and a
8
jp z, .noBlackOut
9
call IncrementDayCareMonExp
10
ld a, [wStepCounter]
11
and $3 ; is the counter a multiple of 4?
12
jp nz, .noBlackOut ; only apply poison damage every fourth step
13
ld [wWhichPokemon], a
14
ld hl, wPartyMon1Status
15
ld de, wPartySpecies
16
.applyDamageLoop
17
ld a, [hl]
18
and 1 << PSN
19
jr z, .nextMon2 ; not poisoned
20
dec hl
21
dec hl
22
ld a, [hld]
23
ld b, a
24
ld a, [hli]
25
or b
26
jr z, .nextMon ; already fainted
27
; subtract 1 from HP
28
ld a, [hl]
29
dec a
30
ld [hld], a
31
inc a
32
jr nz, .noBorrow
33
; borrow 1 from upper byte of HP
34
dec [hl]
35
inc hl
36
jr .nextMon
37
.noBorrow
38
ld a, [hli]
39
or [hl]
40
jr nz, .nextMon ; didn't faint from damage
41
; the mon fainted from the damage
42
push hl
43
inc hl
44
inc hl
45
ld [hl], a
46
ld a, [de]
47
ld [wPokedexNum], a
48
push de
49
ld a, [wWhichPokemon]
50
ld hl, wPartyMonNicks
51
call GetPartyMonName
52
xor a
53
ld [wJoyIgnore], a
54
call EnableAutoTextBoxDrawing
55
ld a, TEXT_MON_FAINTED
56
ldh [hTextID], a
57
call DisplayTextID
58
pop de
59
pop hl
60
.nextMon
61
inc hl
62
inc hl
63
.nextMon2
64
inc de
65
ld a, [de]
66
inc a
67
jr z, .applyDamageLoopDone
68
ld bc, wPartyMon2 - wPartyMon1
69
add hl, bc
70
push hl
71
ld hl, wWhichPokemon
72
inc [hl]
73
pop hl
74
jr .applyDamageLoop
75
.applyDamageLoopDone
76
ld hl, wPartyMon1Status
77
ld a, [wPartyCount]
78
ld d, a
79
ld e, 0
80
.countPoisonedLoop
81
ld a, [hl]
82
and 1 << PSN
83
or e
84
ld e, a
85
ld bc, wPartyMon2 - wPartyMon1
86
add hl, bc
87
dec d
88
jr nz, .countPoisonedLoop
89
ld a, e
90
and a ; are any party members poisoned?
91
jr z, .skipPoisonEffectAndSound
92
ld b, $2
93
predef ChangeBGPalColor0_4Frames ; change BG white to dark gray for 4 frames
94
ld a, SFX_POISONED
95
call PlaySound
96
.skipPoisonEffectAndSound
97
predef AnyPartyAlive
98
ld a, d
99
and a
100
jr nz, .noBlackOut
101
call EnableAutoTextBoxDrawing
102
ld a, TEXT_BLACKED_OUT
103
ldh [hTextID], a
104
call DisplayTextID
105
ld hl, wStatusFlags4
106
set BIT_BATTLE_OVER_OR_BLACKOUT, [hl]
107
ld a, $ff
108
jr .done
109
.noBlackOut
110
xor a
111
.done
112
ld [wOutOfBattleBlackout], a
113
ret
114
115