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
|
PrintCardKeyText:
ld hl, SilphCoMapList
ld a, [wCurMap]
ld b, a
.silphCoMapListLoop
ld a, [hli]
cp -1
ret z
cp b
jr nz, .silphCoMapListLoop
predef GetTileAndCoordsInFrontOfPlayer
ld a, [wTileInFrontOfPlayer]
cp $18
jr z, .cardKeyDoorInFrontOfPlayer
cp $24
jr z, .cardKeyDoorInFrontOfPlayer
ld b, a
ld a, [wCurMap]
cp SILPH_CO_11F
ret nz
ld a, b
cp $5e
ret nz
.cardKeyDoorInFrontOfPlayer
ld b, CARD_KEY
call IsItemInBag
jr z, .noCardKey
call GetCoordsInFrontOfPlayer
push de
tx_pre_id CardKeySuccessText
ldh [hSpriteIndexOrTextID], a
call PrintPredefTextID
pop de
srl d
ld a, d
ld b, a
ld [wCardKeyDoorY], a
srl e
ld a, e
ld c, a
ld [wCardKeyDoorX], a
ld a, [wCurMap]
cp SILPH_CO_11F
jr nz, .notSilphCo11F
ld a, $3
jr .replaceCardKeyDoorTileBlock
.notSilphCo11F
ld a, $e
.replaceCardKeyDoorTileBlock
ld [wNewTileBlockID], a
predef ReplaceTileBlock
ld hl, wCurrentMapScriptFlags
set 5, [hl]
ld a, SFX_GO_INSIDE
jp PlaySound
.noCardKey
tx_pre_id CardKeyFailText
ldh [hSpriteIndexOrTextID], a
jp PrintPredefTextID
INCLUDE "data/events/card_key_maps.asm"
CardKeySuccessText::
text_far _CardKeySuccessText1
sound_get_item_1
text_far _CardKeySuccessText2
text_end
CardKeyFailText::
text_far _CardKeyFailText
text_end
; d = Y
; e = X
GetCoordsInFrontOfPlayer:
ld a, [wYCoord]
ld d, a
ld a, [wXCoord]
ld e, a
ld a, [wSpritePlayerStateData1FacingDirection]
and a
jr nz, .notFacingDown
; facing down
inc d
ret
.notFacingDown
cp SPRITE_FACING_UP
jr nz, .notFacingUp
; facing up
dec d
ret
.notFacingUp
cp SPRITE_FACING_LEFT
jr nz, .notFacingLeft
; facing left
dec e
ret
.notFacingLeft
; facing right
inc e
ret
|