From 2a0895922993285e75510a2fd07415d71724fbd6 Mon Sep 17 00:00:00 2001 From: aerinon Date: Mon, 1 Feb 2021 10:11:38 -0700 Subject: [PATCH] Shop counting items --- events.asm | 1 + inventory.asm | 13 +++++++++---- shopkeeper.asm | 23 ++++++++++++++++++++--- tables.asm | 12 ++++++++++-- 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/events.asm b/events.asm index dbdafb7..31bfda3 100644 --- a/events.asm +++ b/events.asm @@ -88,6 +88,7 @@ RTL OnFileLoad: REP #$10 ; set 16 bit index registers JSL.l EnableForceBlank ; what we wrote over + REP #$20 : LDA.l $30F010 : STA.l $7EF33E : SEP $#20 LDA.b #$07 : STA $210c ; Restore screen 3 to normal tile area diff --git a/inventory.asm b/inventory.asm index 224e6d4..35c0c5a 100644 --- a/inventory.asm +++ b/inventory.asm @@ -286,8 +286,7 @@ AddInventory: CMP.w #271 : BNE + : BRL .shop : + ; villiage of outcasts shop, lumberjack shop, lake hylia shop, dark world magic shop CMP.w #272 : BNE + : BRL .shop : + ; red shield shop CMP.w #284 : BNE + : BRL .shop : + ; bomb shop - ;CMP.w #265 : BNE + : BRL .shop : + ; potion shop - commented this out because it's easier to just block potion refills because this one interferes with the powder item being counted - ;CMP.w #271 : BNE + : BRL .shop : + ; lake hylia shop + CMP.w #265 : BNE + : BRL .shop : + ; potion shop - commented this out because it's easier to just block potion refills because this one interferes with the powder item being counted CMP.w #287 : BNE + : BRL .shop : + ; kakariko shop CMP.w #255 : BNE + : BRL .shop : + ; light world death mountain shop CMP.w #276 : BNE + : BRL .shop : + ; waterfall fairy @@ -295,7 +294,9 @@ AddInventory: CMP.w #278 : BNE + : BRL .shop : + ; pyramid fairy PLP : BRA ++ .shop - PLP : BRL .done + PLP + LDA.l !SHOP_ENABLE_COUNT : BNE ++ + BRL .done ++ .dungeonCounts @@ -1026,9 +1027,13 @@ CollectPowder: ; if for any reason the item value is 0 reload it, just in case %GetPossiblyEncryptedItem(WitchItem, SpriteItemValues) : TAY + - PHA : LDA WitchItem_Player : STA !MULTIWORLD_ITEM_PLAYER_ID : PLA + PHA + LDA WitchItem_Player : STA !MULTIWORLD_ITEM_PLAYER_ID + LDA.b #$01 : STA.l !SHOP_ENABLE_COUNT + PLA STZ $02E9 ; item from NPC JSL.l Link_ReceiveItem + PHA : LDA.b #$00 : STA.l !SHOP_ENABLE_COUNT : PLA ;JSL.l FullInventoryExternal JSL.l ItemSet_Powder RTL diff --git a/shopkeeper.asm b/shopkeeper.asm index 77f6dda..db61bbe 100644 --- a/shopkeeper.asm +++ b/shopkeeper.asm @@ -106,6 +106,7 @@ RTS ;-------------------------------------------------------------------------------- !TILE_UPLOAD_OFFSET_OVERRIDE = "$7F5042" !FREE_TILE_BUFFER = "#$1180" +!SHOP_ENABLE_COUNT = "$7F504F" !SHOP_ID = "$7F5050" !SHOP_TYPE = "$7F5051" !SHOP_INVENTORY = "$7F5052" ; $7F5056 - 5a - 5e @@ -548,6 +549,9 @@ Shopkeeper_SetupHitboxes: PLP : PLY : PLX RTS + +!LOCK_STATS = "$7EF443" +!ITEM_TOTAL = "$7EF423" ;-------------------- ;!SHOP_STATE Shopkeeper_BuyItem: @@ -584,9 +588,16 @@ Shopkeeper_BuyItem: LDA !SHOP_TYPE : AND.b #$80 : BNE ++ ; don't charge if this is a take-any REP #$20 : LDA $7EF360 : !SUB !SHOP_INVENTORY+1, X : STA $7EF360 : SEP #$20 ; Take price away ++ - PHX : LDA #0 : XBA : TXA : LSR #2 : TAX : LDA.l !SHOP_INVENTORY_PLAYER, X : STA !MULTIWORLD_ITEM_PLAYER_ID : PLX + PHX + LDA #0 : XBA : TXA : LSR #2 : TAX : LDA.l !SHOP_INVENTORY_PLAYER, X : STA !MULTIWORLD_ITEM_PLAYER_ID + TXA : !ADD !SHOP_SRAM_INDEX : TAX + LDA.l !SHOP_PURCHASE_COUNTS, X : BNE +++ ;Is this the first time buying this slot? + LDA.l EnableShopItemCount, X : STA.l !SHOP_ENABLE_COUNT ; If so, store the permission to count the item here. + +++ + PLX LDA.l !SHOP_INVENTORY, X : TAY : JSL.l Link_ReceiveItem LDA.l !SHOP_INVENTORY+3, X : INC : STA.l !SHOP_INVENTORY+3, X + LDA.b #0 : STA.l !SHOP_ENABLE_COUNT TXA : LSR #2 : TAX LDA !SHOP_TYPE : BIT.b #$80 : BNE + @@ -603,11 +614,17 @@ Shopkeeper_BuyItem: BIT.b #$20 : BNE .takeAll .takeAny LDA.l !SHOP_STATE : ORA.b #$07 : STA.l !SHOP_STATE - PHX : LDA.l !SHOP_SRAM_INDEX : TAX : LDA.b #$01 : STA.l !SHOP_PURCHASE_COUNTS, X : PLX + PHX + LDA.l !SHOP_SRAM_INDEX : TAX : LDA.b #$01 : STA.l !SHOP_PURCHASE_COUNTS, X + LDA.l EnableShopItemCount, X : STA.l !SHOP_ENABLE_COUNT + PLX BRA ++ .takeAll LDA.l !SHOP_STATE : ORA.w Shopkeeper_ItemMasks, X : STA.l !SHOP_STATE - PHX : LDA.l !SHOP_SRAM_INDEX : TAX : LDA.l !SHOP_STATE : STA.l !SHOP_PURCHASE_COUNTS, X : PLX + PHX + LDA.l !SHOP_SRAM_INDEX : TAX : LDA.l !SHOP_STATE : STA.l !SHOP_PURCHASE_COUNTS, X + LDA.l EnableShopItemCount, X : STA.l !SHOP_ENABLE_COUNT + PLX ++ .done LDA #$0 : STA !SHOP_KEEP_REFILL diff --git a/tables.asm b/tables.asm index 6c8bf60..2dbd0c0 100644 --- a/tables.asm +++ b/tables.asm @@ -1463,8 +1463,8 @@ dw #9999 ; Rupee Limit ; $7F5042 - Tile Upload Offset Override (Low) ; $7F5043 - Tile Upload Offset Override (High) ; $7F5044 - $7F5046 - NMI Auxiliary Function -; $7F5047 - $7F504F - Unused -; $7F5050 - $7F506F - Shop Block +; $7F5047 - $7F504E - Unused +; $7F504F - $7F506F - Shop Block ; $7F5070 - Reserved for OneMind ; $7F5071 - Reserved for OneMind ; $7F5072 - $7F507D - Unused @@ -1828,6 +1828,14 @@ org $30E37D ; PC 0x18637D Enable_TerrorPin_AI_Fix: db #$01 +;Shop slot count as check +org $30E560 ; PC 0x18650 +EnableShopItemCount: +db #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00 +db #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00 +db #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00 +db #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00 + ;-------------------------------------------------------------------------------- ; 0x186380 - 187FFF (unused) ;--------------------------------------------------------------------------------