Merge task #22: the joining player can open the store

The client now shows the "[E / X] Shop" prompt (ShedCounter resolved in
_focus_node); the host holds a partner's interact press up to 0.3 s for
its lagging copy to reach a counter instead of silently dropping it;
interact closes the partner's menu; a partner's purchase equips on its
own slot ("bought" event). PROTOCOL 5.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Forrest 2026-10-06 13:48:30 -04:00
commit 02b990d362
7 changed files with 305 additions and 23 deletions

View file

@ -5,7 +5,9 @@ extends RefCounted
## co-op health), requests from the partner (start the day, build, buy), the partner's scarecrow
## moving, gathering, and shooting on the host (and its pick of weapon), each scarecrow's own
## pouch (#16: gathering, the shed drop-off, paying, one shared capacity, goop to the killer, and
## the partner's pouch put in the shed when they leave), the weapons' stabs and
## the partner's pouch put in the shed when they leave), the partner's shops (#22: the prompt, the
## menus opening on the partner's farm and closing on interact, a press that beats the host's copy
## of P2 to the counter, a weapon bought into P2's hand), the weapons' stabs and
## pumpkin bombs (thrown from the off-hand, not with the right click leaving build mode) reaching the replica (drawn there, doing no damage of their own), enemies, loot,
## and shots reaching the replica,
## the co-op fall rule (one down is out until morning, both down is Game Over) and Retry, message
@ -38,6 +40,7 @@ func run(p_r: GameTestRunner) -> void:
_quiet_wire()
await _partner_moves_and_gathers()
_own_pouches()
_shops()
_night()
_partner_shoots()
_goop_to_killer()
@ -291,6 +294,112 @@ func _own_pouches() -> void:
_pump(6)
## #22: the partner's shops. P2 at the supply shed's counter by day sees its prompt, and interact
## opens the shed's menu on the partner's farm (the host asks for it), never on the host's; the
## host sees P2's menu up. Interact again closes it. A press that reaches the host while its copy
## of P2 is still walking up to the counter there isn't lost: it opens the menu once P2 is in reach
## (but a press long before doesn't open it later). The same at the work area's bench. A weapon
## P2 buys at the shed is paid from P2's pouch and the shed, and goes into P2's hand on both farms.
func _shops() -> void:
var res := host.campaign.state.resources
var counter := client.interactions.shed_counter
var bench := client.interactions.workbench
r.check(host.campaign.is_daytime() and counter != null and bench != null and host.structures.has_workbench(),
"(by day, with the shed's counter and the granted work area on both farms)")
host.player.global_position = AWAY
var at_counter := counter.global_position + Vector3(0.0, 0.0, 1.2)
client.player.global_position = at_counter
_pump(20)
client.interactions._process(0.0)
r.check(host.partner.interactions.focus is ShedCounter and client.interactions.focus == counter and counter._label.visible
and counter._label.text.begins_with("[E / X] Shop"),
"the partner at the shed's counter sees its prompt ('%s')" % counter._label.text.get_slice("\n", 0))
_tap_interact()
r.check(client.shed_panel.is_open and not host.shed_panel.is_open and host.partner.remote.ui_open,
"interact there opens the shed's menu on the partner's farm, not the host's (the host sees P2's menu up)")
_tap_interact()
r.check(not client.shed_panel.is_open and not host.partner.remote.ui_open and not host.shed_panel.is_open,
"interact again closes it on the partner's farm (and the press doesn't open it again)")
# Lag: the press reaches the host along with P2's arrival at the counter, while the host's copy
# of P2 is still on its way there (out of reach for a few ticks).
var off := counter.global_position + Vector3(0.0, 0.0, 4.5)
client.player.global_position = off
_pump(20)
client.player.global_position = at_counter
var taken: int = host.partner.remote._seen[3] # (interact)
var taken_at := -1.0 # how far the host's copy of P2 was from the counter when it took the press
Input.action_press("interact")
for i in 8:
_pump() # (the copy moves, then the host's hands take the press)
if taken_at < 0.0 and host.partner.remote._seen[3] != taken:
var hp := host.partner.body.global_position
taken_at = Vector2(hp.x - counter.global_position.x, hp.z - counter.global_position.z).length()
Input.action_release("interact")
_pump(20)
r.check(taken_at > counter.reach and client.shed_panel.is_open and host.partner.remote.ui_open,
"a press the host takes while its copy of P2 is still %.1f m from the counter opens the menu once the copy is in reach" % taken_at)
client.shed_panel.close()
_pump(10)
client.player.global_position = off
_pump(20)
_tap_interact() # well out of reach: nothing to open
_pump(30)
client.player.global_position = at_counter
_pump(30)
r.check(not client.shed_panel.is_open and not host.partner.remote.ui_open,
"but a press long before P2 got there doesn't open it later")
# The work area's bench.
var at_bench := bench.global_position + (bench.global_position - host.zones.zone(FarmZone.Kind.WORK_AREA).global_position).normalized() * 1.2
client.player.global_position = at_bench
_pump(20)
client.interactions._process(0.0)
r.check(host.partner.interactions.focus is Workbench and client.interactions.focus == bench and bench._label.text.begins_with("[E / X] Upgrades"),
"the partner at the work area's bench sees its prompt ('%s')" % bench._label.text.get_slice("\n", 0))
_tap_interact()
r.check(client.upgrade_panel.is_open and not host.upgrade_panel.is_open and host.partner.remote.ui_open,
"interact there opens the work area's menu on the partner's farm, not the host's")
_tap_interact()
r.check(not client.upgrade_panel.is_open and not host.partner.remote.ui_open, "and interact again closes it")
# Buying a weapon at the shed: P2's pouch, then the shed; into P2's hand.
var id := "shurikens"
var w := ScarecrowCombat.WEAPON_IDS.find(id)
var cost: Dictionary = host.config.costs[id]
client.player.global_position = at_counter
_pump(20)
_tap_interact()
_empty_pouches() # (P2 banked its pouch walking into the shed: fill it again with the menu up)
res.shed = {"wood": 0, "scrap": 0, "straw": 0, "alien_goop": 0}
for m: String in cost: # P2 carries all but one of each; the shed has the rest
res.pouch_of(1)[m] = int(cost[m]) - 1
res.shed[m] = 1
res.pouch_of(0)["scrap"] = 3 # P1's, kept
_pump(SETTLE)
var jingles := int(client.audio.played.get("upgrade", 0))
r.check(client.shed_panel.is_open and not (client.shed_panel._rows[id] as Button).disabled and not Upgrades.owned(host.campaign.state, id),
"the partner's shed menu offers the %s (P2's pouch and the shed can pay)" % id)
client.shed_panel._buy(id)
_pump(SETTLE * 2)
r.check(Upgrades.owned(host.campaign.state, id) and res.pouch_total(1) == 0 and res.shed_total() == 0 and int(res.pouch_of(0)["scrap"]) == 3,
"P2 buys the %s: paid from P2's pouch and the shed, P1's pouch untouched (P1 %s)" % [id, res.pouch_of(0)])
r.check(client.combat.weapon == w and host.partner.combat.weapon == w and host.combat.weapon != w,
"and it goes into P2's hand on both farms (P1's hand unchanged)")
r.check(int(client.audio.played.get("upgrade", 0)) == jingles + 1, "with the purchase's jingle on the partner's side")
client.shed_panel.close()
host.campaign.state.upgrades.erase(id)
_empty_pouches()
client.player.global_position = Vector3(0.5, 0.0, 6.0)
_pump(SETTLE)
r.check(client.combat.weapon == ScarecrowCombat.Weapon.PITCHFORK, "(back to the pitchfork)")
## The partner taps interact: held for a few ticks, then let go, and the news settles.
func _tap_interact() -> void:
Input.action_press("interact")
_pump(4)
Input.action_release("interact")
_pump(20)
func _night() -> void:
host.campaign.advance_phase()
host.campaign.advance_phase()