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
|
|
@ -32,7 +32,10 @@ extends Node3D
|
|||
## 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). 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.
|
||||
## (kit.slot, ResourceStore): a partner standing in the shed banks only their own pouch. The
|
||||
## host's copy of the partner trails the partner's own machine by a few ticks, so a press of
|
||||
## interact made on arrival at a shop's counter can reach the host while the copy is still out of
|
||||
## reach: it stays pending for PRESS_WINDOW seconds, until a counter in reach takes it (#22).
|
||||
|
||||
signal gathered(material: String, amount: int, node: GatherNode)
|
||||
signal deposited(moved: Dictionary)
|
||||
|
|
@ -46,6 +49,8 @@ const LABEL_RANGE := 7.0
|
|||
const REPAIR_REACH := 1.4
|
||||
const POPUP_TIME := 1.1
|
||||
const POPUPS := 6
|
||||
## Seconds a partner's press of interact waits (on the host) for its copy to reach a counter.
|
||||
const PRESS_WINDOW := 0.3
|
||||
|
||||
var config: GameConfig
|
||||
var campaign: CampaignController
|
||||
|
|
@ -78,6 +83,8 @@ var upgrade_elapsed: float = 0.0
|
|||
var _shed: FarmZone
|
||||
var _interact_requested := false
|
||||
var _interact_was_held := false
|
||||
## Co-op: what's left of the partner's pending press (seconds; 0 = none).
|
||||
var _press_left: float = 0.0
|
||||
var _denied := false
|
||||
var _popups: Array[Label3D] = []
|
||||
var _repair_label: Label3D
|
||||
|
|
@ -158,7 +165,7 @@ func step(dt: float) -> void:
|
|||
var held := remote.held(&"interact") if remote != null else Input.is_action_pressed("interact")
|
||||
var pressed := _interact_requested or (held and not _interact_was_held)
|
||||
if remote != null:
|
||||
pressed = remote.take(&"interact")
|
||||
pressed = _remote_press(dt)
|
||||
_interact_requested = false
|
||||
_interact_was_held = held
|
||||
if not held:
|
||||
|
|
@ -172,6 +179,7 @@ func step(dt: float) -> void:
|
|||
repair_target = -1
|
||||
upgrade_target = -1
|
||||
focus = null
|
||||
_press_left = 0.0
|
||||
return
|
||||
var p := Vector2(player.global_position.x, player.global_position.z)
|
||||
if upgrade_panel != null and upgrade_panel.is_open:
|
||||
|
|
@ -261,6 +269,7 @@ func step(dt: float) -> void:
|
|||
_denied = true
|
||||
message.emit(why, Color(1.0, 0.8, 0.5))
|
||||
elif focus is Workbench and pressed:
|
||||
_press_left = 0.0
|
||||
if structures != null and structures.is_broken(structures.workbench_id()):
|
||||
message.emit("Broken -- repair it", Color(1.0, 0.8, 0.5))
|
||||
elif not campaign.is_daytime():
|
||||
|
|
@ -270,6 +279,7 @@ func step(dt: float) -> void:
|
|||
elif remote != null:
|
||||
workbench_requested.emit()
|
||||
elif focus is ShedCounter and pressed:
|
||||
_press_left = 0.0
|
||||
if not campaign.is_daytime():
|
||||
message.emit("The supply shed is for daytime", Color(1.0, 0.8, 0.5))
|
||||
elif shed_panel != null:
|
||||
|
|
@ -286,6 +296,18 @@ func _step_menu(panel: UpgradePanel, counter, p: Vector2, pressed: bool) -> void
|
|||
var reach: float = counter.reach if counter != null else 0.0
|
||||
if pressed or not campaign.is_daytime() or at.distance_to(p) > reach + 0.5 or (build != null and build.active):
|
||||
panel.close()
|
||||
_press_left = 0.0
|
||||
|
||||
|
||||
## Co-op, the partner's hands on the host: whether a press of interact is pending. A new one
|
||||
## (RemoteControls.take) waits up to PRESS_WINDOW seconds for a counter in reach to take it
|
||||
## (which clears _press_left), instead of being dropped on the tick it arrives.
|
||||
func _remote_press(dt: float) -> bool:
|
||||
if remote.take(&"interact"):
|
||||
_press_left = PRESS_WINDOW
|
||||
else:
|
||||
_press_left = maxf(_press_left - dt, 0.0)
|
||||
return _press_left > 0.0
|
||||
|
||||
|
||||
## Why a point can't be gathered right now ("" if it can).
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue