import { ABILITY_LABELS, SKILL_LABELS, fmtMod } from './format'; import type { GearEffect } from '../api/types'; // What a weapon or item can change on the sheet of whoever has it equipped. // Mirrors GEAR_STATS in backend/src/game/calculations.js; the server is what // applies them, this is only for naming them and offering them in a form. const ABILITIES = Object.keys(ABILITY_LABELS); const SKILLS = Object.keys(SKILL_LABELS); export const GEAR_STAT_GROUPS: { label: string; stats: string[] }[] = [ { label: 'Combat', stats: ['AC', 'SPEED', 'INITIATIVE', 'MAX_HP', 'PASSIVE_PERCEPTION'] }, { label: 'Ability scores', stats: ABILITIES }, { label: 'Saving throws', stats: ['SAVES', ...ABILITIES.map((a) => `SAVE_${a}`)] }, { label: 'Skills', stats: ['SKILLS', ...SKILLS.map((s) => `SKILL_${s}`)] }, ]; const FIXED_LABELS: Record = { AC: 'AC', SPEED: 'Speed', INITIATIVE: 'Initiative', MAX_HP: 'Max HP', PASSIVE_PERCEPTION: 'Passive Perception', SAVES: 'All saving throws', SKILLS: 'All skill checks', }; export function gearStatLabel(stat: string): string { if (FIXED_LABELS[stat]) return FIXED_LABELS[stat]; if (stat.startsWith('SAVE_')) return `${ABILITY_LABELS[stat.slice(5)] ?? stat} saves`; if (stat.startsWith('SKILL_')) return SKILL_LABELS[stat.slice(6)] ?? stat; return ABILITY_LABELS[stat] ?? stat; } // "+6 AC", "−10 Speed". export function effectLabel(effect: GearEffect): string { return `${fmtMod(effect.amount).replace('-', '−')} ${gearStatLabel(effect.stat)}`; } // "+6 AC · −10 Speed · Disadvantage on Stealth", or null when it does nothing. export function effectsSummary(effects: GearEffect[] | undefined, note?: string | null): string | null { const parts = [...(effects ?? []).map(effectLabel), ...(note ? [note] : [])]; return parts.length ? parts.join(' · ') : null; }