Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pret
GitHub Repository: pret/pokered
Path: blob/master/engine/events/pokemart.asm
1271 views
1
DisplayPokemartDialogue_::
2
ld a, [wListScrollOffset]
3
ld [wSavedListScrollOffset], a
4
call UpdateSprites
5
xor a
6
ld [wBoughtOrSoldItemInMart], a
7
.loop
8
xor a
9
ld [wListScrollOffset], a
10
ld [wCurrentMenuItem], a
11
ld [wPlayerMonNumber], a
12
inc a
13
ld [wPrintItemPrices], a
14
ld a, MONEY_BOX
15
ld [wTextBoxID], a
16
call DisplayTextBoxID
17
ld a, BUY_SELL_QUIT_MENU
18
ld [wTextBoxID], a
19
call DisplayTextBoxID
20
21
; This code is useless. It copies the address of the pokemart's inventory to hl,
22
; but the address is never used.
23
ld hl, wItemListPointer
24
ld a, [hli]
25
ld l, [hl]
26
ld h, a
27
28
ld a, [wMenuExitMethod]
29
cp CANCELLED_MENU
30
jp z, .done
31
ld a, [wChosenMenuItem]
32
and a ; buying?
33
jp z, .buyMenu
34
dec a ; selling?
35
jp z, .sellMenu
36
dec a ; quitting?
37
jp z, .done
38
.sellMenu
39
40
; the same variables are set again below, so this code has no effect
41
xor a
42
ld [wPrintItemPrices], a
43
ld a, INIT_BAG_ITEM_LIST
44
ld [wInitListType], a
45
callfar InitList
46
47
ld a, [wNumBagItems]
48
and a
49
jp z, .bagEmpty
50
ld hl, PokemonSellingGreetingText
51
call PrintText
52
call SaveScreenTilesToBuffer1 ; save screen
53
.sellMenuLoop
54
call LoadScreenTilesFromBuffer1 ; restore saved screen
55
ld a, MONEY_BOX
56
ld [wTextBoxID], a
57
call DisplayTextBoxID ; draw money text box
58
ld hl, wNumBagItems
59
ld a, l
60
ld [wListPointer], a
61
ld a, h
62
ld [wListPointer + 1], a
63
xor a
64
ld [wPrintItemPrices], a
65
ld [wCurrentMenuItem], a
66
ld a, ITEMLISTMENU
67
ld [wListMenuID], a
68
call DisplayListMenuID
69
jp c, .returnToMainPokemartMenu ; if the player closed the menu
70
.confirmItemSale ; if the player is trying to sell a specific item
71
call IsKeyItem
72
ld a, [wIsKeyItem]
73
and a
74
jr nz, .unsellableItem
75
ld a, [wCurItem]
76
call IsItemHM
77
jr c, .unsellableItem
78
ld a, PRICEDITEMLISTMENU
79
ld [wListMenuID], a
80
ldh [hHalveItemPrices], a ; halve prices when selling
81
call DisplayChooseQuantityMenu
82
inc a
83
jr z, .sellMenuLoop ; if the player closed the choose quantity menu with the B button
84
ld hl, PokemartTellSellPriceText
85
lb bc, 14, 1 ; location that PrintText always prints to, this is useless
86
call PrintText
87
hlcoord 14, 7
88
lb bc, 8, 15
89
ld a, TWO_OPTION_MENU
90
ld [wTextBoxID], a
91
call DisplayTextBoxID ; yes/no menu
92
ld a, [wMenuExitMethod]
93
cp CHOSE_SECOND_ITEM
94
jr z, .sellMenuLoop ; if the player chose No or pressed the B button
95
96
; The following code is supposed to check if the player chose No, but the above
97
; check already catches it.
98
ld a, [wChosenMenuItem]
99
dec a
100
jr z, .sellMenuLoop
101
102
.sellItem
103
ld a, [wBoughtOrSoldItemInMart]
104
and a
105
jr nz, .skipSettingFlag1
106
inc a
107
ld [wBoughtOrSoldItemInMart], a
108
.skipSettingFlag1
109
call AddAmountSoldToMoney
110
ld hl, wNumBagItems
111
call RemoveItemFromInventory
112
jp .sellMenuLoop
113
.unsellableItem
114
ld hl, PokemartUnsellableItemText
115
call PrintText
116
jp .returnToMainPokemartMenu
117
.bagEmpty
118
ld hl, PokemartItemBagEmptyText
119
call PrintText
120
call SaveScreenTilesToBuffer1
121
jp .returnToMainPokemartMenu
122
.buyMenu
123
124
; the same variables are set again below, so this code has no effect
125
ld a, 1
126
ld [wPrintItemPrices], a
127
ld a, INIT_OTHER_ITEM_LIST
128
ld [wInitListType], a
129
callfar InitList
130
131
ld hl, PokemartBuyingGreetingText
132
call PrintText
133
call SaveScreenTilesToBuffer1
134
.buyMenuLoop
135
call LoadScreenTilesFromBuffer1
136
ld a, MONEY_BOX
137
ld [wTextBoxID], a
138
call DisplayTextBoxID
139
ld hl, wItemList
140
ld a, l
141
ld [wListPointer], a
142
ld a, h
143
ld [wListPointer + 1], a
144
xor a
145
ld [wCurrentMenuItem], a
146
inc a
147
ld [wPrintItemPrices], a
148
inc a ; a = 2 (PRICEDITEMLISTMENU)
149
ld [wListMenuID], a
150
call DisplayListMenuID
151
jr c, .returnToMainPokemartMenu ; if the player closed the menu
152
ld a, 99
153
ld [wMaxItemQuantity], a
154
xor a
155
ldh [hHalveItemPrices], a ; don't halve item prices when buying
156
call DisplayChooseQuantityMenu
157
inc a
158
jr z, .buyMenuLoop ; if the player closed the choose quantity menu with the B button
159
ld a, [wCurItem]
160
ld [wNamedObjectIndex], a
161
call GetItemName
162
call CopyToStringBuffer
163
ld hl, PokemartTellBuyPriceText
164
call PrintText
165
hlcoord 14, 7
166
lb bc, 8, 15
167
ld a, TWO_OPTION_MENU
168
ld [wTextBoxID], a
169
call DisplayTextBoxID ; yes/no menu
170
ld a, [wMenuExitMethod]
171
cp CHOSE_SECOND_ITEM
172
jp z, .buyMenuLoop ; if the player chose No or pressed the B button
173
174
; The following code is supposed to check if the player chose No, but the above
175
; check already catches it.
176
ld a, [wChosenMenuItem]
177
dec a
178
jr z, .buyMenuLoop
179
180
.buyItem
181
call .isThereEnoughMoney
182
jr c, .notEnoughMoney
183
ld hl, wNumBagItems
184
call AddItemToInventory
185
jr nc, .bagFull
186
call SubtractAmountPaidFromMoney
187
ld a, [wBoughtOrSoldItemInMart]
188
and a
189
jr nz, .skipSettingFlag2
190
ld a, 1
191
ld [wBoughtOrSoldItemInMart], a
192
.skipSettingFlag2
193
ld a, SFX_PURCHASE
194
call PlaySoundWaitForCurrent
195
call WaitForSoundToFinish
196
ld hl, PokemartBoughtItemText
197
call PrintText
198
jp .buyMenuLoop
199
.returnToMainPokemartMenu
200
call LoadScreenTilesFromBuffer1
201
ld a, MONEY_BOX
202
ld [wTextBoxID], a
203
call DisplayTextBoxID
204
ld hl, PokemartAnythingElseText
205
call PrintText
206
jp .loop
207
.isThereEnoughMoney
208
ld de, wPlayerMoney
209
ld hl, hMoney
210
ld c, 3 ; length of money in bytes
211
jp StringCmp
212
.notEnoughMoney
213
ld hl, PokemartNotEnoughMoneyText
214
call PrintText
215
jr .returnToMainPokemartMenu
216
.bagFull
217
ld hl, PokemartItemBagFullText
218
call PrintText
219
jr .returnToMainPokemartMenu
220
.done
221
ld hl, PokemartThankYouText
222
call PrintText
223
ld a, 1
224
ld [wUpdateSpritesEnabled], a
225
call UpdateSprites
226
ld a, [wSavedListScrollOffset]
227
ld [wListScrollOffset], a
228
ret
229
230
PokemartBuyingGreetingText:
231
text_far _PokemartBuyingGreetingText
232
text_end
233
234
PokemartTellBuyPriceText:
235
text_far _PokemartTellBuyPriceText
236
text_end
237
238
PokemartBoughtItemText:
239
text_far _PokemartBoughtItemText
240
text_end
241
242
PokemartNotEnoughMoneyText:
243
text_far _PokemartNotEnoughMoneyText
244
text_end
245
246
PokemartItemBagFullText:
247
text_far _PokemartItemBagFullText
248
text_end
249
250
PokemonSellingGreetingText:
251
text_far _PokemonSellingGreetingText
252
text_end
253
254
PokemartTellSellPriceText:
255
text_far _PokemartTellSellPriceText
256
text_end
257
258
PokemartItemBagEmptyText:
259
text_far _PokemartItemBagEmptyText
260
text_end
261
262
PokemartUnsellableItemText:
263
text_far _PokemartUnsellableItemText
264
text_end
265
266
PokemartThankYouText:
267
text_far _PokemartThankYouText
268
text_end
269
270
PokemartAnythingElseText:
271
text_far _PokemartAnythingElseText
272
text_end
273
274