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
|
|
@ -11,7 +11,9 @@ extends Node
|
|||
## refused (reliable) the partner's game speaks another PROTOCOL
|
||||
## batch (reliable, each tick with news) events in order: phase changes (with the state),
|
||||
## the end of the campaign, sounds, toasts for the partner, loot and arrival news,
|
||||
## breaches, fear bursts, gather popups, the workbench; enemies removed
|
||||
## breaches, fear bursts, gather popups, opening a shop's menu (the workbench's, the
|
||||
## shed's), a purchase the partner made (bought: the slot and the upgrade id, so a
|
||||
## new weapon goes into its hand); enemies removed
|
||||
## state (reliable, at most STATE_HZ, when it changed) the farm state (the phase clock
|
||||
## alone isn't a change: it is in every snapshot)
|
||||
## loot (reliable, at most LOOT_HZ, when it changed) every item
|
||||
|
|
@ -22,7 +24,8 @@ extends Node
|
|||
## hello (reliable) its player's name and PROTOCOL
|
||||
## input (unreliable, up to INPUT_HZ when it changed, else every INPUT_KEEPALIVE) its
|
||||
## scarecrow's position and facing, held buttons and press counts, aim, build mode,
|
||||
## the upgrade menu (RemoteControls, packed bytes)
|
||||
## whether a shop's menu is up (RemoteControls, packed bytes). A press of interact
|
||||
## that closes the partner's own menu stays on its machine (Sender.take_back)
|
||||
## req (reliable) start the day, start the night early, retry the night, build,
|
||||
## dismantle, buy an upgrade
|
||||
## Unreliable messages stay under CoopLink.UNRELIABLE_LIMIT; nothing depends on any single one
|
||||
|
|
@ -45,8 +48,10 @@ signal welcomed
|
|||
## The wire format: both machines must speak the same one (hello and welcome carry it). 3: #10
|
||||
## added a time field and two int32s (the upgrade target/progress) to _put_avatar/_read_avatar's
|
||||
## per-avatar snapshot record. 4: #16 gave each scarecrow its own pouch (the farm state's
|
||||
## resources.partner_pouch, FarmState.VERSION 7).
|
||||
const PROTOCOL := 4
|
||||
## resources.partner_pouch, FarmState.VERSION 7). 5: #22's partner shops: the "bought" event, the
|
||||
## shed's counter as a snapshot's focus, and the partner's press of interact that closes its own
|
||||
## menu no longer sent (the host keeps a press pending until P2's copy is in reach).
|
||||
const PROTOCOL := 5
|
||||
const SNAP_EVERY := 4 # physics ticks: 15 Hz
|
||||
const INPUT_EVERY := 3 # 20 Hz, when it changed
|
||||
## Seconds: the partner's input goes out at least this often, changed or not.
|
||||
|
|
@ -106,6 +111,8 @@ var _input_age: float = 0.0
|
|||
var _snap_tick: int = -1
|
||||
var _structures_json := ""
|
||||
var _shed_json := ""
|
||||
## Upgrade ids the host bought for this machine's scarecrow, until this farm's state has them.
|
||||
var _bought: Array[String] = []
|
||||
var _is_welcomed := false
|
||||
var _welcome_sent := false
|
||||
var _hello_wait: float = 0.0
|
||||
|
|
@ -555,8 +562,11 @@ func _do_request(r: Array) -> void:
|
|||
if Upgrades.shop_of(c.config, id) == "workbench" and (sim.structures == null or not sim.structures.workbench_available()):
|
||||
_events.append(["toast", "The work area isn't available", Color(1.0, 0.8, 0.5)])
|
||||
return
|
||||
var was := Upgrades.owned(c.state, id)
|
||||
var text := Upgrades.buy(c, id, sim.structures, a.slot) # paid from P2's pouch, then the shed
|
||||
_events.append(["toast", text, Color(0.85, 0.75, 1.0) if text.contains("done:") else Color(1.0, 0.8, 0.5)])
|
||||
if not was and Upgrades.owned(c.state, id):
|
||||
_events.append(["bought", a.slot, id]) # the buyer's game: a new weapon into its hand
|
||||
|
||||
|
||||
## Co-op is on for the farm state (after a retry, a new vacation, or a morning).
|
||||
|
|
@ -646,6 +656,19 @@ func _apply_state(d: Dictionary, everything: bool = false) -> void:
|
|||
sim.shed_panel.refresh()
|
||||
if c.state.phase == CampaignController.Phase.MORNING and sim.review_panel != null:
|
||||
sim.review_panel.refresh()
|
||||
_settle_bought()
|
||||
|
||||
|
||||
## The purchases the host made for this machine's scarecrow that this farm's state has by now
|
||||
## count as bought here (UpgradePanel.confirm_bought: a new weapon goes into its hand). The
|
||||
## "bought" news can come before the farm state that has the upgrade.
|
||||
func _settle_bought() -> void:
|
||||
for id in _bought.duplicate():
|
||||
if Upgrades.owned(sim.campaign.state, id):
|
||||
_bought.erase(id)
|
||||
var panel := sim.shed_panel if Upgrades.shop_of(sim.config, id) == "shed" else sim.upgrade_panel
|
||||
if panel != null:
|
||||
panel.confirm_bought(id)
|
||||
|
||||
|
||||
func _apply_event(e: Array) -> void:
|
||||
|
|
@ -705,6 +728,10 @@ func _apply_event(e: Array) -> void:
|
|||
"shed":
|
||||
if sim.shed_panel != null and c.is_daytime():
|
||||
sim.shed_panel.open()
|
||||
"bought":
|
||||
if int(e[1]) == sim.local_avatar.slot:
|
||||
_bought.append(String(e[2]))
|
||||
_settle_bought()
|
||||
|
||||
|
||||
func _apply_snap(data: PackedByteArray) -> void:
|
||||
|
|
@ -794,8 +821,8 @@ func _apply_avatar(a: Avatar, rec: Dictionary) -> void:
|
|||
elif ch == "" and body.rooted and not sim._menu_open():
|
||||
body.stop_channel()
|
||||
var it := a.interactions
|
||||
it.focus = _gather_node(String(rec["fo"]))
|
||||
it.gathering = _gather_node(String(rec["ga"])) as GatherNode
|
||||
it.focus = _focus_node(String(rec["fo"]))
|
||||
it.gathering = _focus_node(String(rec["ga"])) as GatherNode
|
||||
it.gather_elapsed = float(rec["ge"])
|
||||
it.repair_target = int(rec["rt"])
|
||||
it.repairing = int(rec["rp"])
|
||||
|
|
@ -805,12 +832,17 @@ func _apply_avatar(a: Avatar, rec: Dictionary) -> void:
|
|||
it.upgrade_elapsed = float(rec["ue"])
|
||||
|
||||
|
||||
func _gather_node(node_name: String) -> Node3D:
|
||||
## What a snapshot names as P2's focus (or gathering point) on this farm: a gather point, the
|
||||
## workbench, or the shed's counter, so the local labels show the prompt the host's hands have
|
||||
## (Interactions._process: "[E / X] Shop" at the counter, #22).
|
||||
func _focus_node(node_name: String) -> Node3D:
|
||||
if node_name == "":
|
||||
return null
|
||||
var it := sim.interactions
|
||||
if it.workbench != null and String(it.workbench.name) == node_name:
|
||||
return it.workbench
|
||||
if it.shed_counter != null and String(it.shed_counter.name) == node_name:
|
||||
return it.shed_counter
|
||||
for n in it.nodes:
|
||||
if String(n.name) == node_name:
|
||||
return n
|
||||
|
|
@ -908,6 +940,8 @@ func _reset_world() -> void:
|
|||
## replaced soon; standing still sends little).
|
||||
func _send_input() -> void:
|
||||
var a := sim.local_avatar
|
||||
if sim._menu_open() and _sender.take_back(&"interact") > 0:
|
||||
_close_menus() # interact again closes it, as in solo; that press never reaches the host
|
||||
var ui := sim._menu_open()
|
||||
var rec := _sender.record(a.combat, a.body, sim.build.active, ui, sim.local_frozen)
|
||||
if rec != _last_input or _input_age >= INPUT_KEEPALIVE - 0.001: # (sums of 1/60 fall a hair short)
|
||||
|
|
@ -922,13 +956,19 @@ func _unhandled_input(event: InputEvent) -> void:
|
|||
_sender.note(event)
|
||||
|
||||
|
||||
## Either shop's menu closes here on the same rules as solo (Interactions): walking off its
|
||||
## counter's reach, nightfall, build mode.
|
||||
## Either shop's menu closes here on the same rules as solo (Interactions): interact again (in
|
||||
## _send_input), walking off its counter's reach, nightfall, build mode.
|
||||
func _close_menu_if_needed() -> void:
|
||||
_close_menu(sim.upgrade_panel, sim.interactions.workbench)
|
||||
_close_menu(sim.shed_panel, sim.interactions.shed_counter)
|
||||
|
||||
|
||||
func _close_menus() -> void:
|
||||
for panel: UpgradePanel in [sim.upgrade_panel, sim.shed_panel]:
|
||||
if panel != null:
|
||||
panel.close()
|
||||
|
||||
|
||||
## counter: Workbench or ShedCounter (both just need global_position and reach).
|
||||
func _close_menu(panel: UpgradePanel, counter) -> void:
|
||||
if panel == null or not panel.is_open:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue