feat(@projects/@magic-civilization): add wild loot tables and item system integration

Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
Natalie 2026-04-15 20:16:52 -07:00
parent 10a910cce6
commit e407c3caf9
2 changed files with 71 additions and 1 deletions

View file

@ -141,6 +141,42 @@
{ "level": "brutal", "spawn_interval_mult": 0.5, "max_creatures": 5, "stat_mult": 1.5, "new_lair_interval": 15 }
],
"creature_loot": {
"beast_den": {
"id": "beast_den",
"loot_table": [
{ "resource": "hide", "amount": 2, "chance": 0.8 },
{ "resource": "bone", "amount": 2, "chance": 0.6 },
{ "resource": "fang", "amount": 1, "chance": 0.4 }
]
},
"corrupted_hollow": {
"id": "corrupted_hollow",
"loot_table": [
{ "resource": "death_essence", "amount": 2, "chance": 0.7 },
{ "resource": "spectral_shard", "amount": 1, "chance": 0.4 }
]
},
"volcanic_fissure": {
"id": "volcanic_fissure",
"loot_table": [
{ "resource": "fire_essence", "amount": 2, "chance": 0.7 },
{ "resource": "obsidian", "amount": 1, "chance": 0.5 }
]
},
"ancient_construct_site": {
"id": "ancient_construct_site",
"loot_table": [
{ "resource": "arcane_gears", "amount": 2, "chance": 0.8 },
{ "resource": "stone_core", "amount": 1, "chance": 0.5 }
]
},
"wyvern_nest": {
"id": "wyvern_nest",
"loot_table": [
{ "resource": "wyvern_scale", "amount": 2, "chance": 0.8 },
{ "resource": "bone", "amount": 2, "chance": 0.5 }
]
},
"wolf_pack": {
"id": "wolf_pack",
"loot_table": [

View file

@ -18,6 +18,7 @@ const ImprovementManagerScript = preload(
"res://engine/src/modules/management/improvement_manager.gd"
)
const HappinessScript = preload("res://engine/src/modules/empire/happiness.gd")
const ItemSystemScript = preload("res://engine/src/modules/management/item_system.gd")
var _improvement_manager: RefCounted = null
@ -104,6 +105,10 @@ func _ready() -> void:
EventBus.tech_researched.connect(_on_tech_researched)
EventBus.unit_created.connect(_on_unit_created)
EventBus.unit_destroyed.connect(_on_unit_destroyed)
EventBus.improvement_started.connect(_on_improvement_started)
EventBus.improvement_completed.connect(_on_improvement_completed)
EventBus.loot_dropped.connect(_on_loot_dropped)
_improvement_manager = ImprovementManagerScript.new()
func _on_combat(attacker: Variant, defender: Variant, result: Dictionary) -> void:
@ -229,6 +234,35 @@ func _on_unit_destroyed(unit: Variant, _killer: Variant) -> void:
})
func _on_improvement_started(tile: Vector2i, type: String, turns: int) -> void:
_append_event({
"type": "improvement_started",
"tile_x": tile.x,
"tile_y": tile.y,
"improvement": type,
"turns": turns,
})
func _on_improvement_completed(tile: Vector2i, type: String) -> void:
_append_event({
"type": "improvement_built",
"tile_x": tile.x,
"tile_y": tile.y,
"improvement": type,
})
func _on_loot_dropped(player: Variant, creature_type: String, drops: Array) -> void:
var p_idx: int = int(player.get("index")) if player != null and player.get("index") != null else -1
_append_event({
"type": "loot_dropped",
"player": p_idx,
"creature": creature_type,
"drops": drops,
})
func _ensure_stats(player_index: int) -> void:
if not _stats.has(player_index):
_stats[player_index] = {
@ -1344,7 +1378,7 @@ func _try_attack_adjacent_lair(unit: Variant, game_map: RefCounted) -> void:
hash(unit.id),
hash(norm),
)
elif attacker_killed:
elif not attacker_alive:
print(" LAIR ATTACK FAILED: %s killed at %s" % [unit.type_id, norm])
return