/** * Reads current stat values for the status menu from the live state. * * Health / max / xp / chill / conditions live on the figure; bless, curse, * empower and enfeeble live as modifier-deck cards — the server keeps their * counter in sync with the matching cards in the character's draw pile, so * counting the cards here mirrors the server's own computation. */ import type { CharacterItem, ModifierDeck, MonsterInstance } from '$lib/protocol/types'; /** * The wire `figureId` for a standee (a monster instance or a summon): the * reference app builds it as `name + gfx + standeeNr`. */ export function standeeFigureId(standee: MonsterInstance): string { return standee.name + standee.gfx + standee.standeeNr.toString(); } /** Count modifier cards matching [predicate] in the draw pile. */ function countCards( deck: ModifierDeck | undefined, predicate: (gfx: string) => boolean ): number { if (!deck?.drawPile) return 0; return deck.drawPile.filter((c) => c && predicate(c.gfx)).length; } /** * The stat counters for a character, keyed by the modifier-deck removable * name (which is also the `gfx` wire arg for empower/enfeeble). */ export function characterStatCounters( character: CharacterItem ): { bless: number; curse: number; empower: number; enfeeble: number; } { const deck = character.characterState.modifierDeck; return { bless: countCards(deck, (g) => g === 'bless'), curse: countCards(deck, (g) => g === 'curse'), empower: countCards(deck, (g) => g.includes('empower')), enfeeble: countCards(deck, (g) => g.includes('enfeeble')) }; } /** The stat counters for a standee (its owner's modifier deck). */ export function standeeStatCounters( deck: ModifierDeck | undefined ): { bless: number; curse: number; empower: number; enfeeble: number; } { return { bless: countCards(deck, (g) => g === 'bless'), curse: countCards(deck, (g) => g === 'curse'), empower: countCards(deck, (g) => g.includes('empower')), enfeeble: countCards(deck, (g) => g.includes('enfeeble')) }; }