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:
@@ -99,6 +99,24 @@ const ENEMY_IDLE: Array[Rect2] = [
|
||||
]
|
||||
const BOSS_IDLE := Rect2(16, 428, 32, 36) # big demon
|
||||
|
||||
## ItemDef.visual -> atlas rect. Order matches Items.ORDER: health potion,
|
||||
## Warden's ration. Both come from the tileset's flask row -- there is no food
|
||||
## sprite in this set, so the ration is a gold flask standing in for one until
|
||||
## the art pass revisits it.
|
||||
const ITEM_ICONS: Array[Rect2] = [
|
||||
Rect2(288, 352, 16, 16), # small red flask -> health potion
|
||||
Rect2(336, 352, 16, 16), # small gold flask -> Warden's ration
|
||||
]
|
||||
|
||||
|
||||
## Icon for an item id, falling back to the first entry so an item added
|
||||
## without art draws as something rather than as nothing.
|
||||
static func item_icon(item: StringName) -> Rect2:
|
||||
var def := Items.get_def(item)
|
||||
if def == null:
|
||||
return ITEM_ICONS[0]
|
||||
return ITEM_ICONS[clampi(def.visual, 0, ITEM_ICONS.size() - 1)]
|
||||
|
||||
# --- Bullets ----------------------------------------------------------------
|
||||
# assets/local/bullets.png is composed by tools/build_local_assets.py: 8 frames
|
||||
# across, one row per SimConfig.KIND_*. The raw pack could not be used directly
|
||||
|
||||
@@ -58,6 +58,13 @@ func _process(_delta: float) -> void:
|
||||
_bound.shot_fired.connect(func() -> void: sfx.play(Art.SFX_SHOOT, -14.0))
|
||||
_bound.enemy_died.connect(func() -> void: sfx.play(Art.SFX_ENEMY_DEATH, -8.0))
|
||||
_bound.boss_died.connect(func() -> void: sfx.play(Art.SFX_BOSS_DEATH, -2.0))
|
||||
# Item feedback rides the same rule as every other sound here: it
|
||||
# plays because a server event arrived, never because the client
|
||||
# guessed a pickup succeeded.
|
||||
_bound.item_picked_up.connect(func(_i: StringName) -> void:
|
||||
sfx.play(Art.SFX_ENEMY_DEATH, -16.0))
|
||||
_bound.item_used.connect(func(_i: StringName) -> void:
|
||||
sfx.play(Art.SFX_SHOOT, -10.0))
|
||||
_bound.characters_changed.connect(_refresh_characters)
|
||||
_bound.select_failed.connect(func(why: String) -> void: characters.set_status(why))
|
||||
_refresh_characters()
|
||||
|
||||
@@ -56,6 +56,9 @@ func _draw() -> void:
|
||||
_draw_terrain()
|
||||
if client.instance_kind == Protocol.InstanceKind.LOBBY:
|
||||
_draw_portal()
|
||||
for l in client.ground_loot():
|
||||
if _visible(l["pos"]):
|
||||
_draw_loot(l)
|
||||
for e in client.enemies():
|
||||
if _visible(e["pos"]):
|
||||
_draw_enemy(e)
|
||||
@@ -80,6 +83,9 @@ func _draw_debug() -> void:
|
||||
var b := client.boss_state()
|
||||
if not b.is_empty() and client.boss_def != null:
|
||||
DebugDraw.draw_boss(self, b["pos"], client.boss_def.radius, Rect2())
|
||||
for l in client.ground_loot():
|
||||
draw_arc(l["pos"], SimConfig.LOOT_PICKUP_RADIUS, 0.0, TAU, 24,
|
||||
Color(1.0, 0.9, 0.4, 0.5), 1.0)
|
||||
for p in client.remote_players():
|
||||
DebugDraw.draw_player(self, p["pos"], p["aim"])
|
||||
DebugDraw.draw_player(self, client.predicted_pos, client.aim)
|
||||
@@ -172,6 +178,24 @@ func _draw_portal() -> void:
|
||||
Color(COL_PORTAL, 0.25 + 0.25 * pulse))
|
||||
|
||||
|
||||
## An item on the floor. The server has already decided this player may see it
|
||||
## -- player-instanced loot belonging to someone else never reaches the client
|
||||
## at all -- so there is nothing to filter here beyond the fog.
|
||||
func _draw_loot(l: Dictionary) -> void:
|
||||
var item := Items.by_index(int(l["item"]))
|
||||
var def := Items.get_def(item)
|
||||
if def == null:
|
||||
return
|
||||
var pos: Vector2 = l["pos"]
|
||||
# A slow bob and a glow ring. Loot has to read as "pick me up" from across a
|
||||
# room full of bullets, and a static 16px sprite on a busy floor does not.
|
||||
var t := float(Time.get_ticks_msec()) * 0.004 + float(int(l["id"])) * 0.7
|
||||
var pulse := 0.5 + 0.5 * sin(t)
|
||||
draw_circle(pos, 11.0 + 2.0 * pulse, Color(def.tint, 0.13 + 0.10 * pulse))
|
||||
_draw_sprite(Art.TILESET, Art.item_icon(item),
|
||||
pos + Vector2(0.0, -3.0 * pulse))
|
||||
|
||||
|
||||
func _draw_enemy(e: Dictionary) -> void:
|
||||
var visual := clampi(int(e["visual"]), 0, Art.ENEMY_IDLE.size() - 1)
|
||||
var first: Rect2 = Art.ENEMY_IDLE[visual]
|
||||
|
||||
Reference in New Issue
Block a user