fix(g20): _npcCmd ждёт npc_lua_ префикс + sb.api.setNpcLocalRef
_npcCmd проверял только индекс 'npc:_local_' (для JS-воркера), ref от Lua-shim 'npc_lua_0' пропускался — отложенные setLabel/damage терялись. Также: проверка sb.api?._localToRealNpc была false после рефакторинга (перенёс в local closure). Замена на sb.api?.setNpcLocalRef — публичный метод. Убрал debug-логи.
This commit is contained in:
parent
65de311d59
commit
56c35273ef
@ -326,10 +326,6 @@ export class GameRuntime {
|
||||
}
|
||||
} catch (_) {}
|
||||
} else {
|
||||
if (cmd === 'npc.spawn' || cmd === 'npc.damage' || cmd === 'scene.setLabel' || cmd === 'scene.clearLabel') {
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn('[Lua onCommand]', cmd, JSON.stringify(payload).slice(0, 200));
|
||||
}
|
||||
this._handleCommand(null, cmd, payload);
|
||||
}
|
||||
});
|
||||
@ -1497,7 +1493,8 @@ export class GameRuntime {
|
||||
const nid = this._resolveNpcId(ref);
|
||||
if (nid != null) { fn(nid); return; }
|
||||
// ещё не резолвится — откладываем (только для локальных ref NPC)
|
||||
if (typeof ref === 'string' && ref.indexOf('npc:_local_') === 0) {
|
||||
if (typeof ref === 'string'
|
||||
&& (ref.indexOf('npc:_local_') === 0 || ref.startsWith('npc_lua_'))) {
|
||||
if (!this._pendingNpcCmds) this._pendingNpcCmds = new Map();
|
||||
if (!this._pendingNpcCmds.has(ref)) this._pendingNpcCmds.set(ref, []);
|
||||
this._pendingNpcCmds.get(ref).push(fn);
|
||||
@ -2156,8 +2153,8 @@ export class GameRuntime {
|
||||
// Также сообщаем Lua-sandbox-ам маппинг, чтобы
|
||||
// npc.onDeath по локальному ref находил npcId.
|
||||
for (const sb of this.sandboxes) {
|
||||
if (sb.api?._localToRealNpc) {
|
||||
try { sb.api.setNpcLocalRef?.(payload.ref, 'npc:' + npcId); } catch (_) {}
|
||||
if (sb.api?.setNpcLocalRef) {
|
||||
try { sb.api.setNpcLocalRef(payload.ref, 'npc:' + npcId); } catch (_) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user