BlueGit

timfa questward

Files

questward / shared / definitions / mobs.js

mobs.js

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