diff --git a/game/resources/game_config.tres b/game/resources/game_config.tres index 4e857e5..47d277b 100644 --- a/game/resources/game_config.tres +++ b/game/resources/game_config.tres @@ -89,6 +89,10 @@ costs = { "wide_fear": { "straw": 20, "wood": 4 +}, +"workbench": { +"scrap": 4, +"wood": 6 } } upgrades = { diff --git a/game/scripts/coop_session.gd b/game/scripts/coop_session.gd index 0352b09..326e5c7 100644 --- a/game/scripts/coop_session.gd +++ b/game/scripts/coop_session.gd @@ -547,7 +547,11 @@ func _do_request(r: Array) -> void: _events.append(["toast", "Dismantled the %s%s" % [StructureSystem.NAMES[e["type"]].to_lower(), (": %s back in the shed" % ResourceStore.describe(back)) if not back.is_empty() else ""], Color(0.85, 0.95, 1.0)]) "buy": - var text := Upgrades.buy(c, String(r[1]), sim.structures) + var id := String(r[1]) + 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 text := Upgrades.buy(c, id, sim.structures) _events.append(["toast", text, Color(0.85, 0.75, 1.0) if text.contains("done:") else Color(1.0, 0.8, 0.5)]) diff --git a/game/scripts/game_config.gd b/game/scripts/game_config.gd index a218a1d..1be6388 100644 --- a/game/scripts/game_config.gd +++ b/game/scripts/game_config.gd @@ -188,6 +188,10 @@ extends Resource @export_range(1, 500) var gate_hp: int = 30 @export_range(1, 500) var trap_triggers: int = 10 @export_range(1, 500) var turret_hp: int = 25 +## The Workbench (#9): not built by the player (it's granted once Night 1 is survived -- +## StructureSystem.grant_workbench()), but it has HP, can be damaged, and is repaired like any +## other structure (repair-only: it stays, broken, at 0 HP instead of being destroyed). +@export_range(1, 500) var workbench_hp: int = 50 ## A ground enemy crossing a slowing trap moves at this share of its speed for this long. @export_range(0.05, 1.0) var trap_slow_factor: float = 0.5 @export var trap_slow_time: float = 2.0 @@ -379,6 +383,8 @@ func structure_hp(type: String) -> int: return gate_hp "slowing_trap": return trap_triggers + "workbench": + return workbench_hp return turret_hp diff --git a/game/scripts/interactions.gd b/game/scripts/interactions.gd index 8ce6f7b..c879a8f 100644 --- a/game/scripts/interactions.gd +++ b/game/scripts/interactions.gd @@ -13,7 +13,9 @@ extends Node3D ## Letting go, a hit, fear, nightfall, or a full pouch cancels it. ## * 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. +## else happens here while one is open. The Workbench itself doesn't exist (no prompt, no +## focus, its shop can't be opened) until StructureSystem grants it, after Night 1 (#9); once +## it exists but is broken (0 HP), its shop is refused until it's repaired instead. ## * 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. @@ -258,7 +260,9 @@ func step(dt: float) -> void: _denied = true message.emit(why, Color(1.0, 0.8, 0.5)) elif focus is Workbench and pressed: - if not campaign.is_daytime(): + 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(): message.emit("The work area is for daytime", Color(1.0, 0.8, 0.5)) elif upgrade_panel != null: upgrade_panel.open() @@ -349,7 +353,7 @@ func _nearest(p: Vector2) -> Node3D: if d <= n.reach and score < best_d: best = n best_d = score - if workbench != null: + if workbench != null and structures != null and structures.has_workbench(): var d := Vector2(workbench.global_position.x, workbench.global_position.z).distance_to(p) if d <= workbench.reach and d < best_d: best = workbench @@ -389,8 +393,9 @@ func _process(delta: float) -> void: prompt = "[E / X] Gather" if why == "" else why n.show_state(charges(n), near and kit.alive, prompt) 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) + var granted := structures != null and structures.has_workbench() + var near := granted and 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, granted and structures.is_broken(structures.workbench_id())) 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) diff --git a/game/scripts/review_panel.gd b/game/scripts/review_panel.gd index 5b161b2..8ec9718 100644 --- a/game/scripts/review_panel.gd +++ b/game/scripts/review_panel.gd @@ -131,7 +131,10 @@ func refresh() -> void: lines.append("In the shed: %s. In the pouch: %s." % [_or_none(ResourceStore.describe(r.shed)), _or_none(ResourceStore.describe(r.pouch))]) var plan := waves.tonight() if waves != null else null if plan != null and plan.title != "": - lines.append("Tonight: %s. Upgrades at the work area: %d of %d done." % [plan.title, _upgrades_done(), Upgrades.ORDER.size()]) + if structures != null and structures.has_workbench(): + lines.append("Tonight: %s. Upgrades at the work area: %d of %d done." % [plan.title, _upgrades_done(), Upgrades.ORDER.size()]) + else: # #9: the Workbench hasn't been granted yet -- it arrives once Night 1 is survived + lines.append("Tonight: %s. The work area will be set up once you survive tonight." % plan.title) _body.text = "\n".join(lines) _start.grab_focus.call_deferred() diff --git a/game/scripts/structure_system.gd b/game/scripts/structure_system.gd index 38de927..dca0328 100644 --- a/game/scripts/structure_system.gd +++ b/game/scripts/structure_system.gd @@ -24,6 +24,15 @@ extends Node3D ## fires turret_l3_projectiles shots at once in a fan. A tar patch's footprint and visual grow by ## trap_level_size_mult[level - 1] (L2 double, L3 triple its L1 size); upgrading refuses with a ## reason if the bigger footprint would overlap another structure or the world. +## +## workbench (#9): not built by the player -- not in ORDER, never validated or paid for. Granted +## once (grant_workbench(), idempotent) at the scene's Workbench node when Night 1 is survived +## (CampaignController.night_ending), and derived again on load/retry (sync_from_state(), when +## FarmState.nights_survived >= 1 and no "workbench" record exists yet) in case it was missed. +## Its view is the existing Workbench scene node (hidden until granted), not a built mesh, so it +## shares every other structure's damage/repair/HP bar/tint/wobble/nav/save pipeline for free. +## Repair-only: at 0 HP it's "broken" (Interactions refuses to open its shop) but, unlike every +## other structure, damage() never removes its record -- there's no rebuilding it from scratch. signal layout_changed signal built(id: int, type: String) @@ -43,6 +52,7 @@ const NAMES := { "gate": "Gate", "slowing_trap": "Tar patch", "automated_defense": "Turret", + "workbench": "Workbench", } ## Structure types with a per-instance level (#10); every other type is always level 1. const LEVELABLE: Array[String] = ["automated_defense", "slowing_trap"] @@ -67,6 +77,10 @@ var player: PlayerCharacter ## Co-op: player 2's scarecrow (gates open for it too, and nothing is built onto it). var partner: Node3D +## The scene's Workbench node (Zones/WorkArea/Workbench), found in setup(): its view once +## granted, not built -- see grant_workbench(). +var _workbench_node: Workbench + var _views := {} # id -> Node3D var _bars := {} # id -> MeshInstance3D var _bodies := {} # id -> Array[RID] (physics bodies to leave out of placement queries) @@ -93,6 +107,11 @@ func setup(p_campaign: CampaignController, p_nav: FarmNavigation, p_zones: FarmZ player = p_player nav.set_barrier_cost(roundi(config.barrier_detour / nav.cell_size * FarmNavigation.COST_ORTH)) _bar_shader = load("res://game/resources/hp_bar.gdshader") as Shader + for n in zones.find_children("*", "Node3D", true, false): + if n is Workbench: + _workbench_node = n + break + campaign.night_ending.connect(_on_night_ending) for u in zones.crop_units(): var lo := Vector2(INF, INF) var hi := Vector2(-INF, -INF) @@ -233,11 +252,65 @@ func place(type: String, x: float, z: float, rot: int) -> int: return id +## A non-purchased, unvalidated place(): adds a structure record at (x, z) without validate() or +## pay(), through the rest of the normal pipeline (record, view, nav, built). For structures the +## game grants itself (the Workbench -- grant_workbench()), not ones the player builds. +func grant(type: String, x: float, z: float, rot: int) -> int: + var s := campaign.state + var id := s.next_structure_id + s.next_structure_id += 1 + s.structures.append({"id": id, "type": type, "x": x, "z": z, "rot": rot, "hp": max_hp(type), "level": 1}) + _add_view(s.structures[s.structures.size() - 1]) + _update_nav() + built.emit(id, type) + return id + + +## Idempotent: grants the Workbench at the scene node's position if it isn't a structure record +## yet. Called when Night 1 is survived (_on_night_ending) and, to derive it on load/retry, from +## sync_from_state() (guarded there to FarmState.nights_survived >= 1); tests may call it directly +## to have the workbench from the start, regardless of the night. +func grant_workbench() -> void: + if has_workbench() or _workbench_node == null: + return + var p := _workbench_node.global_position + grant("workbench", p.x, p.z, 0) + + +func has_workbench() -> bool: + return workbench_id() >= 0 + + +## The granted Workbench's structure id, or -1 before it exists. +func workbench_id() -> int: + for e in campaign.state.structures: + if e["type"] == "workbench": + return int(e["id"]) + return -1 + + +## 0 HP: still a record (repair-only, never removed -- see damage()), but its shop can't be opened. +func is_broken(id: int) -> bool: + var e := campaign.state.structure(id) + return not e.is_empty() and int(e["hp"]) <= 0 + + +## Granted and not broken: whether its shop (and a co-op "buy" request for one of its items) may +## open right now. +func workbench_available() -> bool: + var id := workbench_id() + return id >= 0 and not is_broken(id) + + +func _on_night_ending() -> void: + grant_workbench() + + ## Takes a structure down, refunding dismantle_refund of its cost into the shed. Returns the -## refund. +## refund. The Workbench is never dismantlable (it isn't built in the first place). func dismantle(id: int) -> Dictionary: var e := campaign.state.structure(id) - if e.is_empty(): + if e.is_empty() or e["type"] == "workbench": return {} var refund := {} var cost: Dictionary = config.costs.get(e["type"], {}) @@ -250,7 +323,8 @@ func dismantle(id: int) -> Dictionary: return refund -## Damages a structure; at 0 HP it breaks (debris, destroyed). Returns true if it broke. +## Damages a structure; at 0 HP it breaks (debris, destroyed). Returns true if it broke. The +## Workbench is repair-only: at 0 HP it's "broken" (hurt, not destroyed) and its record stays. func damage(id: int, amount: int) -> bool: var e := campaign.state.structure(id) if e.is_empty(): @@ -258,7 +332,7 @@ func damage(id: int, amount: int) -> bool: campaign.state.record_event("structures_damaged", mini(amount, int(e["hp"]))) e["hp"] = maxi(int(e["hp"]) - amount, 0) _wobble[id] = WOBBLE_TIME - if int(e["hp"]) > 0: + if int(e["hp"]) > 0 or e["type"] == "workbench": hurt.emit(id, Vector3(e["x"], 0.0, e["z"])) return false campaign.state.record_event("structures_destroyed") @@ -455,10 +529,20 @@ func step(dt: float) -> void: head.rotation.y = atan2(-dir.x, -dir.z) -## Rebuilds every view and the navigation layer from the farm state (new vacation, retry). +## Rebuilds every view and the navigation layer from the farm state (new vacation, retry). The +## Workbench's view is the scene's own node, not a built one: hide it rather than free it, and +## derive its presence again (nights_survived >= 1, no record yet -- an older save, or a retry +## that somehow missed it) once the state's own structures are back. func sync_from_state() -> void: for id in _views.keys(): - (_views[id] as Node3D).queue_free() + var v: Node3D = _views[id] + if v == _workbench_node: + v.visible = false + var old_bar: MeshInstance3D = _bars.get(id) + if old_bar != null: # its own HP bar is a real child of the scene node: free it by hand + old_bar.queue_free() + else: + v.queue_free() _views.clear() _bars.clear() _bodies.clear() @@ -469,6 +553,8 @@ func sync_from_state() -> void: _gate_open.clear() for e in campaign.state.structures: _add_view(e) + if campaign.state.nights_survived >= 1: + grant_workbench() _update_nav() @@ -525,7 +611,7 @@ func _remove(id: int) -> void: s.structures.remove_at(i) break var view: Node3D = _views.get(id) - if view != null: + if view != null and view != _workbench_node: # the scene's own node is hidden, never freed view.queue_free() for d in [_views, _bars, _bodies, _tints, _wobble, _heads, _turret_cd, _gate_open]: (d as Dictionary).erase(id) @@ -555,13 +641,20 @@ func _update_nav() -> void: layout_changed.emit() +## The Workbench reuses the scene's own node (shown, not built) instead of a fresh _build_view(), +## so there's only ever the one mesh; every other type is built and parented here as usual. func _add_view(e: Dictionary) -> void: var id: int = e["id"] - var view := _build_view(e["type"], e["rot"], int(e.get("level", 1))) - view.name = "%s_%d" % [e["type"], id] - add_child(view) + var view: Node3D + if e["type"] == "workbench" and _workbench_node != null: + view = _workbench_node + view.visible = true + else: + view = _build_view(e["type"], e["rot"], int(e.get("level", 1))) + view.name = "%s_%d" % [e["type"], id] + add_child(view) + view.global_position = Vector3(e["x"], _ground_y(Vector2(e["x"], e["z"])), e["z"]) _views[id] = view - view.global_position = Vector3(e["x"], _ground_y(Vector2(e["x"], e["z"])), e["z"]) var rids: Array[RID] = [] for body in view.find_children("*", "StaticBody3D", true, false): rids.append((body as StaticBody3D).get_rid()) diff --git a/game/scripts/workbench.gd b/game/scripts/workbench.gd index 3188078..c1f7102 100644 --- a/game/scripts/workbench.gd +++ b/game/scripts/workbench.gd @@ -2,14 +2,23 @@ class_name Workbench extends Node3D ## The work area's tool table, where the scarecrow buys upgrades (Upgrades, UpgradePanel): press ## interact here by day to open the menu. Its label shows how many are done. +## #9: not there from the start -- StructureSystem grants it once Night 1 is survived, reusing +## this very node as its view (hidden until then, StructureSystem._add_view toggles it back on; +## see grant_workbench()). It then has HP like any other structure, and can be damaged and +## repaired; at 0 HP it's broken (show_state's broken prompt) until repaired, instead of being +## destroyed. ## How close the scarecrow's center has to be to this node's origin. @export var reach: float = 2.2 +const NORMAL_COLOR := Color(0.85, 0.75, 1.0) +const BROKEN_COLOR := Color(1.0, 0.55, 0.45) + var _label: Label3D func _ready() -> void: + visible = false # granted, not built -- StructureSystem shows it once that's happened _label = Label3D.new() _label.billboard = BaseMaterial3D.BILLBOARD_ENABLED _label.no_depth_test = true @@ -17,16 +26,22 @@ func _ready() -> void: _label.font_size = 40 _label.outline_size = 10 _label.pixel_size = 0.0075 - _label.modulate = Color(0.85, 0.75, 1.0) + _label.modulate = NORMAL_COLOR _label.position = Vector3(0.0, 2.2, 0.0) _label.visible = false add_child(_label) -func show_state(campaign: CampaignController, show: bool, focused: bool) -> void: +## broken (0 HP): the shop can't be opened until it's repaired. +func show_state(campaign: CampaignController, show: bool, focused: bool, broken: bool = false) -> void: _label.visible = show if not show: return + if broken: + _label.modulate = BROKEN_COLOR + _label.text = "Broken -- repair it" if focused else "Broken" + return + _label.modulate = NORMAL_COLOR var done := 0 for id in Upgrades.ORDER: if Upgrades.owned(campaign.state, id): diff --git a/game/tests/test_cycle.gd b/game/tests/test_cycle.gd index 13e6766..5920061 100644 --- a/game/tests/test_cycle.gd +++ b/game/tests/test_cycle.gd @@ -24,6 +24,8 @@ func run(r: GameTestRunner) -> void: sim.waves.rng.seed = 1 # tonight's 11 arrival points, drawn the same every run var player := farm.get_node("Player") as PlayerCharacter player.global_position = AWAY + sim.structures.grant_workbench() # #9: granted up front so it doesn't shift the structure + # counts this test tracks across night 1 (it isn't about the Workbench itself) var review := farm.get_node("Hud/ReviewPanel") as ReviewPanel var hud := farm.get_node("Hud/PhaseHud") as PhaseHud var assets := farm.get_node("Hud/AssetHud") as AssetHud diff --git a/game/tests/test_nights.gd b/game/tests/test_nights.gd index a8868fd..b4fc942 100644 --- a/game/tests/test_nights.gd +++ b/game/tests/test_nights.gd @@ -206,6 +206,9 @@ func _five_nights(r: GameTestRunner, farm: Node3D, sim: FarmSim, player: PlayerC var hud := farm.get_node("Hud/PhaseHud") as PhaseHud c.new_campaign() _step(sim, 1) + sim.structures.grant_workbench() # #9: granted once, up front, so the per-night structure + # count below (broken aside) doesn't trip over the night-1 grant itself + c._morning_snapshot = c.state.to_dict() # ...and this morning's snapshot (the loop checks it) agrees sim.waves.enabled = true player.global_position = AWAY var arrivals := {} diff --git a/game/tests/test_structures.gd b/game/tests/test_structures.gd index 51efe90..bdf8d97 100644 --- a/game/tests/test_structures.gd +++ b/game/tests/test_structures.gd @@ -8,7 +8,11 @@ extends RefCounted ## persistence and retry, an A/B night: the same attack on an open and on a fenced crop field, and ## per-instance leveling (#10): a turret's fire rate and L3 volley, a tar patch's footprint, paid ## independently per placed structure, the rules around it (repair first, room, afford), and that -## the level survives a save/retry round trip. +## the level survives a save/retry round trip; and the Workbench (#9): absent and inaccessible +## (no prompt, no shop, including over a co-op request) before Night 1, granted into state before +## the morning snapshot once it's survived, then damaged by an enemy like any barrier, "broken" +## (not destroyed) at 0 HP with its shop refused, repaired at the normal proportional cost, and +## its presence and HP surviving a save and a retry. const P := CampaignController.Phase const T := ThiefBehavior.State @@ -40,6 +44,7 @@ func run(r: GameTestRunner) -> void: _repair_and_dismantle(r, sim, player) _persistence(r, sim) _ab_night(r, sim, player) + _workbench(r, sim, player) farm.queue_free() await r.process_frame @@ -554,6 +559,117 @@ func _ab_night(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter) -> void r.check(defended[0] < open[0], "defenses change the outcome of the same attack (%d < %d units lost)" % [defended[0], open[0]]) +## Task #9: the Workbench is granted (not built) once Night 1 is survived. A fresh new_campaign() +## (the A/B nights above leave the campaign well past night 1) so "before Night 1" means something. +func _workbench(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter) -> void: + var c := sim.campaign + var st := sim.structures + var it := sim.interactions + var bench := it.workbench + var es := sim.enemies + c.new_campaign() + _step(sim, 1) + r.check(not st.has_workbench() and st.workbench_id() == -1 and not bench.visible, + "a fresh vacation, morning of night 1: the Workbench isn't a structure yet, and its scene node is hidden") + _rich(c) + c.begin_day() + player.global_position = bench.global_position + Vector3(0.0, 0.0, 1.2) + var msgs: Array[String] = [] + it.message.connect(func(t: String, _col: Color) -> void: msgs.append(t)) + Input.action_release("interact") + _tap(sim, "interact") + r.check(not sim.upgrade_panel.is_open, "standing where it will be, before night 1, interact opens no shop") + r.check(msgs.is_empty(), "and no workbench prompt or message fires either (it isn't focused: it doesn't exist) (%s)" % [msgs]) + var coop := CoopSession.new() + coop.sim = sim + coop._do_request(["buy", "straw_stuffing"]) + r.check(not Upgrades.owned(c.state, "straw_stuffing"), "a co-op 'buy' request for a workbench-shop item is refused before the workbench exists") + + # Survive night 1: DAY -> DUSK -> NIGHT -> DAWN -> MORNING. night_ending grants it (before the + # morning snapshot/save, like #13's crop growth). + c.advance_phase() + c.advance_phase() + c.advance_phase() + c.advance_phase() + r.check(c.state.phase == P.MORNING and c.state.nights_survived == 1, "night 1 is behind us") + var id := st.workbench_id() + r.check(id >= 1 and st.has_workbench() and bench.visible and not StructureSystem.ORDER.has("workbench"), + "the Workbench now exists as a real (but not buildable) structure, and its scene node shows") + r.check(int(c.state.structure(id)["hp"]) == st.max_hp("workbench"), "granted at full HP") + var morning_structs: Array = c.state.to_dict()["structures"] + r.check(morning_structs.any(func(e: Dictionary) -> bool: return String(e["type"]) == "workbench"), + "it was already in state before the morning snapshot was taken") + + c.begin_day() + player.global_position = bench.global_position + Vector3(0.0, 0.0, 1.2) + msgs.clear() + _tap(sim, "interact") + r.check(sim.upgrade_panel.is_open, "now its shop opens like any other workbench day") + _tap(sim, "interact") + + # Damaged by an enemy: thief_behavior.gd's generic BREAK state (any barrier in a route, not + # just a "fence breaker"'s guarded ones) -- it's a nav barrier like a fence (StructureSystem + # .blocks() excludes only slowing_trap). + var h := es.spawn(EnemySystem.TYPE_THIEF, bench.global_position.x + 0.6, bench.global_position.z, Vector2.LEFT) + var d := es.resolve_handle(h) + es.state[d] = T.BREAK + es.barrier[d] = id + var hp0 := int(c.state.structure(id)["hp"]) + _step(sim, roundi(es.t_hit_interval[EnemySystem.TYPE_THIEF] * 60.0) + 4) + r.check(int(c.state.structure(id)["hp"]) < hp0, "an enemy breaking against it damages it like any barrier") + es.apply_hit_handle(h, 99) + _step(sim, 1) + + # Broken at 0 HP: the record stays (repair-only, not destroyed/removed); its shop is refused. + var destroyed: Array[String] = [] + st.destroyed.connect(func(_i: int, t: String, _at: Vector3) -> void: destroyed.append(t)) + r.check(not st.damage(id, 9999) and not c.state.structure(id).is_empty() and int(c.state.structure(id)["hp"]) == 0, + "damaging it to 0 HP leaves it 'broken', not destroyed: the record stays") + r.check(destroyed.is_empty(), "no breach/destroyed signal for it") + # Just outside REPAIR_REACH (1.4 m to the footprint's edge, 0.5 m out from center) but inside + # the Workbench's own reach (2.2 m, to its center): repair takes priority within REPAIR_REACH + # (Interactions), so this is where its shop's own refusal shows. + player.global_position = bench.global_position + Vector3(0.0, 0.0, 2.0) + msgs.clear() + _tap(sim, "interact") + r.check(not sim.upgrade_panel.is_open and msgs.has("Broken -- repair it"), "its shop refuses to open while broken (%s)" % [msgs]) + coop._do_request(["buy", "straw_stuffing"]) + r.check(not Upgrades.owned(c.state, "straw_stuffing"), "a co-op 'buy' request is refused while it's broken too") + + # Repaired at the normal proportional cost (StructureSystem.repair_cost/repair), from within + # REPAIR_REACH. + var cost := st.repair_cost(id) + r.check(not cost.is_empty() and cost == sim.config.costs["workbench"], "broken (0 of its HP), repairing costs the full amount (%s)" % [cost]) + c.state.resources.shed = cost.duplicate() + player.global_position = bench.global_position + Vector3(0.0, 0.0, 1.2) + Input.action_press("interact") + _step(sim, roundi(sim.config.repair_time * 60.0) + 2) + Input.action_release("interact") + _step(sim, 1) + r.check(int(c.state.structure(id)["hp"]) == st.max_hp("workbench"), "holding interact repairs it fully, for the proportional cost") + msgs.clear() + _tap(sim, "interact") + r.check(sim.upgrade_panel.is_open, "repaired, its shop opens again") + _tap(sim, "interact") + + # Persistence: presence and HP survive a save (JSON) round trip and a retry. + var d2 := c.state.to_dict() + var back := FarmState.from_dict(JSON.parse_string(JSON.stringify(d2, "", true, true))) + r.check(back != null and back.structure(id)["type"] == "workbench" and int(back.structure(id)["hp"]) == st.max_hp("workbench"), + "its presence and HP survive a save (JSON) round trip") + st.damage(id, 5) + c.advance_phase() # DAY -> DUSK + c.advance_phase() # DUSK -> NIGHT + c.state.scarecrow_hp = 0 + _step(sim, 1) + c.retry_night() + _step(sim, 1) + r.check(st.has_workbench() and int(c.state.structure(st.workbench_id())["hp"]) == st.max_hp("workbench"), + "a retry restores the morning's Workbench, undamaged by what happened after") + player.global_position = AWAY + _settle(sim) + + func _field_fences() -> Array: var parts: Array = [] for k in 15: