pokered/engine/events/pokemart.asm

273 lines
6.1 KiB
NASM
Raw Normal View History

DisplayPokemartDialogue_::
ld a, [wListScrollOffset]
ld [wSavedListScrollOffset], a
call UpdateSprites
2014-05-22 22:13:20 +00:00
xor a
ld [wBoughtOrSoldItemInMart], a
2014-05-22 22:13:20 +00:00
.loop
xor a
ld [wListScrollOffset], a
ld [wCurrentMenuItem], a
ld [wPlayerMonNumber], a
2014-05-22 22:13:20 +00:00
inc a
ld [wPrintItemPrices], a
ld a, MONEY_BOX
ld [wTextBoxID], a
2015-07-13 06:00:48 +00:00
call DisplayTextBoxID
ld a, BUY_SELL_QUIT_MENU
ld [wTextBoxID], a
2015-07-13 06:00:48 +00:00
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
2015-07-13 06:00:48 +00:00
ld a, [wMenuExitMethod]
cp CANCELLED_MENU
jp z, .done
ld a, [wChosenMenuItem]
2014-05-22 22:13:20 +00:00
and a ; buying?
jp z, .buyMenu
2014-05-22 22:13:20 +00:00
dec a ; selling?
jp z, .sellMenu
2014-05-22 22:13:20 +00:00
dec a ; quitting?
jp z, .done
2014-05-22 22:13:20 +00:00
.sellMenu
2015-07-13 06:00:48 +00:00
; the same variables are set again below, so this code has no effect
2014-05-22 22:13:20 +00:00
xor a
ld [wPrintItemPrices], a
ld a, INIT_BAG_ITEM_LIST
ld [wInitListType], a
callab InitList
2015-07-13 06:00:48 +00:00
ld a, [wNumBagItems]
2014-05-22 22:13:20 +00:00
and a
jp z, .bagEmpty
ld hl, PokemonSellingGreetingText
2014-05-22 22:13:20 +00:00
call PrintText
call SaveScreenTilesToBuffer1 ; save screen
.sellMenuLoop
call LoadScreenTilesFromBuffer1 ; restore saved screen
ld a, MONEY_BOX
ld [wTextBoxID], a
2014-05-22 22:13:20 +00:00
call DisplayTextBoxID ; draw money text box
ld hl, wNumBagItems
ld a, l
ld [wListPointer], a
ld a, h
ld [wListPointer + 1], a
2014-05-22 22:13:20 +00:00
xor a
ld [wPrintItemPrices], a
ld [wCurrentMenuItem], a
ld a, ITEMLISTMENU
ld [wListMenuID], a
2014-05-22 22:13:20 +00:00
call DisplayListMenuID
jp c, .returnToMainPokemartMenu ; if the player closed the menu
2014-05-22 22:13:20 +00:00
.confirmItemSale ; if the player is trying to sell a specific item
2015-07-13 06:00:48 +00:00
call IsKeyItem
ld a, [wIsKeyItem]
2014-05-22 22:13:20 +00:00
and a
jr nz, .unsellableItem
ld a, [wcf91]
2014-05-22 22:13:20 +00:00
call IsItemHM
jr c, .unsellableItem
ld a, PRICEDITEMLISTMENU
ld [wListMenuID], a
ld [hHalveItemPrices], a ; halve prices when selling
2014-05-22 22:13:20 +00:00
call DisplayChooseQuantityMenu
inc a
jr z, .sellMenuLoop ; if the player closed the choose quantity menu with the B button
ld hl, PokemartTellSellPriceText
2015-08-05 21:20:29 +00:00
lb bc, 14, 1 ; location that PrintText always prints to, this is useless
2014-05-22 22:13:20 +00:00
call PrintText
2015-07-18 20:52:03 +00:00
coord hl, 14, 7
2016-06-12 04:30:05 +00:00
lb bc, 8, 15
ld a, TWO_OPTION_MENU
ld [wTextBoxID], a
2014-05-22 22:13:20 +00:00
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
2015-07-13 06:00:48 +00:00
; The following code is supposed to check if the player chose No, but the above
; check already catches it.
ld a, [wChosenMenuItem]
2014-05-22 22:13:20 +00:00
dec a
jr z, .sellMenuLoop
2015-07-13 06:00:48 +00:00
2014-05-22 22:13:20 +00:00
.sellItem
ld a, [wBoughtOrSoldItemInMart]
2014-05-22 22:13:20 +00:00
and a
jr nz, .skipSettingFlag1
2014-05-22 22:13:20 +00:00
inc a
ld [wBoughtOrSoldItemInMart], a
2014-05-22 22:13:20 +00:00
.skipSettingFlag1
call AddAmountSoldToMoney
ld hl, wNumBagItems
2014-05-22 22:13:20 +00:00
call RemoveItemFromInventory
jp .sellMenuLoop
.unsellableItem
ld hl, PokemartUnsellableItemText
2014-05-22 22:13:20 +00:00
call PrintText
jp .returnToMainPokemartMenu
.bagEmpty
ld hl, PokemartItemBagEmptyText
2014-05-22 22:13:20 +00:00
call PrintText
2015-07-13 06:00:48 +00:00
call SaveScreenTilesToBuffer1
2014-05-22 22:13:20 +00:00
jp .returnToMainPokemartMenu
.buyMenu
2015-07-13 06:00:48 +00:00
; 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
callab InitList
2015-07-13 06:00:48 +00:00
ld hl, PokemartBuyingGreetingText
2014-05-22 22:13:20 +00:00
call PrintText
2015-07-13 06:00:48 +00:00
call SaveScreenTilesToBuffer1
2014-05-22 22:13:20 +00:00
.buyMenuLoop
2015-07-13 06:00:48 +00:00
call LoadScreenTilesFromBuffer1
ld a, MONEY_BOX
ld [wTextBoxID], a
2015-07-13 06:00:48 +00:00
call DisplayTextBoxID
ld hl, wItemList
ld a, l
ld [wListPointer], a
ld a, h
ld [wListPointer + 1], a
2014-05-22 22:13:20 +00:00
xor a
ld [wCurrentMenuItem], a
2014-05-22 22:13:20 +00:00
inc a
ld [wPrintItemPrices], a
2014-05-22 22:13:20 +00:00
inc a ; a = 2 (PRICEDITEMLISTMENU)
ld [wListMenuID], a
2014-05-22 22:13:20 +00:00
call DisplayListMenuID
jr c, .returnToMainPokemartMenu ; if the player closed the menu
ld a, 99
ld [wMaxItemQuantity], a
2014-05-22 22:13:20 +00:00
xor a
ld [hHalveItemPrices], a ; don't halve item prices when buying
2014-05-22 22:13:20 +00:00
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
2014-05-22 22:13:20 +00:00
call GetItemName
call CopyStringToCF4B ; copy name to wcf4b
ld hl, PokemartTellBuyPriceText
2014-05-22 22:13:20 +00:00
call PrintText
2015-07-18 20:52:03 +00:00
coord hl, 14, 7
2015-08-05 21:20:29 +00:00
lb bc, 8, 15
ld a, TWO_OPTION_MENU
ld [wTextBoxID], a
2014-05-22 22:13:20 +00:00
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
2015-07-13 06:00:48 +00:00
; The following code is supposed to check if the player chose No, but the above
; check already catches it.
ld a, [wChosenMenuItem]
2014-05-22 22:13:20 +00:00
dec a
jr z, .buyMenuLoop
2015-07-13 06:00:48 +00:00
2014-05-22 22:13:20 +00:00
.buyItem
call .isThereEnoughMoney
jr c, .notEnoughMoney
ld hl, wNumBagItems
2014-05-22 22:13:20 +00:00
call AddItemToInventory
jr nc, .bagFull
2014-05-22 22:13:20 +00:00
call SubtractAmountPaidFromMoney
ld a, [wBoughtOrSoldItemInMart]
2014-05-22 22:13:20 +00:00
and a
jr nz, .skipSettingFlag2
ld a, 1
ld [wBoughtOrSoldItemInMart], a
2014-05-22 22:13:20 +00:00
.skipSettingFlag2
ld a, SFX_PURCHASE
call PlaySoundWaitForCurrent
call WaitForSoundToFinish
ld hl, PokemartBoughtItemText
2014-05-22 22:13:20 +00:00
call PrintText
jp .buyMenuLoop
.returnToMainPokemartMenu
call LoadScreenTilesFromBuffer1
ld a, MONEY_BOX
ld [wTextBoxID], a
2015-07-13 06:00:48 +00:00
call DisplayTextBoxID
ld hl, PokemartAnythingElseText
2014-05-22 22:13:20 +00:00
call PrintText
jp .loop
.isThereEnoughMoney
ld de, wPlayerMoney
ld hl, hMoney
ld c, 3 ; length of money in bytes
2014-05-22 22:13:20 +00:00
jp StringCmp
.notEnoughMoney
ld hl, PokemartNotEnoughMoneyText
2014-05-22 22:13:20 +00:00
call PrintText
jr .returnToMainPokemartMenu
.bagFull
ld hl, PokemartItemBagFullText
2014-05-22 22:13:20 +00:00
call PrintText
jr .returnToMainPokemartMenu
.done
ld hl, PokemartThankYouText
2014-05-22 22:13:20 +00:00
call PrintText
ld a, 1
ld [wUpdateSpritesEnabled], a
call UpdateSprites
ld a, [wSavedListScrollOffset]
ld [wListScrollOffset], a
2014-05-22 22:13:20 +00:00
ret
2016-06-12 00:24:04 +00:00
PokemartBuyingGreetingText:
text_far _PokemartBuyingGreetingText
text_end
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
PokemartTellBuyPriceText:
text_far _PokemartTellBuyPriceText
text_end
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
PokemartBoughtItemText:
text_far _PokemartBoughtItemText
text_end
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
PokemartNotEnoughMoneyText:
text_far _PokemartNotEnoughMoneyText
text_end
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
PokemartItemBagFullText:
text_far _PokemartItemBagFullText
text_end
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
PokemonSellingGreetingText:
text_far _PokemonSellingGreetingText
text_end
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
PokemartTellSellPriceText:
text_far _PokemartTellSellPriceText
text_end
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
PokemartItemBagEmptyText:
text_far _PokemartItemBagEmptyText
text_end
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
PokemartUnsellableItemText:
text_far _PokemartUnsellableItemText
text_end
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
PokemartThankYouText:
text_far _PokemartThankYouText
text_end
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
PokemartAnythingElseText:
text_far _PokemartAnythingElseText
text_end