export type AgentAbilityId = 'kill'; export interface AgentAbilityState extends Record { id: AgentAbilityId; name: string; ready: boolean; cooldown_remaining_secs?: number; remaining_uses: number | null; effective_range_px?: number; status?: string; } const KILL_ROLES = new Set([ 'crab_generic', 'neutral_octopus', 'shrimp_warrior', 'shrimp_pistol', ]); const LONG_RANGE_KILL_ROLES = new Set([ 'shrimp_warrior', 'shrimp_pistol', ]); function finiteNumber(value: unknown): number | undefined { return typeof value === 'number' && Number.isFinite(value) ? value : undefined; } function nonEmptyString(value: unknown): string | undefined { return typeof value === 'string' && value.length > 0 ? value : undefined; } /** * Project only the stateful abilities that the current Game State can describe * authoritatively. Reporting/body interactions have no independent cooldown or * charge state in this contract, so they are intentionally absent. */ export function projectAgentAbilities(summary: Record): AgentAbilityState[] | undefined { const you = summary.you && typeof summary.you === 'object' && !Array.isArray(summary.you) ? summary.you as Record : null; if (!you) return undefined; const role = nonEmptyString(you.role); const alive = you.is_alive !== false; const actionablePhase = summary.phase === 'wandering'; const abilities: AgentAbilityState[] = []; const killCooldown = finiteNumber(you.kill_cooldown_secs); const killsRemaining = finiteNumber(you.kills_remaining); if ((role && KILL_ROLES.has(role)) || killCooldown !== undefined || killsRemaining !== undefined) { const remainingUses = killsRemaining === undefined ? null : Math.max(0, Math.trunc(killsRemaining)); abilities.push({ id: 'kill', name: role === 'shrimp_pistol' ? '攻击' : '击杀', ready: actionablePhase && alive && killCooldown !== undefined && killCooldown <= 0 && remainingUses !== 0, ...(killCooldown === undefined ? {} : { cooldown_remaining_secs: Math.max(0, killCooldown) }), remaining_uses: remainingUses, effective_range_px: role && LONG_RANGE_KILL_ROLES.has(role) ? 160 : 80, }); } return abilities.length > 0 ? abilities : undefined; }