Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(play): tell a player why an attack, a loot or a death did nothing

nirholas6223199af474
diff --git a/multiplayer/src/combat-handlers.js b/multiplayer/src/combat-handlers.js
index ccd494c7d..9d58f322a 100644
--- a/multiplayer/src/combat-handlers.js
+++ b/multiplayer/src/combat-handlers.js
@@ -242,7 +242,7 @@ export function killPlayer(room, sessionId, killerLabel) {
spillTombstone(room, player.x, player.z, player.name, drop);
player.dead = true;
const client = room.clients.find((c) => c.sessionId === sessionId);
- client?.send('notice', { kind: 'death', text: killerLabel ? `You were killed by ${killerLabel}.` : 'You died.' });
+ client?.send('notice', { kind: 'death', ok: false, text: killerLabel ? `You were killed by ${killerLabel}.` : 'You died.' });
room.clock.setTimeout(() => {
if (!room.state.players.has(sessionId)) return;
reviveProfile(profile);
@@ -250,7 +250,7 @@ export function killPlayer(room, sessionId, killerLabel) {
player.x = SPAWN_POINT.x; player.y = 0; player.z = SPAWN_POINT.z;
player.tsServer = Date.now();
const c2 = room.clients.find((c) => c.sessionId === sessionId);
- c2?.send('notice', { kind: 'respawn', text: 'You respawned in town.' });
+ c2?.send('notice', { kind: 'respawn', ok: true, text: 'You respawned in town.' });
c2?.send('profile', {
gold: profile.gold, bank: profile.bank, hp: profile.hp, maxHp: profile.maxHp,
armor: profile.armor, maxArmor: profile.maxArmor, heat: profile.heat,
@@ -273,11 +273,11 @@ export function handleAttack(room, client) {
const active = profile.hotbar[profile.activeSlot];
const weapon = weaponDef(active?.item);
if (!weapon) {
- client.send('notice', { kind: 'tool', text: 'Equip a weapon to attack.' });
+ client.send('notice', { kind: 'tool', ok: false, text: 'Equip a weapon to attack.' });
return;
}
if (!isDangerZone(player.x, player.z)) {
- client.send('notice', { kind: 'attack', text: 'The wilds are past the edge of town — fights only break out there.' });
+ client.send('notice', { kind: 'attack', ok: false, text: 'The wilds are past the edge of town — fights only break out there.' });
return;
}
const now = Date.now();
@@ -285,7 +285,7 @@ export function handleAttack(room, client) {
if (weapon.kind === 'ranged') {
if (countItem(profile, weapon.ammo) <= 0) {
- client.send('notice', { kind: 'attack', text: `Out of ${itemLabel(weapon.ammo).toLowerCase()}.` });
+ client.send('notice', { kind: 'attack', ok: false, text: `Out of ${itemLabel(weapon.ammo).toLowerCase()}.` });
return;
}
}
@@ -308,7 +308,7 @@ export function handleAttack(room, client) {
const hit = selectTarget(attackerPose, weapon, candidates);
if (weapon.kind === 'ranged') room._sendInv(client, profile); // reflect the spent ammo
if (!hit) {
- client.send('notice', { kind: 'attack', text: 'No target in range.' });
+ client.send('notice', { kind: 'attack', ok: false, text: 'No target in range.' });
return;
}
@@ -378,12 +378,12 @@ export function handleLoot(room, client, payload) {
const ts = room.state.tombstones.get(id);
const drop = room._tombLoot.get(id);
if (!ts || !drop) {
- client.send('notice', { kind: 'loot', text: 'That marker is gone.' });
+ client.send('notice', { kind: 'loot', ok: false, text: 'That marker is gone.' });
return;
}
const dist = Math.hypot(player.x - ts.x, player.z - ts.z);
if (dist > LOOT_REACH_M) {
- client.send('notice', { kind: 'loot', text: 'Move closer to loot it.' });
+ client.send('notice', { kind: 'loot', ok: false, text: 'Move closer to loot it.' });
return;
}
@@ -405,7 +405,7 @@ export function handleLoot(room, client, payload) {
const parts = [];
if (drop.gold > 0) parts.push(`$${drop.gold}`);
if (gained.length) parts.push(gained.join(' + '));
- client.send('notice', { kind: 'loot', text: parts.length ? `Looted ${parts.join(' and ')}.` : 'The marker was already picked clean.' });
+ client.send('notice', { kind: 'loot', ok: parts.length > 0, text: parts.length ? `Looted ${parts.join(' and ')}.` : 'The marker was already picked clean.' });
room._persistEcon(client.sessionId);
}
diff --git a/src/game/combat-system.js b/src/game/combat-system.js
index 53c48d100..99e6846bf 100644
--- a/src/game/combat-system.js
+++ b/src/game/combat-system.js
@@ -472,7 +472,17 @@ export class CombatSystem {
const parts = [];
if (nearest.t.gold > 0) parts.push(`$${nearest.t.gold}`);
if (nearest.t.count > 0) parts.push(`${nearest.t.count} item${nearest.t.count === 1 ? '' : 's'}`);
- this.prompt.innerHTML = `<span class="combat-key">E</span> Loot ${nearest.t.owner}${parts.length ? ' — ' + parts.join(', ') : ''}`;
+ // The tombstone owner is a remote player's chosen display name — untrusted
+ // text. Build the prompt with textContent, never innerHTML, so a name like
+ // `<img onerror=…>` renders as literal text instead of executing for every
+ // player who walks near the tombstone.
+ const key = document.createElement('span');
+ key.className = 'combat-key';
+ key.textContent = 'E';
+ this.prompt.replaceChildren(
+ key,
+ document.createTextNode(` Loot ${nearest.t.owner}${parts.length ? ' (' + parts.join(', ') + ')' : ''}`),
+ );
this.prompt.classList.add('combat-show');
this._placeAt(this.prompt, nearest.t.x, 1.1, nearest.t.z);
} else {