pokecrystal-board/engine/events/npc_trade.asm

541 lines
9.2 KiB
NASM
Raw Normal View History

2018-06-24 07:09:41 -07:00
NPCTrade::
2015-11-19 15:07:20 -08:00
ld a, e
ld [wJumptableIndex], a
2015-11-22 21:21:21 -08:00
call Trade_GetDialog
2015-11-19 15:07:20 -08:00
ld b, CHECK_FLAG
call TradeFlagAction
ld a, TRADE_DIALOG_AFTER
2015-11-19 15:07:20 -08:00
jr nz, .done
ld a, TRADE_DIALOG_INTRO
2015-11-19 15:07:20 -08:00
call PrintTradeText
call YesNoBox
ld a, TRADE_DIALOG_CANCEL
2015-11-19 15:07:20 -08:00
jr c, .done
; Select givemon from party
ld b, PARTYMENUACTION_GIVE_MON
2017-12-24 09:47:30 -08:00
farcall SelectTradeOrDayCareMon
ld a, TRADE_DIALOG_CANCEL
2015-11-19 15:07:20 -08:00
jr c, .done
ld e, NPCTRADE_GIVEMON
2015-11-19 15:07:20 -08:00
call GetTradeAttribute
2018-01-23 14:39:09 -08:00
ld a, [wCurPartySpecies]
2015-11-19 15:07:20 -08:00
cp [hl]
ld a, TRADE_DIALOG_WRONG
2015-11-19 15:07:20 -08:00
jr nz, .done
call CheckTradeGender
ld a, TRADE_DIALOG_WRONG
2015-11-19 15:07:20 -08:00
jr c, .done
ld b, SET_FLAG
call TradeFlagAction
ld hl, ConnectLinkCableText
call PrintText
2015-11-22 21:21:21 -08:00
call DoNPCTrade
call .TradeAnimation
2015-11-19 15:07:20 -08:00
call GetTradeMonNames
ld hl, TradedForText
call PrintText
call RestartMapMusic
ld a, TRADE_DIALOG_COMPLETE
2015-11-19 15:07:20 -08:00
.done
call PrintTradeText
ret
2018-06-24 07:09:41 -07:00
.TradeAnimation:
2015-11-19 15:07:20 -08:00
call DisableSpriteUpdates
ld a, [wJumptableIndex]
push af
ld a, [wcf64]
push af
predef TradeAnimation
2015-11-19 15:07:20 -08:00
pop af
ld [wcf64], a
pop af
ld [wJumptableIndex], a
2015-12-18 17:07:09 -08:00
call ReturnToMapWithSpeechTextbox
2015-11-19 15:07:20 -08:00
ret
2018-06-24 07:09:41 -07:00
CheckTradeGender:
2015-11-19 15:07:20 -08:00
xor a
2018-01-23 14:39:09 -08:00
ld [wMonType], a
2015-11-19 15:07:20 -08:00
ld e, NPCTRADE_GENDER
2015-11-19 15:07:20 -08:00
call GetTradeAttribute
ld a, [hl]
and a ; TRADE_GENDER_EITHER
2015-12-13 17:33:56 -08:00
jr z, .matching
cp TRADE_GENDER_MALE
2015-12-13 17:33:56 -08:00
jr z, .check_male
; TRADE_GENDER_FEMALE
farcall GetGender
2015-12-13 17:33:56 -08:00
jr nz, .not_matching
jr .matching
2015-11-19 15:07:20 -08:00
2015-12-13 17:33:56 -08:00
.check_male
farcall GetGender
2015-12-13 17:33:56 -08:00
jr z, .not_matching
2015-11-19 15:07:20 -08:00
2015-12-13 17:33:56 -08:00
.matching
2015-11-19 15:07:20 -08:00
and a
ret
2015-12-13 17:33:56 -08:00
.not_matching
2015-11-19 15:07:20 -08:00
scf
ret
2018-06-24 07:09:41 -07:00
TradeFlagAction:
2015-11-22 21:21:21 -08:00
ld hl, wTradeFlags
2015-11-19 15:07:20 -08:00
ld a, [wJumptableIndex]
ld c, a
predef SmallFarFlagAction
2015-11-19 15:07:20 -08:00
ld a, c
and a
ret
2018-06-24 07:09:41 -07:00
Trade_GetDialog:
ld e, NPCTRADE_DIALOG
2015-11-19 15:07:20 -08:00
call GetTradeAttribute
ld a, [hl]
ld [wcf64], a
ret
2018-06-24 07:09:41 -07:00
DoNPCTrade:
ld e, NPCTRADE_GIVEMON
2015-11-19 15:07:20 -08:00
call GetTradeAttribute
ld a, [hl]
2015-11-22 21:21:21 -08:00
ld [wPlayerTrademonSpecies], a
2015-11-19 15:07:20 -08:00
ld e, NPCTRADE_GETMON
2015-11-19 15:07:20 -08:00
call GetTradeAttribute
ld a, [hl]
2015-11-22 21:21:21 -08:00
ld [wOTTrademonSpecies], a
2015-11-19 15:07:20 -08:00
2015-11-22 21:21:21 -08:00
ld a, [wPlayerTrademonSpecies]
ld de, wPlayerTrademonSpeciesName
call GetTradeMonName
call CopyTradeName
2015-11-19 15:07:20 -08:00
2015-11-22 21:21:21 -08:00
ld a, [wOTTrademonSpecies]
ld de, wOTTrademonSpeciesName
call GetTradeMonName
call CopyTradeName
2015-11-19 15:07:20 -08:00
2018-01-23 14:39:09 -08:00
ld hl, wPartyMonOT
2015-11-19 15:07:20 -08:00
ld bc, NAME_LENGTH
2015-11-22 21:21:21 -08:00
call Trade_GetAttributeOfCurrentPartymon
ld de, wPlayerTrademonOTName
call CopyTradeName
2015-11-19 15:07:20 -08:00
2018-01-23 14:39:09 -08:00
ld hl, wPlayerName
2015-11-22 21:21:21 -08:00
ld de, wPlayerTrademonSenderName
call CopyTradeName
2015-11-19 15:07:20 -08:00
2018-01-23 14:39:09 -08:00
ld hl, wPartyMon1ID
2015-11-19 15:07:20 -08:00
ld bc, PARTYMON_STRUCT_LENGTH
2015-11-22 21:21:21 -08:00
call Trade_GetAttributeOfCurrentPartymon
ld de, wPlayerTrademonID
call Trade_CopyTwoBytes
2015-11-19 15:07:20 -08:00
2018-01-23 14:39:09 -08:00
ld hl, wPartyMon1DVs
2015-11-19 15:07:20 -08:00
ld bc, PARTYMON_STRUCT_LENGTH
2015-11-22 21:21:21 -08:00
call Trade_GetAttributeOfCurrentPartymon
ld de, wPlayerTrademonDVs
call Trade_CopyTwoBytes
2015-11-19 15:07:20 -08:00
2018-01-23 14:39:09 -08:00
ld hl, wPartyMon1Species
2015-11-19 15:07:20 -08:00
ld bc, PARTYMON_STRUCT_LENGTH
2015-11-22 21:21:21 -08:00
call Trade_GetAttributeOfCurrentPartymon
2015-11-19 15:07:20 -08:00
ld b, h
ld c, l
2017-12-24 09:47:30 -08:00
farcall GetCaughtGender
2015-11-19 15:07:20 -08:00
ld a, c
2015-11-22 21:21:21 -08:00
ld [wPlayerTrademonCaughtData], a
2015-11-19 15:07:20 -08:00
ld e, NPCTRADE_DIALOG
2015-11-19 15:07:20 -08:00
call GetTradeAttribute
ld a, [hl]
cp TRADE_DIALOGSET_GIRL
2018-01-11 09:00:01 -08:00
ld a, CAUGHT_BY_GIRL
2015-11-22 21:21:21 -08:00
jr c, .okay
2018-01-11 09:00:01 -08:00
ld a, CAUGHT_BY_BOY
2015-11-22 21:21:21 -08:00
.okay
ld [wOTTrademonCaughtData], a
2015-11-19 15:07:20 -08:00
2018-01-23 14:39:09 -08:00
ld hl, wPartyMon1Level
2015-11-19 15:07:20 -08:00
ld bc, PARTYMON_STRUCT_LENGTH
2015-11-22 21:21:21 -08:00
call Trade_GetAttributeOfCurrentPartymon
2015-11-19 15:07:20 -08:00
ld a, [hl]
2018-01-23 14:39:09 -08:00
ld [wCurPartyLevel], a
2015-11-22 21:21:21 -08:00
ld a, [wOTTrademonSpecies]
2018-01-23 14:39:09 -08:00
ld [wCurPartySpecies], a
2015-11-19 15:07:20 -08:00
xor a
ld [wMonType], a ; PARTYMON
ld [wPokemonWithdrawDepositParameter], a ; REMOVE_PARTY
2017-12-24 09:47:30 -08:00
callfar RemoveMonFromPartyOrBox
predef TryAddMonToParty
2015-11-19 15:07:20 -08:00
ld e, NPCTRADE_DIALOG
2015-11-19 15:07:20 -08:00
call GetTradeAttribute
ld a, [hl]
cp TRADE_DIALOG_COMPLETE
2015-11-22 21:21:21 -08:00
ld b, RESET_FLAG
2015-12-13 17:33:56 -08:00
jr c, .incomplete
2015-11-22 21:21:21 -08:00
ld b, SET_FLAG
2015-12-13 17:33:56 -08:00
.incomplete
2017-12-24 09:47:30 -08:00
farcall SetGiftPartyMonCaughtData
2015-11-19 15:07:20 -08:00
ld e, NPCTRADE_NICK
2015-11-19 15:07:20 -08:00
call GetTradeAttribute
2015-11-22 21:21:21 -08:00
ld de, wOTTrademonNickname
call CopyTradeName
2015-11-19 15:07:20 -08:00
2018-01-23 14:39:09 -08:00
ld hl, wPartyMonNicknames
2018-01-20 09:25:55 -08:00
ld bc, MON_NAME_LENGTH
2015-11-22 21:21:21 -08:00
call Trade_GetAttributeOfLastPartymon
ld hl, wOTTrademonNickname
call CopyTradeName
2015-11-19 15:07:20 -08:00
ld e, NPCTRADE_OT_NAME
2015-11-19 15:07:20 -08:00
call GetTradeAttribute
push hl
2015-11-22 21:21:21 -08:00
ld de, wOTTrademonOTName
call CopyTradeName
2015-11-19 15:07:20 -08:00
pop hl
2015-11-22 21:21:21 -08:00
ld de, wOTTrademonSenderName
call CopyTradeName
2015-11-19 15:07:20 -08:00
2018-01-23 14:39:09 -08:00
ld hl, wPartyMonOT
2015-11-19 15:07:20 -08:00
ld bc, NAME_LENGTH
2015-11-22 21:21:21 -08:00
call Trade_GetAttributeOfLastPartymon
ld hl, wOTTrademonOTName
call CopyTradeName
2015-11-19 15:07:20 -08:00
ld e, NPCTRADE_DVS
2015-11-19 15:07:20 -08:00
call GetTradeAttribute
2015-11-22 21:21:21 -08:00
ld de, wOTTrademonDVs
call Trade_CopyTwoBytes
2015-11-19 15:07:20 -08:00
2018-01-23 14:39:09 -08:00
ld hl, wPartyMon1DVs
2015-11-19 15:07:20 -08:00
ld bc, PARTYMON_STRUCT_LENGTH
2015-11-22 21:21:21 -08:00
call Trade_GetAttributeOfLastPartymon
ld hl, wOTTrademonDVs
call Trade_CopyTwoBytes
2015-11-19 15:07:20 -08:00
ld e, NPCTRADE_OT_ID
2015-11-19 15:07:20 -08:00
call GetTradeAttribute
2015-11-22 21:21:21 -08:00
ld de, wOTTrademonID + 1
call Trade_CopyTwoBytesReverseEndian
2015-11-19 15:07:20 -08:00
2018-01-23 14:39:09 -08:00
ld hl, wPartyMon1ID
2015-11-19 15:07:20 -08:00
ld bc, PARTYMON_STRUCT_LENGTH
2015-11-22 21:21:21 -08:00
call Trade_GetAttributeOfLastPartymon
ld hl, wOTTrademonID
call Trade_CopyTwoBytes
2015-11-19 15:07:20 -08:00
ld e, NPCTRADE_ITEM
2015-11-19 15:07:20 -08:00
call GetTradeAttribute
push hl
2018-01-23 14:39:09 -08:00
ld hl, wPartyMon1Item
2015-11-19 15:07:20 -08:00
ld bc, PARTYMON_STRUCT_LENGTH
2015-11-22 21:21:21 -08:00
call Trade_GetAttributeOfLastPartymon
2015-11-19 15:07:20 -08:00
pop hl
ld a, [hl]
ld [de], a
push af
push bc
push de
push hl
2018-01-23 14:39:09 -08:00
ld a, [wCurPartyMon]
2015-11-19 15:07:20 -08:00
push af
2018-01-23 14:39:09 -08:00
ld a, [wPartyCount]
2015-11-19 15:07:20 -08:00
dec a
2018-01-23 14:39:09 -08:00
ld [wCurPartyMon], a
2017-12-24 09:47:30 -08:00
farcall ComputeNPCTrademonStats
2015-11-19 15:07:20 -08:00
pop af
2018-01-23 14:39:09 -08:00
ld [wCurPartyMon], a
2015-11-19 15:07:20 -08:00
pop hl
pop de
pop bc
pop af
ret
GetTradeAttribute:
2015-11-19 15:07:20 -08:00
ld d, 0
push de
ld a, [wJumptableIndex]
and $f
swap a
ld e, a
ld d, 0
ld hl, NPCTrades
add hl, de
add hl, de
2015-11-19 15:07:20 -08:00
pop de
add hl, de
ret
2018-06-24 07:09:41 -07:00
Trade_GetAttributeOfCurrentPartymon:
2018-01-23 14:39:09 -08:00
ld a, [wCurPartyMon]
2015-11-19 15:07:20 -08:00
call AddNTimes
ret
2018-06-24 07:09:41 -07:00
Trade_GetAttributeOfLastPartymon:
2018-01-23 14:39:09 -08:00
ld a, [wPartyCount]
2015-11-19 15:07:20 -08:00
dec a
call AddNTimes
ld e, l
ld d, h
ret
2018-06-24 07:09:41 -07:00
GetTradeMonName:
2015-11-19 15:07:20 -08:00
push de
ld [wNamedObjectIndexBuffer], a
2015-11-19 15:07:20 -08:00
call GetBasePokemonName
2018-01-23 14:39:09 -08:00
ld hl, wStringBuffer1
2015-11-19 15:07:20 -08:00
pop de
ret
2018-06-24 07:09:41 -07:00
CopyTradeName:
2015-11-19 15:07:20 -08:00
ld bc, NAME_LENGTH
call CopyBytes
ret
2018-06-24 07:09:41 -07:00
Unreferenced_Functionfcdfb:
2015-11-19 15:07:20 -08:00
ld bc, 4
call CopyBytes
2015-11-22 21:21:21 -08:00
ld a, "@"
2015-11-19 15:07:20 -08:00
ld [de], a
ret
2018-06-24 07:09:41 -07:00
Unreferenced_Functionfce05:
2015-11-19 15:07:20 -08:00
ld bc, 3
call CopyBytes
2015-11-22 21:21:21 -08:00
ld a, "@"
2015-11-19 15:07:20 -08:00
ld [de], a
ret
2018-06-24 07:09:41 -07:00
Trade_CopyTwoBytes:
2015-11-19 15:07:20 -08:00
ld a, [hli]
ld [de], a
inc de
ld a, [hl]
ld [de], a
ret
2018-06-24 07:09:41 -07:00
Trade_CopyTwoBytesReverseEndian:
2015-11-19 15:07:20 -08:00
ld a, [hli]
ld [de], a
dec de
ld a, [hl]
ld [de], a
ret
2018-06-24 07:09:41 -07:00
GetTradeMonNames:
ld e, NPCTRADE_GETMON
2015-11-19 15:07:20 -08:00
call GetTradeAttribute
ld a, [hl]
2015-11-22 21:21:21 -08:00
call GetTradeMonName
2015-11-19 15:07:20 -08:00
2018-01-23 14:39:09 -08:00
ld de, wStringBuffer2
2015-11-22 21:21:21 -08:00
call CopyTradeName
2015-11-19 15:07:20 -08:00
ld e, NPCTRADE_GIVEMON
2015-11-19 15:07:20 -08:00
call GetTradeAttribute
ld a, [hl]
2015-11-22 21:21:21 -08:00
call GetTradeMonName
2015-11-19 15:07:20 -08:00
2015-12-18 17:07:09 -08:00
ld de, wMonOrItemNameBuffer
2015-11-22 21:21:21 -08:00
call CopyTradeName
2015-11-19 15:07:20 -08:00
2018-01-23 14:39:09 -08:00
ld hl, wStringBuffer1
2015-11-19 15:07:20 -08:00
.loop
ld a, [hli]
cp "@"
jr nz, .loop
dec hl
push hl
ld e, NPCTRADE_GENDER
2015-11-19 15:07:20 -08:00
call GetTradeAttribute
ld a, [hl]
pop hl
and a ; TRADE_GENDER_EITHER
2015-11-19 15:07:20 -08:00
ret z
cp TRADE_GENDER_MALE
2015-11-19 15:07:20 -08:00
ld a, "♂"
jr z, .done
; TRADE_GENDER_FEMALE
2015-11-19 15:07:20 -08:00
ld a, "♀"
.done
ld [hli], a
ld [hl], "@"
ret
2018-01-25 19:19:24 -08:00
INCLUDE "data/events/npc_trades.asm"
2015-11-19 15:07:20 -08:00
2018-06-24 07:09:41 -07:00
PrintTradeText:
2015-11-19 15:07:20 -08:00
push af
call GetTradeMonNames
pop af
ld bc, 2 * 4
ld hl, TradeTexts
call AddNTimes
ld a, [wcf64]
ld c, a
add hl, bc
add hl, bc
2015-11-19 15:07:20 -08:00
ld a, [hli]
ld h, [hl]
ld l, a
call PrintText
ret
2018-06-24 07:09:41 -07:00
TradeTexts:
; entries correspond to TRADE_DIALOG_* × TRADE_DIALOGSET_* constants
; TRADE_DIALOG_INTRO
2015-11-19 15:07:20 -08:00
dw TradeIntroText1
dw TradeIntroText2
dw TradeIntroText3
dw TradeIntroText4
; TRADE_DIALOG_CANCEL
2015-11-19 15:07:20 -08:00
dw TradeCancelText1
dw TradeCancelText2
dw TradeCancelText3
dw TradeCancelText4
; TRADE_DIALOG_WRONG
2015-11-19 15:07:20 -08:00
dw TradeWrongText1
dw TradeWrongText2
dw TradeWrongText3
dw TradeWrongText4
; TRADE_DIALOG_COMPLETE
2015-11-19 15:07:20 -08:00
dw TradeCompleteText1
dw TradeCompleteText2
dw TradeCompleteText3
dw TradeCompleteText4
; TRADE_DIALOG_AFTER
2015-11-19 15:07:20 -08:00
dw TradeAfterText1
dw TradeAfterText2
dw TradeAfterText3
dw TradeAfterText4
ConnectLinkCableText:
2015-11-19 15:07:20 -08:00
; OK, connect the Game Link Cable.
text_far UnknownText_0x1bd407
text_end
2015-11-19 15:07:20 -08:00
TradedForText:
2015-11-19 15:07:20 -08:00
; traded givemon for getmon
text_far UnknownText_0x1bd429
text_asm
2015-11-19 15:07:20 -08:00
ld de, MUSIC_NONE
call PlayMusic
call DelayFrame
ld hl, .done
ret
.done
2015-11-23 18:19:53 -08:00
; sound_dex_fanfare_80_109
; text_pause
text_far UnknownText_0x1bd445
text_end
2015-11-19 15:07:20 -08:00
TradeIntroText1:
2015-11-19 15:07:20 -08:00
; I collect #MON. Do you have @ ? Want to trade it for my @ ?
text_far UnknownText_0x1bd449
text_end
2015-11-19 15:07:20 -08:00
TradeCancelText1:
2015-11-19 15:07:20 -08:00
; You don't want to trade? Aww…
text_far UnknownText_0x1bd48c
text_end
2015-11-19 15:07:20 -08:00
TradeWrongText1:
2015-11-19 15:07:20 -08:00
; Huh? That's not @ . What a letdown…
text_far UnknownText_0x1bd4aa
text_end
2015-11-19 15:07:20 -08:00
TradeCompleteText1:
2015-11-19 15:07:20 -08:00
; Yay! I got myself @ ! Thanks!
text_far UnknownText_0x1bd4d2
text_end
2015-11-19 15:07:20 -08:00
TradeAfterText1:
2015-11-19 15:07:20 -08:00
; Hi, how's my old @ doing?
text_far UnknownText_0x1bd4f4
text_end
2015-11-19 15:07:20 -08:00
TradeIntroText2:
TradeIntroText3:
2015-11-19 15:07:20 -08:00
; Hi, I'm looking for this #MON. If you have @ , would you trade it for my @ ?
text_far UnknownText_0x1bd512
text_end
2015-11-19 15:07:20 -08:00
TradeCancelText2:
TradeCancelText3:
2015-11-19 15:07:20 -08:00
; You don't have one either? Gee, that's really disappointing…
text_far UnknownText_0x1bd565
text_end
2015-11-19 15:07:20 -08:00
TradeWrongText2:
TradeWrongText3:
2015-11-19 15:07:20 -08:00
; You don't have @ ? That's too bad, then.
text_far UnknownText_0x1bd5a1
text_end
2015-11-19 15:07:20 -08:00
TradeCompleteText2:
2015-11-19 15:07:20 -08:00
; Great! Thank you! I finally got @ .
text_far UnknownText_0x1bd5cc
text_end
2015-11-19 15:07:20 -08:00
TradeAfterText2:
2015-11-19 15:07:20 -08:00
; Hi! The @ you traded me is doing great!
text_far UnknownText_0x1bd5f4
text_end
2015-11-19 15:07:20 -08:00
TradeIntroText4:
2015-11-19 15:07:20 -08:00
; 's cute, but I don't have it. Do you have @ ? Want to trade it for my @ ?
text_far UnknownText_0x1bd621
text_end
2015-11-19 15:07:20 -08:00
TradeCancelText4:
2015-11-19 15:07:20 -08:00
; You don't want to trade? Oh, darn…
text_far UnknownText_0x1bd673
text_end
2015-11-19 15:07:20 -08:00
TradeWrongText4:
2015-11-19 15:07:20 -08:00
; That's not @ . Please trade with me if you get one.
text_far UnknownText_0x1bd696
text_end
2015-11-19 15:07:20 -08:00
TradeCompleteText4:
2015-11-19 15:07:20 -08:00
; Wow! Thank you! I always wanted @ !
text_far UnknownText_0x1bd6cd
text_end
2015-11-19 15:07:20 -08:00
TradeAfterText4:
2015-11-19 15:07:20 -08:00
; How is that @ I traded you doing? Your @ 's so cute!
text_far UnknownText_0x1bd6f5
text_end
2015-11-19 15:07:20 -08:00
TradeCompleteText3:
2015-11-19 15:07:20 -08:00
; Uh? What happened?
text_far UnknownText_0x1bd731
text_end
2015-11-19 15:07:20 -08:00
TradeAfterText3:
2015-11-19 15:07:20 -08:00
; Trading is so odd… I still have a lot to learn about it.
text_far UnknownText_0x1bd745
text_end