pokemart.asm 6.0 KB

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