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:
+3 -3
View File
@@ -33,10 +33,10 @@ func test_real_interact_picks_visible_ground_item_then_inventory_action_opens_li
assert_eq(pickup.kind, &"item_picked_up")
assert_eq(pickup.payload.item_id, &"consumable_bandage")
assert_eq(pickup.payload.quantity, 2)
# Achievements may refresh the journal after the pickup; the authoritative
# RunState event remains the HUD seam to verify.
# Assert the journal the player sees after the real interaction; no manual
# refresh may mask a later observer (such as achievements) overwriting it.
var hud := game.get_node("HUD") as GameHud
hud.refresh(state, [pickup], game.get_run_state())
await get_tree().process_frame
assert_string_contains(hud.event_log.get_parsed_text(), "Ramassé : Bandage x2.")
await _dispatch_key(KEY_I)