Stage 3: inventory, ground loot, and two loot visibilities
ci / verify (push) Successful in 48s

Four always-on-screen slots, items as data, and loot tables on enemies and
bosses. Health potions drop rarely from trash and always from the Warden;
the Warden also drops a Warden's Ration, one per living player, which does
nothing at all.

The ration is not filler. Player-instanced loot is a separate code path from
shared loot -- a distinct entity per owner, filtered per peer in the snapshot
encoder -- and the cheapest way to keep that path honest is to have something
in the game that exercises it on every boss kill.

Item actions ride the input frame rather than becoming new client messages.
InputFrame gained BTN_USE, BTN_DROP and a slot byte, which buys the packet-loss
redundancy, the replay guard on last_input_tick, ordering against movement on
the same tick, and a rate limit of one action per tick -- all of which a
separate RPC would have needed bolted back on. The cost is that anything in
the frame which must not repeat has to be edge-triggered, since frames are
resent and a starved server coasts on the last one it holds.

Instanced loot is enforced in NetCodec.encode_snapshot, beside the actor
interest radius: a peer is never told another player's copy exists. Hiding it
client-side would have been the same mistake as relying on fog to hide enemies.

Inventories live on the character and are written to the store on every
transaction, so a crash between "picked it up" and "wrote it down" cannot lose
or duplicate an item. Anything dropped becomes world-shared whatever it was
before, and a potion used at full health is refused rather than spent.

tools/diag_loot.tscn covers drop -> snapshot -> pick up -> persist -> use ->
drop plus both visibilities on the wire, for the same reason diag_progression
exists: bots are poor shots and almost never produce a drop. It asserts each
input frame was actually consumed, after an early version silently dropped its
first press and every later check passed for the wrong reason.

check.sh clean, 266 tests, SMOKE PASS, all three diagnostics green.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-04 21:16:15 +02:00
parent ded7bf96d5
commit 050b8251a7
50 changed files with 2159 additions and 125 deletions
+39
View File
@@ -171,3 +171,42 @@ func test_suggested_names_vary() -> void:
for _i in 40:
seen[Character.random_name(rng)] = true
assert_gt(seen.size(), 10, "a fixed suggestion would be worse than none")
## Inventories live on the character, which is what makes them survive a
## restart, a character swap and a walk into a dungeon.
func test_the_inventory_survives_a_save_and_reload() -> void:
var c := store.create_character(ACC, "Packrat")
var carried: Array[StringName] = [Items.HEALTH_POTION, Items.NONE, Items.WARDENS_RATION]
store.set_inventory(ACC, c.id, carried)
var reloaded := CharacterStore.new(store._path)
assert_true(reloaded.load_from_disk())
var got := reloaded.get_character(ACC, c.id)
assert_eq(got.inventory.size(), SimConfig.INVENTORY_SLOTS)
assert_eq(got.inventory[0], Items.HEALTH_POTION)
assert_eq(got.inventory[1], Items.NONE)
assert_eq(got.inventory[2], Items.WARDENS_RATION)
## A save file written by a build that had an item this one does not must still
## load -- as an empty slot, never as a different item.
func test_an_unknown_item_in_a_save_file_becomes_an_empty_slot() -> void:
var restored := Character.from_dict({
"id": "x", "name": "Old", "xp": 0,
"inventory": ["health_potion", "phlogiston"],
})
assert_eq(restored.inventory[0], Items.HEALTH_POTION)
assert_eq(restored.inventory[1], Items.NONE)
func test_a_character_from_before_inventories_existed_still_loads() -> void:
var restored := Character.from_dict({"id": "y", "name": "Legacy", "xp": 500})
assert_eq(restored.inventory.size(), SimConfig.INVENTORY_SLOTS)
assert_eq(restored.display_name, "Legacy")
func test_setting_an_inventory_on_a_missing_character_is_harmless() -> void:
var nothing: Array[StringName] = [Items.HEALTH_POTION]
store.set_inventory(ACC, "no-such-id", nothing)
assert_eq(store.characters_for(ACC).size(), 0)