lufia2ac: add shops to the cave (#2103)

This PR adds a new, optional aspect to the Ancient Cave experience:
During their run, players can have the opportunity to purchase some additional items or spells to improve their party. If enabled, a shop will appear everytime a certain (configurable) number of floors in the dungeon has been completed. The shop inventories are generated randomly (taking into account player preference as well as a system to ensure that more expensive items can only become available deeper into the run).

For customization, 3 new options are introduced: 
- `shop_interval`: Determines by how many floors the shops are separated (or keeps them turned off entirely)
- `shop_inventory`: Determines what's possible to be for sale. (Players can specify weights for general categories of things such as "weapon" or "spell" or even adjust the probabilities of individual items)
- `gold_modifier`: Determines how much gold is dropped by enemies. This is the player's only source of income and thus controls how much money they will have available to spend in shops
This commit is contained in:
el-u
2023-10-21 23:27:30 +02:00
committed by GitHub
parent 7c2cb34b45
commit 1c4303cce6
7 changed files with 349 additions and 10 deletions

View File

@@ -71,6 +71,11 @@ org $9EDD60 ; name
org $9FA900 ; sprite
incbin "ap_logo/ap_logo.bin"
warnpc $9FA980
; sold out item
org $96F9BA ; properties
DB $00,$00,$00,$10,$00,$00,$00,$00,$00,$00,$00,$00,$00
org $9EDD6C ; name
DB "SOLD OUT " ; overwrites "Crown "
org $D08000 ; signature, start of expanded data area
@@ -825,6 +830,119 @@ SpellRNG:
; shops
pushpc
org $83B442
; DB=$83, x=1, m=1
JSL Shop ; overwrites STA $7FD0BF
pullpc
Shop:
STA $7FD0BF ; (overwritten instruction)
LDY $05AC ; load map number
CPY.b #$F0 ; check if ancient cave
BCC +
LDA $05B4 ; check if going to ancient cave entrance
BEQ +
LDA $7FE696 ; load next to next floor number
DEC
CPY.b #$F1 ; check if going to final floor
BCS ++ ; skip a decrement because next floor number is not incremented on final floor
DEC
++: CMP $D08015 ; check if past initial floor
BCC +
STA $4204 ; WRDIVL; dividend = floor number
STZ $4205 ; WRDIVH
TAX
LDA $D0801A
STA $4206 ; WRDIVB; divisor = shop_interval
STA $211C ; M7B; second factor = shop_interval
JSL $8082C7 ; advance RNG (while waiting for division to complete)
LDY $4216 ; RDMPYL; skip if remainder (i.e., floor number mod shop_interval) is not 0
BNE +
STA $211B
STZ $211B ; M7A; first factor = random number from 0 to 255
TXA
CLC
SBC $2135 ; MPYM; calculate (floor number) - (random number from 0 to shop_interval-1) - 1
STA $30 ; set shop id
STZ $05A8 ; initialize variable for sold out item tracking
STZ $05A9
PHB
PHP
JML $80A33A ; open shop menu
+: RTL
; shop item select
pushpc
org $82DF50
; DB=$83, x=0, m=1
JML ShopItemSelected ; overwrites JSR $8B08 : CMP.b #$01
pullpc
ShopItemSelected:
LDA $1548 ; check inventory free space
BEQ +
JSR LoadShopSlotAsFlag
BIT $05A8 ; test item not already sold
BNE +
JML $82DF79 ; skip quantity selection and go directly to buy/equip
+: JML $82DF80 ; abort and go back to item selection
; track bought shop items
pushpc
org $82E084
; DB=$83, x=0, m=1
JSL ShopBuy ; overwrites LDA.b #$05 : LDX.w #$0007
NOP
org $82E10E
; DB=$83, x=0, m=1
JSL ShopEquip ; overwrites SEP #$10 : LDX $14DC
NOP
pullpc
ShopBuy:
JSR LoadShopSlotAsFlag
TSB $05A8 ; mark item as sold
LDA.b #$05 ; (overwritten instruction)
LDX.w #$0007 ; (overwritten instruction)
RTL
ShopEquip:
JSR LoadShopSlotAsFlag
TSB $05A8 ; mark item as sold
SEP #$10 ; (overwritten instruction)
LDX $14DC ; (overwritten instruction)
RTL
LoadShopSlotAsFlag:
TDC
LDA $14EC ; load currently selected shop slot number
ASL
TAX
LDA $8ED8C3,X ; load predefined bitmask with a single bit set
RTS
; mark bought items as sold out
pushpc
org $8285EA
; DB=$83, x=0, m=0
JSL SoldOut ; overwrites LDA [$FC],Y : AND #$01FF
NOP
pullpc
SoldOut:
LDA $8ED8C3,X ; load predefined bitmask with a single bit set
BIT $05A8 ; test sold items
BEQ +
LDA.w #$01CB ; load sold out item id
BRA ++
+: LDA [$FC],Y ; (overwritten instruction)
AND #$01FF ; (overwritten instruction)
++: RTL
; increase variety of red chest gear after B9
pushpc
org $839176
@@ -1054,6 +1172,7 @@ pullpc
; $F02017 1 iris treasures required
; $F02018 1 party members available
; $F02019 1 capsule monsters available
; $F0201A 1 shop interval
; $F02030 1 selected goal
; $F02031 1 goal completion: boss
; $F02032 1 goal completion: iris_treasure_hunt