Task #26: upgrade tiers and timed shed stock
Workbench stat upgrades get 3 levels: level L costs costs[id] x
upgrade_cost_growth (1.8) ^ (L - 1), each material rounded up, and opens on
day upgrade_level_days[L - 1] ([1, 8, 16]). Each owned level's "mult"/"add"
entry stacks. Level 1 keeps the user's values and costs (rapid fire 3.0x).
Shed items arrive on set days ("from_day"): corn shooter 1, shurikens 2,
pumpkin bombs 3, potato cannon 6, radar 8, propane torch 10, alien ray 14.
- Upgrades: level(), max_level(), maxed(), cost(cfg, id, level),
next_cost(), per_level(), text_at(), name_at() (roman numerals),
from_day(), level_day(), arrived(). owned() stays "level >= 1". blocker()
adds "Arrives on day N" and "Level N opens on day D"; buy() takes the next
level and applies that level's side effect; upgrades_bought counts every
level. FarmState.upgrades keeps id -> level, so saves don't change shape.
- UpgradePanel: "Rapid fire II" with the next level's text and cost, the
blocker reason, "Max" at the last level; a shed item before its day shows
its name greyed with "Arrives on day N" ("?" plus the day if hidden). The
title counts items at their last level. Every level bought jingles.
- Co-op: the host sends "bought" for any level (no wire change; PROTOCOL
stays 5).
- soak_night.gd buys the lowest next level first across UPGRADE_ORDER.
- Tests: level costs, day gates, stacking, from_day, save/morning/retry/co-op,
an old {"rapid_fire": 1} save as level 1. Existing tests set the day where
they buy stock that now arrives later.
- RULES.md Upgrades: per-level effects and costs, stock schedule.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
6a9575dfe4
commit
91b9e52e96
12 changed files with 531 additions and 137 deletions
|
|
@ -12,9 +12,11 @@ extends RefCounted
|
|||
## supply shed's own shop (#6): weapons (corn_shooter, pumpkin_bomb) bought at its counter
|
||||
## (ShedCounter), not the workbench, with the walk-in pouch deposit unaffected. And a pouch per
|
||||
## scarecrow (#16): filled, deposited, and spent from by its own avatar slot, one shared capacity.
|
||||
## And upgrade levels and timed shed stock (#26, _tiers and _stock).
|
||||
|
||||
const P := CampaignController.Phase
|
||||
const DT := 1.0 / 60.0
|
||||
const TIERS_SAVE := "user://test_economy_tiers.json"
|
||||
|
||||
|
||||
func run(r: GameTestRunner) -> void:
|
||||
|
|
@ -24,6 +26,8 @@ func run(r: GameTestRunner) -> void:
|
|||
_goop_persistence(r)
|
||||
_pouch_upgrade(r)
|
||||
await _hidden_items(r)
|
||||
await _tiers(r)
|
||||
await _stock(r)
|
||||
var farm := (load("res://game/scenes/farm.tscn") as PackedScene).instantiate() as Node3D
|
||||
r.root.add_child(farm)
|
||||
await r.process_frame
|
||||
|
|
@ -162,7 +166,8 @@ func _pouch_upgrade(r: GameTestRunner) -> void:
|
|||
"Bigger pouch raises capacity from 8 to 16 (%s)" % msg)
|
||||
r.check(s.resources.pouch_room(0) == 16 and s.resources.pouch_room(1) == 16, "for both scarecrows' pouches (#16: one shared capacity)")
|
||||
r.check(s.resources.shed_total() == 0, "it costs the configured materials")
|
||||
r.check(Upgrades.buy(c, "pouch_upgrade").contains("already done"), "it can only be bought once")
|
||||
r.check(Upgrades.buy(c, "pouch_upgrade").contains("level 2 opens on day 8") and s.resources.pouch_capacity == 16,
|
||||
"its next level waits for day 8")
|
||||
# It carries into the next morning (same mechanic as straw_stuffing/scarecrow_max_hp).
|
||||
while s.phase != P.MORNING:
|
||||
c.advance_phase()
|
||||
|
|
@ -248,6 +253,177 @@ func _hidden_items(r: GameTestRunner) -> void:
|
|||
"a retry (restoring the morning snapshot) drops the failed night's own goop, un-revealing it, but keeps the earlier completed night's")
|
||||
|
||||
|
||||
## Upgrade levels (#26): the workbench's stat upgrades have 3 levels; Sprint, the weapons, and
|
||||
## Radar one. Level L costs costs[id] x upgrade_cost_growth^(L - 1), each material rounded up,
|
||||
## and opens on day upgrade_level_days[L - 1] (8 for level 2, 16 for level 3). Each buy() takes
|
||||
## one level, and every owned level's effect applies (heavy seeds: 2, 3, 4 damage; rapid fire's
|
||||
## multipliers multiply). upgrades_bought counts every level. The menu names the next level
|
||||
## ("Heavy seeds II") with its text and cost, says when it opens, and shows "Max" at the end.
|
||||
## Levels survive a save, the next morning, and a retry, and an old save's {"rapid_fire": 1}
|
||||
## loads as level 1.
|
||||
func _tiers(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 tiered := 0
|
||||
for id: String in cfg.upgrades:
|
||||
if Upgrades.max_level(cfg, id) == 3:
|
||||
tiered += 1
|
||||
r.check(tiered == 9 and Upgrades.max_level(cfg, "sprint") == 1 and Upgrades.max_level(cfg, "corn_shooter") == 1
|
||||
and Upgrades.max_level(cfg, "alien_ray") == 1 and Upgrades.max_level(cfg, "radar") == 1,
|
||||
"the nine stat upgrades have 3 levels; Sprint, the weapons, and Radar one (%d with 3)" % tiered)
|
||||
# Costs grow.
|
||||
var grows := true
|
||||
for id: String in cfg.upgrades:
|
||||
var base := Upgrades.cost(cfg, id, 1)
|
||||
grows = grows and base == cfg.costs.get(id, {})
|
||||
for m in base:
|
||||
var l2 := int(Upgrades.cost(cfg, id, 2)[m])
|
||||
var l3 := int(Upgrades.cost(cfg, id, 3)[m])
|
||||
grows = grows and l2 == ceili(int(base[m]) * cfg.upgrade_cost_growth - 0.0001) and l3 == ceili(int(base[m]) * pow(cfg.upgrade_cost_growth, 2) - 0.0001)
|
||||
grows = grows and int(base[m]) < l2 and l2 < l3
|
||||
r.check(grows, "level 1 costs costs[id]; each next level %.1fx the one before, each material rounded up" % cfg.upgrade_cost_growth)
|
||||
var keep: Dictionary = cfg.costs["heavy_seeds"]
|
||||
cfg.costs["heavy_seeds"] = {"scrap": 10, "straw": 25}
|
||||
r.check(Upgrades.cost(cfg, "heavy_seeds", 2) == {"scrap": 18, "straw": 45} and Upgrades.cost(cfg, "heavy_seeds", 3) == {"scrap": 33, "straw": 81},
|
||||
"e.g. 10 scrap, 25 straw: then 18, 45; then 33 (32.4 rounded up), 81 (not 82 from 25 x 3.24's float error)")
|
||||
cfg.costs["heavy_seeds"] = keep
|
||||
|
||||
# Day gates and stacking effects, in the menu too.
|
||||
var panel := UpgradePanel.new()
|
||||
r.root.add_child(panel)
|
||||
await r.process_frame
|
||||
panel.setup(c, null, null)
|
||||
c.begin_day()
|
||||
s.resources.shed = {"wood": 999, "scrap": 999, "straw": 999, "alien_goop": 0}
|
||||
s.upgrades["corn_shooter"] = 1
|
||||
panel.refresh()
|
||||
var row := panel._rows["heavy_seeds"] as Button
|
||||
r.check(row.text == "Heavy seeds I — Each kernel does 2 damage (%s)" % ResourceStore.describe(Upgrades.cost(cfg, "heavy_seeds", 1)) and not row.disabled,
|
||||
"the menu offers level I: '%s'" % row.text)
|
||||
var damage := cfg.shot_damage
|
||||
r.check(Upgrades.buy(c, "heavy_seeds").contains("done:") and Upgrades.level(s, "heavy_seeds") == 1
|
||||
and roundi(Upgrades.value(cfg, s, "shot_damage")) == damage + 1, "level 1 on day 1: kernels do %d damage" % (damage + 1))
|
||||
r.check(Upgrades.blocker(c, "heavy_seeds") == "Level 2 opens on day 8" and Upgrades.buy(c, "heavy_seeds") == "Heavy seeds: level 2 opens on day 8"
|
||||
and Upgrades.level(s, "heavy_seeds") == 1, "level 2 can't be bought before day 8")
|
||||
panel.refresh()
|
||||
r.check(row.disabled and row.text.begins_with("Heavy seeds II — Each kernel does 3 damage (%s)" % ResourceStore.describe(Upgrades.cost(cfg, "heavy_seeds", 2)))
|
||||
and row.text.ends_with("Level 2 opens on day 8"), "the menu shows level II, its cost, and when it opens: '%s'" % row.text)
|
||||
s.night = 7
|
||||
r.check(Upgrades.blocker(c, "heavy_seeds") == "Level 2 opens on day 8", "(not on day 7 either)")
|
||||
s.night = 8
|
||||
var shed := s.resources.shed.duplicate()
|
||||
var l2 := Upgrades.cost(cfg, "heavy_seeds", 2)
|
||||
var msg := Upgrades.buy(c, "heavy_seeds")
|
||||
var paid := true
|
||||
for m in l2:
|
||||
paid = paid and int(shed[m]) - int(s.resources.shed[m]) == int(l2[m])
|
||||
r.check(msg == "Heavy seeds II done: each kernel does 3 damage" and Upgrades.level(s, "heavy_seeds") == 2 and paid
|
||||
and roundi(Upgrades.value(cfg, s, "shot_damage")) == damage + 2, "on day 8, level 2 for %s: kernels do %d ('%s')" % [ResourceStore.describe(l2), damage + 2, msg])
|
||||
r.check(Upgrades.blocker(c, "heavy_seeds") == "Level 3 opens on day 16", "level 3 waits for day 16")
|
||||
s.night = 16
|
||||
r.check(Upgrades.buy(c, "heavy_seeds").contains("done:") and Upgrades.level(s, "heavy_seeds") == 3
|
||||
and roundi(Upgrades.value(cfg, s, "shot_damage")) == damage + 3, "on day 16, level 3: kernels do %d" % (damage + 3))
|
||||
r.check(Upgrades.blocker(c, "heavy_seeds") == "Done" and Upgrades.buy(c, "heavy_seeds") == "Heavy seeds: already done"
|
||||
and Upgrades.level(s, "heavy_seeds") == 3, "and that's the last")
|
||||
panel.refresh()
|
||||
r.check(row.disabled and row.text == "Heavy seeds III — Each kernel does 4 damage (Max)", "the menu says Max: '%s'" % row.text)
|
||||
var mult: Variant = cfg.upgrades["rapid_fire"]["mult"]
|
||||
Upgrades.buy(c, "rapid_fire")
|
||||
Upgrades.buy(c, "rapid_fire")
|
||||
var rate := cfg.fire_rate * Upgrades.per_level(mult, 1) * Upgrades.per_level(mult, 2)
|
||||
r.check(Upgrades.level(s, "rapid_fire") == 2 and is_equal_approx(Upgrades.value(cfg, s, "fire_rate"), rate),
|
||||
"rapid fire's levels multiply: level 2 fires %.2f a second (%.2f x %.2f x %.2f)" % [Upgrades.value(cfg, s, "fire_rate"), cfg.fire_rate,
|
||||
Upgrades.per_level(mult, 1), Upgrades.per_level(mult, 2)])
|
||||
var hp := s.scarecrow_max_hp
|
||||
var cap := s.resources.pouch_capacity
|
||||
var stuffing := 0
|
||||
var pouch := 0
|
||||
for lvl in [1, 2, 3]:
|
||||
Upgrades.buy(c, "straw_stuffing")
|
||||
Upgrades.buy(c, "pouch_upgrade")
|
||||
stuffing += roundi(Upgrades.per_level(cfg.upgrades["straw_stuffing"]["add"], lvl))
|
||||
pouch += roundi(Upgrades.per_level(cfg.upgrades["pouch_upgrade"]["add"], lvl))
|
||||
r.check(Upgrades.level(s, "straw_stuffing") == 3 and s.scarecrow_max_hp == hp + stuffing and s.scarecrow_hp == s.scarecrow_max_hp,
|
||||
"three levels of straw stuffing: +%d max health" % stuffing)
|
||||
r.check(Upgrades.level(s, "pouch_upgrade") == 3 and s.resources.pouch_capacity == cap + pouch, "three levels of the bigger pouch: %d units" % s.resources.pouch_capacity)
|
||||
r.check(int(s.night_events.get("upgrades_bought", 0)) == 11, "upgrades bought counts every level (%d)" % int(s.night_events.get("upgrades_bought", 0)))
|
||||
var done := 0
|
||||
for id: String in panel._rows:
|
||||
done += 1 if Upgrades.maxed(cfg, s, id) else 0
|
||||
panel.refresh()
|
||||
r.check(done == 3 and panel._title.text.ends_with("(3 of %d done)" % panel._rows.size()), "the title counts the ones at their last level: '%s'" % panel._title.text)
|
||||
panel.queue_free()
|
||||
|
||||
# Levels persist: through a save, into the next morning, and in a retry from that morning.
|
||||
var levels := s.upgrades.duplicate()
|
||||
s.night = 1 # (back to the first day, so the vacation doesn't end below)
|
||||
var back := FarmState.from_dict(JSON.parse_string(JSON.stringify(s.to_dict(), "", true, true)))
|
||||
r.check(back != null and back.upgrades == levels and Upgrades.level(back, "heavy_seeds") == 3, "levels survive a save (JSON)")
|
||||
while s.phase != P.MORNING:
|
||||
c.advance_phase()
|
||||
r.check(c.state.upgrades == levels, "and carry into the next morning")
|
||||
c.begin_day()
|
||||
c.advance_phase() # DAY -> DUSK
|
||||
c.advance_phase() # DUSK -> NIGHT
|
||||
r.check(c.retry_night() and c.state != s and c.state.upgrades == levels and c.state.resources.pouch_capacity == cap + pouch,
|
||||
"and a retry from that morning keeps them")
|
||||
# A save from before levels: {"rapid_fire": 1} is level 1.
|
||||
var old := c.state.to_dict()
|
||||
old["upgrades"] = {"corn_shooter": 1, "rapid_fire": 1}
|
||||
var was := SaveGame.read(TIERS_SAVE).state if SaveGame.write(old, TIERS_SAVE) == OK else null
|
||||
SaveGame.delete(TIERS_SAVE)
|
||||
r.check(was != null and Upgrades.level(was, "rapid_fire") == 1 and Upgrades.owned(was, "rapid_fire")
|
||||
and is_equal_approx(Upgrades.value(cfg, was, "fire_rate"), cfg.fire_rate * Upgrades.per_level(mult, 1))
|
||||
and Upgrades.next_cost(cfg, was, "rapid_fire") == Upgrades.cost(cfg, "rapid_fire", 2),
|
||||
"an old save's {\"rapid_fire\": 1} loads as level 1, with level 2 next")
|
||||
c.queue_free()
|
||||
|
||||
|
||||
## 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.
|
||||
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
|
||||
var s := c.state
|
||||
var days := {}
|
||||
for id in Upgrades.ORDER:
|
||||
if Upgrades.shop_of(cfg, id) == "shed":
|
||||
days[id] = Upgrades.from_day(cfg, id)
|
||||
r.check(days == {"corn_shooter": 1, "shurikens": 2, "pumpkin_bomb": 3, "potato_cannon": 6, "radar": 8, "propane_torch": 10, "alien_ray": 14},
|
||||
"the shed's stock days: %s" % days)
|
||||
var panel := UpgradePanel.new()
|
||||
r.root.add_child(panel)
|
||||
await r.process_frame
|
||||
panel.setup(c, null, null, "shed")
|
||||
c.begin_day()
|
||||
s.resources.shed = {"wood": 999, "scrap": 999, "straw": 999, "alien_goop": 999}
|
||||
panel.refresh()
|
||||
var row := panel._rows["potato_cannon"] as Button
|
||||
r.check(Upgrades.blocker(c, "potato_cannon") == "Arrives on day 6" and Upgrades.buy(c, "potato_cannon") == "Potato cannon: arrives on day 6"
|
||||
and not Upgrades.owned(s, "potato_cannon") and not Upgrades.arrived(s, cfg, "potato_cannon"), "on day 1 the potato cannon isn't in stock and can't be bought")
|
||||
r.check(row.disabled and row.text == "Potato cannon Arrives on day 6", "its row shows just its name, greyed, and its day: '%s'" % row.text)
|
||||
r.check((panel._rows["alien_ray"] as Button).text == "? Arrives on day 14" and (panel._rows["alien_ray"] as Button).disabled,
|
||||
"a hidden item not in stock shows '?' and its day: '%s'" % (panel._rows["alien_ray"] as Button).text)
|
||||
r.check(not (panel._rows["corn_shooter"] as Button).disabled and Upgrades.blocker(c, "corn_shooter") == "", "the corn shooter is in stock on day 1")
|
||||
s.night = 5
|
||||
r.check(Upgrades.blocker(c, "potato_cannon") == "Arrives on day 6" and Upgrades.blocker(c, "pumpkin_bomb") == "", "(day 5: not yet; the pumpkin bombs, from day 3, are)")
|
||||
s.night = 6
|
||||
panel.refresh()
|
||||
r.check(Upgrades.arrived(s, cfg, "potato_cannon") and Upgrades.blocker(c, "potato_cannon") == "" and not row.disabled
|
||||
and row.text.begins_with("Potato cannon — "), "on day 6 it's in stock: '%s'" % row.text)
|
||||
r.check(Upgrades.buy(c, "potato_cannon").contains("done:") and Upgrades.owned(s, "potato_cannon"), "and can be bought")
|
||||
panel.refresh()
|
||||
r.check(row.disabled and row.text.ends_with(" (Done)"), "a one-off says Done: '%s'" % row.text)
|
||||
s.night = 14
|
||||
panel.refresh()
|
||||
r.check((panel._rows["alien_ray"] as Button).text == "?" and Upgrades.blocker(c, "alien_ray") == "Not discovered yet",
|
||||
"in stock but not discovered yet, it's a bare '?'")
|
||||
panel.queue_free()
|
||||
c.queue_free()
|
||||
|
||||
|
||||
func _layout(r: GameTestRunner, sim: FarmSim) -> void:
|
||||
var by_material := {}
|
||||
var names := {}
|
||||
|
|
@ -426,7 +602,7 @@ func _stuffing(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter) -> void
|
|||
var it := sim.interactions
|
||||
var bench := it.workbench
|
||||
var menu := sim.upgrade_panel
|
||||
var add := int(sim.config.upgrades["straw_stuffing"]["add"])
|
||||
var add := roundi(Upgrades.per_level(sim.config.upgrades["straw_stuffing"]["add"], 1))
|
||||
var msgs: Array[String] = []
|
||||
it.message.connect(func(t: String, _col: Color) -> void: msgs.append(t))
|
||||
menu.message.connect(func(t: String, _col: Color) -> void: msgs.append(t))
|
||||
|
|
@ -447,7 +623,8 @@ func _stuffing(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter) -> void
|
|||
r.check(Upgrades.owned(s, "straw_stuffing") and s.scarecrow_max_hp == max_hp + add and s.scarecrow_hp == s.scarecrow_max_hp,
|
||||
"Straw stuffing: +%d max HP (%s)" % [add, msgs[-1]])
|
||||
r.check(s.resources.shed == {"wood": 0, "scrap": 0, "straw": 0} and s.resources.pouch["wood"] == 0, "it costs 12 straw and 4 wood")
|
||||
r.check(row.disabled and row.text.contains("Done"), "it can only be bought once")
|
||||
r.check(row.disabled and row.text.begins_with("Straw stuffing II —") and row.text.contains("Level 2 opens on day 8"),
|
||||
"the row offers level II, closed until day 8: '%s'" % row.text)
|
||||
_press(sim)
|
||||
r.check(not menu.is_open and not player.rooted, "interact again closes the menu")
|
||||
_press(sim)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue