Add alien_goop as a 4th ResourceStore material alongside wood/scrap/straw, dropped only by killed Aliens (TYPE_THIEF) at a config-tunable rate/quantity (GameConfig.alien_goop_drop_chance default 0.33, alien_goop_drop_qty default 1), credited straight into the pouch like a gathered material via a new enemy_removed hook in FarmSim (seeded RNG for reproducible trials). It's stealable from the shed through the existing most-stocked-material sack mechanic once it outranks the others (ShedStock gets a placeholder front/ label spot for it, reusing the wood pile's proven-walkable spot; no new art). ResourceStore.from_dict() now treats a shed/pouch entry missing a material as 0 instead of rejecting it (old saves predate Alien Goop), and to_dict() always fills in every material so round-trips are consistent regardless of how the live dict was built; every method summing across MATERIALS reads with get(m, 0) so a hand-built 3-key dict elsewhere doesn't error out. New checks in test_economy.gd: _goop_persistence (retry discards goop gained since the morning; the morning snapshot round-trips through JSON) and _goop_drops (1000-kill statistical drop-rate check against config, type restriction to Aliens only, pouch-capacity-respecting credit, and shed-theft eligibility). Updated _state()'s and test_cycle.gd's hardcoded 3-key shed dicts for the new 4th material. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
69 lines
2.7 KiB
GDScript
69 lines
2.7 KiB
GDScript
class_name GatherNode
|
|
extends Node3D
|
|
## A spot where the scarecrow gathers one material by day: holding interact for gather_time
|
|
## puts yield_amount into the pouch and uses one of max_charges. Its children are the props it
|
|
## is made of; they fade grey once it is used up. Used charges come back overnight
|
|
## (regen_per_night each, applied by Interactions). The farm state keeps only points below
|
|
## full, keyed by this node's name, so names must be unique among gather points.
|
|
|
|
const COLORS := {
|
|
"wood": Color(0.95, 0.68, 0.4),
|
|
"scrap": Color(0.72, 0.84, 0.95),
|
|
"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_range(1, 20) var max_charges: int = 2
|
|
@export_range(1, 20) var yield_amount: int = 2
|
|
@export_range(1, 20) var regen_per_night: int = 20
|
|
## How close the scarecrow's center has to be to this node's origin to gather.
|
|
@export var reach: float = 1.8
|
|
## Clip the scarecrow loops while gathering here.
|
|
@export var clip: StringName = &"PickUp"
|
|
|
|
var _faded := false
|
|
var _fade: StandardMaterial3D
|
|
var _label: Label3D
|
|
var _top: float = 1.5
|
|
|
|
|
|
func _ready() -> void:
|
|
_fade = StandardMaterial3D.new()
|
|
_fade.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
|
|
_fade.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
|
|
_fade.albedo_color = Color(0.45, 0.45, 0.45, 0.6)
|
|
for vi in find_children("*", "VisualInstance3D", true, false):
|
|
var box := (vi as VisualInstance3D).global_transform * (vi as VisualInstance3D).get_aabb()
|
|
_top = maxf(_top, box.end.y - global_position.y)
|
|
_label = Label3D.new()
|
|
_label.billboard = BaseMaterial3D.BILLBOARD_ENABLED
|
|
_label.no_depth_test = true
|
|
_label.shaded = false
|
|
_label.font_size = 40
|
|
_label.outline_size = 10
|
|
_label.pixel_size = 0.0075
|
|
_label.modulate = COLORS[material]
|
|
_label.position = Vector3(0.0, minf(_top, 4.0) + 0.5, 0.0)
|
|
_label.visible = false
|
|
add_child(_label)
|
|
|
|
|
|
## Top of the point's props (local), for popups.
|
|
func top() -> float:
|
|
return minf(_top, 4.0)
|
|
|
|
|
|
## Updates the faded look and the floating label (hidden when show is false).
|
|
func show_state(charges: int, show: bool, prompt: String) -> void:
|
|
var empty := charges <= 0
|
|
if empty != _faded:
|
|
_faded = empty
|
|
for mi in find_children("*", "MeshInstance3D", true, false):
|
|
(mi as MeshInstance3D).material_overlay = _fade if empty else null
|
|
_label.visible = show
|
|
if show:
|
|
var text := "%s %d/%d" % [material.capitalize(), charges, max_charges]
|
|
_label.text = text if prompt == "" else text + "\n" + prompt
|