Task #22: the joining player can open the store
Cause: the open path itself worked. A real two-process run with an E key event opened the shed's menu when P2 stood at the counter. What failed in play was reach: - The partner's game never showed the counter's "[E / X] Shop" prompt. CoopSession._gather_node resolved only the workbench and gather points, so P2's replicated focus was null at the counter. P2 couldn't tell where the 2.2 m reach around the counter's invisible point was. - The host took P2's press on the first tick after the input record arrived, before its copy of P2 had eased to the position in that same record. It dropped the press silently if the lagging copy was out of reach. Walking in at 5 or 9 m/s and pressing E at 2.1 m (inside the reach on P2's screen) failed 3/3. The host's copy was 2.31-2.66 m out. Fixes: - The snapshot's focus now resolves the ShedCounter (_focus_node), so the prompt shows. - The host keeps a partner's interact press pending for 0.3 s (Interactions.PRESS_WINDOW) until a counter in reach takes it. - Interact while the partner's shop menu is open closes it on the partner's machine, and that press is taken back (RemoteControls.Sender.take_back), so the host never reopens it. - When the host completes P2's "buy", it sends a "bought" event. Once P2's farm state has the upgrade, the partner's panel emits bought (UpgradePanel.confirm_bought). As in solo, the new weapon goes into P2's hand and the jingle plays. Still paid from P2's pouch, then the shed. - CoopSession.PROTOCOL 4 -> 5. Tests: test_coop _shops covers both shops opening on the client only, the prompt, interact closing, a press taken while the host's copy is 3.8 m out still opening, an early press not opening later, and a client weapon buy paid from P2's pouch and the shed and equipped on both farms. coop_smoke now opens and closes the shed by day with E key events, both standing and on arrival at a run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
287b6ac6cc
commit
315e6890f7
7 changed files with 305 additions and 23 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue