Merge task #9: Workbench arrives after Night 1, targetable, repair-only
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
4e3692b99d
12 changed files with 312 additions and 23 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 := {}
|
||||
|
|
|
|||
|
|
@ -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,146 @@ 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")
|
||||
|
||||
# Targeting (Decision 3): FarmSim._breaker_goals() treats an unbroken Workbench as guarding its
|
||||
# own work area, alongside whatever else is actually guarding something -- PenRing.build_gate_only
|
||||
# places one real guarding structure (the same single-gate setup test_roster.gd's own fence-
|
||||
# breaker test uses), so this proves the Workbench joins a non-empty guarding set, not just a
|
||||
# fallback when nothing else guards anything.
|
||||
var gate_id := PenRing.build_gate_only(sim)
|
||||
_settle(sim)
|
||||
var goals := sim._breaker_goals()
|
||||
r.check(_goals_near(sim, goals, bench.global_position) and _goals_near(sim, goals, Vector3(PenRing.EAST_X, 0.0, PenRing.GATE_Z)),
|
||||
"an unbroken Workbench is in the breaker goals alongside the pen gate guarding the pen")
|
||||
# Spawned far closer to the Work Area than to the pen, a fence breaker -- with no hand-set
|
||||
# state or barrier, driven only by its own AI -- heads for and smashes the Workbench on its own.
|
||||
# The scarecrow stays well clear (AWAY): close by, the breaker would aggro onto it instead
|
||||
# (ThiefBehavior._aggro, aggro_range 4 m) and never reach BREAK.
|
||||
player.global_position = AWAY
|
||||
var hb := sim.spawn_enemy(EnemySystem.TYPE_BREAKER, LootSystem.ANY, GameTestRunner.EDGE["driveway"])
|
||||
var at := _until(sim, func() -> bool: return es.resolve_handle(hb) >= 0 and es.state[es.resolve_handle(hb)] == T.BREAK, 40.0)
|
||||
var dh := es.resolve_handle(hb)
|
||||
r.check(at < 40.0 and dh >= 0 and es.barrier[dh] == id,
|
||||
"a fence breaker (no hand-set state) targets and walks to the Workbench on its own (%.1f s)" % at)
|
||||
var hp0 := int(c.state.structure(id)["hp"])
|
||||
_step(sim, roundi(es.t_hit_interval[EnemySystem.TYPE_BREAKER] * 60.0) + 4)
|
||||
r.check(int(c.state.structure(id)["hp"]) < hp0, "and actually damages it")
|
||||
es.apply_hit_handle(hb, 99)
|
||||
_step(sim, 1)
|
||||
st.dismantle(gate_id)
|
||||
_settle(sim)
|
||||
|
||||
# Broken at 0 HP: the record stays (repair-only, not destroyed/removed); its shop is refused,
|
||||
# and it drops out of the breaker goals (nothing left to gain by sending another breaker at it).
|
||||
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")
|
||||
r.check(not _goals_near(sim, sim._breaker_goals(), bench.global_position), "a broken Workbench drops out of the breaker goals")
|
||||
# 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)
|
||||
|
||||
|
||||
## Whether any of FarmSim._breaker_goals()'s cells (walkable cells near a guarding barrier's
|
||||
## footprint) sit near a world position -- 3 m is generous (the goal cells themselves are within
|
||||
## ~1.1 m of a footprint's edge) but well short of the distance between the Workbench and the pen
|
||||
## gate used alongside it above, so it can't mistake one guarding structure's goals for the other's.
|
||||
func _goals_near(sim: FarmSim, goals: PackedInt32Array, at: Vector3) -> bool:
|
||||
var p := Vector2(at.x, at.z)
|
||||
for cell in goals:
|
||||
if sim.nav.cell_center(cell).distance_to(p) <= 3.0:
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
func _field_fences() -> Array:
|
||||
var parts: Array = []
|
||||
for k in 15:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue