fix: distinguish dropped and collected enemy loot

This commit is contained in:
goose
2026-10-09 10:34:12 -04:00
parent 0090753675
commit 0d8ba84cf2
4 changed files with 64 additions and 37 deletions
+16 -14
View File
@@ -19,34 +19,36 @@ func test_real_game_resolves_damage_and_death_before_a3_feedback_and_journals_st
observed.append(event)
)
var gold_before_kill := game.get_run_state().gold
game.submit_test_action(Vector2i.RIGHT)
assert_false(state.enemies.has(&"goblin")) # domain result is synchronous
var recent := game.get_run_state().recent_events(8).filter(func(event: GameEvent) -> bool: return event.kind in [&"attack_started", &"attack_hit", &"damage_dealt", &"actor_died", &"xp_granted", &"loot_dropped"])
assert_eq(recent.map(func(event: GameEvent) -> StringName: return event.kind), [&"attack_started", &"attack_hit", &"damage_dealt", &"actor_died", &"xp_granted", &"loot_dropped"])
assert_eq(recent[2].payload.damage, 3)
assert_true(state.floor_state.ground_items.has(enemy.cell))
if state.floor_state.ground_items.has(enemy.cell):
assert_false(state.floor_state.ground_items[enemy.cell].is_empty())
assert_true(state.floor_state.ground_items[enemy.cell][0] is ItemInstance)
var loot_event: GameEvent = recent.filter(func(event: GameEvent) -> bool: return event.kind == &"loot_dropped")[0]
assert_true(loot_event.payload.has("items"))
assert_true(loot_event.payload.has("gold"))
# The deterministic demo-run seed yields a bandage and 26 gold here. Read the
# payload first so the test proves this literal French oracle describes real loot.
var expected_quantities := {&"consumable_bandage": 1}
for item: Dictionary in loot_event.payload.items:
assert_true(expected_quantities.has(StringName(item.item_id)))
assert_eq(int(item.quantity), int(expected_quantities[StringName(item.item_id)]))
# Each item announced by the kill is an actual ItemInstance at the corpse,
# whereas gold bypasses the ground and is immediately added to RunState.
assert_true(state.floor_state.ground_items.has(enemy.cell))
var ground_items: Array = state.floor_state.ground_items.get(enemy.cell, [])
for item_data: Dictionary in loot_event.payload.items:
var matching_items := ground_items.filter(func(item: Variant) -> bool:
return item is ItemInstance and item.definition.id == StringName(item_data.item_id) and item.quantity == int(item_data.quantity)
)
assert_false(matching_items.is_empty(), "Loot payload item must exist as an ItemInstance on the ground")
assert_eq(game.get_run_state().gold, gold_before_kill + int(loot_event.payload.gold), "Enemy gold must be collected immediately")
assert_eq(int(loot_event.payload.gold), 26)
await _wait_for_feedback(observed)
assert_eq(observed.map(func(event: GameEvent) -> StringName: return event.kind), [&"attack_started", &"attack_hit", &"damage_dealt", &"actor_died", &"xp_granted", &"loot_dropped"])
# This is the live journal produced by the normal combat flow. Do not manually
# refresh it: achievement observation must not erase the player's loot detail.
await get_tree().process_frame
var hud := game.get_node("HUD") as GameHud
# Achievement entries can refresh the live journal after combat. Re-render the
# actual loot event to isolate the real HUD localization seam.
hud.refresh(state, [loot_event], game.get_run_state())
var journal_text := hud.event_log.get_parsed_text()
assert_string_contains(journal_text, "Butin au sol : Bandage x1, 26 or.")
assert_string_contains(journal_text, "Butin — au sol : Bandage x1 ; or récupéré : 26.")
assert_eq(journal_text.find("consumable_bandage"), -1)
func _wait_for_feedback(observed: Array[GameEvent]) -> void: