diff --git a/src/editor/engine/BabylonScene.js b/src/editor/engine/BabylonScene.js index d6f7e0d..24b3605 100644 --- a/src/editor/engine/BabylonScene.js +++ b/src/editor/engine/BabylonScene.js @@ -6229,6 +6229,10 @@ export class BabylonScene { if (hit?.mesh && this.zombieManager) { this.zombieManager.damageByMesh(hit.mesh, hit.damage || 25); } + // Урон скриптовым NPC (киты-враги) → авто-floater над мобом (задача 40). + if (hit?.mesh && this.npcManager) { + try { this.npcManager.damageByMesh(hit.mesh, hit.damage || 25); } catch (e) {} + } if (this._onWeaponHit) { try { this._onWeaponHit(hit); } catch (e) {} } diff --git a/src/editor/engine/GameRuntime.js b/src/editor/engine/GameRuntime.js index 8290234..45c5ca1 100644 --- a/src/editor/engine/GameRuntime.js +++ b/src/editor/engine/GameRuntime.js @@ -1910,6 +1910,15 @@ export class GameRuntime { } catch (e) { /* ignore */ } return; } + if (cmd === 'fx.autoMobFloaters') { + try { + if (this.scene3d?.npcManager) { + this.scene3d.npcManager._autoFloater = payload?.enabled + ? { opts: payload?.opts || {} } : null; + } + } catch (e) { /* ignore */ } + return; + } // === Beam / Trail — лучи и следы (Фаза 5.2) === if (cmd === 'fx.create') { diff --git a/src/editor/engine/NpcManager.js b/src/editor/engine/NpcManager.js index d1a2506..b7e9ff7 100644 --- a/src/editor/engine/NpcManager.js +++ b/src/editor/engine/NpcManager.js @@ -292,10 +292,36 @@ export class NpcManager { damage(id, amount) { const npc = this.npcs.get(Number(id)); if (!npc || npc.dead) return; - npc.hp = Math.max(0, npc.hp - (Number(amount) || 0)); + const amt = Number(amount) || 0; + npc.hp = Math.max(0, npc.hp - amt); + // Авто-floater над мобом (задача 40 доп): game.fx.autoMobFloaters(true). + if (this._autoFloater && amt > 0 && this.scene3d?.floaters) { + try { + this.scene3d.floaters.spawn( + { x: npc.x, y: (npc.y || 0) + 2.2, z: npc.z }, amt, this._autoFloater.opts || {}); + } catch (e) { /* ignore */ } + } if (npc.hp <= 0) this._killNpc(npc); } + /** Нанести урон NPC по мешу-попаданию (бластер/оружие). Ищет NPC, чьи меши + * содержат hit-меш (или предка). Вызывает damage() → авто-floater. */ + damageByMesh(mesh, amount) { + if (!mesh) return false; + for (const npc of this.npcs.values()) { + if (npc.dead) continue; + const root = npc.data && npc.data.rootMesh; + if (!root) continue; + let m = mesh, hit = false; + for (let i = 0; i < 8 && m; i++) { + if (m === root) { hit = true; break; } + m = m.parent; + } + if (hit) { this.damage(npc.id, amount); return true; } + } + return false; + } + /** Удалить NPC по id (без эффекта смерти — просто убрать). */ removeNpc(id) { const npc = this.npcs.get(Number(id)); diff --git a/src/editor/engine/ScriptSandboxWorker.js b/src/editor/engine/ScriptSandboxWorker.js index d7498fb..c810d54 100644 --- a/src/editor/engine/ScriptSandboxWorker.js +++ b/src/editor/engine/ScriptSandboxWorker.js @@ -3455,6 +3455,13 @@ const game = { const pos = _normFxPoint(position); _send('fx.damageFloater', { position: pos, value, opts: opts || {} }); }, + /** + * Авто-floater'ы над мобами (NPC) при потере HP. Включил один раз — любой + * урон по NPC сам показывает облачко «-N». game.fx.autoMobFloaters(true). + */ + autoMobFloaters(enabled, opts) { + _send('fx.autoMobFloaters', { enabled: enabled !== false, opts: opts || {} }); + }, /** * Луч между двумя точками. opts: { from, to — {x,y,z} или ref * объекта (тогда луч следит за ним); color: '#hex', width }.