pokecrystal-board/engine/events/npc_trade.asm

519 lines
8.4 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
call GetTradeAttr
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, NPCTradeCableText
2015-11-19 15:07:20 -08:00
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
; wTradeDialog aliases wFrameCounter, which TradeAnimation uses
ld a, [wTradeDialog]
2015-11-19 15:07:20 -08:00
push af
predef TradeAnimation
2015-11-19 15:07:20 -08:00
pop af
ld [wTradeDialog], a
2015-11-19 15:07:20 -08:00
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
call GetTradeAttr
2015-11-19 15:07:20 -08:00
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
call GetTradeAttr
2015-11-19 15:07:20 -08:00
ld a, [hl]
ld [wTradeDialog], a
2015-11-19 15:07:20 -08:00
ret
2018-06-24 07:09:41 -07:00
DoNPCTrade:
ld e, NPCTRADE_GIVEMON
call GetTradeAttr
2015-11-19 15:07:20 -08:00
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
call GetTradeAttr
2015-11-19 15:07:20 -08:00
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
ld hl, wPartyMonOTs
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
call GetTradeAttr
2015-11-19 15:07:20 -08:00
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
call GetTradeAttr
2015-11-19 15:07:20 -08:00
ld a, [hl]
2020-07-25 15:36:49 -07:00
cp TRADE_DIALOGSET_GIRL
ld b, CAUGHT_BY_UNKNOWN
2015-12-13 17:33:56 -08:00
jr c, .incomplete
2020-07-25 15:36:49 -07:00
ld b, CAUGHT_BY_GIRL
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_NICKNAME
call GetTradeAttr
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
call GetTradeAttr
2015-11-19 15:07:20 -08:00
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
ld hl, wPartyMonOTs
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
call GetTradeAttr
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
call GetTradeAttr
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
call GetTradeAttr
2015-11-19 15:07:20 -08:00
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
GetTradeAttr:
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 [wNamedObjectIndex], 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
2020-10-05 13:15:57 -07:00
Trade_CopyFourCharString: ; unreferenced
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
2020-10-05 13:15:57 -07:00
Trade_CopyThreeCharString: ; unreferenced
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
call GetTradeAttr
2015-11-19 15:07:20 -08:00
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
call GetTradeAttr
2015-11-19 15:07:20 -08:00
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
call GetTradeAttr
2015-11-19 15:07:20 -08:00
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, [wTradeDialog]
2015-11-19 15:07:20 -08:00
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
dw NPCTradeIntroText1
dw NPCTradeIntroText2
dw NPCTradeIntroText2
dw NPCTradeIntroText3
; TRADE_DIALOG_CANCEL
dw NPCTradeCancelText1
dw NPCTradeCancelText2
dw NPCTradeCancelText2
dw NPCTradeCancelText3
; TRADE_DIALOG_WRONG
dw NPCTradeWrongText1
dw NPCTradeWrongText2
dw NPCTradeWrongText2
dw NPCTradeWrongText3
; TRADE_DIALOG_COMPLETE
dw NPCTradeCompleteText1
dw NPCTradeCompleteText2
dw NPCTradeCompleteText4
dw NPCTradeCompleteText3
; TRADE_DIALOG_AFTER
dw NPCTradeAfterText1
dw NPCTradeAfterText2
dw NPCTradeAfterText4
dw NPCTradeAfterText3
NPCTradeCableText:
text_far _NPCTradeCableText
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 Text_NPCTraded
text_asm
2015-11-19 15:07:20 -08:00
ld de, MUSIC_NONE
call PlayMusic
call DelayFrame
ld hl, .done
ret
.done
text_far _NPCTradeFanfareText
text_end
2015-11-19 15:07:20 -08:00
NPCTradeIntroText1:
text_far _NPCTradeIntroText1
text_end
2015-11-19 15:07:20 -08:00
NPCTradeCancelText1:
text_far _NPCTradeCancelText1
text_end
2015-11-19 15:07:20 -08:00
NPCTradeWrongText1:
text_far _NPCTradeWrongText1
text_end
2015-11-19 15:07:20 -08:00
NPCTradeCompleteText1:
text_far _NPCTradeCompleteText1
text_end
2015-11-19 15:07:20 -08:00
NPCTradeAfterText1:
text_far _NPCTradeAfterText1
text_end
2015-11-19 15:07:20 -08:00
NPCTradeIntroText2:
text_far _NPCTradeIntroText2
text_end
2015-11-19 15:07:20 -08:00
NPCTradeCancelText2:
text_far _NPCTradeCancelText2
text_end
2015-11-19 15:07:20 -08:00
NPCTradeWrongText2:
text_far _NPCTradeWrongText2
text_end
2015-11-19 15:07:20 -08:00
NPCTradeCompleteText2:
text_far _NPCTradeCompleteText2
text_end
2015-11-19 15:07:20 -08:00
NPCTradeAfterText2:
text_far _NPCTradeAfterText2
text_end
2015-11-19 15:07:20 -08:00
NPCTradeIntroText3:
text_far _NPCTradeIntroText3
text_end
2015-11-19 15:07:20 -08:00
NPCTradeCancelText3:
text_far _NPCTradeCancelText3
text_end
2015-11-19 15:07:20 -08:00
NPCTradeWrongText3:
text_far _NPCTradeWrongText3
text_end
2015-11-19 15:07:20 -08:00
NPCTradeCompleteText3:
text_far _NPCTradeCompleteText3
text_end
2015-11-19 15:07:20 -08:00
NPCTradeAfterText3:
text_far _NPCTradeAfterText3
text_end
2015-11-19 15:07:20 -08:00
NPCTradeCompleteText4:
text_far _NPCTradeCompleteText4
text_end
2015-11-19 15:07:20 -08:00
NPCTradeAfterText4:
text_far _NPCTradeAfterText4
text_end