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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
DisplayPokemartDialogue_::
ld a, [wListScrollOffset]
ld [wSavedListScrollOffset], a
call UpdateSprites
xor a
ld [wBoughtOrSoldItemInMart], a
.loop
xor a
ld [wListScrollOffset], a
ld [wCurrentMenuItem], a
ld [wPlayerMonNumber], a
inc a
ld [wPrintItemPrices], a
ld a, MONEY_BOX
ld [wTextBoxID], a
call DisplayTextBoxID
ld a, BUY_SELL_QUIT_MENU
ld [wTextBoxID], a
call DisplayTextBoxID
; This code is useless. It copies the address of the pokemart's inventory to hl,
; but the address is never used.
ld hl, wItemListPointer
ld a, [hli]
ld l, [hl]
ld h, a
ld a, [wMenuExitMethod]
cp CANCELLED_MENU
jp z, .done
ld a, [wChosenMenuItem]
and a ; buying?
jp z, .buyMenu
dec a ; selling?
jp z, .sellMenu
dec a ; quitting?
jp z, .done
.sellMenu
; the same variables are set again below, so this code has no effect
xor a
ld [wPrintItemPrices], a
ld a, INIT_BAG_ITEM_LIST
ld [wInitListType], a
callfar InitList
ld a, [wNumBagItems]
and a
jp z, .bagEmpty
ld hl, PokemonSellingGreetingText
call PrintText
call SaveScreenTilesToBuffer1 ; save screen
.sellMenuLoop
call LoadScreenTilesFromBuffer1 ; restore saved screen
ld a, MONEY_BOX
ld [wTextBoxID], a
call DisplayTextBoxID ; draw money text box
ld hl, wNumBagItems
ld a, l
ld [wListPointer], a
ld a, h
ld [wListPointer + 1], a
xor a
ld [wPrintItemPrices], a
ld [wCurrentMenuItem], a
ld a, ITEMLISTMENU
ld [wListMenuID], a
call DisplayListMenuID
jp c, .returnToMainPokemartMenu ; if the player closed the menu
.confirmItemSale ; if the player is trying to sell a specific item
call IsKeyItem
ld a, [wIsKeyItem]
and a
jr nz, .unsellableItem
ld a, [wcf91]
call IsItemHM
jr c, .unsellableItem
ld a, PRICEDITEMLISTMENU
ld [wListMenuID], a
ldh [hHalveItemPrices], a ; halve prices when selling
call DisplayChooseQuantityMenu
inc a
jr z, .sellMenuLoop ; if the player closed the choose quantity menu with the B button
ld hl, PokemartTellSellPriceText
lb bc, 14, 1 ; location that PrintText always prints to, this is useless
call PrintText
hlcoord 14, 7
lb bc, 8, 15
ld a, TWO_OPTION_MENU
ld [wTextBoxID], a
call DisplayTextBoxID ; yes/no menu
ld a, [wMenuExitMethod]
cp CHOSE_SECOND_ITEM
jr z, .sellMenuLoop ; if the player chose No or pressed the B button
; The following code is supposed to check if the player chose No, but the above
; check already catches it.
ld a, [wChosenMenuItem]
dec a
jr z, .sellMenuLoop
.sellItem
ld a, [wBoughtOrSoldItemInMart]
and a
jr nz, .skipSettingFlag1
inc a
ld [wBoughtOrSoldItemInMart], a
.skipSettingFlag1
call AddAmountSoldToMoney
ld hl, wNumBagItems
call RemoveItemFromInventory
jp .sellMenuLoop
.unsellableItem
ld hl, PokemartUnsellableItemText
call PrintText
jp .returnToMainPokemartMenu
.bagEmpty
ld hl, PokemartItemBagEmptyText
call PrintText
call SaveScreenTilesToBuffer1
jp .returnToMainPokemartMenu
.buyMenu
; the same variables are set again below, so this code has no effect
ld a, 1
ld [wPrintItemPrices], a
ld a, INIT_OTHER_ITEM_LIST
ld [wInitListType], a
callfar InitList
ld hl, PokemartBuyingGreetingText
call PrintText
call SaveScreenTilesToBuffer1
.buyMenuLoop
call LoadScreenTilesFromBuffer1
ld a, MONEY_BOX
ld [wTextBoxID], a
call DisplayTextBoxID
ld hl, wItemList
ld a, l
ld [wListPointer], a
ld a, h
ld [wListPointer + 1], a
xor a
ld [wCurrentMenuItem], a
inc a
ld [wPrintItemPrices], a
inc a ; a = 2 (PRICEDITEMLISTMENU)
ld [wListMenuID], a
call DisplayListMenuID
jr c, .returnToMainPokemartMenu ; if the player closed the menu
ld a, 99
ld [wMaxItemQuantity], a
xor a
ldh [hHalveItemPrices], a ; don't halve item prices when buying
call DisplayChooseQuantityMenu
inc a
jr z, .buyMenuLoop ; if the player closed the choose quantity menu with the B button
ld a, [wcf91] ; item ID
ld [wd11e], a ; store item ID for GetItemName
call GetItemName
call CopyToStringBuffer
ld hl, PokemartTellBuyPriceText
call PrintText
hlcoord 14, 7
lb bc, 8, 15
ld a, TWO_OPTION_MENU
ld [wTextBoxID], a
call DisplayTextBoxID ; yes/no menu
ld a, [wMenuExitMethod]
cp CHOSE_SECOND_ITEM
jp z, .buyMenuLoop ; if the player chose No or pressed the B button
; The following code is supposed to check if the player chose No, but the above
; check already catches it.
ld a, [wChosenMenuItem]
dec a
jr z, .buyMenuLoop
.buyItem
call .isThereEnoughMoney
jr c, .notEnoughMoney
ld hl, wNumBagItems
call AddItemToInventory
jr nc, .bagFull
call SubtractAmountPaidFromMoney
ld a, [wBoughtOrSoldItemInMart]
and a
jr nz, .skipSettingFlag2
ld a, 1
ld [wBoughtOrSoldItemInMart], a
.skipSettingFlag2
ld a, SFX_PURCHASE
call PlaySoundWaitForCurrent
call WaitForSoundToFinish
ld hl, PokemartBoughtItemText
call PrintText
jp .buyMenuLoop
.returnToMainPokemartMenu
call LoadScreenTilesFromBuffer1
ld a, MONEY_BOX
ld [wTextBoxID], a
call DisplayTextBoxID
ld hl, PokemartAnythingElseText
call PrintText
jp .loop
.isThereEnoughMoney
ld de, wPlayerMoney
ld hl, hMoney
ld c, 3 ; length of money in bytes
jp StringCmp
.notEnoughMoney
ld hl, PokemartNotEnoughMoneyText
call PrintText
jr .returnToMainPokemartMenu
.bagFull
ld hl, PokemartItemBagFullText
call PrintText
jr .returnToMainPokemartMenu
.done
ld hl, PokemartThankYouText
call PrintText
ld a, 1
ld [wUpdateSpritesEnabled], a
call UpdateSprites
ld a, [wSavedListScrollOffset]
ld [wListScrollOffset], a
ret
PokemartBuyingGreetingText:
text_far _PokemartBuyingGreetingText
text_end
PokemartTellBuyPriceText:
text_far _PokemartTellBuyPriceText
text_end
PokemartBoughtItemText:
text_far _PokemartBoughtItemText
text_end
PokemartNotEnoughMoneyText:
text_far _PokemartNotEnoughMoneyText
text_end
PokemartItemBagFullText:
text_far _PokemartItemBagFullText
text_end
PokemonSellingGreetingText:
text_far _PokemonSellingGreetingText
text_end
PokemartTellSellPriceText:
text_far _PokemartTellSellPriceText
text_end
PokemartItemBagEmptyText:
text_far _PokemartItemBagEmptyText
text_end
PokemartUnsellableItemText:
text_far _PokemartUnsellableItemText
text_end
PokemartThankYouText:
text_far _PokemartThankYouText
text_end
PokemartAnythingElseText:
text_far _PokemartAnythingElseText
text_end
|