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:
@@ -5,6 +5,11 @@ extends CanvasLayer
|
||||
const MARGIN := 24.0
|
||||
const BAR_W := 260.0
|
||||
const BAR_H := 16.0
|
||||
## Inventory slot box, and the gap between boxes.
|
||||
const SLOT := 46.0
|
||||
const SLOT_GAP := 8.0
|
||||
## How far above the bottom of the screen the inventory row sits.
|
||||
const SLOT_BOTTOM := 26.0
|
||||
|
||||
signal respawn_pressed
|
||||
|
||||
@@ -136,6 +141,8 @@ func _draw_hud() -> void:
|
||||
|
||||
_draw_cleared_countdown()
|
||||
_draw_roster()
|
||||
_draw_inventory()
|
||||
_draw_pickup_prompt()
|
||||
|
||||
if not client.my_alive:
|
||||
# Centred on the canvas, which is only correct because _canvas actually
|
||||
@@ -150,6 +157,64 @@ func _draw_hud() -> void:
|
||||
Color(1.0, 0.2, 0.25, 0.18 * _hit_flash))
|
||||
|
||||
|
||||
## Four slots, always on screen. Deliberately not a panel you open: an
|
||||
## inventory you have to stop and read is a menu, and a menu is a death in a
|
||||
## game where the floor is bullets. Everything drawn here comes from the
|
||||
## snapshot, so it is what the server says you have, never a local guess.
|
||||
func _draw_inventory() -> void:
|
||||
if client.my_inventory.is_empty():
|
||||
return
|
||||
var count := client.my_inventory.size()
|
||||
var total := float(count) * SLOT + float(count - 1) * SLOT_GAP
|
||||
var origin := Vector2((_canvas.size.x - total) * 0.5,
|
||||
_canvas.size.y - SLOT_BOTTOM - SLOT)
|
||||
var held := client.held_slot()
|
||||
for i in count:
|
||||
var at := origin + Vector2(float(i) * (SLOT + SLOT_GAP), 0.0)
|
||||
var item := Items.by_index(int(client.my_inventory[i]))
|
||||
var def := Items.get_def(item)
|
||||
var frame_col := Color(0.55, 0.6, 0.72, 0.75) if i == held \
|
||||
else Color(0.3, 0.33, 0.42, 0.6)
|
||||
_canvas.draw_rect(Rect2(at, Vector2(SLOT, SLOT)), Color(0.07, 0.08, 0.12, 0.72))
|
||||
_canvas.draw_rect(Rect2(at, Vector2(SLOT, SLOT)), frame_col, false, 1.5)
|
||||
# The slot number, because the key that uses it is the only thing the
|
||||
# player actually needs to know about a slot.
|
||||
_canvas.draw_string(ThemeDB.fallback_font, at + Vector2(4.0, 13.0),
|
||||
str(i + 1), HORIZONTAL_ALIGNMENT_LEFT, -1, 11,
|
||||
Color(0.5, 0.55, 0.68))
|
||||
if def == null:
|
||||
continue
|
||||
var icon := Art.item_icon(item)
|
||||
var size := icon.size * Art.SCALE
|
||||
_canvas.draw_texture_rect_region(Art.TILESET,
|
||||
Rect2(at + (Vector2(SLOT, SLOT) - size) * 0.5, size), icon)
|
||||
_canvas.draw_string(ThemeDB.fallback_font,
|
||||
Vector2(origin.x, origin.y + SLOT + 15.0),
|
||||
"1-%d use shift+1-%d drop E pick up" % [count, count],
|
||||
HORIZONTAL_ALIGNMENT_LEFT, -1, 11, Color(0.5, 0.55, 0.66))
|
||||
|
||||
|
||||
## What pressing interact right now would do. The server runs the same search
|
||||
## for itself and does not care what this concluded -- this is a label, not a
|
||||
## decision.
|
||||
func _draw_pickup_prompt() -> void:
|
||||
var near := client.loot_in_reach()
|
||||
if near.is_empty() or not client.my_alive:
|
||||
return
|
||||
var item := Items.by_index(int(near["item"]))
|
||||
var def := Items.get_def(item)
|
||||
if def == null:
|
||||
return
|
||||
var full := client.inventory_full()
|
||||
var text := "inventory full -- %s stays where it is" % def.display_name \
|
||||
if full else "E take %s" % def.display_name
|
||||
var tint := Color(0.85, 0.5, 0.45) if full else def.tint
|
||||
_canvas.draw_string(ThemeDB.fallback_font,
|
||||
Vector2(_canvas.size.x * 0.5 - 150.0,
|
||||
_canvas.size.y - SLOT_BOTTOM - SLOT - 22.0),
|
||||
text, HORIZONTAL_ALIGNMENT_CENTER, 300.0, 14, tint)
|
||||
|
||||
|
||||
## A thin bar under health: progress toward the next level, and the level
|
||||
## itself. Drawn from the server's numbers, never recomputed locally.
|
||||
func _draw_xp_bar(at: Vector2) -> void:
|
||||
|
||||
Reference in New Issue
Block a user