Adds a second UpgradePanel instance (shop "shed") at the Supply Shed's new
ShedCounter node, opened by interact like the Workbench. corn_shooter and
pumpkin_bomb move there ("shop": "shed" in GameConfig.upgrades); the
Workbench's panel (shop "workbench", the default) keeps rapid_fire,
heavy_seeds, and the rest, with "requires" still crossing shops. Co-op buys
go through the same ["buy", id] host gate; a shed_requested signal mirrors
workbench_requested so the partner's own shed panel opens. The shed's
walk-in pouch deposit is unaffected (no interact, not gated by the
counter's reach).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
121 lines
5.8 KiB
GDScript
121 lines
5.8 KiB
GDScript
class_name Upgrades
|
|
extends RefCounted
|
|
## The farm's upgrades and shop items (definitions in GameConfig.upgrades, costs in
|
|
## GameConfig.costs): bought once each, by day, at one of two shops (shop_of, "workbench" by
|
|
## default: player/weapon stat and buildable upgrades, at the work area; "shed": weapons and
|
|
## other purchasable items, at the supply shed's counter), each its own UpgradePanel instance.
|
|
## Bought ones are kept in FarmState.upgrades (id -> 1), so they carry over between nights and
|
|
## come back with a retry. Systems ask value() for a stat with the owned upgrades applied instead
|
|
## of reading GameConfig directly: the corn shooter's fire rate and shot damage, fear's radius and
|
|
## cooldown, fences' and gates' health (barrier_hp), the automated defense's range, and the traps'
|
|
## slow time. Straw stuffing raises the scarecrow's max health (FarmState) when bought, and the
|
|
## Bigger pouch upgrade raises pouch_capacity (ResourceStore) the same way. Sprint, the corn
|
|
## shooter, and pumpkin bombs change no stat: owning them unlocks sprinting (PlayerCharacter) and
|
|
## the two weapons (ScarecrowCombat). Rapid fire and heavy seeds (bought at the workbench) need
|
|
## the corn shooter (bought at the shed) first ("requires" crosses shops freely).
|
|
|
|
## Menu order, grouped by track.
|
|
const ORDER: Array[String] = ["corn_shooter", "rapid_fire", "heavy_seeds", "pumpkin_bomb", "wide_fear", "quick_fear",
|
|
"straw_stuffing", "pouch_upgrade", "sprint", "reinforced_fences", "long_range", "sticky_tar"]
|
|
|
|
|
|
static func owned(state: FarmState, id: String) -> bool:
|
|
return int(state.upgrades.get(id, 0)) > 0
|
|
|
|
|
|
static func cost(cfg: GameConfig, id: String) -> Dictionary:
|
|
return cfg.costs.get(id, {})
|
|
|
|
|
|
## Which shop sells an upgrade: "workbench" (the default: player/weapon stat and buildable
|
|
## upgrades, at the work area) or "shed" (weapons and other purchasable items, at the supply
|
|
## shed's counter). UpgradePanel filters ORDER by this to build the two shops' rows; "requires"
|
|
## can still cross shops (e.g. rapid_fire at the workbench requiring corn_shooter from the shed).
|
|
static func shop_of(cfg: GameConfig, id: String) -> String:
|
|
return String(cfg.upgrades.get(id, {}).get("shop", "workbench"))
|
|
|
|
|
|
## Total Alien Goop collected this vacation so far: every completed night's "gathered_alien_goop"
|
|
## (FarmState.totals(), from night_log) plus the current cycle's own count (night_events). This is
|
|
## a running total, not a current balance (spending or being robbed of goop doesn't un-reveal
|
|
## anything), so it's unaffected by the shed/pouch and persists through save (night_log is saved)
|
|
## and retry (retry restores the morning snapshot, dropping the failed night's own goop).
|
|
static func goop_collected(state: FarmState) -> int:
|
|
if state == null:
|
|
return 0
|
|
return int(state.totals().get("gathered_alien_goop", 0)) + int(state.night_events.get("gathered_alien_goop", 0))
|
|
|
|
|
|
## Whether a shop item's reveal condition is met (always true unless its definition sets
|
|
## "hidden": true). A hidden item reveals once goop_collected() reaches its "reveal_goop" (falls
|
|
## back to GameConfig.hidden_reveal_goop).
|
|
static func revealed(state: FarmState, cfg: GameConfig, id: String) -> bool:
|
|
var u: Dictionary = cfg.upgrades.get(id, {})
|
|
if not bool(u.get("hidden", false)):
|
|
return true
|
|
return goop_collected(state) >= int(u.get("reveal_goop", cfg.hidden_reveal_goop))
|
|
|
|
|
|
## A stat with every owned upgrade applied (barrier_hp is a multiplier, 1 without upgrades).
|
|
static func value(cfg: GameConfig, state: FarmState, stat: String) -> float:
|
|
var v := 1.0 if stat == "barrier_hp" else float(cfg.get(stat))
|
|
if state == null:
|
|
return v
|
|
for id: String in cfg.upgrades:
|
|
var u: Dictionary = cfg.upgrades[id]
|
|
if String(u.get("stat", "")) != stat or not owned(state, id):
|
|
continue
|
|
if u.has("mult"):
|
|
v *= float(u["mult"])
|
|
if u.has("add"):
|
|
v += float(u["add"])
|
|
return v
|
|
|
|
|
|
## Why an upgrade can't be bought right now ("" if it can).
|
|
static func blocker(campaign: CampaignController, id: String) -> String:
|
|
var cfg := campaign.config
|
|
var s := campaign.state
|
|
if not cfg.upgrades.has(id):
|
|
return "No such upgrade"
|
|
if owned(s, id):
|
|
return "Done"
|
|
if not revealed(s, cfg, id):
|
|
return "Not discovered yet"
|
|
var needs := String(cfg.upgrades[id].get("requires", ""))
|
|
if needs != "" and not owned(s, needs):
|
|
return "Needs the %s first" % String(cfg.upgrades.get(needs, {}).get("name", needs)).to_lower()
|
|
if not campaign.is_daytime():
|
|
return "The work area is for daytime"
|
|
if not s.resources.can_afford(cost(cfg, id)):
|
|
return "Need %s more" % ResourceStore.describe(s.resources.missing(cost(cfg, id)))
|
|
return ""
|
|
|
|
|
|
## Buys an upgrade if it can be bought. Returns the message for the player.
|
|
static func buy(campaign: CampaignController, id: String, structures: StructureSystem = null) -> String:
|
|
var cfg := campaign.config
|
|
var s := campaign.state
|
|
var u: Dictionary = cfg.upgrades.get(id, {})
|
|
var why := blocker(campaign, id)
|
|
if why != "":
|
|
return "%s: %s" % [u.get("name", id), why.to_lower() if why != "Done" else "already done"]
|
|
var barrier_before := value(cfg, s, "barrier_hp")
|
|
s.pay(cost(cfg, id))
|
|
s.upgrades[id] = 1
|
|
s.record_event("upgrades_bought")
|
|
match String(u.get("stat", "")):
|
|
"scarecrow_max_hp": # both scarecrows'
|
|
s.scarecrow_max_hp += int(u.get("add", 0))
|
|
s.scarecrow_hp += int(u.get("add", 0))
|
|
s.partner_max_hp += int(u.get("add", 0))
|
|
s.partner_hp += int(u.get("add", 0))
|
|
"barrier_hp":
|
|
# Standing fences and gates keep their share of health.
|
|
var k := value(cfg, s, "barrier_hp") / barrier_before
|
|
for e in s.structures:
|
|
if e["type"] == "fence" or e["type"] == "gate":
|
|
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, not read from cfg each time
|
|
s.resources.pouch_capacity += int(u.get("add", 0))
|
|
return "%s done: %s" % [u.get("name", id), String(u.get("text", "")).to_lower()]
|