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
|
|
@ -10,7 +10,8 @@ extends RefCounted
|
|||
## and hidden/reveal shop items (#5): an item flagged "hidden" shows only "?" and can't be bought
|
||||
## until enough Alien Goop has been collected in total, then shows and buys normally; and the
|
||||
## supply shed's own shop (#6): weapons (corn_shooter, pumpkin_bomb) bought at its counter
|
||||
## (ShedCounter), not the workbench, with the walk-in pouch deposit unaffected.
|
||||
## (ShedCounter), not the workbench, with the walk-in pouch deposit unaffected. And a pouch per
|
||||
## scarecrow (#16): filled, deposited, and spent from by its own avatar slot, one shared capacity.
|
||||
|
||||
const P := CampaignController.Phase
|
||||
const DT := 1.0 / 60.0
|
||||
|
|
@ -18,6 +19,7 @@ const DT := 1.0 / 60.0
|
|||
|
||||
func run(r: GameTestRunner) -> void:
|
||||
_store(r)
|
||||
_pouches(r)
|
||||
_state(r)
|
||||
_goop_persistence(r)
|
||||
_pouch_upgrade(r)
|
||||
|
|
@ -64,7 +66,9 @@ func _store(r: GameTestRunner) -> void:
|
|||
"a negative amount": func(d: Dictionary) -> void: d["shed"]["wood"] = -1,
|
||||
"an unknown material": func(d: Dictionary) -> void: d["pouch"]["gold"] = 1,
|
||||
"an overfull pouch": func(d: Dictionary) -> void: d["pouch"]["wood"] = 99,
|
||||
"an overfull partner pouch": func(d: Dictionary) -> void: d["partner_pouch"]["wood"] = 99,
|
||||
"a missing part": func(d: Dictionary) -> void: d.erase("shed"),
|
||||
"a missing partner pouch": func(d: Dictionary) -> void: d.erase("partner_pouch"),
|
||||
}
|
||||
for label: String in bad:
|
||||
var d := s.to_dict()
|
||||
|
|
@ -74,6 +78,37 @@ func _store(r: GameTestRunner) -> void:
|
|||
r.check(ResourceStore.from_dict(d) == null, "the store rejects %s" % label)
|
||||
|
||||
|
||||
## #16: a pouch per scarecrow (avatar slot; 0 is player 1, the default), sharing one capacity.
|
||||
## Each fills, deposits, and pays from its own; the shed is shared.
|
||||
func _pouches(r: GameTestRunner) -> void:
|
||||
var s := ResourceStore.new()
|
||||
s.pouch_capacity = 10
|
||||
r.check(s.add_to_pouch("wood", 6, 1) == 6 and s.pouch_total(1) == 6 and s.pouch_total() == 0
|
||||
and s.pouch_room(1) == 4 and s.pouch_room() == 10, "player 2's pouch fills on its own; player 1's (the default) stays empty")
|
||||
r.check(s.add_to_pouch("straw", 9, 1) == 4 and s.add_to_pouch("straw", 9) == 9,
|
||||
"each pouch takes what fits in it, the same capacity for both")
|
||||
var moved := s.deposit()
|
||||
r.check(moved == {"straw": 9} and s.pouch_total() == 0 and s.pouch_total(1) == 10 and s.shed["straw"] == 9,
|
||||
"depositing player 1's pouch leaves player 2's alone")
|
||||
r.check(s.deposit(1) == {"wood": 6, "straw": 4} and s.pouch_total(1) == 0 and s.shed["wood"] == 6 and s.shed["straw"] == 13,
|
||||
"player 2 deposits their own")
|
||||
s.shed = {"wood": 1, "scrap": 0, "straw": 0, "alien_goop": 0}
|
||||
s.pouch["wood"] = 3
|
||||
s.pouch_of(1)["wood"] = 2
|
||||
r.check(s.available("wood") == 4 and s.available("wood", 1) == 3 and s.missing({"wood": 4}, 1) == {"wood": 1}
|
||||
and s.can_afford({"wood": 4}) and not s.can_afford({"wood": 4}, 1), "each can spend their own pouch and the shed, never the other's pouch")
|
||||
r.check(not s.pay({"wood": 4}, 1) and s.pouch["wood"] == 3 and s.pouch_of(1)["wood"] == 2 and s.shed["wood"] == 1,
|
||||
"a cost player 2 can't meet pays nothing (player 1's wood isn't touched)")
|
||||
r.check(s.pay({"wood": 3}, 1) and s.pouch_of(1)["wood"] == 0 and s.shed["wood"] == 0 and s.pouch["wood"] == 3,
|
||||
"player 2 pays from their own pouch first, then the shed")
|
||||
r.check(is_same(s.pouch_of(5), s.pouch_of(1)) and is_same(s.pouch_of(-1), s.pouch), "an out-of-range slot reads as the nearest pouch")
|
||||
s.pouch_of(1)["alien_goop"] = 2
|
||||
var d := s.to_dict()
|
||||
r.check(d["pouch"]["wood"] == 3 and d["partner_pouch"]["alien_goop"] == 2, "to_dict() keeps player 1's as pouch and player 2's as partner_pouch")
|
||||
var back := ResourceStore.from_dict(JSON.parse_string(JSON.stringify(d)))
|
||||
r.check(back != null and back.to_dict() == d and back.pouch_total(1) == 2, "both pouches round-trip through JSON")
|
||||
|
||||
|
||||
func _state(r: GameTestRunner) -> void:
|
||||
var cfg := (load("res://game/resources/game_config.tres") as GameConfig).duplicate() as GameConfig
|
||||
var s := FarmState.create(cfg)
|
||||
|
|
@ -125,6 +160,7 @@ func _pouch_upgrade(r: GameTestRunner) -> void:
|
|||
var msg := Upgrades.buy(c, "pouch_upgrade")
|
||||
r.check(Upgrades.owned(s, "pouch_upgrade") and msg.contains("done:") and s.resources.pouch_capacity == 16,
|
||||
"Bigger pouch raises capacity from 8 to 16 (%s)" % msg)
|
||||
r.check(s.resources.pouch_room(0) == 16 and s.resources.pouch_room(1) == 16, "for both scarecrows' pouches (#16: one shared capacity)")
|
||||
r.check(s.resources.shed_total() == 0, "it costs the configured materials")
|
||||
r.check(Upgrades.buy(c, "pouch_upgrade").contains("already done"), "it can only be bought once")
|
||||
# It carries into the next morning (same mechanic as straw_stuffing/scarecrow_max_hp).
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue