diff --git a/README.md b/README.md index dabfa39..ca54a72 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,8 @@ pack (`assets/farm/ithappy/farm/prefabs/assets/`). [`game/RULES.md`](game/RULES.md) and the development plan in [`first-game-plan.md`](first-game-plan.md). `CampaignDebug` is a debug readout of the phase and farm state, hidden until F1. Debug keys: F6 ends the current phase, F7 cycles 1× / 5× / 20× - speed, F9 sets the scarecrow to 0 HP, F10 strips the farm (every category), R retries after a + speed, F8 unlocks everything (every upgrade and shop item at its last level, free; + `CampaignDebug.unlock_all`), F9 sets the scarecrow to 0 HP, F10 strips the farm (every category), R retries after a Game Over, and T / G / H send in a thief / a crow / a fence breaker. F2 cycles tonight's plan through the debug scenarios (`game/resources/scenarios/`). They introduce the enemies one type at a time (crows, thieves, fence breakers), then pairs, then all three. In the morning review, diff --git a/game/scripts/campaign_controller.gd b/game/scripts/campaign_controller.gd index 5dc0fc8..af7ab27 100644 --- a/game/scripts/campaign_controller.gd +++ b/game/scripts/campaign_controller.gd @@ -114,6 +114,12 @@ func morning_snapshot() -> Dictionary: return _morning_snapshot.duplicate(true) +## The farm as it is now becomes this morning's snapshot, the one a retry goes back to (debug: F8 +## in the morning review, so a retry keeps what it unlocked). Nothing is saved. +func retake_morning_snapshot() -> void: + _morning_snapshot = state.to_dict() + + ## D9: restarts the current night from its morning (the autosave point). func retry_night() -> bool: if remote_request.is_valid(): diff --git a/game/scripts/campaign_debug.gd b/game/scripts/campaign_debug.gd index 0b3cd74..b4a1057 100644 --- a/game/scripts/campaign_debug.gd +++ b/game/scripts/campaign_debug.gd @@ -10,6 +10,8 @@ extends CanvasLayer ## R after Game Over: retry the night; after the farmers return: new vacation ## F6 end the current phase now ## F7 cycle game speed 1x / 5x / 20x +## F8 unlock everything: every upgrade and shop item at its last level, free +## (unlock_all; debug builds only, not on a co-op partner's machine) ## F9 debug: scarecrow to 0 HP ## F10 debug: strip every farm asset ## T / G / H debug: send in a thief / a crow / a fence breaker (FarmSim) @@ -73,6 +75,8 @@ func _unhandled_input(event: InputEvent) -> void: KEY_F7: _speed_index = (_speed_index + 1) % SPEEDS.size() Engine.time_scale = SPEEDS[_speed_index] + KEY_F8: + unlock_all() KEY_F9: s.scarecrow_hp = 0 KEY_F10: @@ -108,6 +112,23 @@ func jump_morning(step: int) -> bool: ## Next debug scenario as tonight's plan (after the last, the real plan again). +## Debug builds, until the vacation ends: every upgrade and shop item at its last level, free +## (Upgrades.grant_all), to try the late game's kit at once. On the morning review a retry keeps +## it (the morning snapshot is retaken); later in the day a retry goes back to that morning +## without it. Nothing is saved until the next morning's autosave. Returns the levels it added. +func unlock_all() -> int: + if not OS.is_debug_build() or campaign.is_over() or campaign.remote_request.is_valid(): + return 0 + var n := Upgrades.grant_all(campaign, sim.structures if sim != null else null) + if campaign.state.phase == CampaignController.Phase.MORNING: + campaign.retake_morning_snapshot() + if sim != null: + for panel: UpgradePanel in [sim.upgrade_panel, sim.shed_panel]: + if panel != null and panel.is_open: + panel.refresh() + return n + + func cycle_scenario() -> void: if sim == null: return @@ -147,5 +168,5 @@ func _describe() -> String: lines.append("[N] start the night early") if sim != null and sim.waves.debug_plan != null: lines.append("Scenario: %s (F2 next)" % sim.waves.debug_plan.title) - lines.append("F1 hide · F2 scenario · F3 / Shift+F3 next / previous morning · F6 next phase · F7 speed · F9 scarecrow to 0 HP · F10 strip farm · T/G/H thief/crow/breaker") + lines.append("F1 hide · F2 scenario · F3 / Shift+F3 next / previous morning · F6 next phase · F7 speed · F8 unlock everything · F9 scarecrow to 0 HP · F10 strip farm · T/G/H thief/crow/breaker") return "\n".join(lines) diff --git a/game/scripts/upgrades.gd b/game/scripts/upgrades.gd index 9c97c8f..6e29215 100644 --- a/game/scripts/upgrades.gd +++ b/game/scripts/upgrades.gd @@ -211,11 +211,22 @@ static func buy(campaign: CampaignController, id: String, structures: StructureS if why != "": return "%s: %s" % [u.get("name", id), why.to_lower() if why != "Done" else "already done"] var lvl := level(s, id) + 1 + s.pay(cost(cfg, id, lvl), slot) + s.record_event("upgrades_bought") # every level counts + level_up(campaign, id, structures) + return "%s done: %s" % [name_at(cfg, id, lvl), text_at(cfg, id, lvl).to_lower()] + + +## Raises an upgrade one level and applies that level's effect, with no checks and nothing paid: +## buy() once it has checked and paid, and grant_all() for free. +static func level_up(campaign: CampaignController, id: String, structures: StructureSystem = null) -> void: + var cfg := campaign.config + var s := campaign.state + var u: Dictionary = cfg.upgrades.get(id, {}) + var lvl := level(s, id) + 1 var add := roundi(per_level(u.get("add", 0), lvl)) var barrier_before := value(cfg, s, "barrier_hp") - s.pay(cost(cfg, id, lvl), slot) s.upgrades[id] = lvl - s.record_event("upgrades_bought") # every level counts match String(u.get("stat", "")): "scarecrow_max_hp": # both scarecrows' s.scarecrow_max_hp += add @@ -230,4 +241,15 @@ static func buy(campaign: CampaignController, id: String, structures: StructureS e["hp"] = mini(roundi(int(e["hp"]) * k), structures.max_hp(e["type"]) if structures != null else 1 << 20) "pouch_capacity": # the live value lives in ResourceStore (one for every pouch), not read from cfg each time s.resources.pouch_capacity += add - return "%s done: %s" % [name_at(cfg, id, lvl), text_at(cfg, id, lvl).to_lower()] + + +## Debug (CampaignDebug, F8): every upgrade and shop item to its last level, free, whatever the +## day, the goop, or "requires" say, each level's effect applied as if bought. Not counted as +## bought in the night record. Returns how many levels it added. +static func grant_all(campaign: CampaignController, structures: StructureSystem = null) -> int: + var n := 0 + for id: String in campaign.config.upgrades: + while not maxed(campaign.config, campaign.state, id): + level_up(campaign, id, structures) + n += 1 + return n diff --git a/game/tests/test_economy.gd b/game/tests/test_economy.gd index 8d72d3d..369b61e 100644 --- a/game/tests/test_economy.gd +++ b/game/tests/test_economy.gd @@ -28,6 +28,7 @@ func run(r: GameTestRunner) -> void: await _hidden_items(r) await _tiers(r) await _stock(r) + await _unlock_all(r) var farm := (load("res://game/scenes/farm.tscn") as PackedScene).instantiate() as Node3D r.root.add_child(farm) await r.process_frame @@ -383,6 +384,51 @@ func _tiers(r: GameTestRunner) -> void: ## Timed shed stock (#26): each shed item arrives on its day ("from_day"; day N is the day before ## night N) and can't be bought before it. Its row shows just its name, greyed, and "Arrives on ## day N"; a hidden one shows "?" and its day until it arrives, then the bare "?" until revealed. +## Debug F8 (CampaignDebug.unlock_all): on day 1, every upgrade and shop item goes to its last +## level for free, each level's effect applied; a retry from the morning review keeps it, one from +## later in the day goes back to the morning without it. +func _unlock_all(r: GameTestRunner) -> void: + var c := r.make_campaign((load("res://game/resources/game_config.tres") as GameConfig).duplicate(true) as GameConfig) + var cfg := c.config + var s := c.state + var debug := CampaignDebug.new() + debug.campaign = c + r.root.add_child(debug) + await r.process_frame + var hp := s.scarecrow_max_hp + var pouch := s.resources.pouch_capacity + var shed: Dictionary = s.resources.shed.duplicate() + var damage := Upgrades.value(cfg, s, "shot_damage") + var key := InputEventKey.new() + key.physical_keycode = KEY_F8 + key.pressed = true + debug._unhandled_input(key) + var all_max := true + for id: String in cfg.upgrades: + all_max = all_max and Upgrades.maxed(cfg, s, id) and Upgrades.blocker(c, id) == "Done" + r.check(all_max and s.night == 1 and Upgrades.levels_bought(cfg, s) == Upgrades.levels_total(cfg), + "F8 on the first morning: every upgrade and shop item at its last level (%d levels), hidden and not-yet-arrived ones too" + % Upgrades.levels_bought(cfg, s)) + r.check(s.resources.shed == shed and int(s.night_events.get("upgrades_bought", 0)) == 0, "free, and not counted as bought") + r.check(s.scarecrow_max_hp == hp + 6 and s.scarecrow_hp == hp + 6 and s.resources.pouch_capacity == pouch + 16 + and is_equal_approx(Upgrades.value(cfg, s, "shot_damage"), damage + 3), + "each level's effect applies: max health %d -> %d, pouch %d -> %d, kernels %.0f -> %.0f" + % [hp, s.scarecrow_max_hp, pouch, s.resources.pouch_capacity, damage, Upgrades.value(cfg, s, "shot_damage")]) + r.check(debug.unlock_all() == 0, "pressing it again adds nothing") + c.retry_night() + r.check(Upgrades.levels_bought(cfg, c.state) == Upgrades.levels_total(cfg), "from the morning review, a retry keeps it") + c.new_campaign() + c.begin_day() + r.check(debug.unlock_all() == Upgrades.levels_total(cfg), "it works by day too") + c.retry_night() + r.check(Upgrades.levels_bought(cfg, c.state) == 0, "a retry from later in the day goes back to the morning without it") + c.outcome = CampaignController.Outcome.GAME_OVER_SCARECROW + c.state.phase = CampaignController.Phase.GAME_OVER + r.check(debug.unlock_all() == 0 and Upgrades.levels_bought(cfg, c.state) == 0, "nothing once the vacation is over") + debug.queue_free() + c.queue_free() + + func _stock(r: GameTestRunner) -> void: var c := r.make_campaign((load("res://game/resources/game_config.tres") as GameConfig).duplicate(true) as GameConfig) var cfg := c.config