BlueGit

timfa questward

Files

questward / shared / definitions / mobs.js

mobs.js

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