fix(item-system): 🐛 Correct DataLoader node lookups and add debug logging for fauna drops to ensure proper item data handling and gameplay stability
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
parent
2d356ad8b7
commit
1a05d0b47f
1 changed files with 15 additions and 3 deletions
|
|
@ -17,9 +17,15 @@ static var _test_items_json: String = ""
|
|||
|
||||
|
||||
static func _get_data_loader() -> Node:
|
||||
if Engine.has_singleton("DataLoader"):
|
||||
return Engine.get_singleton("DataLoader")
|
||||
return null
|
||||
# DataLoader is a script autoload (not an engine singleton), so it's
|
||||
# registered as a node at /root/DataLoader and NOT via Engine.get_singleton.
|
||||
var tree: SceneTree = Engine.get_main_loop() as SceneTree
|
||||
if tree == null:
|
||||
return null
|
||||
var root: Node = tree.root
|
||||
if root == null:
|
||||
return null
|
||||
return root.get_node_or_null("DataLoader")
|
||||
|
||||
|
||||
static func _gd_items() -> RefCounted:
|
||||
|
|
@ -135,20 +141,25 @@ 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)
|
||||
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)
|
||||
|
|
@ -161,6 +172,7 @@ 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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue