import { ClawclawStrategy, type StrategyDecision, type StrategyInput, type ClawclawStrategyManifest, } from '@myclaw163/clawclaw-cli/strategy-plugin'; import { ClawclawPerception, type PerceptionModuleInput, type PerceptionModuleResult, } from '@myclaw163/clawclaw-cli/perception-plugin'; type Parameters = { readonly x: number; readonly y: number; }; /** The strategy executes when it is granted control. */ export default class AutoEscape extends ClawclawStrategy { static readonly manifest = { apiVersion: 3, id: 'community.auto-escape', description: '有人进入设定范围时,前往 Agent 指定的撤离点。靠近不等于对方有敌意。', execution: 'serial', inputs: [ { id: 'x', type: 'number', description: '当前地图上可达的撤离点 X。', default: 2708 }, { id: 'y', type: 'number', description: '当前地图上可达的撤离点 Y。', default: 2320 }, ], runtime: { defaultMs: 10000 }, } as const satisfies ClawclawStrategyManifest; private requestedGoal?: string; decide(input: Readonly>): StrategyDecision { const self = input.gameState.you; if (!self?.is_alive || self.x === undefined || self.y === undefined) return {}; const { x, y } = input.input; if (Math.hypot(self.x - x, self.y - y) < 30) { return { finish: { outcome: 'completed', reason: 'arrived' } }; } const goal = `${x}:${y}`; if (goal !== this.requestedGoal) { this.requestedGoal = goal; return { actions: [{ action: 'move', target_x: x, target_y: y }], status: { summary: '正在前往撤离点。', activity: 'moving' } }; } return { status: { summary: '等待权威位置确认到达撤离点。', activity: 'moving' } }; } } export class Trigger extends ClawclawPerception { static readonly manifest = { apiVersion: 3, id: 'community.nearby', description: '有玩家靠近时请求本策略撤离。', inputs: [{ id: 'triggerDistance', type: 'number', description: '触发距离(像素)。', default: 160, min: 1, max: 1000 }], strategies: { escape: { name: 'community.auto-escape', reflexPriority: 40, cooldownMs: 3000, rearm: 'after_clear', maxRuntimeMs: 10000 } }, } as const; evaluate(input: Readonly): PerceptionModuleResult { const players = input.frame?.observation.players ?? []; const self = players.find(player => player.observer); if (!self) return {}; const distance = Number(input.config.triggerDistance); const nearby = players.some(player => !player.observer && Math.hypot(player.x - self.x, player.y - self.y) <= distance); return { activations: nearby ? [{ strategy: 'escape', reason: 'player_nearby' }] : [] }; } }