Task #6: Supply Shed as its own weapon shop, separate from the Workbench
Adds a second UpgradePanel instance (shop "shed") at the Supply Shed's new
ShedCounter node, opened by interact like the Workbench. corn_shooter and
pumpkin_bomb move there ("shop": "shed" in GameConfig.upgrades); the
Workbench's panel (shop "workbench", the default) keeps rapid_fire,
heavy_seeds, and the rest, with "requires" still crossing shops. Co-op buys
go through the same ["buy", id] host gate; a shed_requested signal mirrors
workbench_requested so the partner's own shed panel opens. The shed's
walk-in pouch deposit is unaffected (no interact, not gated by the
counter's reach).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
1ccf825bbf
commit
308854d52c
17 changed files with 260 additions and 64 deletions
|
|
@ -1,31 +1,37 @@
|
|||
class_name Interactions
|
||||
extends Node3D
|
||||
## The scarecrow's hands: gathering at GatherNodes, buying at the Workbench, repairing damaged
|
||||
## structures, and dropping the pouch off at the supply shed. Nothing here works in build mode.
|
||||
## * Focus: the nearest gather point or workbench within its reach, preferring points with
|
||||
## charges left over used-up ones; nearby points show their charges, the focused one its
|
||||
## prompt (or why it can't be used).
|
||||
## The scarecrow's hands: gathering at GatherNodes, buying at the Workbench or the supply shed's
|
||||
## ShedCounter, repairing damaged structures, and dropping the pouch off at the supply shed.
|
||||
## Nothing here works in build mode.
|
||||
## * Focus: the nearest gather point, workbench, or shed counter within its reach, preferring
|
||||
## gather points with charges left over used-up ones; nearby points show their charges, the
|
||||
## focused one its prompt (or why it can't be used).
|
||||
## * Gather: hold interact by day (D8) at a point with charges left and room in the pouch for
|
||||
## the whole yield (so a charge is never half wasted).
|
||||
## The scarecrow is rooted for gather_time looping the point's clip, then yield_amount goes
|
||||
## into the pouch ("+2 wood" pops up) and one charge is used. Keep holding to gather again.
|
||||
## Letting go, a hit, fear, nightfall, or a full pouch cancels it.
|
||||
## * Workbench: press interact by day to open the upgrade menu (UpgradePanel); interact again,
|
||||
## walking away, or nightfall closes it. Nothing else happens here while it's open.
|
||||
## * Workbench / shed counter: press interact by day to open that shop's menu (UpgradePanel,
|
||||
## shop "workbench" or "shed"); interact again, walking away, or nightfall closes it. Nothing
|
||||
## else happens here while one is open.
|
||||
## * Repair: a damaged structure within REPAIR_REACH comes first. Hold interact for
|
||||
## repair_time (any phase) to repair it fully for StructureSystem.repair_cost (paid at the
|
||||
## end); it is refused, once per press, without the materials.
|
||||
## * Deposit: walking into the Supply Shed zone empties the pouch into the shed.
|
||||
## * Deposit: walking into the Supply Shed zone empties the pouch into the shed (no interact,
|
||||
## and not gated by the shed counter's reach or the shed shop being open).
|
||||
## * Overnight (the end of the dawn grace) every used point regains regen_per_night charges.
|
||||
## 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), and leaves the gather labels to the local player's (show_labels).
|
||||
## (workbench_requested / shed_requested), and leaves the gather labels to the local player's
|
||||
## (show_labels).
|
||||
|
||||
signal gathered(material: String, amount: int, node: GatherNode)
|
||||
signal deposited(moved: Dictionary)
|
||||
signal message(text: String, color: Color)
|
||||
## A remote kit pressed interact at the workbench by day (its game opens the upgrade menu).
|
||||
signal workbench_requested
|
||||
## A remote kit pressed interact at the shed counter by day (its game opens the shed's shop).
|
||||
signal shed_requested
|
||||
|
||||
const LABEL_RANGE := 7.0
|
||||
const REPAIR_REACH := 1.4
|
||||
|
|
@ -41,11 +47,13 @@ var zones: FarmZones
|
|||
var structures: StructureSystem
|
||||
var build: BuildMode
|
||||
var upgrade_panel: UpgradePanel
|
||||
var shed_panel: UpgradePanel
|
||||
## The partner's input on the host (co-op), and whether this one draws the gather labels.
|
||||
var remote: RemoteControls
|
||||
var show_labels := true
|
||||
var nodes: Array[GatherNode] = []
|
||||
var workbench: Workbench
|
||||
var shed_counter: ShedCounter
|
||||
var focus: Node3D
|
||||
var gathering: GatherNode
|
||||
var gather_elapsed: float = 0.0
|
||||
|
|
@ -76,6 +84,8 @@ func setup(cfg: GameConfig, p_campaign: CampaignController, p_player: PlayerChar
|
|||
nodes.append(n)
|
||||
elif n is Workbench and workbench == null:
|
||||
workbench = n
|
||||
elif n is ShedCounter and shed_counter == null:
|
||||
shed_counter = n
|
||||
kit.damaged.connect(func(_hp: int) -> void: cancel())
|
||||
kit.fear_used.connect(func(_p: Vector3, _n: int) -> void: cancel())
|
||||
_repair_label = Label3D.new()
|
||||
|
|
@ -114,7 +124,8 @@ func channeling() -> bool:
|
|||
|
||||
|
||||
func can_shoot() -> bool:
|
||||
return not channeling() and not (upgrade_panel != null and upgrade_panel.is_open) and not (remote != null and remote.ui_open)
|
||||
return not channeling() and not (upgrade_panel != null and upgrade_panel.is_open) \
|
||||
and not (shed_panel != null and shed_panel.is_open) and not (remote != null and remote.ui_open)
|
||||
|
||||
|
||||
## One physics tick, after the scarecrow kit.
|
||||
|
|
@ -130,15 +141,18 @@ func step(dt: float) -> void:
|
|||
if not kit.alive or (build != null and build.active) or (remote != null and (remote.build_active or remote.ui_open)):
|
||||
if upgrade_panel != null:
|
||||
upgrade_panel.close()
|
||||
if shed_panel != null:
|
||||
shed_panel.close()
|
||||
cancel()
|
||||
repair_target = -1
|
||||
focus = null
|
||||
return
|
||||
var p := Vector2(player.global_position.x, player.global_position.z)
|
||||
if upgrade_panel != null and upgrade_panel.is_open:
|
||||
var bench := Vector2(workbench.global_position.x, workbench.global_position.z) if workbench != null else p
|
||||
if pressed or not campaign.is_daytime() or bench.distance_to(p) > workbench.reach + 0.5 or (build != null and build.active):
|
||||
upgrade_panel.close()
|
||||
_step_menu(upgrade_panel, workbench, p, pressed)
|
||||
return
|
||||
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()
|
||||
|
|
@ -197,6 +211,23 @@ func step(dt: float) -> void:
|
|||
upgrade_panel.open()
|
||||
elif remote != null:
|
||||
workbench_requested.emit()
|
||||
elif focus is ShedCounter and pressed:
|
||||
if not campaign.is_daytime():
|
||||
message.emit("The supply shed is for daytime", Color(1.0, 0.8, 0.5))
|
||||
elif shed_panel != null:
|
||||
shed_panel.open()
|
||||
elif remote != null:
|
||||
shed_requested.emit()
|
||||
|
||||
|
||||
## A shop's menu is open: closes it on interact again, by walking off its counter's reach, at
|
||||
## nightfall, or entering build mode (workbench: Workbench; shed: ShedCounter; both just need
|
||||
## global_position and reach).
|
||||
func _step_menu(panel: UpgradePanel, counter, p: Vector2, pressed: bool) -> void:
|
||||
var at := Vector2(counter.global_position.x, counter.global_position.z) if counter != null else p
|
||||
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()
|
||||
|
||||
|
||||
## Why a point can't be gathered right now ("" if it can).
|
||||
|
|
@ -257,6 +288,11 @@ func _nearest(p: Vector2) -> Node3D:
|
|||
if d <= workbench.reach and d < best_d:
|
||||
best = workbench
|
||||
best_d = d
|
||||
if shed_counter != null:
|
||||
var d := Vector2(shed_counter.global_position.x, shed_counter.global_position.z).distance_to(p)
|
||||
if d <= shed_counter.reach and d < best_d:
|
||||
best = shed_counter
|
||||
best_d = d
|
||||
return best
|
||||
|
||||
|
||||
|
|
@ -289,6 +325,9 @@ func _process(delta: float) -> void:
|
|||
if workbench != null and show_labels:
|
||||
var near := Vector2(workbench.global_position.x - p.x, workbench.global_position.z - p.z).length() < LABEL_RANGE
|
||||
workbench.show_state(campaign, near and kit.alive, focus == workbench)
|
||||
if shed_counter != null and show_labels:
|
||||
var near := Vector2(shed_counter.global_position.x - p.x, shed_counter.global_position.z - p.z).length() < LABEL_RANGE
|
||||
shed_counter.show_state(campaign, near and kit.alive, focus == shed_counter)
|
||||
var shown := (repairing if repairing >= 0 else repair_target) if show_labels else -1
|
||||
_repair_label.visible = shown >= 0
|
||||
if shown >= 0:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue