import type { CharacterProfile } from "../app/types"; import type { ArenaActorSnapshot, ArenaAuthoritativeSnapshot } from "./arenaTypes"; export function controlledArenaActor(snapshot: ArenaAuthoritativeSnapshot | null, character: Pick | null): ArenaActorSnapshot | null { if (!snapshot) return null; return snapshot.actors.find((actor) => actor.id === snapshot.controlledActorId) ?? snapshot.actors.find((actor) => character && actor.characterId === character.id && !actor.isBot) ?? (snapshot.mode === "practice" ? snapshot.actors.find((actor) => actor.id === "practice-player") : null) ?? null; } export function arenaTargetActor(snapshot: ArenaAuthoritativeSnapshot | null, id: string | null): ArenaActorSnapshot | null { const player = snapshot?.actors.find((actor) => actor.id === id); if (player) return player; for (const owner of snapshot?.actors ?? []) { const summon = owner.combat?.summons.find((entry) => entry.id === id); if (summon) return { ...owner, id: summon.id, name: summon.name, position: summon.position, health: summon.health, maxHealth: summon.maxHealth, alive: summon.health > 0 }; } return null; } export function arenaIntentFeedback(reason?: string): string { return ({ "preparation": "Wait for the gates to open.", "invalid-target": "Select a living target.", "out-of-range": "Target is out of range.", "line-of-sight": "Target is out of sight.", "resource": "Not enough resource.", "cooldown": "Ability is not ready yet.", "already-casting": "Already casting.", "moving": "Stop moving to cast.", "controlled": "You cannot cast while controlled or silenced.", "not-learned": "That ability is not learned by this character.", "not-facing": "Face your target.", "must-be-behind": "Move behind your target.", "invalid-destination": "Choose a reachable location in range.", "insufficient-resource": "Not enough resource.", "school-locked": "That spell school is locked.", "player-controlled": "You cannot act while controlled.", "actor-unavailable": "You cannot act right now.", } as Record)[reason ?? ""] ?? "Unable to use that ability."; }