Merge task #4: Alien Goop resource and drop-on-kill
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
2fa3aa305f
9 changed files with 178 additions and 37 deletions
|
|
@ -111,6 +111,9 @@ var _hunt_cell: int = -1
|
||||||
var _hunt_wait: float = 0.0
|
var _hunt_wait: float = 0.0
|
||||||
var _rebuild_usec: int = 0
|
var _rebuild_usec: int = 0
|
||||||
var _rebuild_ticks: int = 0
|
var _rebuild_ticks: int = 0
|
||||||
|
## Alien Goop's drop-on-kill roll (Decision 11): seeded like LootSystem's category RNG, for
|
||||||
|
## reproducible trials.
|
||||||
|
var _goop_rng := RandomNumberGenerator.new()
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
|
@ -178,6 +181,8 @@ func _ready() -> void:
|
||||||
push_warning("The pen holds %d animals but GameConfig.start_animals is %d" % [animals.count, config.start_animals])
|
push_warning("The pen holds %d animals but GameConfig.start_animals is %d" % [animals.count, config.start_animals])
|
||||||
enemies.enemy_removed.connect(loot.on_enemy_removed)
|
enemies.enemy_removed.connect(loot.on_enemy_removed)
|
||||||
enemies.enemy_removed.connect(_count_removal)
|
enemies.enemy_removed.connect(_count_removal)
|
||||||
|
_goop_rng.seed = 20261005
|
||||||
|
enemies.enemy_removed.connect(_drop_alien_goop)
|
||||||
projectiles = FarmProjectiles.new()
|
projectiles = FarmProjectiles.new()
|
||||||
projectiles.name = "Shots"
|
projectiles.name = "Shots"
|
||||||
add_child(projectiles)
|
add_child(projectiles)
|
||||||
|
|
@ -594,6 +599,22 @@ func _count_removal(handle: int, reason: EnemySystem.Removal, _x: float, _z: flo
|
||||||
campaign.state.record_event("escaped")
|
campaign.state.record_event("escaped")
|
||||||
|
|
||||||
|
|
||||||
|
## Alien Goop (Decision 11): a killed Alien (the thief type, display-named "Alien") has a
|
||||||
|
## config-tunable chance to drop goop, credited like a gathered material straight into the
|
||||||
|
## pouch (respecting its capacity; a full pouch simply loses the drop, same as any overflow).
|
||||||
|
func _drop_alien_goop(handle: int, reason: EnemySystem.Removal, _x: float, _z: float, _carry: int, _target: int) -> void:
|
||||||
|
if reason != EnemySystem.Removal.KILLED:
|
||||||
|
return
|
||||||
|
var d := enemies.resolve_handle(handle)
|
||||||
|
if d < 0 or enemies.type[d] != EnemySystem.TYPE_THIEF:
|
||||||
|
return
|
||||||
|
if _goop_rng.randf() >= config.alien_goop_drop_chance:
|
||||||
|
return
|
||||||
|
var added := campaign.state.resources.add_to_pouch("alien_goop", config.alien_goop_drop_qty)
|
||||||
|
if added > 0:
|
||||||
|
campaign.state.record_event("gathered_alien_goop", added)
|
||||||
|
|
||||||
|
|
||||||
## Keeps the field toward the scarecrow fresh while anything is fighting it.
|
## Keeps the field toward the scarecrow fresh while anything is fighting it.
|
||||||
func _update_hunt(dt: float) -> void:
|
func _update_hunt(dt: float) -> void:
|
||||||
_hunt_wait = maxf(_hunt_wait - dt, 0.0)
|
_hunt_wait = maxf(_hunt_wait - dt, 0.0)
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,8 @@ const EVENTS: Array[String] = [
|
||||||
"killed_crow", "killed_thief", "killed_breaker", "escaped",
|
"killed_crow", "killed_thief", "killed_breaker", "escaped",
|
||||||
"scarecrow_damage", "patches",
|
"scarecrow_damage", "patches",
|
||||||
"structures_built", "structures_damaged", "structures_destroyed", "repairs", "upgrades_bought",
|
"structures_built", "structures_damaged", "structures_destroyed", "repairs", "upgrades_bought",
|
||||||
"gathered_wood", "gathered_scrap", "gathered_straw", "spent_wood", "spent_scrap", "spent_straw",
|
"gathered_wood", "gathered_scrap", "gathered_straw", "gathered_alien_goop",
|
||||||
|
"spent_wood", "spent_scrap", "spent_straw", "spent_alien_goop",
|
||||||
]
|
]
|
||||||
## The keys of a night_log entry: the night, crops and animals lost, then every EVENTS key.
|
## The keys of a night_log entry: the night, crops and animals lost, then every EVENTS key.
|
||||||
const LOG_KEYS: Array[String] = [
|
const LOG_KEYS: Array[String] = [
|
||||||
|
|
@ -37,7 +38,8 @@ const LOG_KEYS: Array[String] = [
|
||||||
"killed_crow", "killed_thief", "killed_breaker", "escaped",
|
"killed_crow", "killed_thief", "killed_breaker", "escaped",
|
||||||
"scarecrow_damage", "patches",
|
"scarecrow_damage", "patches",
|
||||||
"structures_built", "structures_damaged", "structures_destroyed", "repairs", "upgrades_bought",
|
"structures_built", "structures_damaged", "structures_destroyed", "repairs", "upgrades_bought",
|
||||||
"gathered_wood", "gathered_scrap", "gathered_straw", "spent_wood", "spent_scrap", "spent_straw",
|
"gathered_wood", "gathered_scrap", "gathered_straw", "gathered_alien_goop",
|
||||||
|
"spent_wood", "spent_scrap", "spent_straw", "spent_alien_goop",
|
||||||
]
|
]
|
||||||
|
|
||||||
## Current night (1-based). The morning, day, dusk, night, and dawn of a cycle all belong to it.
|
## Current night (1-based). The morning, day, dusk, night, and dawn of a cycle all belong to it.
|
||||||
|
|
@ -119,7 +121,8 @@ static func create(cfg: GameConfig) -> FarmState:
|
||||||
s.crops_total = cfg.start_crops
|
s.crops_total = cfg.start_crops
|
||||||
s.animals_total = cfg.start_animals
|
s.animals_total = cfg.start_animals
|
||||||
s.resources.pouch_capacity = cfg.pouch_capacity
|
s.resources.pouch_capacity = cfg.pouch_capacity
|
||||||
s.resources.shed = {"wood": cfg.start_wood, "scrap": cfg.start_scrap, "straw": cfg.start_straw}
|
s.resources.shed = {"wood": cfg.start_wood, "scrap": cfg.start_scrap, "straw": cfg.start_straw,
|
||||||
|
"alien_goop": cfg.start_alien_goop}
|
||||||
s.supplies_total = s.resources.shed_total()
|
s.supplies_total = s.resources.shed_total()
|
||||||
for e in cfg.start_structures:
|
for e in cfg.start_structures:
|
||||||
var t := String(e["type"])
|
var t := String(e["type"])
|
||||||
|
|
|
||||||
|
|
@ -91,10 +91,12 @@ extends Resource
|
||||||
@export var pickup_radius: float = 1.3
|
@export var pickup_radius: float = 1.3
|
||||||
|
|
||||||
@export_group("Resources")
|
@export_group("Resources")
|
||||||
## Wood, scrap, and straw in the supply shed when the vacation starts.
|
## Wood, scrap, and straw in the supply shed when the vacation starts. Alien Goop is never a
|
||||||
|
## starting stock (it's found only by killing Aliens), but the shed still tracks a count for it.
|
||||||
@export_range(0, 999) var start_wood: int = 4
|
@export_range(0, 999) var start_wood: int = 4
|
||||||
@export_range(0, 999) var start_scrap: int = 2
|
@export_range(0, 999) var start_scrap: int = 2
|
||||||
@export_range(0, 999) var start_straw: int = 4
|
@export_range(0, 999) var start_straw: int = 4
|
||||||
|
@export_range(0, 999) var start_alien_goop: int = 0
|
||||||
## The scarecrow's pouch holds this many units in total; it empties into the shed on entry.
|
## The scarecrow's pouch holds this many units in total; it empties into the shed on entry.
|
||||||
@export_range(1, 200) var pouch_capacity: int = 16
|
@export_range(1, 200) var pouch_capacity: int = 16
|
||||||
## Seconds of holding interact per gather (each takes one charge of the gather point).
|
## Seconds of holding interact per gather (each takes one charge of the gather point).
|
||||||
|
|
@ -271,6 +273,10 @@ extends Resource
|
||||||
@export var trickle_type: String = "crow"
|
@export var trickle_type: String = "crow"
|
||||||
## What trickle enemies go for: "crops", "animals", "supplies", or "any" (of their type's targets).
|
## What trickle enemies go for: "crops", "animals", "supplies", or "any" (of their type's targets).
|
||||||
@export var trickle_target: String = "any"
|
@export var trickle_target: String = "any"
|
||||||
|
## Alien Goop (Decision 11): a killed Alien (TYPE_THIEF) drops this much goop this often, credited
|
||||||
|
## straight into the pouch like a gathered material (ResourceStore.MATERIALS).
|
||||||
|
@export_range(0.0, 1.0) var alien_goop_drop_chance: float = 0.33
|
||||||
|
@export_range(0, 20) var alien_goop_drop_qty: int = 1
|
||||||
|
|
||||||
|
|
||||||
## A row of the enemy roster.
|
## A row of the enemy roster.
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,9 @@ const COLORS := {
|
||||||
"wood": Color(0.95, 0.68, 0.4),
|
"wood": Color(0.95, 0.68, 0.4),
|
||||||
"scrap": Color(0.72, 0.84, 0.95),
|
"scrap": Color(0.72, 0.84, 0.95),
|
||||||
"straw": Color(1.0, 0.9, 0.42),
|
"straw": Color(1.0, 0.9, 0.42),
|
||||||
|
## Alien Goop isn't gathered at a GatherNode (dropped by killed Aliens instead); its color is
|
||||||
|
## used by the HUD and shed pile label, keyed off ResourceStore.MATERIALS like the others.
|
||||||
|
"alien_goop": Color(0.55, 0.95, 0.35),
|
||||||
}
|
}
|
||||||
|
|
||||||
@export_enum("wood", "scrap", "straw") var material: String = "wood"
|
@export_enum("wood", "scrap", "straw") var material: String = "wood"
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ func _process(delta: float) -> void:
|
||||||
func _amounts(d: Dictionary) -> String:
|
func _amounts(d: Dictionary) -> String:
|
||||||
var parts: Array[String] = []
|
var parts: Array[String] = []
|
||||||
for m in ResourceStore.MATERIALS:
|
for m in ResourceStore.MATERIALS:
|
||||||
parts.append("[color=#%s]%s %d[/color]" % [GatherNode.COLORS[m].to_html(false), m.capitalize(), int(d[m])])
|
parts.append("[color=#%s]%s %d[/color]" % [GatherNode.COLORS[m].to_html(false), m.capitalize(), int(d.get(m, 0))])
|
||||||
return " ".join(parts)
|
return " ".join(parts)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,28 +1,31 @@
|
||||||
class_name ResourceStore
|
class_name ResourceStore
|
||||||
extends RefCounted
|
extends RefCounted
|
||||||
## The farm's construction materials (wood, scrap, straw): stock stored in the supply shed, and
|
## The farm's construction materials (wood, scrap, straw, alien goop): stock stored in the supply
|
||||||
## what the scarecrow carries in its pouch (pouch_capacity units across all materials). The
|
## shed, and what the scarecrow carries in its pouch (pouch_capacity units across all materials).
|
||||||
## pouch empties into the shed when the scarecrow walks in. Costs are paid all-or-nothing, from
|
## The pouch empties into the shed when the scarecrow walks in. Costs are paid all-or-nothing,
|
||||||
## the pouch first and then the shed. Only shed stock can be stolen.
|
## from the pouch first and then the shed. Only shed stock can be stolen.
|
||||||
|
## Methods that sum across MATERIALS read with get(m, 0): a shed/pouch dict built or replaced
|
||||||
|
## elsewhere (tests, old saves) without every material present is treated as 0 for the rest,
|
||||||
|
## rather than erroring.
|
||||||
|
|
||||||
const MATERIALS: Array[String] = ["wood", "scrap", "straw"]
|
const MATERIALS: Array[String] = ["wood", "scrap", "straw", "alien_goop"]
|
||||||
|
|
||||||
var shed := {"wood": 0, "scrap": 0, "straw": 0}
|
var shed := {"wood": 0, "scrap": 0, "straw": 0, "alien_goop": 0}
|
||||||
var pouch := {"wood": 0, "scrap": 0, "straw": 0}
|
var pouch := {"wood": 0, "scrap": 0, "straw": 0, "alien_goop": 0}
|
||||||
var pouch_capacity: int = 15
|
var pouch_capacity: int = 15
|
||||||
|
|
||||||
|
|
||||||
func pouch_total() -> int:
|
func pouch_total() -> int:
|
||||||
var n := 0
|
var n := 0
|
||||||
for m in MATERIALS:
|
for m in MATERIALS:
|
||||||
n += int(pouch[m])
|
n += int(pouch.get(m, 0))
|
||||||
return n
|
return n
|
||||||
|
|
||||||
|
|
||||||
func shed_total() -> int:
|
func shed_total() -> int:
|
||||||
var n := 0
|
var n := 0
|
||||||
for m in MATERIALS:
|
for m in MATERIALS:
|
||||||
n += int(shed[m])
|
n += int(shed.get(m, 0))
|
||||||
return n
|
return n
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -31,8 +34,8 @@ func most_stocked() -> String:
|
||||||
var best := ""
|
var best := ""
|
||||||
var most := 0
|
var most := 0
|
||||||
for m in MATERIALS:
|
for m in MATERIALS:
|
||||||
if int(shed[m]) > most:
|
if int(shed.get(m, 0)) > most:
|
||||||
most = int(shed[m])
|
most = int(shed.get(m, 0))
|
||||||
best = m
|
best = m
|
||||||
return best
|
return best
|
||||||
|
|
||||||
|
|
@ -44,7 +47,7 @@ func pouch_room() -> int:
|
||||||
## Puts up to amount into the pouch, as much as fits. Returns how much went in.
|
## Puts up to amount into the pouch, as much as fits. Returns how much went in.
|
||||||
func add_to_pouch(material: String, amount: int) -> int:
|
func add_to_pouch(material: String, amount: int) -> int:
|
||||||
var added := mini(maxi(amount, 0), pouch_room())
|
var added := mini(maxi(amount, 0), pouch_room())
|
||||||
pouch[material] = int(pouch[material]) + added
|
pouch[material] = int(pouch.get(material, 0)) + added
|
||||||
return added
|
return added
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -52,16 +55,16 @@ func add_to_pouch(material: String, amount: int) -> int:
|
||||||
func deposit() -> Dictionary:
|
func deposit() -> Dictionary:
|
||||||
var moved := {}
|
var moved := {}
|
||||||
for m in MATERIALS:
|
for m in MATERIALS:
|
||||||
var n := int(pouch[m])
|
var n := int(pouch.get(m, 0))
|
||||||
if n > 0:
|
if n > 0:
|
||||||
shed[m] = int(shed[m]) + n
|
shed[m] = int(shed.get(m, 0)) + n
|
||||||
pouch[m] = 0
|
pouch[m] = 0
|
||||||
moved[m] = n
|
moved[m] = n
|
||||||
return moved
|
return moved
|
||||||
|
|
||||||
|
|
||||||
func available(material: String) -> int:
|
func available(material: String) -> int:
|
||||||
return int(shed[material]) + int(pouch[material])
|
return int(shed.get(material, 0)) + int(pouch.get(material, 0))
|
||||||
|
|
||||||
|
|
||||||
## What a cost still lacks (material -> amount short; empty when affordable).
|
## What a cost still lacks (material -> amount short; empty when affordable).
|
||||||
|
|
@ -91,10 +94,23 @@ func pay(cost: Dictionary) -> bool:
|
||||||
|
|
||||||
|
|
||||||
func to_dict() -> Dictionary:
|
func to_dict() -> Dictionary:
|
||||||
return {"shed": shed.duplicate(), "pouch": pouch.duplicate(), "pouch_capacity": pouch_capacity}
|
return {"shed": _filled(shed), "pouch": _filled(pouch), "pouch_capacity": pouch_capacity}
|
||||||
|
|
||||||
|
|
||||||
## Returns null for unknown materials, missing entries, negative amounts, or an overfull pouch.
|
## A copy with every material present (one missing from shed/pouch, e.g. because it was replaced
|
||||||
|
## elsewhere without every material present, defaults to 0): to_dict() always reads the same way
|
||||||
|
## whether or not the live dict happens to have every key, so it matches what from_dict() (and an
|
||||||
|
## old save that predates a new material) produces.
|
||||||
|
static func _filled(d: Dictionary) -> Dictionary:
|
||||||
|
var out := {}
|
||||||
|
for m in MATERIALS:
|
||||||
|
out[m] = int(d.get(m, 0))
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
## Returns null for unknown materials, negative amounts, or an overfull pouch. A material missing
|
||||||
|
## from shed/pouch (an older save from before it existed, e.g. Alien Goop) is treated as 0, not
|
||||||
|
## rejected, so new materials stay load-compatible with old saves.
|
||||||
static func from_dict(d: Variant) -> ResourceStore:
|
static func from_dict(d: Variant) -> ResourceStore:
|
||||||
if not d is Dictionary:
|
if not d is Dictionary:
|
||||||
return null
|
return null
|
||||||
|
|
@ -105,13 +121,17 @@ static func from_dict(d: Variant) -> ResourceStore:
|
||||||
r.pouch_capacity = int(dd["pouch_capacity"])
|
r.pouch_capacity = int(dd["pouch_capacity"])
|
||||||
for part in ["shed", "pouch"]:
|
for part in ["shed", "pouch"]:
|
||||||
var src: Dictionary = dd[part]
|
var src: Dictionary = dd[part]
|
||||||
if src.size() != MATERIALS.size():
|
for key in src:
|
||||||
return null
|
if not MATERIALS.has(String(key)):
|
||||||
for m in MATERIALS:
|
return null # unknown material
|
||||||
if not src.has(m) or int(src[m]) < 0:
|
|
||||||
return null
|
|
||||||
var into: Dictionary = r.shed if part == "shed" else r.pouch
|
var into: Dictionary = r.shed if part == "shed" else r.pouch
|
||||||
|
for m in MATERIALS:
|
||||||
|
if src.has(m):
|
||||||
|
if int(src[m]) < 0:
|
||||||
|
return null
|
||||||
into[m] = int(src[m])
|
into[m] = int(src[m])
|
||||||
|
else:
|
||||||
|
into[m] = 0
|
||||||
return r if r.pouch_capacity >= 1 and r.pouch_total() <= r.pouch_capacity else null
|
return r if r.pouch_capacity >= 1 and r.pouch_total() <= r.pouch_capacity else null
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,16 @@ const PILES := {
|
||||||
"front": Vector2(6.75, -16.25),
|
"front": Vector2(6.75, -16.25),
|
||||||
"label": Vector3(6.2, 3.2, -18.4),
|
"label": Vector3(6.2, 3.2, -18.4),
|
||||||
},
|
},
|
||||||
|
## No pile of its own yet (placeholder: it never shows props), but it needs a real front/label
|
||||||
|
## spot so a supply thief sent for it (once it's the shed's most-stocked material) has
|
||||||
|
## somewhere reachable to stand; the wood pile's spot is already proven walkable.
|
||||||
|
"alien_goop": {
|
||||||
|
"adopt": [],
|
||||||
|
"extra": [],
|
||||||
|
"per": 1,
|
||||||
|
"front": Vector2(2.6, -18.6),
|
||||||
|
"label": Vector3(4.2, 2.6, -18.3),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var campaign: CampaignController
|
var campaign: CampaignController
|
||||||
|
|
@ -114,13 +124,15 @@ static func props_for(material: String, amount: int, slot_count: int) -> int:
|
||||||
|
|
||||||
|
|
||||||
## Shows each pile for the shed's stock (after the navigation is built; then on every change).
|
## Shows each pile for the shed's stock (after the navigation is built; then on every change).
|
||||||
|
## Reads the shed with get(m, 0): a shed dict replaced elsewhere without every material present
|
||||||
|
## (tests, old saves) is treated as 0 for a pile not in it, rather than erroring.
|
||||||
func refresh() -> void:
|
func refresh() -> void:
|
||||||
var shed := campaign.state.resources.shed
|
var shed := campaign.state.resources.shed
|
||||||
for m: String in slots:
|
for m: String in slots:
|
||||||
var list: Array = slots[m]
|
var list: Array = slots[m]
|
||||||
var n := props_for(m, int(shed[m]), list.size())
|
var n := props_for(m, int(shed.get(m, 0)), list.size())
|
||||||
shown[m] = n
|
shown[m] = n
|
||||||
_last[m] = int(shed[m])
|
_last[m] = int(shed.get(m, 0))
|
||||||
for i in list.size():
|
for i in list.size():
|
||||||
var on := i < n
|
var on := i < n
|
||||||
(list[i] as Node3D).visible = on
|
(list[i] as Node3D).visible = on
|
||||||
|
|
@ -133,7 +145,7 @@ func _process(_delta: float) -> void:
|
||||||
return
|
return
|
||||||
var shed := campaign.state.resources.shed
|
var shed := campaign.state.resources.shed
|
||||||
for m: String in slots:
|
for m: String in slots:
|
||||||
if int(shed[m]) != int(_last.get(m, -1)):
|
if int(shed.get(m, 0)) != int(_last.get(m, -1)):
|
||||||
refresh()
|
refresh()
|
||||||
break
|
break
|
||||||
var near := player != null
|
var near := player != null
|
||||||
|
|
@ -142,4 +154,4 @@ func _process(_delta: float) -> void:
|
||||||
var at: Vector3 = PILES[m]["label"]
|
var at: Vector3 = PILES[m]["label"]
|
||||||
l.visible = near and Vector2(player.global_position.x - at.x, player.global_position.z - at.z).length() < LABEL_RANGE
|
l.visible = near and Vector2(player.global_position.x - at.x, player.global_position.z - at.z).length() < LABEL_RANGE
|
||||||
if l.visible:
|
if l.visible:
|
||||||
l.text = "%s %d" % [m.capitalize(), int(shed[m])]
|
l.text = "%s %d" % [m.capitalize(), int(shed.get(m, 0))]
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ func _day(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter, hud: PhaseHu
|
||||||
Input.action_release("interact")
|
Input.action_release("interact")
|
||||||
_step(sim, 1)
|
_step(sim, 1)
|
||||||
r.check(s.resources.pouch["wood"] == 2, "gathered 2 wood into the pouch")
|
r.check(s.resources.pouch["wood"] == 2, "gathered 2 wood into the pouch")
|
||||||
s.resources.shed = {"wood": 20, "scrap": 20, "straw": 20}
|
s.resources.shed = {"wood": 20, "scrap": 20, "straw": 20, "alien_goop": 0}
|
||||||
_start_structures = sim.structures.count()
|
_start_structures = sim.structures.count()
|
||||||
var fence := sim.structures.place("fence", 30.0, -18.5, 0)
|
var fence := sim.structures.place("fence", 30.0, -18.5, 0)
|
||||||
sim.structures.place("automated_defense", 38.0, -17.0, 0)
|
sim.structures.place("automated_defense", 38.0, -17.0, 0)
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,9 @@ extends RefCounted
|
||||||
## through JSON, and on the real farm (FarmSim stepped by hand): the gather points' layout,
|
## through JSON, and on the real farm (FarmSim stepped by hand): the gather points' layout,
|
||||||
## gathering by day only (charges, rooted, cancelled by letting go / a hit / fear, a full pouch,
|
## gathering by day only (charges, rooted, cancelled by letting go / a hit / fear, a full pouch,
|
||||||
## nightfall), the shed drop-off, overnight regrowth, retry restoring the morning's materials,
|
## nightfall), the shed drop-off, overnight regrowth, retry restoring the morning's materials,
|
||||||
## patching's straw cost, and buying the Straw Stuffing upgrade from the workbench's menu.
|
## patching's straw cost, buying the Straw Stuffing upgrade from the workbench's menu, and Alien
|
||||||
|
## Goop (#4): dropped only by killed Aliens (thieves) at a config-tunable rate, credited like a
|
||||||
|
## gathered material, stealable from the shed once it's the stock on top, and surviving retry.
|
||||||
|
|
||||||
const P := CampaignController.Phase
|
const P := CampaignController.Phase
|
||||||
const DT := 1.0 / 60.0
|
const DT := 1.0 / 60.0
|
||||||
|
|
@ -13,6 +15,7 @@ const DT := 1.0 / 60.0
|
||||||
func run(r: GameTestRunner) -> void:
|
func run(r: GameTestRunner) -> void:
|
||||||
_store(r)
|
_store(r)
|
||||||
_state(r)
|
_state(r)
|
||||||
|
_goop_persistence(r)
|
||||||
var farm := (load("res://game/scenes/farm.tscn") as PackedScene).instantiate() as Node3D
|
var farm := (load("res://game/scenes/farm.tscn") as PackedScene).instantiate() as Node3D
|
||||||
r.root.add_child(farm)
|
r.root.add_child(farm)
|
||||||
await r.process_frame
|
await r.process_frame
|
||||||
|
|
@ -26,6 +29,7 @@ func run(r: GameTestRunner) -> void:
|
||||||
_deposit_and_night(r, sim, player)
|
_deposit_and_night(r, sim, player)
|
||||||
_patch_cost(r, sim)
|
_patch_cost(r, sim)
|
||||||
_stuffing(r, sim, player)
|
_stuffing(r, sim, player)
|
||||||
|
_goop_drops(r, sim)
|
||||||
farm.queue_free()
|
farm.queue_free()
|
||||||
await r.process_frame
|
await r.process_frame
|
||||||
|
|
||||||
|
|
@ -66,18 +70,38 @@ func _store(r: GameTestRunner) -> void:
|
||||||
func _state(r: GameTestRunner) -> void:
|
func _state(r: GameTestRunner) -> void:
|
||||||
var cfg := (load("res://game/resources/game_config.tres") as GameConfig).duplicate() as GameConfig
|
var cfg := (load("res://game/resources/game_config.tres") as GameConfig).duplicate() as GameConfig
|
||||||
var s := FarmState.create(cfg)
|
var s := FarmState.create(cfg)
|
||||||
r.check(s.resources.shed == {"wood": cfg.start_wood, "scrap": cfg.start_scrap, "straw": cfg.start_straw}
|
r.check(s.resources.shed == {"wood": cfg.start_wood, "scrap": cfg.start_scrap, "straw": cfg.start_straw, "alien_goop": cfg.start_alien_goop}
|
||||||
and s.resources.pouch_capacity == cfg.pouch_capacity, "a new farm starts with the configured stock and pouch size")
|
and s.resources.pouch_capacity == cfg.pouch_capacity, "a new farm starts with the configured stock and pouch size (Alien Goop a 4th material, starting at 0)")
|
||||||
s.resources.add_to_pouch("scrap", 3)
|
s.resources.add_to_pouch("scrap", 3)
|
||||||
|
s.resources.add_to_pouch("alien_goop", 2)
|
||||||
s.gather_charges = {"Snag": 1, "Wreck": 0}
|
s.gather_charges = {"Snag": 1, "Wreck": 0}
|
||||||
s.upgrades = {"straw_stuffing": 1}
|
s.upgrades = {"straw_stuffing": 1}
|
||||||
var d := s.to_dict()
|
var d := s.to_dict()
|
||||||
var back := FarmState.from_dict(JSON.parse_string(JSON.stringify(d)))
|
var back := FarmState.from_dict(JSON.parse_string(JSON.stringify(d)))
|
||||||
r.check(back != null and back.to_dict() == d, "FarmState keeps materials, used gather points, and upgrades through JSON")
|
r.check(back != null and back.to_dict() == d, "FarmState keeps materials (including Alien Goop), used gather points, and upgrades through JSON")
|
||||||
d["gather_charges"] = {"Snag": -2}
|
d["gather_charges"] = {"Snag": -2}
|
||||||
r.check(FarmState.from_dict(d) == null, "FarmState rejects negative gather charges")
|
r.check(FarmState.from_dict(d) == null, "FarmState rejects negative gather charges")
|
||||||
|
|
||||||
|
|
||||||
|
## Alien Goop round-trips like the other materials: a retry discards what was gained since the
|
||||||
|
## morning (same mechanic _deposit_and_night checks for wood/scrap below), and the morning
|
||||||
|
## snapshot itself (what SaveGame writes) survives a JSON round-trip.
|
||||||
|
func _goop_persistence(r: GameTestRunner) -> void:
|
||||||
|
var cfg := (load("res://game/resources/game_config.tres") as GameConfig).duplicate() as GameConfig
|
||||||
|
var c := r.make_campaign(cfg)
|
||||||
|
var morning := c.state.to_dict()
|
||||||
|
c.begin_day()
|
||||||
|
c.state.resources.add_to_pouch("alien_goop", 5)
|
||||||
|
c.state.resources.shed["alien_goop"] = 3
|
||||||
|
c.advance_phase() # DAY -> DUSK
|
||||||
|
c.advance_phase() # DUSK -> NIGHT
|
||||||
|
c.retry_night()
|
||||||
|
r.check(c.state.phase == P.MORNING and c.state.resources.to_dict() == morning["resources"],
|
||||||
|
"a retry discards Alien Goop gained since the morning, same as the other materials")
|
||||||
|
var back := FarmState.from_dict(JSON.parse_string(JSON.stringify(morning)))
|
||||||
|
r.check(back != null and back.resources.shed.get("alien_goop", -1) == 0, "the morning snapshot (what's saved) round-trips Alien Goop through JSON")
|
||||||
|
|
||||||
|
|
||||||
func _layout(r: GameTestRunner, sim: FarmSim) -> void:
|
func _layout(r: GameTestRunner, sim: FarmSim) -> void:
|
||||||
var by_material := {}
|
var by_material := {}
|
||||||
var names := {}
|
var names := {}
|
||||||
|
|
@ -284,6 +308,58 @@ func _stuffing(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter) -> void
|
||||||
menu.close()
|
menu.close()
|
||||||
|
|
||||||
|
|
||||||
|
## Alien Goop (#4): dropped only by killed Aliens (thieves), at GameConfig's rate and quantity,
|
||||||
|
## credited like a gathered material (respecting the pouch's capacity), and stealable from the
|
||||||
|
## shed like any other material once it's the one on top.
|
||||||
|
func _goop_drops(r: GameTestRunner, sim: FarmSim) -> void:
|
||||||
|
var es := sim.enemies
|
||||||
|
var s := sim.campaign.state
|
||||||
|
var cfg := sim.config
|
||||||
|
var pouch_cap_before := s.resources.pouch_capacity
|
||||||
|
s.resources.pouch_capacity = 1000000 # room for every drop; isolates the chance roll from capacity
|
||||||
|
# Statistical: over many kills, the drop rate roughly matches the config chance (the drop
|
||||||
|
# roll uses a seeded RNG, so this is also reproducible run to run).
|
||||||
|
const N := 1000
|
||||||
|
var before := int(s.night_events.get("gathered_alien_goop", 0))
|
||||||
|
for i in N:
|
||||||
|
var h := es.spawn(EnemySystem.TYPE_THIEF, 12.0, -30.0, Vector2.UP)
|
||||||
|
es.apply_hit_handle(h, 99)
|
||||||
|
_step(sim, 1)
|
||||||
|
var gained := int(s.night_events.get("gathered_alien_goop", 0)) - before
|
||||||
|
var rate := float(gained) / float(N * cfg.alien_goop_drop_qty)
|
||||||
|
r.check(absf(rate - cfg.alien_goop_drop_chance) < 0.06,
|
||||||
|
"killing %d Aliens drops goop about %.0f%% of the time (got %.1f%%, %d units)" % [N, cfg.alien_goop_drop_chance * 100.0, rate * 100.0, gained])
|
||||||
|
# Type restriction: only thieves ("Alien") drop goop, not crows or fence breakers.
|
||||||
|
var before2 := int(s.night_events.get("gathered_alien_goop", 0))
|
||||||
|
for i in 50:
|
||||||
|
var hc := es.spawn(EnemySystem.TYPE_CROW, 12.0, -30.0, Vector2.UP)
|
||||||
|
es.apply_hit_handle(hc, 99)
|
||||||
|
_step(sim, 1)
|
||||||
|
var hb := es.spawn(EnemySystem.TYPE_BREAKER, 12.0, -30.0, Vector2.UP)
|
||||||
|
es.apply_hit_handle(hb, 99)
|
||||||
|
_step(sim, 1)
|
||||||
|
r.check(int(s.night_events.get("gathered_alien_goop", 0)) == before2, "only Aliens (thieves) drop goop, not crows or fence breakers")
|
||||||
|
# Deterministic: a guaranteed drop is credited like a gathered material, capped by pouch room.
|
||||||
|
cfg.alien_goop_drop_chance = 1.0
|
||||||
|
cfg.alien_goop_drop_qty = 3
|
||||||
|
s.resources.pouch_capacity = s.resources.pouch_total() + 2 # room for only 2 of the 3
|
||||||
|
var pouch_before := s.resources.pouch_total()
|
||||||
|
var h2 := es.spawn(EnemySystem.TYPE_THIEF, 12.0, -30.0, Vector2.UP)
|
||||||
|
es.apply_hit_handle(h2, 99)
|
||||||
|
_step(sim, 1)
|
||||||
|
r.check(s.resources.pouch_total() == pouch_before + 2, "a drop only adds what fits in the pouch (2 of 3, the pouch nearly full)")
|
||||||
|
cfg.alien_goop_drop_chance = 0.33
|
||||||
|
cfg.alien_goop_drop_qty = 1
|
||||||
|
s.resources.pouch_capacity = pouch_cap_before
|
||||||
|
# Stealable from the shed: once goop is the shed's most-stocked material, a supply claim
|
||||||
|
# takes it, and the shed's own pile wiring gives the thief somewhere real to stand.
|
||||||
|
s.resources.shed = {"wood": 0, "scrap": 0, "straw": 0, "alien_goop": 20}
|
||||||
|
var sack := sim.loot._claim_home(LootSystem.Category.SUPPLY)
|
||||||
|
r.check(sack > 0 and sim.loot.sack_material[sack] == "alien_goop" and sim.loot.home[sack] != Vector2.ZERO,
|
||||||
|
"a sack claimed at the shed takes goop when it's the most-stocked material, at a real spot")
|
||||||
|
s.resources.shed = {"wood": 0, "scrap": 0, "straw": 0, "alien_goop": 0}
|
||||||
|
|
||||||
|
|
||||||
func _node(it: Interactions, node_name: String) -> GatherNode:
|
func _node(it: Interactions, node_name: String) -> GatherNode:
|
||||||
for n in it.nodes:
|
for n in it.nodes:
|
||||||
if n.name == node_name:
|
if n.name == node_name:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue