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
|
|
@ -31,7 +31,8 @@ extends Node3D
|
|||
## In co-op each scarecrow has its own Interactions. The partner's, on the host, reads its
|
||||
## RemoteControls (remote), asks the partner's game to open its own upgrade menu
|
||||
## (workbench_requested / shed_requested), and leaves the gather labels to the local player's
|
||||
## (show_labels).
|
||||
## (show_labels). Each one gathers into, deposits, and pays from its own scarecrow's pouch
|
||||
## (kit.slot, ResourceStore): a partner standing in the shed banks only their own pouch.
|
||||
|
||||
signal gathered(material: String, amount: int, node: GatherNode)
|
||||
signal deposited(moved: Dictionary)
|
||||
|
|
@ -179,8 +180,8 @@ func step(dt: float) -> void:
|
|||
if shed_panel != null and shed_panel.is_open:
|
||||
_step_menu(shed_panel, shed_counter, p, pressed)
|
||||
return
|
||||
if _shed != null and _shed.contains(player.global_position) and campaign.state.resources.pouch_total() > 0:
|
||||
var moved := campaign.state.resources.deposit()
|
||||
if _shed != null and _shed.contains(player.global_position) and campaign.state.resources.pouch_total(kit.slot) > 0:
|
||||
var moved := campaign.state.resources.deposit(kit.slot)
|
||||
deposited.emit(moved)
|
||||
message.emit("Stored %s in the shed" % ResourceStore.describe(moved), Color(0.85, 0.95, 1.0))
|
||||
if repairing >= 0:
|
||||
|
|
@ -192,11 +193,11 @@ func step(dt: float) -> void:
|
|||
var id := repairing
|
||||
var cost := structures.repair_cost(id)
|
||||
cancel()
|
||||
if structures.repair(id):
|
||||
if structures.repair(id, kit.slot):
|
||||
message.emit("Repaired (%s)" % ResourceStore.describe(cost), Color(0.6, 1.0, 0.55))
|
||||
return
|
||||
if upgrading >= 0:
|
||||
if not held or not campaign.is_daytime() or structures.upgrade_blocker(upgrading) != "":
|
||||
if not held or not campaign.is_daytime() or structures.upgrade_blocker(upgrading, kit.slot) != "":
|
||||
cancel()
|
||||
return
|
||||
upgrade_elapsed += dt
|
||||
|
|
@ -204,7 +205,7 @@ func step(dt: float) -> void:
|
|||
var id := upgrading
|
||||
var cost := structures.upgrade_cost(id)
|
||||
cancel()
|
||||
if structures.upgrade(id):
|
||||
if structures.upgrade(id, kit.slot):
|
||||
message.emit("Upgraded to L%d (%s)" % [structures.level_of(id), ResourceStore.describe(cost)], Color(0.6, 1.0, 0.55))
|
||||
return
|
||||
if gathering != null:
|
||||
|
|
@ -223,13 +224,13 @@ func step(dt: float) -> void:
|
|||
focus = null
|
||||
if held and not kit.patching:
|
||||
var cost := structures.repair_cost(repair_target)
|
||||
if campaign.state.resources.can_afford(cost):
|
||||
if campaign.state.resources.can_afford(cost, kit.slot):
|
||||
repairing = repair_target
|
||||
repair_elapsed = 0.0
|
||||
player.start_channel(&"Hammering")
|
||||
elif not _denied:
|
||||
_denied = true
|
||||
message.emit("Not enough to repair: need %s more" % ResourceStore.describe(campaign.state.resources.missing(cost)), Color(1.0, 0.8, 0.5))
|
||||
message.emit("Not enough to repair: need %s more" % ResourceStore.describe(campaign.state.resources.missing(cost, kit.slot)), Color(1.0, 0.8, 0.5))
|
||||
return
|
||||
upgrade_target = structures.upgradeable_near(p, REPAIR_REACH) if structures != null else -1
|
||||
if upgrade_target >= 0:
|
||||
|
|
@ -240,7 +241,7 @@ func step(dt: float) -> void:
|
|||
_denied = true
|
||||
message.emit("Upgrading is for daytime", Color(1.0, 0.8, 0.5))
|
||||
else:
|
||||
var why := structures.upgrade_blocker(upgrade_target)
|
||||
var why := structures.upgrade_blocker(upgrade_target, kit.slot)
|
||||
if why == "":
|
||||
upgrading = upgrade_target
|
||||
upgrade_elapsed = 0.0
|
||||
|
|
@ -293,7 +294,7 @@ func _blocker(n: GatherNode) -> String:
|
|||
return "Gathering is for daytime"
|
||||
if charges(n) <= 0:
|
||||
return "Nothing left here; it grows back overnight"
|
||||
if campaign.state.resources.pouch_room() < n.yield_amount:
|
||||
if campaign.state.resources.pouch_room(kit.slot) < n.yield_amount:
|
||||
return "Pouch full: drop it off at the supply shed"
|
||||
return ""
|
||||
|
||||
|
|
@ -303,7 +304,7 @@ func _blocker(n: GatherNode) -> String:
|
|||
func _upgrade_prompt(id: int) -> String:
|
||||
if not campaign.is_daytime():
|
||||
return "Upgrading is for daytime"
|
||||
var why := structures.upgrade_blocker(id)
|
||||
var why := structures.upgrade_blocker(id, kit.slot)
|
||||
if why == "":
|
||||
return "[E / X] Upgrade to L%d (%s)" % [structures.level_of(id) + 1, ResourceStore.describe(structures.upgrade_cost(id))]
|
||||
return why
|
||||
|
|
@ -336,7 +337,7 @@ func regen_overnight() -> void:
|
|||
func _finish_gather() -> void:
|
||||
var n := gathering
|
||||
var s := campaign.state
|
||||
var added := s.resources.add_to_pouch(n.material, n.yield_amount)
|
||||
var added := s.resources.add_to_pouch(n.material, n.yield_amount, kit.slot)
|
||||
var left := charges(n) - 1
|
||||
s.gather_charges[String(n.name)] = left
|
||||
cancel()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue