Task #10: per-instance Turret/Tar Patch leveling (L1-L3)
Adds a per-placed-structure "level" (1-3) to automated_defense and slowing_trap, upgraded independently (not account-wide) by holding interact at that specific structure, by day, once it's undamaged (repair still takes priority while it isn't), for a config-tunable per-level cost. Turret L2 fires turret_level_fire_mult (3x, matching the live Rapid Fire multiplier) as often; L3 keeps that rate and fires turret_l3_projectiles shots at once in a fan. A tar patch's trigger footprint and visual grow by trap_level_size_mult per level (L2 double, L3 triple its L1 size); a bigger footprint that would overlap a neighbor or the world refuses the upgrade with a reason. FarmState.VERSION bumps 5->6 (STRUCTURE_KEYS gains "level"; migrate() backfills level 1 on older saves, following the v2->v3 precedent for night_log). Co-op: an upgrade is driven the same way repair already is -- entirely host-side, off the partner's held interact button, no new "req" case -- so the only wire change is forwarding the upgrade channel's target/progress in the avatar snapshot, same as repair's. New test_structures.gd coverage: fire interval and projectile count per turret level, tar patch footprint per level, each proven independently for two separately-placed structures of the same type, plus the upgrade rules (repair-first, room, afford) and that level survives a save/retry round trip. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
0613cca408
commit
62324ff4b1
8 changed files with 468 additions and 33 deletions
|
|
@ -17,6 +17,12 @@ extends Node3D
|
|||
## * 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.
|
||||
## * Upgrade (#10): a levelable structure (turret, tar patch) within REPAIR_REACH, undamaged
|
||||
## (repair takes priority while it isn't), comes next. Hold interact by day for
|
||||
## structure_upgrade_time to level it up one, for StructureSystem.upgrade_cost (paid at the
|
||||
## end); refused, once per press, without the materials, room (a bigger tar patch may not fit),
|
||||
## or at Max level. Night-gated like the workbench, unlike repair, since it's a build-mode-style
|
||||
## decision, not an emergency fix.
|
||||
## * 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.
|
||||
|
|
@ -61,6 +67,10 @@ var gather_elapsed: float = 0.0
|
|||
var repair_target: int = -1
|
||||
var repairing: int = -1
|
||||
var repair_elapsed: float = 0.0
|
||||
## Levelable structure in reach, undamaged (-1 = none), and the one being upgraded (#10).
|
||||
var upgrade_target: int = -1
|
||||
var upgrading: int = -1
|
||||
var upgrade_elapsed: float = 0.0
|
||||
|
||||
var _shed: FarmZone
|
||||
var _interact_requested := false
|
||||
|
|
@ -68,6 +78,7 @@ var _interact_was_held := false
|
|||
var _denied := false
|
||||
var _popups: Array[Label3D] = []
|
||||
var _repair_label: Label3D
|
||||
var _upgrade_label: Label3D
|
||||
var _popup_left := PackedFloat32Array()
|
||||
|
||||
|
||||
|
|
@ -99,6 +110,17 @@ func setup(cfg: GameConfig, p_campaign: CampaignController, p_player: PlayerChar
|
|||
_repair_label.top_level = true
|
||||
_repair_label.visible = false
|
||||
add_child(_repair_label)
|
||||
_upgrade_label = Label3D.new()
|
||||
_upgrade_label.billboard = BaseMaterial3D.BILLBOARD_ENABLED
|
||||
_upgrade_label.no_depth_test = true
|
||||
_upgrade_label.shaded = false
|
||||
_upgrade_label.font_size = 40
|
||||
_upgrade_label.outline_size = 10
|
||||
_upgrade_label.pixel_size = 0.0075
|
||||
_upgrade_label.modulate = Color(0.75, 0.95, 1.0)
|
||||
_upgrade_label.top_level = true
|
||||
_upgrade_label.visible = false
|
||||
add_child(_upgrade_label)
|
||||
_popup_left.resize(POPUPS)
|
||||
for i in POPUPS:
|
||||
var l := Label3D.new()
|
||||
|
|
@ -120,7 +142,7 @@ func charges(n: GatherNode) -> int:
|
|||
|
||||
|
||||
func channeling() -> bool:
|
||||
return gathering != null or repairing >= 0
|
||||
return gathering != null or repairing >= 0 or upgrading >= 0
|
||||
|
||||
|
||||
func can_shoot() -> bool:
|
||||
|
|
@ -145,6 +167,7 @@ func step(dt: float) -> void:
|
|||
shed_panel.close()
|
||||
cancel()
|
||||
repair_target = -1
|
||||
upgrade_target = -1
|
||||
focus = null
|
||||
return
|
||||
var p := Vector2(player.global_position.x, player.global_position.z)
|
||||
|
|
@ -170,6 +193,18 @@ func step(dt: float) -> void:
|
|||
if structures.repair(id):
|
||||
message.emit("Repaired (%s)" % ResourceStore.describe(cost), Color(0.6, 1.0, 0.55))
|
||||
return
|
||||
if upgrading >= 0:
|
||||
if not held or not campaign.is_daytime() or structures.upgrade_blocker(upgrading) != "":
|
||||
cancel()
|
||||
return
|
||||
upgrade_elapsed += dt
|
||||
if upgrade_elapsed >= config.structure_upgrade_time:
|
||||
var id := upgrading
|
||||
var cost := structures.upgrade_cost(id)
|
||||
cancel()
|
||||
if structures.upgrade(id):
|
||||
message.emit("Upgraded to L%d (%s)" % [structures.level_of(id), ResourceStore.describe(cost)], Color(0.6, 1.0, 0.55))
|
||||
return
|
||||
if gathering != null:
|
||||
if not held or _blocker(gathering) != "":
|
||||
cancel()
|
||||
|
|
@ -194,6 +229,24 @@ func step(dt: float) -> void:
|
|||
_denied = true
|
||||
message.emit("Not enough to repair: need %s more" % ResourceStore.describe(campaign.state.resources.missing(cost)), Color(1.0, 0.8, 0.5))
|
||||
return
|
||||
upgrade_target = structures.upgradeable_near(p, REPAIR_REACH) if structures != null else -1
|
||||
if upgrade_target >= 0:
|
||||
focus = null
|
||||
if held and not kit.patching:
|
||||
if not campaign.is_daytime():
|
||||
if not _denied:
|
||||
_denied = true
|
||||
message.emit("Upgrading is for daytime", Color(1.0, 0.8, 0.5))
|
||||
else:
|
||||
var why := structures.upgrade_blocker(upgrade_target)
|
||||
if why == "":
|
||||
upgrading = upgrade_target
|
||||
upgrade_elapsed = 0.0
|
||||
player.start_channel(&"Hammering")
|
||||
elif not _denied:
|
||||
_denied = true
|
||||
message.emit(why, Color(1.0, 0.8, 0.5))
|
||||
return
|
||||
focus = _nearest(p)
|
||||
if focus is GatherNode and held and not kit.patching:
|
||||
var why := _blocker(focus)
|
||||
|
|
@ -241,12 +294,25 @@ func _blocker(n: GatherNode) -> String:
|
|||
return ""
|
||||
|
||||
|
||||
## The upgrade prompt for a levelable structure in reach: what it costs, "Max level", why it
|
||||
## can't right now, or that upgrading (unlike repair) is for daytime.
|
||||
func _upgrade_prompt(id: int) -> String:
|
||||
if not campaign.is_daytime():
|
||||
return "Upgrading is for daytime"
|
||||
var why := structures.upgrade_blocker(id)
|
||||
if why == "":
|
||||
return "[E / X] Upgrade to L%d (%s)" % [structures.level_of(id) + 1, ResourceStore.describe(structures.upgrade_cost(id))]
|
||||
return why
|
||||
|
||||
|
||||
func cancel() -> void:
|
||||
if gathering != null or repairing >= 0:
|
||||
if gathering != null or repairing >= 0 or upgrading >= 0:
|
||||
gathering = null
|
||||
gather_elapsed = 0.0
|
||||
repairing = -1
|
||||
repair_elapsed = 0.0
|
||||
upgrading = -1
|
||||
upgrade_elapsed = 0.0
|
||||
player.stop_channel()
|
||||
|
||||
|
||||
|
|
@ -337,6 +403,14 @@ func _process(delta: float) -> void:
|
|||
var cost := structures.repair_cost(shown)
|
||||
_repair_label.text = "%s %d/%d\n%s" % [StructureSystem.NAMES[e["type"]], int(e["hp"]), structures.max_hp(e["type"]),
|
||||
"Repairing..." if repairing >= 0 else "[E / X] Repair (%s)" % ResourceStore.describe(cost)]
|
||||
var ushown := (upgrading if upgrading >= 0 else upgrade_target) if show_labels else -1
|
||||
_upgrade_label.visible = ushown >= 0
|
||||
if ushown >= 0:
|
||||
var e := campaign.state.structure(ushown)
|
||||
if not e.is_empty():
|
||||
_upgrade_label.global_position = Vector3(e["x"], 3.3, e["z"])
|
||||
_upgrade_label.text = "%s L%d\n%s" % [StructureSystem.NAMES[e["type"]], int(e.get("level", 1)),
|
||||
"Upgrading..." if upgrading >= 0 else _upgrade_prompt(ushown)]
|
||||
for i in POPUPS:
|
||||
if _popup_left[i] <= 0.0:
|
||||
continue
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue