pokered/engine/overworld/pokemart.asm

273 lines
5.9 KiB
NASM
Raw Normal View History

2016-06-12 00:24:04 +00:00
DisplayPokemartDialogue_:
2014-05-22 22:13:20 +00:00
ld a,[wListScrollOffset]
2015-07-13 06:00:48 +00:00
ld [wSavedListScrollOffset],a
call UpdateSprites
2014-05-22 22:13:20 +00:00
xor a
2015-07-13 06:00:48 +00:00
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
2015-07-13 06:00:48 +00:00
ld [wPrintItemPrices],a
2015-02-07 20:27:36 +00:00
ld a,MONEY_BOX
2015-02-07 10:43:08 +00:00
ld [wTextBoxID],a
2015-07-13 06:00:48 +00:00
call DisplayTextBoxID
2015-02-07 20:27:36 +00:00
ld a,BUY_SELL_QUIT_MENU
2015-02-07 10:43:08 +00:00
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
2014-05-22 22:13:20 +00:00
ld a,[hli]
ld l,[hl]
2015-07-13 06:00:48 +00:00
ld h,a
ld a,[wMenuExitMethod]
cp a,CANCELLED_MENU
2014-05-22 22:13:20 +00:00
jp z,.done
2015-07-13 06:00:48 +00:00
ld a,[wChosenMenuItem]
2014-05-22 22:13:20 +00:00
and a ; buying?
jp z,.buyMenu
dec a ; selling?
jp z,.sellMenu
dec a ; quitting?
jp z,.done
.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
2015-07-13 06:00:48 +00:00
ld [wPrintItemPrices],a
ld a,INIT_BAG_ITEM_LIST
ld [wInitListType],a
callab InitList
2015-07-13 06:00:48 +00:00
2014-05-22 22:13:20 +00:00
ld a,[wNumBagItems]
and a
jp z,.bagEmpty
ld hl,PokemonSellingGreetingText
call PrintText
call SaveScreenTilesToBuffer1 ; save screen
.sellMenuLoop
call LoadScreenTilesFromBuffer1 ; restore saved screen
2015-02-07 20:27:36 +00:00
ld a,MONEY_BOX
2015-02-07 10:43:08 +00:00
ld [wTextBoxID],a
2014-05-22 22:13:20 +00:00
call DisplayTextBoxID ; draw money text box
ld hl,wNumBagItems
ld a,l
2015-07-15 06:16:06 +00:00
ld [wListPointer],a
2014-05-22 22:13:20 +00:00
ld a,h
2015-07-15 06:16:06 +00:00
ld [wListPointer + 1],a
2014-05-22 22:13:20 +00:00
xor a
2015-07-13 06:00:48 +00:00
ld [wPrintItemPrices],a
2014-05-22 22:13:20 +00:00
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
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
2015-07-13 06:00:48 +00:00
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
2015-02-07 20:27:36 +00:00
ld a,TWO_OPTION_MENU
2015-02-07 10:43:08 +00:00
ld [wTextBoxID],a
2014-05-22 22:13:20 +00:00
call DisplayTextBoxID ; yes/no menu
2015-07-13 06:00:48 +00:00
ld a,[wMenuExitMethod]
cp a,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]
2014-05-22 22:13:20 +00:00
dec a
2015-07-13 06:00:48 +00:00
jr z,.sellMenuLoop
2014-05-22 22:13:20 +00:00
.sellItem
2015-07-13 06:00:48 +00:00
ld a,[wBoughtOrSoldItemInMart]
2014-05-22 22:13:20 +00:00
and a
jr nz,.skipSettingFlag1
inc a
2015-07-13 06:00:48 +00:00
ld [wBoughtOrSoldItemInMart],a
2014-05-22 22:13:20 +00:00
.skipSettingFlag1
call AddAmountSoldToMoney
ld hl,wNumBagItems
call RemoveItemFromInventory
jp .sellMenuLoop
.unsellableItem
ld hl,PokemartUnsellableItemText
call PrintText
jp .returnToMainPokemartMenu
.bagEmpty
ld hl,PokemartItemBagEmptyText
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
2014-05-22 22:13:20 +00:00
ld hl,PokemartBuyingGreetingText
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
2015-02-07 20:27:36 +00:00
ld a,MONEY_BOX
2015-02-07 10:43:08 +00:00
ld [wTextBoxID],a
2015-07-13 06:00:48 +00:00
call DisplayTextBoxID
2015-07-15 06:16:06 +00:00
ld hl,wItemList
2014-05-22 22:13:20 +00:00
ld a,l
2015-07-15 06:16:06 +00:00
ld [wListPointer],a
2014-05-22 22:13:20 +00:00
ld a,h
2015-07-15 06:16:06 +00:00
ld [wListPointer + 1],a
2014-05-22 22:13:20 +00:00
xor a
ld [wCurrentMenuItem],a
inc a
2015-07-13 06:00:48 +00:00
ld [wPrintItemPrices],a
2014-05-22 22:13:20 +00:00
inc a ; a = 2 (PRICEDITEMLISTMENU)
ld [wListMenuID],a
call DisplayListMenuID
jr c,.returnToMainPokemartMenu ; if the player closed the menu
2015-07-13 06:00:48 +00:00
ld a,99
ld [wMaxItemQuantity],a
2014-05-22 22:13:20 +00:00
xor a
2015-07-13 06:00:48 +00:00
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
2014-05-22 22:13:20 +00:00
ld hl,PokemartTellBuyPriceText
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
2015-02-07 20:27:36 +00:00
ld a,TWO_OPTION_MENU
2015-02-07 10:43:08 +00:00
ld [wTextBoxID],a
2014-05-22 22:13:20 +00:00
call DisplayTextBoxID ; yes/no menu
2015-07-13 06:00:48 +00:00
ld a,[wMenuExitMethod]
cp a,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]
2014-05-22 22:13:20 +00:00
dec a
2015-07-13 06:00:48 +00:00
jr z,.buyMenuLoop
2014-05-22 22:13:20 +00:00
.buyItem
call .isThereEnoughMoney
jr c,.notEnoughMoney
ld hl,wNumBagItems
call AddItemToInventory
jr nc,.bagFull
call SubtractAmountPaidFromMoney
2015-07-13 06:00:48 +00:00
ld a,[wBoughtOrSoldItemInMart]
2014-05-22 22:13:20 +00:00
and a
jr nz,.skipSettingFlag2
2015-07-13 06:00:48 +00:00
ld a,1
ld [wBoughtOrSoldItemInMart],a
2014-05-22 22:13:20 +00:00
.skipSettingFlag2
2015-07-19 08:46:12 +00:00
ld a,SFX_PURCHASE
call PlaySoundWaitForCurrent
call WaitForSoundToFinish
2014-05-22 22:13:20 +00:00
ld hl,PokemartBoughtItemText
call PrintText
jp .buyMenuLoop
.returnToMainPokemartMenu
call LoadScreenTilesFromBuffer1
2015-02-07 20:27:36 +00:00
ld a,MONEY_BOX
2015-02-07 10:43:08 +00:00
ld [wTextBoxID],a
2015-07-13 06:00:48 +00:00
call DisplayTextBoxID
2014-05-22 22:13:20 +00:00
ld hl,PokemartAnythingElseText
call PrintText
jp .loop
.isThereEnoughMoney
ld de,wPlayerMoney
2015-07-17 08:21:40 +00:00
ld hl,hMoney
2014-05-22 22:13:20 +00:00
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
2015-07-13 06:00:48 +00:00
ld a,1
2014-09-13 07:50:56 +00:00
ld [wUpdateSpritesEnabled],a
call UpdateSprites
2015-07-13 06:00:48 +00:00
ld a,[wSavedListScrollOffset]
2014-05-22 22:13:20 +00:00
ld [wListScrollOffset],a
ret
2016-06-12 00:24:04 +00:00
PokemartBuyingGreetingText:
2014-05-22 22:13:20 +00:00
TX_FAR _PokemartBuyingGreetingText
db "@"
2016-06-12 00:24:04 +00:00
PokemartTellBuyPriceText:
2014-05-22 22:13:20 +00:00
TX_FAR _PokemartTellBuyPriceText
db "@"
2016-06-12 00:24:04 +00:00
PokemartBoughtItemText:
2014-05-22 22:13:20 +00:00
TX_FAR _PokemartBoughtItemText
db "@"
2016-06-12 00:24:04 +00:00
PokemartNotEnoughMoneyText:
2014-05-22 22:13:20 +00:00
TX_FAR _PokemartNotEnoughMoneyText
db "@"
2016-06-12 00:24:04 +00:00
PokemartItemBagFullText:
2014-05-22 22:13:20 +00:00
TX_FAR _PokemartItemBagFullText
db "@"
2016-06-12 00:24:04 +00:00
PokemonSellingGreetingText:
2014-05-22 22:13:20 +00:00
TX_FAR _PokemonSellingGreetingText
db "@"
2016-06-12 00:24:04 +00:00
PokemartTellSellPriceText:
2014-05-22 22:13:20 +00:00
TX_FAR _PokemartTellSellPriceText
db "@"
2016-06-12 00:24:04 +00:00
PokemartItemBagEmptyText:
2014-05-22 22:13:20 +00:00
TX_FAR _PokemartItemBagEmptyText
db "@"
2016-06-12 00:24:04 +00:00
PokemartUnsellableItemText:
2014-05-22 22:13:20 +00:00
TX_FAR _PokemartUnsellableItemText
db "@"
2016-06-12 00:24:04 +00:00
PokemartThankYouText:
2014-05-22 22:13:20 +00:00
TX_FAR _PokemartThankYouText
db "@"
2016-06-12 00:24:04 +00:00
PokemartAnythingElseText:
2014-05-22 22:13:20 +00:00
TX_FAR _PokemartAnythingElseText
db "@"