BlueGit

timfa questward

Files

questward / shared / definitions / mobs.js

mobs.js

mobs.js 20.4 KiB Download Raw
1import { spriteImageName } from "./tileSprites.js";
2import { centralExchangeStaffCount } from "../market/exchange.js";
3import { LeatherItemId } from "./leatherItems.js";
4import { CraftingItemId } from "./craftingItems.js";
5import { RangedItemId } from "./rangedItems.js";
6import { ArmourItemId } from "./armourItems.js";
7import { WoodItemId } from "./woodItems.js";
8import { ItemId } from "./items.js";
9import { spellDefinition } from "./spells.js";
10import { ClothTier } from "./materialTiers.js";
11import { ClothItemId } from "./clothItems.js";
12
13export const MobId = Object.freeze({
14 deer: "deer",
15 pigeon: "pigeon",
16 rat: "rat",
17 chicken: "chicken",
18 sheep: "sheep",
19 cashmereGoat: "cashmere-goat",
20 humanoid: "humanoid",
21 /** Humanoid guards that respond to bounty kills within wander range. */
22 townGuard: "town-guard",
23 /** Editor/spawner identity for Central Exchange staff (always humanoid bodies). */
24 centralExchange: "central-exchange",
25 /** Temporary Shade summon (spell). */
26 shade: "shade",
27 /** Elemental sprite — random element on spawn, drops essence, emits light. */
28 sprite: "sprite",
29 /** Fairy — drops fairy silk fibre on death. */
30 fairy: "fairy"
31});
32
33/** @typedef {{ itemId: number, chance: number, quantity?: number, quantityMin?: number, quantityMax?: number }} MobDrop */
34/** @typedef {{ isPlayer: boolean, text: string }} DialogueLine */
35/** @typedef {{ trigger: string, text: string, available?: (ctx: object) => boolean }} DialogueResponse */
36
37/**
38 * Target mob content schema (rendering fields stay alongside gameplay fields for now).
39 * - displayName: shown name
40 * - health / maxHealth: hit points
41 * - attackSkill: one skill level for hit chance and damage
42 * - drops: { itemId, chance } roll on death
43 * - sells: default item IDs for shop stock (overridable per spawner)
44 * - dialogue: branching trees with triggers, lines, responses, and action hooks (later)
45 * - usePlayerBody: draw male/female character body instead of a mob sprite
46 */
47export const MOB_DEFINITIONS = Object.freeze({
48 [MobId.deer]: Object.freeze({
49 mobTypeId: MobId.deer,
50 key: "deer",
51 assetFolder: "mobs",
52 displayName: "Deer",
53 health: 8,
54 maxHealth: 8,
55 attackSkill: 2,
56 attackCooldownMs: 1000,
57 drops: Object.freeze([
58 { itemId: LeatherItemId.softLeather, chance: 1 },
59 { itemId: CraftingItemId.rawMeat, chance: 1 }
60 ]),
61 sells: Object.freeze([]),
62 dialogue: Object.freeze([]),
63 persistent: false,
64 flying: false,
65 freeFlight: false,
66 ambient: false,
67 talkable: false,
68 untargetable: false,
69 aggressive: false,
70 gait: "walk",
71 sex: "male",
72 frames: 1,
73 framesPerRow: 1,
74 animationSpeed: 0
75 }),
76 [MobId.pigeon]: Object.freeze({
77 mobTypeId: MobId.pigeon,
78 key: "pigeon",
79 assetFolder: "pigeons",
80 displayName: "Pigeon",
81 health: 1,
82 maxHealth: 1,
83 canFight: false,
84 drops: Object.freeze([]),
85 sells: Object.freeze([]),
86 dialogue: Object.freeze([]),
87 persistent: false,
88 flying: true,
89 freeFlight: true,
90 ambient: false,
91 talkable: false,
92 untargetable: true,
93 aggressive: false,
94 gait: "walk",
95 sex: "male",
96 frames: 2,
97 framesPerRow: 2,
98 animationSpeed: 0.18,
99 defaultState: "pigeon-flying",
100 flightSpeedTilesPerSec: 2.5
101 }),
102 [MobId.rat]: Object.freeze({
103 mobTypeId: MobId.rat,
104 key: "rat",
105 assetFolder: "mobs",
106 displayName: "Rat",
107 health: 12,
108 maxHealth: 12,
109 attackSkill: 3,
110 attackCooldownMs: 900,
111 drops: Object.freeze([]),
112 sells: Object.freeze([]),
113 dialogue: Object.freeze([]),
114 persistent: false,
115 flying: false,
116 freeFlight: false,
117 ambient: false,
118 talkable: false,
119 untargetable: false,
120 /** Auto-engage nearby players when in range with line of sight. */
121 aggressive: true,
122 aggroRangeTiles: 5,
123 elementAffinities: Object.freeze({ fire: "weak" }),
124 gait: "walk",
125 sex: "male",
126 frames: 1,
127 framesPerRow: 1,
128 animationSpeed: 0
129 }),
130 [MobId.chicken]: Object.freeze({
131 mobTypeId: MobId.chicken,
132 key: "chicken",
133 assetFolder: "mobs",
134 displayName: "Chicken",
135 health: 5,
136 maxHealth: 5,
137 attackSkill: 1,
138 attackCooldownMs: 1200,
139 drops: Object.freeze([
140 { itemId: RangedItemId.feather, chance: 1, quantityMin: 1, quantityMax: 3 },
141 { itemId: ItemId.egg, chance: 0.2 }
142 ]),
143 sells: Object.freeze([]),
144 dialogue: Object.freeze([]),
145 persistent: false,
146 flying: false,
147 freeFlight: false,
148 ambient: false,
149 talkable: false,
150 untargetable: false,
151 aggressive: false,
152 gait: "walk",
153 sex: "female",
154 frames: 1,
155 framesPerRow: 1,
156 animationSpeed: 0
157 }),
158 [MobId.sheep]: Object.freeze({
159 mobTypeId: MobId.sheep,
160 key: "sheep",
161 assetFolder: "mobs",
162 displayName: "Sheep",
163 health: 8,
164 maxHealth: 8,
165 attackSkill: 1,
166 attackCooldownMs: 1200,
167 drops: Object.freeze([
168 { itemId: LeatherItemId.softLeather, chance: 0.5 },
169 { itemId: CraftingItemId.rawMutton, chance: 1 }
170 ]),
171 sells: Object.freeze([]),
172 dialogue: Object.freeze([]),
173 persistent: false,
174 flying: false,
175 freeFlight: false,
176 ambient: false,
177 talkable: false,
178 untargetable: false,
179 aggressive: false,
180 gait: "walk",
181 sex: "female",
182 frames: 1,
183 framesPerRow: 1,
184 animationSpeed: 0,
185 defaultState: "fleece",
186 shearable: Object.freeze({
187 clothTier: ClothTier.wool,
188 fleeceState: "fleece",
189 shornState: "shorn"
190 })
191 }),
192 [MobId.cashmereGoat]: Object.freeze({
193 mobTypeId: MobId.cashmereGoat,
194 key: "cashmere-goat",
195 assetFolder: "mobs",
196 displayName: "Goat",
197 health: 10,
198 maxHealth: 10,
199 attackSkill: 2,
200 attackCooldownMs: 1100,
201 drops: Object.freeze([
202 { itemId: LeatherItemId.softLeather, chance: 0.6 },
203 { itemId: CraftingItemId.rawGoat, chance: 1 }
204 ]),
205 sells: Object.freeze([]),
206 dialogue: Object.freeze([]),
207 persistent: false,
208 flying: false,
209 freeFlight: false,
210 ambient: false,
211 talkable: false,
212 untargetable: false,
213 aggressive: false,
214 gait: "walk",
215 sex: "female",
216 frames: 1,
217 framesPerRow: 1,
218 animationSpeed: 0,
219 defaultState: "fleece",
220 shearable: Object.freeze({
221 clothTier: ClothTier.cashmere,
222 fleeceState: "fleece",
223 shornState: "shorn"
224 })
225 }),
226 [MobId.shade]: Object.freeze({
227 mobTypeId: MobId.shade,
228 key: "shade",
229 assetFolder: "mobs",
230 displayName: "Shade",
231 health: 10,
232 maxHealth: 10,
233 maxHealthFromLevel: "levelPlus10",
234 attackSkill: 5,
235 attackCooldownMs: 900,
236 drops: Object.freeze([]),
237 sells: Object.freeze([]),
238 dialogue: Object.freeze([]),
239 persistent: false,
240 flying: false,
241 freeFlight: false,
242 ambient: false,
243 talkable: false,
244 untargetable: false,
245 aggressive: false,
246 /** Reuse rat art until a dedicated shade sprite exists. */
247 spriteKey: "rat",
248 gait: "walk",
249 sex: "male",
250 frames: 1,
251 framesPerRow: 1,
252 animationSpeed: 0
253 }),
254 [MobId.sprite]: Object.freeze({
255 mobTypeId: MobId.sprite,
256 key: "sprite",
257 assetFolder: "mobs",
258 displayName: "Sprite",
259 health: 35,
260 maxHealth: 35,
261 maxHealthFromLevel: "levelPlus10",
262 attackSkill: 25,
263 attackCooldownMs: 1100,
264 drops: Object.freeze([]),
265 /** Essence drop is resolved from the creature's chosen element on death. */
266 essenceDropChance: 1,
267 sells: Object.freeze([]),
268 dialogue: Object.freeze([]),
269 persistent: false,
270 flying: false,
271 freeFlight: false,
272 ambient: false,
273 talkable: false,
274 untargetable: false,
275 aggressive: true,
276 aggroRangeTiles: 6,
277 preferSpellAttack: true,
278 lightRadiusTiles: 2,
279 randomElementOnSpawn: true,
280 bloomBody: true,
281 gait: "walk",
282 sex: "male",
283 frames: 2,
284 framesPerRow: 2,
285 animationSpeed: 0.5
286 }),
287 [MobId.fairy]: Object.freeze({
288 mobTypeId: MobId.fairy,
289 key: "fairy",
290 assetFolder: "mobs",
291 displayName: "Fairy",
292 health: 40,
293 maxHealth: 40,
294 maxHealthFromLevel: "levelPlus10",
295 attackSkill: 55,
296 attackCooldownMs: 1000,
297 drops: Object.freeze([
298 { itemId: ClothItemId.fairySilk, chance: 0.7 }
299 ]),
300 sells: Object.freeze([]),
301 dialogue: Object.freeze([]),
302 persistent: false,
303 flying: true,
304 freeFlight: false,
305 ambient: false,
306 talkable: false,
307 untargetable: false,
308 aggressive: true,
309 aggroRangeTiles: 5,
310 /** Prefer sprite-style elemental bolts over melee. */
311 preferSpellAttack: true,
312 /** Cast a random-element sprite bolt each attack (no fixed spawn element). */
313 randomElementSpell: true,
314 /** On hit, flee until at least this many tiles from the hit source (then stop until hit again). */
315 fleeOnHitTiles: 2,
316 /** Dimmer than elemental sprites (radius 2). */
317 lightRadiusTiles: 1,
318 bloomBody: true,
319 /** Shirt/skirt/hair use dual-channel body tints rolled on spawn. */
320 dualChannelAppearance: true,
321 gait: "walk",
322 sex: "female",
323 frames: 2,
324 framesPerRow: 2,
325 animationSpeed: 0.45,
326 defaultState: "fairy"
327 }),
328 [MobId.humanoid]: Object.freeze({
329 mobTypeId: MobId.humanoid,
330 key: "humanoid",
331 assetFolder: "characters",
332 displayName: "Humanoid",
333 health: 10,
334 maxHealth: 10,
335 /** HP = spawner level + 10 (same floor as a starting player's Health). */
336 maxHealthFromLevel: "levelPlus10",
337 drops: Object.freeze([]),
338 sells: Object.freeze([]),
339 dialogue: Object.freeze([]),
340 persistent: false,
341 flying: false,
342 freeFlight: false,
343 ambient: false,
344 talkable: true,
345 untargetable: false,
346 aggressive: false,
347 usePlayerBody: true,
348 gait: "walk",
349 sex: "male",
350 frames: 1,
351 framesPerRow: 1,
352 animationSpeed: 0
353 }),
354 [MobId.townGuard]: Object.freeze({
355 mobTypeId: MobId.townGuard,
356 key: "town-guard",
357 assetFolder: "characters",
358 displayName: "Town Guard",
359 health: 10,
360 maxHealth: 10,
361 maxHealthFromLevel: "levelPlus10",
362 drops: Object.freeze([]),
363 sells: Object.freeze([]),
364 dialogue: Object.freeze([]),
365 persistent: false,
366 flying: false,
367 freeFlight: false,
368 ambient: false,
369 talkable: false,
370 untargetable: false,
371 aggressive: false,
372 usePlayerBody: true,
373 townGuard: true,
374 gait: "walk",
375 sex: "male",
376 frames: 1,
377 framesPerRow: 1,
378 animationSpeed: 0
379 }),
380 [MobId.centralExchange]: Object.freeze({
381 mobTypeId: MobId.centralExchange,
382 key: "central-exchange",
383 assetFolder: "characters",
384 displayName: "Central Exchange staff",
385 health: 10,
386 maxHealth: 10,
387 maxHealthFromLevel: "levelPlus10",
388 drops: Object.freeze([]),
389 sells: Object.freeze([]),
390 dialogue: Object.freeze([]),
391 persistent: false,
392 flying: false,
393 freeFlight: false,
394 ambient: false,
395 talkable: false,
396 untargetable: false,
397 aggressive: false,
398 usePlayerBody: true,
399 centralExchange: true,
400 gait: "walk",
401 sex: "male",
402 frames: 1,
403 framesPerRow: 1,
404 animationSpeed: 0
405 })
406});
407
408export function mobDefinition (mobTypeId)
409{
410 return MOB_DEFINITIONS[mobTypeId] ?? null;
411}
412
413export function mobSpriteName (mobTypeId, visualState = null)
414{
415 const def = mobDefinition(mobTypeId);
416 const key = def?.spriteKey ?? def?.key ?? def?.mobTypeId ?? "deer";
417 if (def?.usePlayerBody)
418 {
419 // Editor palette preview; live entities use appearance.sex → bodySprite().
420 return spriteImageName("character", "player-body-male", "player-body-male");
421 }
422 if (def?.sprite)
423 { return def.sprite; }
424 const state = visualState ?? def?.defaultState ?? key;
425 return spriteImageName("mob", key, state);
426}
427
428/** Whether this mob definition can be sheared for cloth fibre. */
429export function mobIsShearable (mobTypeId)
430{
431 return !!mobDefinition(mobTypeId)?.shearable;
432}
433
434export function defaultSpawnerConfig (spawnerId, mobTypeId = MobId.deer)
435{
436 const humanoid = isHumanoidMob(mobTypeId) || mobTypeId === MobId.humanoid;
437 const townGuard = mobTypeId === MobId.townGuard;
438 const centralExchange = mobTypeId === MobId.centralExchange;
439 const bodyNpc = humanoid || townGuard || centralExchange;
440 const level = townGuard
441 ? 30
442 : (mobTypeId === MobId.sprite
443 ? 25
444 : (mobTypeId === MobId.fairy ? 70 : 1));
445 const bounty = townGuard ? 500 : 0;
446 return {
447 spawnerId,
448 mobTypeId,
449 maxAlive: centralExchange
450 ? centralExchangeStaffCount()
451 : (bodyNpc ? 1 : 3),
452 /** Seconds after death before this spawner may refill that slot (0 = next spawner tick). */
453 respawnDelaySeconds: 25,
454 spawnRangeTiles: bodyNpc ? 1 : 4,
455 maxWanderRangeTiles: bodyNpc ? 1 : 8,
456 level,
457 bounty,
458 /** Humanoid spawners only: auto-engage players in aggro range. Forces bounty 0. */
459 aggressive: false,
460 sex: "male",
461 displayName: townGuard ? "Town Guard" : (humanoid ? "Shopkeeper" : ""),
462 equipment: townGuard
463 ? {
464 head: ArmourItemId.ironHelmet,
465 chest: ArmourItemId.ironChestplate,
466 legs: ArmourItemId.bronzeGreaves,
467 boots: ArmourItemId.ironBoots,
468 weapon: WoodItemId.oakQuarterstaff,
469 offhand: null
470 }
471 : emptySpawnerEquipment(),
472 sells: [],
473 drops: [],
474 spells: [],
475 buysItems: false,
476 hiddenDiscount: 0.9,
477 centralExchange,
478 townGuard,
479 dialogueId: null
480 };
481}
482
483function emptySpawnerEquipment ()
484{
485 return {
486 head: null,
487 chest: null,
488 legs: null,
489 boots: null,
490 weapon: null,
491 offhand: null
492 };
493}
494
495/**
496 * Spawner equipment entry: legacy itemId number, or `{ itemId, dyeColor? }` for dyed clothing.
497 * Normalized form keeps a plain number when undyed (world-save compatible).
498 */
499function normalizeEquipmentEntry (value)
500{
501 if (value == null || value === "" || value === "0")
502 { return null; }
503 let itemId = 0;
504 let dyeColor = null;
505 if (typeof value === "object")
506 {
507 itemId = Number(value.itemId) | 0;
508 dyeColor = normalizeDyeColor(value.dyeColor);
509 }
510 else
511 { itemId = Number(value) | 0; }
512 if (!Number.isFinite(itemId) || itemId <= 0)
513 { return null; }
514 if (!dyeColor)
515 { return itemId; }
516 return Object.freeze({ itemId, dyeColor });
517}
518
519function normalizeDyeColor (raw)
520{
521 if (!raw || typeof raw !== "object")
522 { return null; }
523 const r = Number(raw.r);
524 const g = Number(raw.g);
525 const b = Number(raw.b);
526 if (![r, g, b].every(Number.isFinite))
527 { return null; }
528 const asByte = r > 1 || g > 1 || b > 1;
529 return Object.freeze({
530 r: Math.min(1, Math.max(0, asByte ? r / 255 : r)),
531 g: Math.min(1, Math.max(0, asByte ? g / 255 : g)),
532 b: Math.min(1, Math.max(0, asByte ? b / 255 : b))
533 });
534}
535
536function normalizeEquipment (raw)
537{
538 const next = emptySpawnerEquipment();
539 if (!raw || typeof raw !== "object")
540 { return next; }
541 for (const slot of Object.keys(next))
542 { next[slot] = normalizeEquipmentEntry(raw[slot]); }
543 return next;
544}
545
546/** Resolve authored spawner equipment into itemId (+ optional dye). */
547export function spawnerEquipmentSlot (entry)
548{
549 if (entry == null)
550 { return { itemId: 0, dyeColor: null }; }
551 if (typeof entry === "object")
552 {
553 return {
554 itemId: Number(entry.itemId) | 0,
555 dyeColor: entry.dyeColor ?? null
556 };
557 }
558 return { itemId: Number(entry) | 0, dyeColor: null };
559}
560
561function normalizeSells (raw)
562{
563 if (!Array.isArray(raw))
564 { return []; }
565 const lines = [];
566 const seen = new Set();
567 for (const entry of raw)
568 {
569 let itemId;
570 let quantity = 0;
571 if (entry && typeof entry === "object")
572 {
573 itemId = Number(entry.itemId);
574 quantity = Math.max(0, Number(entry.quantity) || 0) | 0;
575 }
576 else
577 { itemId = Number(entry); }
578 if (!Number.isFinite(itemId) || itemId <= 0 || seen.has(itemId | 0))
579 { continue; }
580 seen.add(itemId | 0);
581 lines.push({ itemId: itemId | 0, quantity });
582 }
583 return lines;
584}
585
586/**
587 * Spawner loot lines. Chance is 0–1 (UI edits as 0–100%).
588 * Quantity is rolled inclusively between quantityMin and quantityMax when the drop hits.
589 * @returns {ReadonlyArray<{ itemId: number, chance: number, quantityMin: number, quantityMax: number }>}
590 */
591function normalizeDrops (raw)
592{
593 if (!Array.isArray(raw))
594 { return []; }
595 const lines = [];
596 const seen = new Set();
597 for (const entry of raw)
598 {
599 if (!entry || typeof entry !== "object")
600 { continue; }
601 const itemId = Number(entry.itemId) | 0;
602 if (!Number.isFinite(itemId) || itemId <= 0 || seen.has(itemId))
603 { continue; }
604 seen.add(itemId);
605 let chance = Number(entry.chance);
606 if (!Number.isFinite(chance))
607 { chance = 1; }
608 // Accept editor percent (0–100) or fraction (0–1).
609 if (chance > 1)
610 { chance = chance / 100; }
611 chance = Math.min(1, Math.max(0, chance));
612 let quantityMin = Math.max(0, Math.floor(Number(
613 entry.quantityMin ?? entry.quantity ?? 1
614 )));
615 let quantityMax = Math.max(0, Math.floor(Number(
616 entry.quantityMax ?? entry.quantityMin ?? entry.quantity ?? quantityMin
617 )));
618 if (!Number.isFinite(quantityMin))
619 { quantityMin = 1; }
620 if (!Number.isFinite(quantityMax))
621 { quantityMax = quantityMin; }
622 if (quantityMax < quantityMin)
623 { quantityMax = quantityMin; }
624 lines.push(Object.freeze({ itemId, chance, quantityMin, quantityMax }));
625 }
626 return lines;
627}
628
629function normalizeSpells (raw)
630{
631 if (!Array.isArray(raw))
632 { return []; }
633 const lines = [];
634 const seen = new Set();
635 for (const entry of raw)
636 {
637 if (!entry || typeof entry !== "object")
638 { continue; }
639 const spellId = String(entry.spellId ?? "").trim();
640 // Drop unknown / retired ids (e.g. legacy spark) so spawners stay loadable.
641 if (!spellId || seen.has(spellId) || !spellDefinition(spellId))
642 { continue; }
643 seen.add(spellId);
644 // Cast chance is derived from mob level at spawn time — not stored.
645 lines.push({ spellId });
646 }
647 return lines;
648}
649
650/** Clamp wander ≥ spawn; coerce numeric fields; keep humanoid shop/appearance options. */
651export function normalizeSpawnerConfig (config, spawnerId = "spawner")
652{
653 const mobTypeId = config?.mobTypeId ?? MobId.deer;
654 const centralExchange = mobTypeId === MobId.centralExchange || !!config?.centralExchange;
655 const townGuard = !centralExchange && (mobTypeId === MobId.townGuard || !!config?.townGuard);
656 const effectiveMob = centralExchange
657 ? MobId.centralExchange
658 : (townGuard ? MobId.townGuard : mobTypeId);
659 const base = defaultSpawnerConfig(spawnerId, effectiveMob);
660 const merged = { ...base, ...(config ?? {}), spawnerId: config?.spawnerId || spawnerId, mobTypeId: effectiveMob };
661 const spawnRangeTiles = Math.max(1, Math.min(32, Number(merged.spawnRangeTiles) || base.spawnRangeTiles));
662 const maxWanderRangeTiles = Math.max(
663 spawnRangeTiles,
664 Math.min(64, Number(merged.maxWanderRangeTiles) || spawnRangeTiles)
665 );
666 const sex = merged.sex === "female" ? "female" : "male";
667 const hiddenDiscount = Math.min(1, Math.max(0.01, Number(merged.hiddenDiscount) || base.hiddenDiscount));
668 const displayName = String(merged.displayName ?? "").trim().slice(0, 48);
669 const staffCap = centralExchangeStaffCount();
670 const level = Math.max(1, Math.min(99, Number(merged.level) || base.level || 1)) | 0;
671 const bodyNpc = isHumanoidMob(effectiveMob) || centralExchange || townGuard;
672 const aggressive = bodyNpc ? !!merged.aggressive : false;
673 const bounty = aggressive ? 0 : (Math.max(0, Number(merged.bounty) || 0) | 0);
674 return {
675 spawnerId: String(merged.spawnerId),
676 mobTypeId: effectiveMob,
677 maxAlive: centralExchange
678 ? staffCap
679 : Math.max(1, Math.min(20, Number(merged.maxAlive) || base.maxAlive)),
680 respawnDelaySeconds: Math.max(
681 0,
682 Math.min(
683 86_400,
684 Math.floor(
685 Number(
686 merged.respawnDelaySeconds != null && merged.respawnDelaySeconds !== ""
687 ? merged.respawnDelaySeconds
688 : base.respawnDelaySeconds
689 ) || 0
690 )
691 )
692 ),
693 spawnRangeTiles,
694 maxWanderRangeTiles,
695 level,
696 bounty,
697 aggressive,
698 sex,
699 displayName,
700 equipment: normalizeEquipment(merged.equipment),
701 sells: centralExchange ? [] : normalizeSells(merged.sells),
702 drops: bodyNpc ? normalizeDrops(merged.drops) : [],
703 spells: normalizeSpells(merged.spells),
704 buysItems: centralExchange ? false : !!merged.buysItems,
705 hiddenDiscount,
706 centralExchange,
707 townGuard,
708 dialogueId: bodyNpc
709 ? (String(merged.dialogueId ?? "").trim().slice(0, 64) || null)
710 : null
711 };
712}
713
714export function listAmbientMobTypes ()
715{
716 return Object.values(MOB_DEFINITIONS).filter((def) => def.ambient);
717}
718
719/** Every mob type that can be authored as a world-editor spawner. */
720export function listSpawnableMobTypes ()
721{
722 return Object.values(MOB_DEFINITIONS);
723}
724
725export function isHumanoidMob (mobTypeId)
726{
727 return mobDefinition(mobTypeId)?.usePlayerBody === true;
728}
729
730export function isTownGuardMob (mobTypeId)
731{
732 return mobTypeId === MobId.townGuard || !!mobDefinition(mobTypeId)?.townGuard;
733}
734
735export function isCentralExchangeSpawner (configOrMobTypeId)
736{
737 if (configOrMobTypeId && typeof configOrMobTypeId === "object")
738 { return !!configOrMobTypeId.centralExchange || configOrMobTypeId.mobTypeId === MobId.centralExchange; }
739 return configOrMobTypeId === MobId.centralExchange;
740}
741
742/** Max HP for a mob at the given spawner level. */
743export function mobMaxHealthForLevel (def, level)
744{
745 const lv = Math.max(1, Math.floor(Number(level) || 1));
746 const formula = def?.maxHealthFromLevel;
747 if (formula === "levelPlus10" || (!formula && def?.usePlayerBody))
748 { return lv + 10; }
749 const base = Math.max(1, Number(def?.health ?? def?.maxHealth ?? 8) || 8);
750 return Math.max(1, base + (lv - 1));
751}
752
753/** Display label for hover / UI: `Lv.5 Deer`. */
754export function mobLevelDisplayName (level, displayName)
755{
756 const lv = Math.max(1, Math.floor(Number(level) || 1));
757 const name = String(displayName ?? "").trim() || "Creature";
758 return `Lv.${lv} ${name}`;
759}