BlueGit

timfa questward

Files

questward / shared / definitions / mobs.js

mobs.js

mobs.js 20.6 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 /** Spawner shades are hostile; summoned shades opt out via Component.summon. */
246 aggressive: true,
247 aggroRangeTiles: 5,
248 bloomBody: true,
249 gait: "walk",
250 sex: "male",
251 /** Body sheet is static; bloom flickers on its own. */
252 frames: 1,
253 framesPerRow: 1,
254 animationSpeed: 0,
255 bloomFrames: 2,
256 bloomFramesPerRow: 2,
257 /** Match elemental sprite bloom cadence. */
258 bloomAnimationSpeed: 0.5,
259 defaultState: "shade"
260 }),
261 [MobId.sprite]: Object.freeze({
262 mobTypeId: MobId.sprite,
263 key: "sprite",
264 assetFolder: "mobs",
265 displayName: "Sprite",
266 health: 35,
267 maxHealth: 35,
268 maxHealthFromLevel: "levelPlus10",
269 attackSkill: 25,
270 attackCooldownMs: 1100,
271 drops: Object.freeze([]),
272 /** Essence drop is resolved from the creature's chosen element on death. */
273 essenceDropChance: 1,
274 sells: Object.freeze([]),
275 dialogue: Object.freeze([]),
276 persistent: false,
277 flying: false,
278 freeFlight: false,
279 ambient: false,
280 talkable: false,
281 untargetable: false,
282 aggressive: true,
283 aggroRangeTiles: 6,
284 preferSpellAttack: true,
285 lightRadiusTiles: 2,
286 randomElementOnSpawn: true,
287 bloomBody: true,
288 gait: "walk",
289 sex: "male",
290 frames: 2,
291 framesPerRow: 2,
292 animationSpeed: 0.5
293 }),
294 [MobId.fairy]: Object.freeze({
295 mobTypeId: MobId.fairy,
296 key: "fairy",
297 assetFolder: "mobs",
298 displayName: "Fairy",
299 health: 40,
300 maxHealth: 40,
301 maxHealthFromLevel: "levelPlus10",
302 attackSkill: 55,
303 attackCooldownMs: 1000,
304 drops: Object.freeze([
305 { itemId: ClothItemId.fairySilk, chance: 0.7 }
306 ]),
307 sells: Object.freeze([]),
308 dialogue: Object.freeze([]),
309 persistent: false,
310 flying: true,
311 freeFlight: false,
312 ambient: false,
313 talkable: false,
314 untargetable: false,
315 aggressive: true,
316 aggroRangeTiles: 5,
317 /** Prefer sprite-style elemental bolts over melee. */
318 preferSpellAttack: true,
319 /** Cast a random-element sprite bolt each attack (no fixed spawn element). */
320 randomElementSpell: true,
321 /** On hit, flee until at least this many tiles from the hit source (then stop until hit again). */
322 fleeOnHitTiles: 2,
323 /** Dimmer than elemental sprites (radius 2). */
324 lightRadiusTiles: 1,
325 bloomBody: true,
326 /** Shirt/skirt/hair use dual-channel body tints rolled on spawn. */
327 dualChannelAppearance: true,
328 gait: "walk",
329 sex: "female",
330 frames: 2,
331 framesPerRow: 2,
332 animationSpeed: 0.45,
333 defaultState: "fairy"
334 }),
335 [MobId.humanoid]: Object.freeze({
336 mobTypeId: MobId.humanoid,
337 key: "humanoid",
338 assetFolder: "characters",
339 displayName: "Humanoid",
340 health: 10,
341 maxHealth: 10,
342 /** HP = spawner level + 10 (same floor as a starting player's Health). */
343 maxHealthFromLevel: "levelPlus10",
344 drops: Object.freeze([]),
345 sells: Object.freeze([]),
346 dialogue: Object.freeze([]),
347 persistent: false,
348 flying: false,
349 freeFlight: false,
350 ambient: false,
351 talkable: true,
352 untargetable: false,
353 aggressive: false,
354 usePlayerBody: true,
355 gait: "walk",
356 sex: "male",
357 frames: 1,
358 framesPerRow: 1,
359 animationSpeed: 0
360 }),
361 [MobId.townGuard]: Object.freeze({
362 mobTypeId: MobId.townGuard,
363 key: "town-guard",
364 assetFolder: "characters",
365 displayName: "Town Guard",
366 health: 10,
367 maxHealth: 10,
368 maxHealthFromLevel: "levelPlus10",
369 drops: Object.freeze([]),
370 sells: Object.freeze([]),
371 dialogue: Object.freeze([]),
372 persistent: false,
373 flying: false,
374 freeFlight: false,
375 ambient: false,
376 talkable: false,
377 untargetable: false,
378 aggressive: false,
379 usePlayerBody: true,
380 townGuard: true,
381 gait: "walk",
382 sex: "male",
383 frames: 1,
384 framesPerRow: 1,
385 animationSpeed: 0
386 }),
387 [MobId.centralExchange]: Object.freeze({
388 mobTypeId: MobId.centralExchange,
389 key: "central-exchange",
390 assetFolder: "characters",
391 displayName: "Central Exchange staff",
392 health: 10,
393 maxHealth: 10,
394 maxHealthFromLevel: "levelPlus10",
395 drops: Object.freeze([]),
396 sells: Object.freeze([]),
397 dialogue: Object.freeze([]),
398 persistent: false,
399 flying: false,
400 freeFlight: false,
401 ambient: false,
402 talkable: false,
403 untargetable: false,
404 aggressive: false,
405 usePlayerBody: true,
406 centralExchange: true,
407 gait: "walk",
408 sex: "male",
409 frames: 1,
410 framesPerRow: 1,
411 animationSpeed: 0
412 })
413});
414
415export function mobDefinition (mobTypeId)
416{
417 return MOB_DEFINITIONS[mobTypeId] ?? null;
418}
419
420export function mobSpriteName (mobTypeId, visualState = null)
421{
422 const def = mobDefinition(mobTypeId);
423 const key = def?.spriteKey ?? def?.key ?? def?.mobTypeId ?? "deer";
424 if (def?.usePlayerBody)
425 {
426 // Editor palette preview; live entities use appearance.sex → bodySprite().
427 return spriteImageName("character", "player-body-male", "player-body-male");
428 }
429 if (def?.sprite)
430 { return def.sprite; }
431 const state = visualState ?? def?.defaultState ?? key;
432 return spriteImageName("mob", key, state);
433}
434
435/** Whether this mob definition can be sheared for cloth fibre. */
436export function mobIsShearable (mobTypeId)
437{
438 return !!mobDefinition(mobTypeId)?.shearable;
439}
440
441export function defaultSpawnerConfig (spawnerId, mobTypeId = MobId.deer)
442{
443 const humanoid = isHumanoidMob(mobTypeId) || mobTypeId === MobId.humanoid;
444 const townGuard = mobTypeId === MobId.townGuard;
445 const centralExchange = mobTypeId === MobId.centralExchange;
446 const bodyNpc = humanoid || townGuard || centralExchange;
447 const level = townGuard
448 ? 30
449 : (mobTypeId === MobId.sprite
450 ? 25
451 : (mobTypeId === MobId.fairy ? 70 : 1));
452 const bounty = townGuard ? 500 : 0;
453 return {
454 spawnerId,
455 mobTypeId,
456 maxAlive: centralExchange
457 ? centralExchangeStaffCount()
458 : (bodyNpc ? 1 : 3),
459 /** Seconds after death before this spawner may refill that slot (0 = next spawner tick). */
460 respawnDelaySeconds: 25,
461 spawnRangeTiles: bodyNpc ? 1 : 4,
462 maxWanderRangeTiles: bodyNpc ? 1 : 8,
463 level,
464 bounty,
465 /** Humanoid spawners only: auto-engage players in aggro range. Forces bounty 0. */
466 aggressive: false,
467 sex: "male",
468 displayName: townGuard ? "Town Guard" : (humanoid ? "Shopkeeper" : ""),
469 equipment: townGuard
470 ? {
471 head: ArmourItemId.ironHelmet,
472 chest: ArmourItemId.ironChestplate,
473 legs: ArmourItemId.bronzeGreaves,
474 boots: ArmourItemId.ironBoots,
475 weapon: WoodItemId.oakQuarterstaff,
476 offhand: null
477 }
478 : emptySpawnerEquipment(),
479 sells: [],
480 drops: [],
481 spells: [],
482 buysItems: false,
483 hiddenDiscount: 0.9,
484 centralExchange,
485 townGuard,
486 dialogueId: null
487 };
488}
489
490function emptySpawnerEquipment ()
491{
492 return {
493 head: null,
494 chest: null,
495 legs: null,
496 boots: null,
497 weapon: null,
498 offhand: null
499 };
500}
501
502/**
503 * Spawner equipment entry: legacy itemId number, or `{ itemId, dyeColor? }` for dyed clothing.
504 * Normalized form keeps a plain number when undyed (world-save compatible).
505 */
506function normalizeEquipmentEntry (value)
507{
508 if (value == null || value === "" || value === "0")
509 { return null; }
510 let itemId = 0;
511 let dyeColor = null;
512 if (typeof value === "object")
513 {
514 itemId = Number(value.itemId) | 0;
515 dyeColor = normalizeDyeColor(value.dyeColor);
516 }
517 else
518 { itemId = Number(value) | 0; }
519 if (!Number.isFinite(itemId) || itemId <= 0)
520 { return null; }
521 if (!dyeColor)
522 { return itemId; }
523 return Object.freeze({ itemId, dyeColor });
524}
525
526function normalizeDyeColor (raw)
527{
528 if (!raw || typeof raw !== "object")
529 { return null; }
530 const r = Number(raw.r);
531 const g = Number(raw.g);
532 const b = Number(raw.b);
533 if (![r, g, b].every(Number.isFinite))
534 { return null; }
535 const asByte = r > 1 || g > 1 || b > 1;
536 return Object.freeze({
537 r: Math.min(1, Math.max(0, asByte ? r / 255 : r)),
538 g: Math.min(1, Math.max(0, asByte ? g / 255 : g)),
539 b: Math.min(1, Math.max(0, asByte ? b / 255 : b))
540 });
541}
542
543function normalizeEquipment (raw)
544{
545 const next = emptySpawnerEquipment();
546 if (!raw || typeof raw !== "object")
547 { return next; }
548 for (const slot of Object.keys(next))
549 { next[slot] = normalizeEquipmentEntry(raw[slot]); }
550 return next;
551}
552
553/** Resolve authored spawner equipment into itemId (+ optional dye). */
554export function spawnerEquipmentSlot (entry)
555{
556 if (entry == null)
557 { return { itemId: 0, dyeColor: null }; }
558 if (typeof entry === "object")
559 {
560 return {
561 itemId: Number(entry.itemId) | 0,
562 dyeColor: entry.dyeColor ?? null
563 };
564 }
565 return { itemId: Number(entry) | 0, dyeColor: null };
566}
567
568function normalizeSells (raw)
569{
570 if (!Array.isArray(raw))
571 { return []; }
572 const lines = [];
573 const seen = new Set();
574 for (const entry of raw)
575 {
576 let itemId;
577 let quantity = 0;
578 if (entry && typeof entry === "object")
579 {
580 itemId = Number(entry.itemId);
581 quantity = Math.max(0, Number(entry.quantity) || 0) | 0;
582 }
583 else
584 { itemId = Number(entry); }
585 if (!Number.isFinite(itemId) || itemId <= 0 || seen.has(itemId | 0))
586 { continue; }
587 seen.add(itemId | 0);
588 lines.push({ itemId: itemId | 0, quantity });
589 }
590 return lines;
591}
592
593/**
594 * Spawner loot lines. Chance is 0–1 (UI edits as 0–100%).
595 * Quantity is rolled inclusively between quantityMin and quantityMax when the drop hits.
596 * @returns {ReadonlyArray<{ itemId: number, chance: number, quantityMin: number, quantityMax: number }>}
597 */
598function normalizeDrops (raw)
599{
600 if (!Array.isArray(raw))
601 { return []; }
602 const lines = [];
603 const seen = new Set();
604 for (const entry of raw)
605 {
606 if (!entry || typeof entry !== "object")
607 { continue; }
608 const itemId = Number(entry.itemId) | 0;
609 if (!Number.isFinite(itemId) || itemId <= 0 || seen.has(itemId))
610 { continue; }
611 seen.add(itemId);
612 let chance = Number(entry.chance);
613 if (!Number.isFinite(chance))
614 { chance = 1; }
615 // Accept editor percent (0–100) or fraction (0–1).
616 if (chance > 1)
617 { chance = chance / 100; }
618 chance = Math.min(1, Math.max(0, chance));
619 let quantityMin = Math.max(0, Math.floor(Number(
620 entry.quantityMin ?? entry.quantity ?? 1
621 )));
622 let quantityMax = Math.max(0, Math.floor(Number(
623 entry.quantityMax ?? entry.quantityMin ?? entry.quantity ?? quantityMin
624 )));
625 if (!Number.isFinite(quantityMin))
626 { quantityMin = 1; }
627 if (!Number.isFinite(quantityMax))
628 { quantityMax = quantityMin; }
629 if (quantityMax < quantityMin)
630 { quantityMax = quantityMin; }
631 lines.push(Object.freeze({ itemId, chance, quantityMin, quantityMax }));
632 }
633 return lines;
634}
635
636function normalizeSpells (raw)
637{
638 if (!Array.isArray(raw))
639 { return []; }
640 const lines = [];
641 const seen = new Set();
642 for (const entry of raw)
643 {
644 if (!entry || typeof entry !== "object")
645 { continue; }
646 const spellId = String(entry.spellId ?? "").trim();
647 // Drop unknown / retired ids (e.g. legacy spark) so spawners stay loadable.
648 if (!spellId || seen.has(spellId) || !spellDefinition(spellId))
649 { continue; }
650 seen.add(spellId);
651 // Cast chance is derived from mob level at spawn time — not stored.
652 lines.push({ spellId });
653 }
654 return lines;
655}
656
657/** Clamp wander ≥ spawn; coerce numeric fields; keep humanoid shop/appearance options. */
658export function normalizeSpawnerConfig (config, spawnerId = "spawner")
659{
660 const mobTypeId = config?.mobTypeId ?? MobId.deer;
661 const centralExchange = mobTypeId === MobId.centralExchange || !!config?.centralExchange;
662 const townGuard = !centralExchange && (mobTypeId === MobId.townGuard || !!config?.townGuard);
663 const effectiveMob = centralExchange
664 ? MobId.centralExchange
665 : (townGuard ? MobId.townGuard : mobTypeId);
666 const base = defaultSpawnerConfig(spawnerId, effectiveMob);
667 const merged = { ...base, ...(config ?? {}), spawnerId: config?.spawnerId || spawnerId, mobTypeId: effectiveMob };
668 const spawnRangeTiles = Math.max(1, Math.min(32, Number(merged.spawnRangeTiles) || base.spawnRangeTiles));
669 const maxWanderRangeTiles = Math.max(
670 spawnRangeTiles,
671 Math.min(64, Number(merged.maxWanderRangeTiles) || spawnRangeTiles)
672 );
673 const sex = merged.sex === "female" ? "female" : "male";
674 const hiddenDiscount = Math.min(1, Math.max(0.01, Number(merged.hiddenDiscount) || base.hiddenDiscount));
675 const displayName = String(merged.displayName ?? "").trim().slice(0, 48);
676 const staffCap = centralExchangeStaffCount();
677 const level = Math.max(1, Math.min(99, Number(merged.level) || base.level || 1)) | 0;
678 const bodyNpc = isHumanoidMob(effectiveMob) || centralExchange || townGuard;
679 const aggressive = bodyNpc ? !!merged.aggressive : false;
680 const bounty = aggressive ? 0 : (Math.max(0, Number(merged.bounty) || 0) | 0);
681 return {
682 spawnerId: String(merged.spawnerId),
683 mobTypeId: effectiveMob,
684 maxAlive: centralExchange
685 ? staffCap
686 : Math.max(1, Math.min(20, Number(merged.maxAlive) || base.maxAlive)),
687 respawnDelaySeconds: Math.max(
688 0,
689 Math.min(
690 86_400,
691 Math.floor(
692 Number(
693 merged.respawnDelaySeconds != null && merged.respawnDelaySeconds !== ""
694 ? merged.respawnDelaySeconds
695 : base.respawnDelaySeconds
696 ) || 0
697 )
698 )
699 ),
700 spawnRangeTiles,
701 maxWanderRangeTiles,
702 level,
703 bounty,
704 aggressive,
705 sex,
706 displayName,
707 equipment: normalizeEquipment(merged.equipment),
708 sells: centralExchange ? [] : normalizeSells(merged.sells),
709 drops: bodyNpc ? normalizeDrops(merged.drops) : [],
710 spells: normalizeSpells(merged.spells),
711 buysItems: centralExchange ? false : !!merged.buysItems,
712 hiddenDiscount,
713 centralExchange,
714 townGuard,
715 dialogueId: bodyNpc
716 ? (String(merged.dialogueId ?? "").trim().slice(0, 64) || null)
717 : null
718 };
719}
720
721export function listAmbientMobTypes ()
722{
723 return Object.values(MOB_DEFINITIONS).filter((def) => def.ambient);
724}
725
726/** Every mob type that can be authored as a world-editor spawner. */
727export function listSpawnableMobTypes ()
728{
729 return Object.values(MOB_DEFINITIONS);
730}
731
732export function isHumanoidMob (mobTypeId)
733{
734 return mobDefinition(mobTypeId)?.usePlayerBody === true;
735}
736
737export function isTownGuardMob (mobTypeId)
738{
739 return mobTypeId === MobId.townGuard || !!mobDefinition(mobTypeId)?.townGuard;
740}
741
742export function isCentralExchangeSpawner (configOrMobTypeId)
743{
744 if (configOrMobTypeId && typeof configOrMobTypeId === "object")
745 { return !!configOrMobTypeId.centralExchange || configOrMobTypeId.mobTypeId === MobId.centralExchange; }
746 return configOrMobTypeId === MobId.centralExchange;
747}
748
749/** Max HP for a mob at the given spawner level. */
750export function mobMaxHealthForLevel (def, level)
751{
752 const lv = Math.max(1, Math.floor(Number(level) || 1));
753 const formula = def?.maxHealthFromLevel;
754 if (formula === "levelPlus10" || (!formula && def?.usePlayerBody))
755 { return lv + 10; }
756 const base = Math.max(1, Number(def?.health ?? def?.maxHealth ?? 8) || 8);
757 return Math.max(1, base + (lv - 1));
758}
759
760/** Display label for hover / UI: `Lv.5 Deer`. */
761export function mobLevelDisplayName (level, displayName)
762{
763 const lv = Math.max(1, Math.floor(Number(level) || 1));
764 const name = String(displayName ?? "").trim() || "Creature";
765 return `Lv.${lv} ${name}`;
766}