Task #16: per-player pouch in co-op
Each scarecrow carries its own pouch (ResourceStore.pouches by avatar slot; slot 0 is the solo player / host, `pouch` stays slot 0's), with one shared pouch_capacity so a Bigger pouch grows both. The shed stays shared. - Gathering, the shed drop-off, repair, upgrade-in-place, patching, building and buying all act on the acting avatar's slot. The host pays the partner's "place" and "buy" requests from P2's pouch and the shed. - The partner's build mode, build hotbar, shop menus and materials HUD check affordability against P2's pouch (FarmSim.set_local). - Alien Goop goes to the killer's pouch: FarmSim sets EnemySystem.attacker around each avatar's combat step and shots carry their shooter's slot; bomb/turret kills go to the nearest scarecrow. The replica no longer rolls goop locally. - When the partner leaves, their pouch goes into the shed (and is named in the toast); a co-op save continued alone banks P2's pouch at morning. - FarmState.VERSION 7 (resources.partner_pouch) with a v6 migration; CoopSession.PROTOCOL 4. - Tests: per-slot store rules, v6 save migration, and test_coop cases for separate gathering, no cross-banking in the shed, own-pouch paying, shared capacity, goop credit and leaving. test_coop's crowd case now resets the loopback's drop counter so earlier traffic can't change which messages it loses. - Docs: COOP.md and RULES.md no longer say the pouch is shared. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
26b735d3e6
commit
fa7f67fe04
23 changed files with 535 additions and 138 deletions
|
|
@ -9,7 +9,8 @@ extends RefCounted
|
|||
## of reading GameConfig directly: the corn shooter's fire rate and shot damage, fear's radius and
|
||||
## cooldown, fences' and gates' health (barrier_hp), the automated defense's range, and the traps'
|
||||
## slow time. Straw stuffing raises the scarecrow's max health (FarmState) when bought, and the
|
||||
## Bigger pouch upgrade raises pouch_capacity (ResourceStore) the same way. Sprint, the corn
|
||||
## Bigger pouch upgrade raises pouch_capacity (ResourceStore, shared: every scarecrow's pouch
|
||||
## grows) the same way. The buyer pays from their own pouch and the shed (slot). Sprint, the corn
|
||||
## shooter, and pumpkin bombs change no stat: owning them unlocks sprinting (PlayerCharacter) and
|
||||
## the two weapons (ScarecrowCombat). Rapid fire and heavy seeds (bought at the workbench) need
|
||||
## the corn shooter (bought at the shed) first ("requires" crosses shops freely).
|
||||
|
|
@ -73,8 +74,9 @@ static func value(cfg: GameConfig, state: FarmState, stat: String) -> float:
|
|||
return v
|
||||
|
||||
|
||||
## Why an upgrade can't be bought right now ("" if it can).
|
||||
static func blocker(campaign: CampaignController, id: String) -> String:
|
||||
## Why an upgrade can't be bought right now ("" if it can), by the scarecrow in this avatar slot
|
||||
## (its pouch and the shed pay).
|
||||
static func blocker(campaign: CampaignController, id: String, slot: int = 0) -> String:
|
||||
var cfg := campaign.config
|
||||
var s := campaign.state
|
||||
if not cfg.upgrades.has(id):
|
||||
|
|
@ -88,21 +90,22 @@ static func blocker(campaign: CampaignController, id: String) -> String:
|
|||
return "Needs the %s first" % String(cfg.upgrades.get(needs, {}).get("name", needs)).to_lower()
|
||||
if not campaign.is_daytime():
|
||||
return "The work area is for daytime"
|
||||
if not s.resources.can_afford(cost(cfg, id)):
|
||||
return "Need %s more" % ResourceStore.describe(s.resources.missing(cost(cfg, id)))
|
||||
if not s.resources.can_afford(cost(cfg, id), slot):
|
||||
return "Need %s more" % ResourceStore.describe(s.resources.missing(cost(cfg, id), slot))
|
||||
return ""
|
||||
|
||||
|
||||
## Buys an upgrade if it can be bought. Returns the message for the player.
|
||||
static func buy(campaign: CampaignController, id: String, structures: StructureSystem = null) -> String:
|
||||
## Buys an upgrade if it can be bought, paid by the scarecrow in this avatar slot (its pouch,
|
||||
## then the shed). Returns the message for the player.
|
||||
static func buy(campaign: CampaignController, id: String, structures: StructureSystem = null, slot: int = 0) -> String:
|
||||
var cfg := campaign.config
|
||||
var s := campaign.state
|
||||
var u: Dictionary = cfg.upgrades.get(id, {})
|
||||
var why := blocker(campaign, id)
|
||||
var why := blocker(campaign, id, slot)
|
||||
if why != "":
|
||||
return "%s: %s" % [u.get("name", id), why.to_lower() if why != "Done" else "already done"]
|
||||
var barrier_before := value(cfg, s, "barrier_hp")
|
||||
s.pay(cost(cfg, id))
|
||||
s.pay(cost(cfg, id), slot)
|
||||
s.upgrades[id] = 1
|
||||
s.record_event("upgrades_bought")
|
||||
match String(u.get("stat", "")):
|
||||
|
|
@ -117,6 +120,6 @@ static func buy(campaign: CampaignController, id: String, structures: StructureS
|
|||
for e in s.structures:
|
||||
if e["type"] == "fence" or e["type"] == "gate":
|
||||
e["hp"] = mini(roundi(int(e["hp"]) * k), structures.max_hp(e["type"]) if structures != null else 1 << 20)
|
||||
"pouch_capacity": # the live value lives in ResourceStore, not read from cfg each time
|
||||
"pouch_capacity": # the live value lives in ResourceStore (one for every pouch), not read from cfg each time
|
||||
s.resources.pouch_capacity += int(u.get("add", 0))
|
||||
return "%s done: %s" % [u.get("name", id), String(u.get("text", "")).to_lower()]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue