BlueGit

timfa questward

Files

questward / shared / definitions / mobs.js

mobs.js

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