# given a treasure id & subid in b & c, if the treasure needs to be upgraded, # set hl = the start of the upgraded treasure data + 1 and b = the new # treasure ID. 16/562a/getUpgradedTreasure: | ; Filter out the fake "Sword spinslash" treasure given at Hero's Cave chest ; and while opening Maku Tree gate solely for cosmetic purpose ld a,b cp TREASURE_SWORD jr nz,@notSpinSlash ld a,c cp $03 ld a,b ret nc @notSpinSlash: ; Check that item was obtained before call checkTreasureObtained ld c,a ld a,b ret nc cp TREASURE_TUNE_OF_ECHOES jr nz,@harpDone ld a,TREASURE_TUNE_OF_CURRENTS ld e,a call checkTreasureObtained jr nc,@harpDone ld b,e @harpDone: push hl ld hl,progressiveUpgrades ld e,$03 call searchDoubleKey jr nc,@done ; We found a matching entry in progressiveUpgrades table ldi a,(hl) ld b,a ldi a,(hl) ld e,(hl) pop hl ld h,e ld l,a inc hl ret @done: pop hl ret # set hl = the address of the treasure with ID b and sub ID c, accounting for # progressive upgrades. call through getTreasureDataBCE or # getTreasureDataSprite! 16/565d/getTreasureData_body: | ld hl,$5332 ; treasureObjectData in bank 16 ld a,b add a,a rst 10 ld a,b add a,a rst 10 bit 7,(hl) jr z,@next inc hl ldi a,(hl) ld h,(hl) ld l,a @next: ld a,c add a,a add a,a rst 10 inc hl jp getUpgradedTreasure # load fianl treasure ID, param, and text into b, c, and e. 16/5676/getTreasureDataBCE: | call getTreasureData_body ld c,(hl) inc hl ld e,(hl) ret # load final treasure sprite into e. 16/5686/getTreasureDataSprite: | call getTreasureData_body inc hl inc hl ld e,(hl) ret # return treasure data address and collect mode modified as necessary, given # a treasure ID in dx42. lookupCollectMode must happen before upgradeTreasure # for multiworld things to work correctly. 16//modifyTreasure: | call lookupCollectMode push af call upgradeTreasure pop af ld b,a swap a ret # given a treasure at dx40, return hl = the start of the treasure data + 1, # accounting for progressive upgrades. also writes the new treasure ID to # d070, which is used to set the treasure obtained flag. 16//upgradeTreasure: | ld e,$42 ld a,(de) ld b,a inc de ld a,(de) ld c,a ; call getMultiworldItemDest ; call z,getUpgradedTreasure call getUpgradedTreasure ld e,$70 ld a,b ld (de),a ret ## AGES SPECIFICS # progressive item upgrade data (old ID, old related var, new ID, new addr) 16/5695/progressiveUpgrades: | db TREASURE_SHIELD,$01,TREASURE_SHIELD dw $54c2 # iron shield db TREASURE_SHIELD,$02,TREASURE_SHIELD dw $54c6 # mirror shield db TREASURE_SWORD,$01,TREASURE_SWORD dw $54ea # noble sword db TREASURE_SWORD,$02,TREASURE_SWORD dw $54ee # master sword db TREASURE_SWITCH_HOOK,$01,TREASURE_SWITCH_HOOK dw $5512 # long switch db TREASURE_BRACELET,$01,TREASURE_BRACELET dw $5552 # power glove db TREASURE_SEED_SATCHEL,$01,TREASURE_SEED_SATCHEL dw $5576 # satchel upgrade 1 db TREASURE_SEED_SATCHEL,$02,TREASURE_SEED_SATCHEL dw $5576 # satchel upgrade 2 (same deal) db TREASURE_TUNE_OF_ECHOES,$00,TREASURE_TUNE_OF_CURRENTS dw $53ca # tune of currents db TREASURE_TUNE_OF_CURRENTS,$00,TREASURE_TUNE_OF_AGES dw $53ce # tune of ages db TREASURE_FLIPPERS,$00,TREASURE_MERMAID_SUIT dw $545a # mermaid suit db ff 16/4539/: call modifyTreasure # this is a replacement for giveTreasure that accounts for item progression. # call through giveTreasureCustom or giveTreasureCustomSilent, since this # function doesn't xor the a that it returns. importantly, this replacement # treats c as a subID, not a param, so this should *not* be called by # non-randomized whatevers. 00//giveTreasureCustom_body: | ld b,a push hl ld e,$16 ld hl,getTreasureDataBCE call interBankCall pop hl ld a,b jp giveTreasure # just gives the treasure, no sound or text. 00//giveTreasureCustomSilent: | call giveTreasureCustom_body xor a ret # gives the treasure, plays its sound, and shows its text. 00//giveTreasureCustom: | call giveTreasureCustom_body jr z,@noSound push hl call playSound pop hl @noSound: ld a,e cp $ff ret z ld b,$00 ld c,e call checkCustomTreasureTextId call showText xor a ret #0a/7b93/: call giveTreasureCustom