BlueGit

timfa questward

Files

questward / shared / definitions / equipmentStatCategories.js

equipmentStatCategories.js

equipmentStatCategories.js 19.8 KiB Download Raw
1import { SkillId } from "./skills.js";
2import { EquipmentKind } from "./equipmentKinds.js";
3import
4{
5 MATERIAL_TIER_ORDER,
6 WOOD_TIER_ORDER,
7 CLOTH_TIER_ORDER,
8 LEATHER_TIER_ORDER,
9 MATERIAL_DISPLAY_NAME,
10 CLOTH_DISPLAY_NAME,
11 LEATHER_DISPLAY_NAME,
12 WoodTier,
13 tierStatBonus,
14 tierRank
15} from "./materialTiers.js";
16import { ARMOUR_CRAFT_PIECES, armourItemIdForTier } from "./armourItems.js";
17import { sweaterItemId, shirtItemId, shortsItemId, skirtItemId, trousersItemId } from "./clothItems.js";
18import { leatherShoesItemId } from "./leatherItems.js";
19import { LEATHER_ARMOUR_PIECES, leatherArmourItemIdForTier } from "./leatherArmourItems.js";
20import
21{
22 wizardHatItemId,
23 wizardRobeTopItemId,
24 wizardRobeBottomsItemId,
25 wizardShoesItemId
26} from "./wizardItems.js";
27import { ItemId, itemDefinition, ITEM_DEFINITIONS } from "./items.js";
28import { quarterstaffItemIdForWood } from "./woodItems.js";
29import { swordItemIdForMetal } from "./swordItems.js";
30import { warAxeItemIdForMetal } from "./warAxeItems.js";
31import { arrowItemId, bowItemId } from "./rangedItems.js";
32import { staffItemIdForWood } from "./gemItems.js";
33
34/** Tier key for non-tiered singleton rows. */
35export const SINGLETON_TIER_KEY = "_";
36
37export const EquipmentStatCategoryId = Object.freeze({
38 metalArmour: "metalArmour",
39 leatherArmour: "leatherArmour",
40 meleeWeapons: "meleeWeapons",
41 rangedWeapons: "rangedWeapons",
42 magicStaves: "magicStaves",
43 wizardArmour: "wizardArmour",
44 clothing: "clothing"
45});
46
47/**
48 * Equipment kinds that grant worn combat/stat bonuses and must appear in a category.
49 * Tools / lantern are excluded.
50 */
51export const BONUS_EQUIPMENT_KINDS = Object.freeze(new Set([
52 EquipmentKind.metalWeapon,
53 EquipmentKind.clubWeapon,
54 EquipmentKind.bow,
55 EquipmentKind.arrowAmmo,
56 EquipmentKind.metalArmour,
57 EquipmentKind.leatherArmour,
58 EquipmentKind.clothArmour,
59 EquipmentKind.wizardCloth,
60 EquipmentKind.shield,
61 EquipmentKind.staff
62]));
63
64function woodDisplayName (tier)
65{
66 return MATERIAL_DISPLAY_NAME[tier] ?? tier;
67}
68
69function metalDisplayName (tier)
70{
71 return MATERIAL_DISPLAY_NAME[tier] ?? tier;
72}
73
74/**
75 * @typedef {object} EquipmentStatSection
76 * @property {string} [id]
77 * @property {string} [label]
78 * @property {ReadonlyArray<string>} tierOrder
79 * @property {(tier: string) => string} tierDisplayName
80 * @property {ReadonlyArray<object>} rows
81 */
82
83/**
84 * @typedef {object} EquipmentStatCategory
85 * @property {string} id
86 * @property {string} label
87 * @property {ReadonlyArray<string>} stats
88 * @property {ReadonlyArray<EquipmentStatSection>} sections
89 */
90
91/** @type {ReadonlyArray<EquipmentStatCategory>} */
92export const EQUIPMENT_STAT_CATEGORIES = Object.freeze([
93 Object.freeze({
94 id: EquipmentStatCategoryId.metalArmour,
95 label: "Metal armour",
96 stats: Object.freeze([
97 SkillId.defence,
98 SkillId.strength,
99 SkillId.agility,
100 SkillId.magic,
101 SkillId.archery
102 ]),
103 sections: Object.freeze([
104 Object.freeze({
105 id: "metal",
106 tierOrder: MATERIAL_TIER_ORDER,
107 tierDisplayName: metalDisplayName,
108 rows: Object.freeze(ARMOUR_CRAFT_PIECES.map((piece) => Object.freeze({
109 pieceKey: piece.suffix === "full-helm" ? "fullHelm"
110 : piece.suffix === "horned-helm" ? "hornedHelm"
111 : piece.suffix,
112 label: piece.label.charAt(0).toUpperCase() + piece.label.slice(1),
113 defaultBonusExtra: piece.fullHelm ? 1 : 0,
114 defaultBonusByStat: Object.freeze({
115 [SkillId.defence]: "tier",
116 [SkillId.strength]: "tierQuarterCeil",
117 [SkillId.agility]: "tierQuarterCeil",
118 [SkillId.magic]: "negativeRank",
119 [SkillId.archery]: "negativeRank"
120 }),
121 resolveItemId: (tier) => armourItemIdForTier(tier, piece.idKey)
122 })))
123 })
124 ])
125 }),
126 Object.freeze({
127 id: EquipmentStatCategoryId.leatherArmour,
128 label: "Leather armour",
129 stats: Object.freeze([SkillId.agility, SkillId.defence]),
130 sections: Object.freeze([
131 Object.freeze({
132 id: "leather",
133 tierOrder: LEATHER_TIER_ORDER,
134 tierDisplayName: (tier) => LEATHER_DISPLAY_NAME[tier] ?? tier,
135 rows: Object.freeze([
136 Object.freeze({
137 pieceKey: "shoes",
138 label: "Leather shoes",
139 defaultBonusByStat: Object.freeze({
140 [SkillId.agility]: "tier",
141 [SkillId.defence]: "tierHalf"
142 }),
143 resolveItemId: (tier) => leatherShoesItemId(tier)
144 }),
145 ...LEATHER_ARMOUR_PIECES.map((piece) => Object.freeze({
146 pieceKey: piece.pieceKey,
147 label: piece.label.charAt(0).toUpperCase() + piece.label.slice(1),
148 defaultBonusByStat: Object.freeze({
149 [SkillId.agility]: "tier",
150 [SkillId.defence]: "tierHalf"
151 }),
152 resolveItemId: (tier) => leatherArmourItemIdForTier(tier, piece.idKey)
153 }))
154 ])
155 })
156 ])
157 }),
158 Object.freeze({
159 id: EquipmentStatCategoryId.meleeWeapons,
160 label: "Melee weapons",
161 stats: Object.freeze([SkillId.strength, SkillId.swordfighting]),
162 sections: Object.freeze([
163 Object.freeze({
164 id: "wood",
165 label: "Clubs",
166 tierOrder: WOOD_TIER_ORDER,
167 tierDisplayName: woodDisplayName,
168 rows: Object.freeze([
169 Object.freeze({
170 pieceKey: "club",
171 label: "Stick / Quarterstaff",
172 /** Strength curve only — cheap; no weapon-skill bonus. */
173 defaultBonusByStat: Object.freeze({ [SkillId.strength]: "tier" }),
174 resolveItemId: (tier) => (tier === WoodTier.pine
175 ? ItemId.stick
176 : quarterstaffItemIdForWood(tier))
177 })
178 ])
179 }),
180 Object.freeze({
181 id: "swords",
182 label: "Swords",
183 tierOrder: MATERIAL_TIER_ORDER,
184 tierDisplayName: metalDisplayName,
185 rows: Object.freeze([
186 Object.freeze({
187 pieceKey: "sword",
188 label: "Sword",
189 /** Normal strength + swordfighting equal to tier rank (1…7). */
190 defaultBonusByStat: Object.freeze({
191 [SkillId.strength]: "tier",
192 [SkillId.swordfighting]: "rank"
193 }),
194 resolveItemId: (tier) => swordItemIdForMetal(tier)
195 })
196 ])
197 }),
198 Object.freeze({
199 id: "warAxes",
200 label: "War axes",
201 tierOrder: MATERIAL_TIER_ORDER,
202 tierDisplayName: metalDisplayName,
203 rows: Object.freeze([
204 Object.freeze({
205 pieceKey: "warAxe",
206 label: "War axe",
207 /** Normal strength curve +1 at every tier. */
208 defaultBonusByStat: Object.freeze({ [SkillId.strength]: "tier" }),
209 defaultBonusExtra: 1,
210 resolveItemId: (tier) => warAxeItemIdForMetal(tier)
211 })
212 ])
213 })
214 ])
215 }),
216 Object.freeze({
217 id: EquipmentStatCategoryId.rangedWeapons,
218 label: "Ranged weapons",
219 stats: Object.freeze([SkillId.dexterity]),
220 sections: Object.freeze([
221 Object.freeze({
222 id: "bows",
223 label: "Bows",
224 tierOrder: WOOD_TIER_ORDER,
225 tierDisplayName: woodDisplayName,
226 rows: Object.freeze([
227 Object.freeze({
228 pieceKey: "bow",
229 label: "Bow",
230 resolveItemId: (tier) => bowItemId(tier)
231 })
232 ])
233 }),
234 Object.freeze({
235 id: "arrows",
236 label: "Arrows",
237 tierOrder: MATERIAL_TIER_ORDER,
238 tierDisplayName: metalDisplayName,
239 rows: Object.freeze([
240 Object.freeze({
241 pieceKey: "arrow",
242 label: "Arrow",
243 resolveItemId: (tier) => arrowItemId(tier)
244 })
245 ])
246 })
247 ])
248 }),
249 Object.freeze({
250 id: EquipmentStatCategoryId.magicStaves,
251 label: "Magic staves",
252 stats: Object.freeze([SkillId.magic]),
253 sections: Object.freeze([
254 Object.freeze({
255 id: "wood",
256 tierOrder: WOOD_TIER_ORDER,
257 tierDisplayName: woodDisplayName,
258 rows: Object.freeze([
259 Object.freeze({
260 pieceKey: "staff",
261 label: "Staff",
262 resolveItemId: (tier) => staffItemIdForWood(tier)
263 })
264 ])
265 })
266 ])
267 }),
268 Object.freeze({
269 id: EquipmentStatCategoryId.wizardArmour,
270 label: "Wizard armour",
271 stats: Object.freeze([SkillId.magic]),
272 sections: Object.freeze([
273 Object.freeze({
274 id: "cloth",
275 tierOrder: CLOTH_TIER_ORDER,
276 tierDisplayName: (tier) => CLOTH_DISPLAY_NAME[tier] ?? tier,
277 rows: Object.freeze([
278 Object.freeze({
279 pieceKey: "hat",
280 label: "Hat",
281 defaultBonusByStat: Object.freeze({ [SkillId.magic]: "tier" }),
282 resolveItemId: (tier) => wizardHatItemId(tier)
283 }),
284 Object.freeze({
285 pieceKey: "robetop",
286 label: "Robe top",
287 defaultBonusByStat: Object.freeze({ [SkillId.magic]: "tier" }),
288 resolveItemId: (tier) => wizardRobeTopItemId(tier)
289 }),
290 Object.freeze({
291 pieceKey: "robebottoms",
292 label: "Robe bottoms",
293 defaultBonusByStat: Object.freeze({ [SkillId.magic]: "tier" }),
294 resolveItemId: (tier) => wizardRobeBottomsItemId(tier)
295 }),
296 Object.freeze({
297 pieceKey: "shoes",
298 label: "Shoes",
299 defaultBonusByStat: Object.freeze({ [SkillId.magic]: "tier" }),
300 resolveItemId: (tier) => wizardShoesItemId(tier)
301 })
302 ])
303 })
304 ])
305 }),
306 Object.freeze({
307 id: EquipmentStatCategoryId.clothing,
308 label: "Clothing",
309 stats: Object.freeze([SkillId.defence]),
310 sections: Object.freeze([
311 Object.freeze({
312 id: "sweaters",
313 label: "Sweaters",
314 tierOrder: CLOTH_TIER_ORDER,
315 tierDisplayName: (tier) => CLOTH_DISPLAY_NAME[tier] ?? tier,
316 rows: Object.freeze([
317 Object.freeze({
318 pieceKey: "sweater",
319 label: "Sweater",
320 defaultBonus: 0,
321 resolveItemId: (tier) => sweaterItemId(tier)
322 })
323 ])
324 }),
325 Object.freeze({
326 id: "shirts",
327 label: "Shirts",
328 tierOrder: CLOTH_TIER_ORDER,
329 tierDisplayName: (tier) => CLOTH_DISPLAY_NAME[tier] ?? tier,
330 rows: Object.freeze([
331 Object.freeze({
332 pieceKey: "shirt",
333 label: "Shirt",
334 defaultBonus: 0,
335 resolveItemId: (tier) => shirtItemId(tier)
336 })
337 ])
338 }),
339 Object.freeze({
340 id: "shorts",
341 label: "Shorts",
342 tierOrder: CLOTH_TIER_ORDER,
343 tierDisplayName: (tier) => CLOTH_DISPLAY_NAME[tier] ?? tier,
344 rows: Object.freeze([
345 Object.freeze({
346 pieceKey: "shorts",
347 label: "Shorts",
348 defaultBonus: 0,
349 resolveItemId: (tier) => shortsItemId(tier)
350 })
351 ])
352 }),
353 Object.freeze({
354 id: "skirts",
355 label: "Skirts",
356 tierOrder: CLOTH_TIER_ORDER,
357 tierDisplayName: (tier) => CLOTH_DISPLAY_NAME[tier] ?? tier,
358 rows: Object.freeze([
359 Object.freeze({
360 pieceKey: "skirt",
361 label: "Skirt",
362 defaultBonus: 0,
363 resolveItemId: (tier) => skirtItemId(tier)
364 })
365 ])
366 }),
367 Object.freeze({
368 id: "trousers",
369 label: "Trousers",
370 tierOrder: CLOTH_TIER_ORDER,
371 tierDisplayName: (tier) => CLOTH_DISPLAY_NAME[tier] ?? tier,
372 rows: Object.freeze([
373 Object.freeze({
374 pieceKey: "trousers",
375 label: "Trousers",
376 defaultBonus: 0,
377 resolveItemId: (tier) => trousersItemId(tier)
378 })
379 ])
380 })
381 ])
382 })
383]);
384
385export function equipmentStatCategory (categoryId)
386{
387 return EQUIPMENT_STAT_CATEGORIES.find((entry) => entry.id === categoryId) ?? null;
388}
389
390/** Flat list of all piece rows with category + section context. */
391export function listEquipmentStatRows ()
392{
393 const out = [];
394 for (const category of EQUIPMENT_STAT_CATEGORIES)
395 {
396 for (const section of category.sections)
397 {
398 for (const row of section.rows)
399 {
400 out.push({
401 categoryId: category.id,
402 stats: category.stats,
403 section,
404 row
405 });
406 }
407 }
408 }
409 return out;
410}
411
412/**
413 * Map itemId → { categoryId, pieceKey, stats, singleton, section }.
414 * Built lazily so item defs are fully loaded.
415 */
416let _itemLookup = null;
417
418export function equipmentStatLookupForItem (itemId)
419{
420 if (!_itemLookup)
421 { _itemLookup = buildItemLookup(); }
422 return _itemLookup.get(itemId | 0) ?? null;
423}
424
425function buildItemLookup ()
426{
427 const map = new Map();
428 for (const entry of listEquipmentStatRows())
429 {
430 const { categoryId, stats, section, row } = entry;
431 for (const tier of section.tierOrder)
432 {
433 const itemId = row.resolveItemId?.(tier) ?? (row.singleton ? row.itemId : null);
434 if (itemId == null)
435 { continue; }
436 map.set(itemId | 0, Object.freeze({
437 categoryId,
438 pieceKey: row.pieceKey,
439 stats,
440 singleton: !!row.singleton,
441 tierKey: row.singleton ? SINGLETON_TIER_KEY : tier
442 }));
443 }
444 }
445 return map;
446}
447
448/** Reset cached lookup (tests). */
449export function clearEquipmentStatLookupCache ()
450{
451 _itemLookup = null;
452}
453
454function emptyStatBag (stats)
455{
456 const bag = {};
457 for (const skillId of stats)
458 { bag[skillId] = 0; }
459 return bag;
460}
461
462function resolveDefaultBonusMode (mode, tier, row)
463{
464 const key = tier === SINGLETON_TIER_KEY ? null : tier;
465 const extra = Number(row.defaultBonusExtra) || 0;
466 if (mode === "rank")
467 { return Math.max(0, Math.floor(tierRank(key) + extra)); }
468 if (mode === "negativeRank")
469 { return -Math.max(0, Math.floor(tierRank(key))); }
470 if (mode === "tierHalf")
471 {
472 const base = row.defaultBonus != null
473 ? Number(row.defaultBonus) || 0
474 : tierStatBonus(key);
475 return Math.max(0, Math.floor(base / 2) + extra);
476 }
477 if (mode === "tierQuarterCeil")
478 {
479 const base = row.defaultBonus != null
480 ? Number(row.defaultBonus) || 0
481 : tierStatBonus(key);
482 return Math.max(0, Math.ceil(base / 4));
483 }
484 if (mode === "tier" || mode == null)
485 {
486 const base = row.defaultBonus != null
487 ? Number(row.defaultBonus) || 0
488 : tierStatBonus(key);
489 return Math.max(0, Math.floor(base + extra));
490 }
491 const n = Math.floor(Number(mode));
492 return Number.isFinite(n) ? Math.max(0, n) : 0;
493}
494
495function defaultCellForRow (row, stats, tier)
496{
497 const cell = emptyStatBag(stats);
498 const byStat = row.defaultBonusByStat;
499 if (byStat && typeof byStat === "object")
500 {
501 for (const [skillId, mode] of Object.entries(byStat))
502 {
503 if (!Object.prototype.hasOwnProperty.call(cell, skillId))
504 { continue; }
505 cell[skillId] = resolveDefaultBonusMode(mode, tier, row);
506 }
507 return cell;
508 }
509 const value = resolveDefaultBonusMode("tier", tier, row);
510 if (row.bonusStat)
511 {
512 if (Object.prototype.hasOwnProperty.call(cell, row.bonusStat))
513 { cell[row.bonusStat] = value; }
514 return cell;
515 }
516 for (const skillId of stats)
517 { cell[skillId] = value; }
518 return cell;
519}
520
521/** Seed defaults from current tier curve (full helm +1, cosmetics 0). */
522export function defaultEquipmentStatBonuses ()
523{
524 const out = {};
525 for (const category of EQUIPMENT_STAT_CATEGORIES)
526 {
527 const cat = {};
528 for (const section of category.sections)
529 {
530 for (const row of section.rows)
531 {
532 const byTier = {};
533 for (const tier of section.tierOrder)
534 {
535 const itemId = row.resolveItemId?.(tier) ?? (row.singleton ? row.itemId : null);
536 if (itemId == null && !row.singleton)
537 { continue; }
538 byTier[tier] = defaultCellForRow(row, category.stats, tier);
539 }
540 cat[row.pieceKey] = byTier;
541 }
542 }
543 out[category.id] = cat;
544 }
545 return out;
546}
547
548function coerceBonusInt (raw)
549{
550 const n = Math.floor(Number(raw));
551 if (!Number.isFinite(n))
552 { return 0; }
553 return Math.max(-99, Math.min(99, n));
554}
555
556/**
557 * Merge authored blob with defaults; drop unknown keys; fill missing cells.
558 * @param {object|null|undefined} raw
559 */
560export function normalizeEquipmentStatBonuses (raw)
561{
562 const defaults = defaultEquipmentStatBonuses();
563 const src = raw && typeof raw === "object" ? raw : {};
564 const out = {};
565 for (const category of EQUIPMENT_STAT_CATEGORIES)
566 {
567 const srcCat = src[category.id] && typeof src[category.id] === "object"
568 ? src[category.id]
569 : {};
570 const defCat = defaults[category.id] ?? {};
571 const cat = {};
572 for (const section of category.sections)
573 {
574 for (const row of section.rows)
575 {
576 const srcPiece = srcCat[row.pieceKey] && typeof srcCat[row.pieceKey] === "object"
577 ? srcCat[row.pieceKey]
578 : {};
579 const defPiece = defCat[row.pieceKey] ?? {};
580 const byTier = {};
581 for (const tier of section.tierOrder)
582 {
583 const itemId = row.resolveItemId?.(tier) ?? (row.singleton ? row.itemId : null);
584 if (itemId == null && !row.singleton)
585 { continue; }
586 const srcCell = srcPiece[tier] && typeof srcPiece[tier] === "object"
587 ? srcPiece[tier]
588 : null;
589 const defCell = defPiece[tier] ?? defaultCellForRow(row, category.stats, tier);
590 const cell = {};
591 for (const skillId of category.stats)
592 {
593 cell[skillId] = srcCell && Object.prototype.hasOwnProperty.call(srcCell, skillId)
594 ? coerceBonusInt(srcCell[skillId])
595 : coerceBonusInt(defCell[skillId]);
596 }
597 byTier[tier] = cell;
598 }
599 cat[row.pieceKey] = byTier;
600 }
601 }
602 out[category.id] = cat;
603 }
604 return out;
605}
606
607/**
608 * Resolve per-skill bonuses for one equipped item def.
609 * @returns {Record<string, number>|null}
610 */
611export function bonusForEquippedItem (definition, settingsBonuses = null)
612{
613 const equipment = definition?.equipment;
614 if (!equipment?.kind || !BONUS_EQUIPMENT_KINDS.has(equipment.kind))
615 { return null; }
616 const itemId = definition.itemId;
617 const lookup = equipmentStatLookupForItem(itemId);
618 if (!lookup)
619 { return null; }
620 const table = settingsBonuses && typeof settingsBonuses === "object"
621 ? settingsBonuses
622 : defaultEquipmentStatBonuses();
623 const piece = table[lookup.categoryId]?.[lookup.pieceKey];
624 if (!piece)
625 { return emptyStatBag(lookup.stats); }
626 const tierKey = lookup.singleton
627 ? SINGLETON_TIER_KEY
628 : (equipment.tier ?? definition.tier ?? lookup.tierKey);
629 const cell = piece[tierKey] ?? piece[lookup.tierKey];
630 if (!cell)
631 { return emptyStatBag(lookup.stats); }
632 const out = {};
633 for (const skillId of lookup.stats)
634 { out[skillId] = coerceBonusInt(cell[skillId]); }
635 return out;
636}
637
638/**
639 * Changelog bullets for equipmentStatBonuses edits.
640 * @param {(itemId: number) => string|null} [displayNameFor]
641 */
642export function diffEquipmentStatBonuses (previous, next, displayNameFor = null)
643{
644 const prev = normalizeEquipmentStatBonuses(previous);
645 const upcoming = normalizeEquipmentStatBonuses(next);
646 const bullets = [];
647 for (const category of EQUIPMENT_STAT_CATEGORIES)
648 {
649 for (const section of category.sections)
650 {
651 for (const row of section.rows)
652 {
653 for (const tier of section.tierOrder)
654 {
655 const from = prev[category.id]?.[row.pieceKey]?.[tier];
656 const to = upcoming[category.id]?.[row.pieceKey]?.[tier];
657 if (!from && !to)
658 { continue; }
659 for (const skillId of category.stats)
660 {
661 const a = coerceBonusInt(from?.[skillId]);
662 const b = coerceBonusInt(to?.[skillId]);
663 if (a === b)
664 { continue; }
665 const itemId = row.resolveItemId?.(tier) ?? row.itemId;
666 const name = (itemId != null && displayNameFor?.(itemId))
667 || `${row.label} (${section.tierDisplayName(tier)})`;
668 bullets.push(`${name} ${skillId} bonus changed from ${a} to ${b}.`);
669 }
670 }
671 }
672 }
673 }
674 return bullets;
675}
676
677export function equipmentStatBonusMapsEqual (a, b)
678{
679 const left = normalizeEquipmentStatBonuses(a);
680 const right = normalizeEquipmentStatBonuses(b);
681 return JSON.stringify(left) === JSON.stringify(right);
682}
683
684/**
685 * Every equippable item with a bonus kind must appear in exactly one category row.
686 * @returns {{ ok: true } | { ok: false, missing: number[], duplicates: number[] }}
687 */
688export function assertAllBonusGearCategorized ()
689{
690 clearEquipmentStatLookupCache();
691 const seen = new Map();
692 const duplicates = [];
693 for (const entry of listEquipmentStatRows())
694 {
695 for (const tier of entry.section.tierOrder)
696 {
697 const itemId = entry.row.resolveItemId?.(tier) ?? entry.row.itemId;
698 if (itemId == null)
699 { continue; }
700 const id = itemId | 0;
701 if (seen.has(id))
702 { duplicates.push(id); }
703 else
704 { seen.set(id, entry); }
705 }
706 }
707 const missing = [];
708 for (const def of Object.values(ITEM_DEFINITIONS))
709 {
710 const kind = def?.equipment?.kind;
711 if (!kind || !BONUS_EQUIPMENT_KINDS.has(kind))
712 { continue; }
713 if (!seen.has(def.itemId | 0))
714 { missing.push(def.itemId | 0); }
715 }
716 if (missing.length || duplicates.length)
717 { return { ok: false, missing, duplicates }; }
718 return { ok: true };
719}
720
721/** Preview item id for a row at tier (editor icon). */
722export function equipmentStatRowItemId (row, tier)
723{
724 if (row.singleton)
725 { return row.itemId ?? row.resolveItemId?.(SINGLETON_TIER_KEY) ?? null; }
726 return row.resolveItemId?.(tier) ?? null;
727}
728
729export function equipmentStatRowDefaultTier (section, row)
730{
731 for (const tier of section.tierOrder)
732 {
733 if (equipmentStatRowItemId(row, tier) != null)
734 { return tier; }
735 }
736 return section.tierOrder[0] ?? SINGLETON_TIER_KEY;
737}
738
739/** Display helper — re-export itemDefinition for callers that only import this module. */
740export { itemDefinition };