in_game_trades.asm 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. DoInGameTradeDialogue:
  2. ; trigger the trade offer/action specified by wWhichTrade
  3. call SaveScreenTilesToBuffer2
  4. ld hl, TradeMons
  5. ld a, [wWhichTrade]
  6. ld b, a
  7. swap a
  8. sub b
  9. sub b
  10. ld c, a
  11. ld b, 0
  12. add hl, bc
  13. ld a, [hli]
  14. ld [wInGameTradeGiveMonSpecies], a
  15. ld a, [hli]
  16. ld [wInGameTradeReceiveMonSpecies], a
  17. ld a, [hli]
  18. push af
  19. ld de, wInGameTradeMonNick
  20. ld bc, NAME_LENGTH
  21. call CopyData
  22. pop af
  23. ld l, a
  24. ld h, 0
  25. ld de, InGameTradeTextPointers
  26. add hl, hl
  27. add hl, de
  28. ld a, [hli]
  29. ld [wInGameTradeTextPointerTablePointer], a
  30. ld a, [hl]
  31. ld [wInGameTradeTextPointerTablePointer + 1], a
  32. ld a, [wInGameTradeGiveMonSpecies]
  33. ld de, wInGameTradeGiveMonName
  34. call InGameTrade_GetMonName
  35. ld a, [wInGameTradeReceiveMonSpecies]
  36. ld de, wInGameTradeReceiveMonName
  37. call InGameTrade_GetMonName
  38. ld hl, wCompletedInGameTradeFlags
  39. ld a, [wWhichTrade]
  40. ld c, a
  41. ld b, FLAG_TEST
  42. predef FlagActionPredef
  43. ld a, c
  44. and a
  45. ld a, $4
  46. ld [wInGameTradeTextPointerTableIndex], a
  47. jr nz, .printText
  48. ; if the trade hasn't been done yet
  49. xor a
  50. ld [wInGameTradeTextPointerTableIndex], a
  51. call .printText
  52. ld a, $1
  53. ld [wInGameTradeTextPointerTableIndex], a
  54. call YesNoChoice
  55. ld a, [wCurrentMenuItem]
  56. and a
  57. jr nz, .printText
  58. call InGameTrade_DoTrade
  59. jr c, .printText
  60. ld hl, TradedForText
  61. call PrintText
  62. .printText
  63. ld hl, wInGameTradeTextPointerTableIndex
  64. ld a, [hld] ; wInGameTradeTextPointerTableIndex
  65. ld e, a
  66. ld d, 0
  67. ld a, [hld] ; wInGameTradeTextPointerTablePointer + 1
  68. ld l, [hl] ; wInGameTradeTextPointerTablePointer
  69. ld h, a
  70. add hl, de
  71. add hl, de
  72. ld a, [hli]
  73. ld h, [hl]
  74. ld l, a
  75. jp PrintText
  76. ; copies name of species a to hl
  77. InGameTrade_GetMonName:
  78. push de
  79. ld [wd11e], a
  80. call GetMonName
  81. ld hl, wcd6d
  82. pop de
  83. ld bc, NAME_LENGTH
  84. jp CopyData
  85. INCLUDE "data/trades.asm"
  86. InGameTrade_DoTrade:
  87. xor a ; NORMAL_PARTY_MENU
  88. ld [wPartyMenuTypeOrMessageID], a
  89. dec a
  90. ld [wUpdateSpritesEnabled], a
  91. call DisplayPartyMenu
  92. push af
  93. call InGameTrade_RestoreScreen
  94. pop af
  95. ld a, $1
  96. jp c, .tradeFailed ; jump if the player didn't select a pokemon
  97. ld a, [wInGameTradeGiveMonSpecies]
  98. ld b, a
  99. ld a, [wcf91]
  100. cp b
  101. ld a, $2
  102. jr nz, .tradeFailed ; jump if the selected mon's species is not the required one
  103. ld a, [wWhichPokemon]
  104. ld hl, wPartyMon1Level
  105. ld bc, wPartyMon2 - wPartyMon1
  106. call AddNTimes
  107. ld a, [hl]
  108. ld [wCurEnemyLVL], a
  109. ld hl, wCompletedInGameTradeFlags
  110. ld a, [wWhichTrade]
  111. ld c, a
  112. ld b, FLAG_SET
  113. predef FlagActionPredef
  114. ld hl, ConnectCableText
  115. call PrintText
  116. ld a, [wWhichPokemon]
  117. push af
  118. ld a, [wCurEnemyLVL]
  119. push af
  120. call LoadHpBarAndStatusTilePatterns
  121. call InGameTrade_PrepareTradeData
  122. predef InternalClockTradeAnim
  123. pop af
  124. ld [wCurEnemyLVL], a
  125. pop af
  126. ld [wWhichPokemon], a
  127. ld a, [wInGameTradeReceiveMonSpecies]
  128. ld [wcf91], a
  129. xor a
  130. ld [wMonDataLocation], a ; not used
  131. ld [wRemoveMonFromBox], a
  132. call RemovePokemon
  133. ld a, $80 ; prevent the player from naming the mon
  134. ld [wMonDataLocation], a
  135. call AddPartyMon
  136. call InGameTrade_CopyDataToReceivedMon
  137. callab EvolveTradeMon
  138. call ClearScreen
  139. call InGameTrade_RestoreScreen
  140. callba RedrawMapView
  141. and a
  142. ld a, $3
  143. jr .tradeSucceeded
  144. .tradeFailed
  145. scf
  146. .tradeSucceeded
  147. ld [wInGameTradeTextPointerTableIndex], a
  148. ret
  149. InGameTrade_RestoreScreen:
  150. call GBPalWhiteOutWithDelay3
  151. call RestoreScreenTilesAndReloadTilePatterns
  152. call ReloadTilesetTilePatterns
  153. call LoadScreenTilesFromBuffer2
  154. call Delay3
  155. call LoadGBPal
  156. ld c, 10
  157. call DelayFrames
  158. jpba LoadWildData
  159. InGameTrade_PrepareTradeData:
  160. ld hl, wTradedPlayerMonSpecies
  161. ld a, [wInGameTradeGiveMonSpecies]
  162. ld [hli], a ; wTradedPlayerMonSpecies
  163. ld a, [wInGameTradeReceiveMonSpecies]
  164. ld [hl], a ; wTradedEnemyMonSpecies
  165. ld hl, wPartyMonOT
  166. ld bc, NAME_LENGTH
  167. ld a, [wWhichPokemon]
  168. call AddNTimes
  169. ld de, wTradedPlayerMonOT
  170. ld bc, NAME_LENGTH
  171. call InGameTrade_CopyData
  172. ld hl, InGameTrade_TrainerString
  173. ld de, wTradedEnemyMonOT
  174. call InGameTrade_CopyData
  175. ld de, wLinkEnemyTrainerName
  176. call InGameTrade_CopyData
  177. ld hl, wPartyMon1OTID
  178. ld bc, wPartyMon2 - wPartyMon1
  179. ld a, [wWhichPokemon]
  180. call AddNTimes
  181. ld de, wTradedPlayerMonOTID
  182. ld bc, $2
  183. call InGameTrade_CopyData
  184. call Random
  185. ld hl, hRandomAdd
  186. ld de, wTradedEnemyMonOTID
  187. jp CopyData
  188. InGameTrade_CopyData:
  189. push hl
  190. push bc
  191. call CopyData
  192. pop bc
  193. pop hl
  194. ret
  195. InGameTrade_CopyDataToReceivedMon:
  196. ld hl, wPartyMonNicks
  197. ld bc, NAME_LENGTH
  198. call InGameTrade_GetReceivedMonPointer
  199. ld hl, wInGameTradeMonNick
  200. ld bc, NAME_LENGTH
  201. call CopyData
  202. ld hl, wPartyMonOT
  203. ld bc, NAME_LENGTH
  204. call InGameTrade_GetReceivedMonPointer
  205. ld hl, InGameTrade_TrainerString
  206. ld bc, NAME_LENGTH
  207. call CopyData
  208. ld hl, wPartyMon1OTID
  209. ld bc, wPartyMon2 - wPartyMon1
  210. call InGameTrade_GetReceivedMonPointer
  211. ld hl, wTradedEnemyMonOTID
  212. ld bc, $2
  213. jp CopyData
  214. ; the received mon's index is (partyCount - 1),
  215. ; so this adds bc to hl (partyCount - 1) times and moves the result to de
  216. InGameTrade_GetReceivedMonPointer:
  217. ld a, [wPartyCount]
  218. dec a
  219. call AddNTimes
  220. ld e, l
  221. ld d, h
  222. ret
  223. InGameTrade_TrainerString:
  224. ; "TRAINER@@@@@@@@@@"
  225. db $5d, "@@@@@@@@@@"
  226. InGameTradeTextPointers:
  227. dw TradeTextPointers1
  228. dw TradeTextPointers2
  229. dw TradeTextPointers3
  230. TradeTextPointers1:
  231. dw WannaTrade1Text
  232. dw NoTrade1Text
  233. dw WrongMon1Text
  234. dw Thanks1Text
  235. dw AfterTrade1Text
  236. TradeTextPointers2:
  237. dw WannaTrade2Text
  238. dw NoTrade2Text
  239. dw WrongMon2Text
  240. dw Thanks2Text
  241. dw AfterTrade2Text
  242. TradeTextPointers3:
  243. dw WannaTrade3Text
  244. dw NoTrade3Text
  245. dw WrongMon3Text
  246. dw Thanks3Text
  247. dw AfterTrade3Text
  248. ConnectCableText:
  249. TX_FAR _ConnectCableText
  250. db "@"
  251. TradedForText:
  252. TX_FAR _TradedForText
  253. TX_SFX_KEY_ITEM
  254. TX_DELAY
  255. db "@"
  256. WannaTrade1Text:
  257. TX_FAR _WannaTrade1Text
  258. db "@"
  259. NoTrade1Text:
  260. TX_FAR _NoTrade1Text
  261. db "@"
  262. WrongMon1Text:
  263. TX_FAR _WrongMon1Text
  264. db "@"
  265. Thanks1Text:
  266. TX_FAR _Thanks1Text
  267. db "@"
  268. AfterTrade1Text:
  269. TX_FAR _AfterTrade1Text
  270. db "@"
  271. WannaTrade2Text:
  272. TX_FAR _WannaTrade2Text
  273. db "@"
  274. NoTrade2Text:
  275. TX_FAR _NoTrade2Text
  276. db "@"
  277. WrongMon2Text:
  278. TX_FAR _WrongMon2Text
  279. db "@"
  280. Thanks2Text:
  281. TX_FAR _Thanks2Text
  282. db "@"
  283. AfterTrade2Text:
  284. TX_FAR _AfterTrade2Text
  285. db "@"
  286. WannaTrade3Text:
  287. TX_FAR _WannaTrade3Text
  288. db "@"
  289. NoTrade3Text:
  290. TX_FAR _NoTrade3Text
  291. db "@"
  292. WrongMon3Text:
  293. TX_FAR _WrongMon3Text
  294. db "@"
  295. Thanks3Text:
  296. TX_FAR _Thanks3Text
  297. db "@"
  298. AfterTrade3Text:
  299. TX_FAR _AfterTrade3Text
  300. db "@"