BlueGit

timfa questward

Files

questward / shared / definitions / mobs.js

mobs.js

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