feat(item-system): Implement core item management, scoring, and decision-making logic

Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
autocommit 2026-04-15 21:05:36 -07:00
parent 19546af0ea
commit 81914d4f20

View file

@ -141,25 +141,30 @@ static func roll_fauna_drops(
if killer_player == null:
return
var fauna: Dictionary = _lookup_fauna(victim_species_id)
print(" [ItemSystem] roll_fauna_drops species=%s fauna_empty=%s" % [victim_species_id, fauna.is_empty()])
if fauna.is_empty():
return
var loot_table: Array = fauna.get("loot_table", [])
var seed: int = _mix(turn_seed, killer_id, victim_id)
var all_drops: Array = []
print(" [ItemSystem] loot_table size=%d seed=%d" % [loot_table.size(), seed])
if loot_table.size() > 0:
var roller: RefCounted = ClassDB.instantiate("GdLootRoller") as RefCounted
if roller != null:
var table_json: String = JSON.stringify(loot_table)
print(" [ItemSystem] table_json=%s" % table_json)
# Coerce `amount` to int — JSON.stringify turns Variant ints
# from Dictionary into floats ("2.0"), which Rust's serde u32
# parser rejects.
var sanitized: Array = []
for entry: Dictionary in loot_table:
sanitized.append({
"resource": str(entry.get("resource", "")),
"amount": int(entry.get("amount", 1)),
"chance": float(entry.get("chance", 0.0)),
})
var table_json: String = JSON.stringify(sanitized)
var drops: Array = roller.call("roll_loot_table", table_json, seed)
print(" [ItemSystem] rolled drops count=%d" % drops.size())
for drop: Dictionary in drops:
_apply_stockpile_drop(killer_player, drop)
all_drops.append(drop)
else:
print(" [ItemSystem] GdLootRoller unavailable, using fallback")
all_drops.append_array(_fallback_roll(loot_table, seed))
for drop: Dictionary in all_drops:
_apply_stockpile_drop(killer_player, drop)
@ -172,7 +177,6 @@ static func roll_fauna_drops(
for item_id: String in relics:
_apply_apex_relic(killer_player, item_id)
all_drops.append({"item": item_id, "amount": 1})
print(" [ItemSystem] total all_drops=%d" % all_drops.size())
if all_drops.size() > 0:
EventBus.loot_dropped.emit(killer_player, victim_species_id, all_drops)