@myclaw163/clawclaw-cli 0.8.40 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/custom-modules/README.md +6 -6
- package/docs/custom-modules/api-reference.md +42 -4
- package/docs/custom-modules/behavior.md +9 -3
- package/docs/custom-modules/examples/speech-reminder.ts +1 -1
- package/docs/custom-modules/examples/task-reminder.ts +1 -1
- package/docs/custom-modules/perception.md +756 -47
- package/docs/user-guide/README.md +50 -0
- package/docs/user-guide/api-reference.md +745 -0
- package/docs/user-guide/behavior.md +369 -0
- package/docs/user-guide/installation.md +123 -0
- package/docs/user-guide/perception.md +788 -0
- package/docs/user-guide/skill.md +67 -0
- package/package.json +4 -2
- package/skills/clawclaw/SKILL.md +6 -6
- package/skills/clawclaw/references/BEHAVIORS.md +1 -1
- package/skills/clawclaw/references/CUSTOM-BEHAVIOR-DEVELOPMENT.md +9 -3
- package/skills/clawclaw/references/CUSTOM-MODULE-API.md +42 -4
- package/skills/clawclaw/references/CUSTOM-MODULES.md +5 -5
- package/skills/clawclaw/references/CUSTOM-PERCEPTION-DEVELOPMENT.md +761 -47
- package/src/runtime/clawclaw/task-choice-projection.ts +19 -25
- package/src/sdk/behavior-plugin/index.ts +3 -0
- package/src/sdk/index.ts +2 -0
- package/src/sdk/module-input/index.ts +15 -1
- package/src/sdk/task-availability.ts +70 -0
- package/docs/custom-modules/perception-reactions.md +0 -189
- package/docs/custom-modules/perception-visual.md +0 -324
- package/docs/custom-modules/reminders.md +0 -168
- package/skills/clawclaw/references/CUSTOM-REACTION-DEVELOPMENT.md +0 -189
- package/skills/clawclaw/references/CUSTOM-REMINDER-DEVELOPMENT.md +0 -168
- package/skills/clawclaw/references/CUSTOM-VISUAL-PERCEPTION-DEVELOPMENT.md +0 -328
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { loadClawclawMapAsset } from '../../lib/game-context.js';
|
|
2
|
+
import { getCrabSabotageAvailability, getTaskAvailability } from '../../sdk/task-availability.js';
|
|
3
|
+
import type { GameState, GameTask, GameTaskKind } from '../../sdk/module-input/index.js';
|
|
2
4
|
|
|
3
5
|
type RecordValue = Readonly<Record<string, any>>;
|
|
4
6
|
const record = (value: unknown): RecordValue => value && typeof value === 'object' && !Array.isArray(value)
|
|
@@ -13,9 +15,7 @@ export function isCrabPlayer(game: unknown): boolean {
|
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
export function crabSabotageReady(game: unknown): boolean {
|
|
16
|
-
|
|
17
|
-
return sabotage.status === 'ready' && record(state.emergency).active !== true
|
|
18
|
-
&& !(typeof sabotage.cooldown_remaining_secs === 'number' && sabotage.cooldown_remaining_secs > 0);
|
|
18
|
+
return getCrabSabotageAvailability(record(game) as unknown as GameState).state === 'ready';
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
function staticTaskType(task: RecordValue): number | undefined {
|
|
@@ -46,15 +46,18 @@ function ongoingTask(game: unknown, task: RecordValue): boolean {
|
|
|
46
46
|
return activity.kind === 'task' && taskName(task) && taskName(task) === label(activity.task_name) ? true : false;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
/**
|
|
49
|
+
/** Preserve every assignment and attach a deterministic, bounded public availability projection. */
|
|
50
50
|
export function projectTaskChoices<T extends RecordValue>(game: unknown, tasks: readonly T[]): T[] {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
const state = record(game);
|
|
52
|
+
const projected = tasks.map(task => {
|
|
53
|
+
const kind: GameTaskKind = task.is_fake_shrimp === true ? 'fake_shrimp'
|
|
54
|
+
: isSabotageTask(game, task) ? 'sabotage'
|
|
55
|
+
: staticTaskType(task) === 2 || (record(state.emergency).active === true
|
|
56
|
+
&& taskName(task) === label(record(state.emergency).task_name)) ? 'emergency' : 'ordinary';
|
|
57
|
+
return { ...task, kind, ...(ongoingTask(game, task) && task.status !== 'completed' ? { status: 'in_progress' } : {}) };
|
|
57
58
|
});
|
|
59
|
+
const snapshot = { ...state, you: { ...record(state.you), tasks: projected } } as unknown as GameState;
|
|
60
|
+
return projected.map(task => ({ ...task, availability: getTaskAvailability(snapshot, task as unknown as GameTask) }) as T);
|
|
58
61
|
}
|
|
59
62
|
|
|
60
63
|
/** A public projection only. Persisted Source snapshots and task-change history remain untouched. */
|
|
@@ -64,23 +67,14 @@ export function projectTaskChoiceGameState<T extends Record<string, any>>(source
|
|
|
64
67
|
return game as T;
|
|
65
68
|
}
|
|
66
69
|
|
|
67
|
-
/**
|
|
68
|
-
export function projectTaskChoiceLocations<T extends RecordValue>(
|
|
69
|
-
return locations
|
|
70
|
+
/** Static map points remain visible; they are neither assignments nor a readiness claim. */
|
|
71
|
+
export function projectTaskChoiceLocations<T extends RecordValue>(_game: unknown, locations: readonly T[]): T[] {
|
|
72
|
+
return [...locations];
|
|
70
73
|
}
|
|
71
74
|
|
|
72
|
-
/**
|
|
73
|
-
export function projectTaskChoiceEventPayload(
|
|
74
|
-
|
|
75
|
-
if (type === 'tasks_changed') {
|
|
76
|
-
if (Array.isArray(result.tasks)) result.tasks = projectTaskChoices(game, result.tasks);
|
|
77
|
-
if (Array.isArray(result.delta)) result.delta = result.delta.filter(change =>
|
|
78
|
-
change.change === 'removed' || projectTaskChoices(game, [record(change.task)]).length > 0);
|
|
79
|
-
}
|
|
80
|
-
if (result.newly_assigned_task && projectTaskChoices(game, [record(result.newly_assigned_task)]).length === 0) {
|
|
81
|
-
delete result.newly_assigned_task;
|
|
82
|
-
}
|
|
83
|
-
return result;
|
|
75
|
+
/** Occurrence facts keep their original complete content; current readiness belongs to State. */
|
|
76
|
+
export function projectTaskChoiceEventPayload(_game: unknown, _type: string, payload: RecordValue): Record<string, any> {
|
|
77
|
+
return structuredClone(payload);
|
|
84
78
|
}
|
|
85
79
|
|
|
86
80
|
/** Also reject stale/remembered task names at the Action boundary, before HTTP submission. */
|
|
@@ -7,6 +7,9 @@ import type { ClawclawResourceLocalizations } from '../resource-metadata.js';
|
|
|
7
7
|
|
|
8
8
|
export const BEHAVIOR_PLUGIN_API_VERSION = 3 as const;
|
|
9
9
|
|
|
10
|
+
export { getTaskAvailability, getAvailableTasks, isTaskAvailable, getTaskKind } from '../task-availability.js';
|
|
11
|
+
export type { GameTaskAvailability, GameTaskKind } from '../module-input/index.js';
|
|
12
|
+
|
|
10
13
|
export {
|
|
11
14
|
hasValidClawclawResourceLocalizations,
|
|
12
15
|
resolveClawclawResourceMetadata,
|
package/src/sdk/index.ts
CHANGED
|
@@ -25,6 +25,8 @@
|
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
27
|
export { Action } from './action.js';
|
|
28
|
+
export { getTaskAvailability, getAvailableTasks, isTaskAvailable, getTaskKind } from './task-availability.js';
|
|
29
|
+
export type { GameTaskAvailability, GameTaskKind } from './module-input/index.js';
|
|
28
30
|
export { GameClient } from '../lib/game-client.js';
|
|
29
31
|
export type { GameClientConfig } from '../lib/game-client.js';
|
|
30
32
|
export type {
|
|
@@ -18,6 +18,17 @@ export interface GamePlayerActivity {
|
|
|
18
18
|
readonly target_y?: number;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
export type GameTaskKind = 'ordinary' | 'fake_shrimp' | 'sabotage' | 'emergency';
|
|
22
|
+
|
|
23
|
+
export interface GameTaskAvailability {
|
|
24
|
+
readonly state: 'ready' | 'cooldown' | 'blocked' | 'in_progress' | 'completed' | 'unknown';
|
|
25
|
+
readonly reason?: 'sabotage_cooldown' | 'emergency_active' | 'sabotage_state_unavailable'
|
|
26
|
+
| 'task_state_unavailable' | 'player_state_unavailable' | 'not_assigned' | 'not_alive'
|
|
27
|
+
| 'not_wandering' | 'emergency_inactive' | 'task_in_progress' | 'task_completed';
|
|
28
|
+
/** Authoritative shared cooldown, not an SDK wall-clock estimate. */
|
|
29
|
+
readonly remaining_secs?: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
21
32
|
export interface GameTask {
|
|
22
33
|
/** Stable task identity when the backend provides one. */
|
|
23
34
|
readonly task_id?: string;
|
|
@@ -29,6 +40,9 @@ export interface GameTask {
|
|
|
29
40
|
readonly is_fake_shrimp: boolean;
|
|
30
41
|
readonly status?: 'normal' | 'in_progress' | 'completed';
|
|
31
42
|
readonly task_note?: string;
|
|
43
|
+
/** CCL read projection; does not change the underlying assignment or execution status. */
|
|
44
|
+
readonly kind?: GameTaskKind;
|
|
45
|
+
readonly availability?: Readonly<GameTaskAvailability>;
|
|
32
46
|
}
|
|
33
47
|
|
|
34
48
|
export interface GameSelf {
|
|
@@ -44,7 +58,7 @@ export interface GameSelf {
|
|
|
44
58
|
readonly kills_remaining?: number | null;
|
|
45
59
|
readonly activity?: Readonly<GamePlayerActivity>;
|
|
46
60
|
readonly crab_teammates?: readonly Readonly<PlayerRef>[];
|
|
47
|
-
/**
|
|
61
|
+
/** Complete current assignments, including cooldown/blocked tasks and execution/completion facts. */
|
|
48
62
|
readonly tasks?: readonly Readonly<GameTask>[];
|
|
49
63
|
}
|
|
50
64
|
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { GameState, GameTask, GameTaskAvailability, GameTaskKind } from './module-input/index.js';
|
|
2
|
+
|
|
3
|
+
type TaskRef = Pick<GameTask, 'name'> & Partial<GameTask>;
|
|
4
|
+
const label = (value: string | undefined): string => value?.trim().normalize('NFC').toLocaleLowerCase() ?? '';
|
|
5
|
+
|
|
6
|
+
/** Task readiness is independent of distance; Action/server still validate actual execution. */
|
|
7
|
+
export function getCrabSabotageAvailability(state: Readonly<GameState>): GameTaskAvailability {
|
|
8
|
+
const sabotage = state.crab_sabotage;
|
|
9
|
+
if (state.emergency?.active === true || sabotage?.status === 'emergency_active') {
|
|
10
|
+
return { state: 'blocked', reason: 'emergency_active' };
|
|
11
|
+
}
|
|
12
|
+
const remaining = sabotage?.cooldown_remaining_secs;
|
|
13
|
+
if (sabotage?.status === 'cooldown_charged' || (typeof remaining === 'number' && remaining > 0)) {
|
|
14
|
+
return { state: 'cooldown', reason: 'sabotage_cooldown',
|
|
15
|
+
...(typeof remaining === 'number' && Number.isFinite(remaining) && remaining >= 0
|
|
16
|
+
? { remaining_secs: remaining } : {}) };
|
|
17
|
+
}
|
|
18
|
+
return sabotage?.status === 'ready'
|
|
19
|
+
? { state: 'ready' }
|
|
20
|
+
: { state: 'unknown', reason: 'sabotage_state_unavailable' };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getTaskKind(state: Readonly<GameState>, task: Readonly<TaskRef>): GameTaskKind {
|
|
24
|
+
if (task.kind) return task.kind;
|
|
25
|
+
if (task.is_fake_shrimp === true) return 'fake_shrimp';
|
|
26
|
+
if (state.emergency?.active === true && label(state.emergency.task_name) === label(task.name)) return 'emergency';
|
|
27
|
+
return (state.you?.faction === 'crab' || state.you?.role === 'crab_generic') && task.is_fake_shrimp === false
|
|
28
|
+
? 'sabotage' : 'ordinary';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Recompute from this snapshot, never from a cached task's availability/countdown. */
|
|
32
|
+
export function getTaskAvailability(state: Readonly<GameState>, task: Readonly<TaskRef> | string): GameTaskAvailability {
|
|
33
|
+
const tasks = state.you?.tasks;
|
|
34
|
+
if (!Array.isArray(tasks)) return { state: 'unknown', reason: 'task_state_unavailable' };
|
|
35
|
+
const requested = typeof task === 'string'
|
|
36
|
+
? tasks.find(candidate => label(candidate.name) === label(task) || (!!candidate.task_id && label(candidate.task_id) === label(task))) ?? { name: task }
|
|
37
|
+
: task;
|
|
38
|
+
const current = tasks.find(candidate => requested.task_id
|
|
39
|
+
? candidate.task_id === requested.task_id
|
|
40
|
+
: label(candidate.name) === label(requested.name)
|
|
41
|
+
&& (!requested.room || label(candidate.room) === label(requested.room))
|
|
42
|
+
&& (requested.x === undefined || candidate.x === requested.x)
|
|
43
|
+
&& (requested.y === undefined || candidate.y === requested.y));
|
|
44
|
+
if (!current) return { state: 'blocked', reason: 'not_assigned' };
|
|
45
|
+
if (current.status === 'completed') return { state: 'completed', reason: 'task_completed' };
|
|
46
|
+
if (state.you?.is_alive === false) return { state: 'blocked', reason: 'not_alive' };
|
|
47
|
+
if (state.you?.is_alive !== true || state.phase === undefined) return { state: 'unknown', reason: 'player_state_unavailable' };
|
|
48
|
+
if (state.phase !== 'wandering') return { state: 'blocked', reason: 'not_wandering' };
|
|
49
|
+
if (current.status === 'in_progress'
|
|
50
|
+
|| (state.you?.activity?.kind === 'task' && label(state.you.activity.task_name) === label(current.name))) {
|
|
51
|
+
return { state: 'in_progress', reason: 'task_in_progress' };
|
|
52
|
+
}
|
|
53
|
+
if (current.status !== 'normal') return { state: 'unknown', reason: 'task_state_unavailable' };
|
|
54
|
+
const kind = getTaskKind(state, current);
|
|
55
|
+
if (kind === 'sabotage') return getCrabSabotageAvailability(state);
|
|
56
|
+
if (kind === 'emergency' && (state.emergency?.active !== true || label(state.emergency.task_name) !== label(current.name))) {
|
|
57
|
+
return { state: 'blocked', reason: 'emergency_inactive' };
|
|
58
|
+
}
|
|
59
|
+
return { state: 'ready' };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Ready to select as a task goal; this does not imply that the player is already at its location. */
|
|
63
|
+
export function isTaskAvailable(state: Readonly<GameState>, task: Readonly<TaskRef> | string): boolean {
|
|
64
|
+
return getTaskAvailability(state, task).state === 'ready';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The full authoritative assignment list remains in you.tasks, including blocked tasks and facts. */
|
|
68
|
+
export function getAvailableTasks(state: Readonly<GameState>): readonly Readonly<GameTask>[] {
|
|
69
|
+
return (state.you?.tasks ?? []).filter(task => isTaskAvailable(state, task));
|
|
70
|
+
}
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
# 编写反应型感知
|
|
2
|
-
|
|
3
|
-
反应型感知使用 `ClawclawReaction`,根据当前可见信息或明确订阅的事件判断条件。它可以发送自己的通知,也可以请求启动已装配的策略。它不直接执行移动、击杀等动作。
|
|
4
|
-
|
|
5
|
-
如果你还不确定该选哪一类,先看[感知开发总览](./perception.md)。本文先给一个只通知的完整示例,再给同一条件下触发策略的版本;两份示例任选其一装配。
|
|
6
|
-
|
|
7
|
-
## 先写一个只通知的模块
|
|
8
|
-
|
|
9
|
-
规则是“存活且处于游荡阶段时,有其他可见玩家靠近到 160 像素内”。靠近只是一条可见事实,不代表对方有敌意。示例在条件首次成立时记录一条静默通知,条件持续成立时不重复发送。
|
|
10
|
-
|
|
11
|
-
将下面的完整文件保存为 `nearby-notice.ts`:
|
|
12
|
-
|
|
13
|
-
```ts
|
|
14
|
-
import {
|
|
15
|
-
ClawclawReaction,
|
|
16
|
-
type ReactionInput,
|
|
17
|
-
type ReactionResult,
|
|
18
|
-
} from '@myclaw163/clawclaw-cli/perception-plugin';
|
|
19
|
-
|
|
20
|
-
export default class NearbyNotice extends ClawclawReaction {
|
|
21
|
-
static readonly manifest = {
|
|
22
|
-
apiVersion: 2,
|
|
23
|
-
kind: 'reaction',
|
|
24
|
-
id: 'nearby_notice',
|
|
25
|
-
description: '其他可见玩家靠近时记录一条通知。',
|
|
26
|
-
consumes: [],
|
|
27
|
-
produces: ['reaction.player_close'],
|
|
28
|
-
inputs: [{ id: 'distance', type: 'number', description: '靠近阈值,单位像素。', default: 160 }],
|
|
29
|
-
config: { distance: 160 },
|
|
30
|
-
} as const;
|
|
31
|
-
|
|
32
|
-
evaluate(input: Readonly<ReactionInput>): ReactionResult {
|
|
33
|
-
const previous = input.state as { close?: boolean } | undefined;
|
|
34
|
-
const players = input.frame?.observation.players ?? [];
|
|
35
|
-
const self = players.find(player => player.observer);
|
|
36
|
-
const close = input.gameState?.phase === 'wandering' && input.gameState.you?.is_alive === true
|
|
37
|
-
&& !!self && players.some(player => !player.observer && player.alive !== false
|
|
38
|
-
&& Math.hypot(player.x - self.x, player.y - self.y) < Number(input.config.distance));
|
|
39
|
-
return {
|
|
40
|
-
state: { close },
|
|
41
|
-
events: close && !previous?.close ? [{
|
|
42
|
-
type: 'reaction.player_close',
|
|
43
|
-
key: `close:${input.gameState!.tick}`,
|
|
44
|
-
wakeAgent: false,
|
|
45
|
-
payload: { text: '有其他可见玩家靠近。' },
|
|
46
|
-
}] : [],
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
这里需要先理解四个地方:
|
|
53
|
-
|
|
54
|
-
- `manifest` 声明模块 ID、可能产生的事件和可配置参数。
|
|
55
|
-
- `evaluate(input)` 判断当前条件。`consumes: []` 表示不订阅事件,本例只检查可见帧。
|
|
56
|
-
- `events` 是这个模块自己的通知。改为 `wakeAgent: true` 才允许这条通知主动唤醒 Agent。
|
|
57
|
-
- 返回的 `state` 是下次调用的私有记忆。每次调用会创建新实例,因此不要用类字段记住上次结果,也不要修改只读的 `input.state`。
|
|
58
|
-
|
|
59
|
-
按[安装与验证](./perception.md#安装与验证)装配后,观察 `reaction.player_close`。离开距离阈值后再次靠近,才会产生新一次通知。
|
|
60
|
-
|
|
61
|
-
## 再增加策略触发
|
|
62
|
-
|
|
63
|
-
本例复用[策略教程中的前往指定位置策略](./behavior.md#先写一个完整策略),操作名为 `community.go-to-point`。当目标坐标由你选作撤离点时,它就可以执行“前往撤离点”这件事。它不会自动寻找安全位置,示例坐标也不保证适合当前地图。
|
|
64
|
-
|
|
65
|
-
先完成策略的装配,并按策略教程以 short 手动验证目标坐标可达。然后保存下面的完整文件为 `nearby-escape.ts`,替代上面的只通知示例:
|
|
66
|
-
|
|
67
|
-
```ts
|
|
68
|
-
import {
|
|
69
|
-
ClawclawReaction,
|
|
70
|
-
type ReactionInput,
|
|
71
|
-
type ReactionResult,
|
|
72
|
-
} from '@myclaw163/clawclaw-cli/perception-plugin';
|
|
73
|
-
|
|
74
|
-
// 教学规则:靠近不代表敌意;撤离点需先在当前地图中验证。
|
|
75
|
-
export default class NearbyEscape extends ClawclawReaction {
|
|
76
|
-
static readonly manifest = {
|
|
77
|
-
apiVersion: 2,
|
|
78
|
-
kind: 'reaction',
|
|
79
|
-
id: 'nearby_escape',
|
|
80
|
-
description: '可见玩家靠近时记录通知,并请求前往已配置的撤离点。',
|
|
81
|
-
consumes: [],
|
|
82
|
-
produces: ['reaction.player_close'],
|
|
83
|
-
behaviors: {
|
|
84
|
-
escape: {
|
|
85
|
-
name: 'community.go-to-point',
|
|
86
|
-
layer: 'reflex',
|
|
87
|
-
reflexPriority: 10,
|
|
88
|
-
cooldownMs: 3000,
|
|
89
|
-
rearm: 'after_clear',
|
|
90
|
-
maxRuntimeMs: 10000,
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
inputs: [
|
|
94
|
-
{ id: 'distance', type: 'number', description: '靠近阈值,单位像素。', default: 160 },
|
|
95
|
-
{ id: 'retreatX', type: 'number', description: '撤离点 X 坐标。', default: 640 },
|
|
96
|
-
{ id: 'retreatY', type: 'number', description: '撤离点 Y 坐标。', default: 360 },
|
|
97
|
-
],
|
|
98
|
-
config: { distance: 160, retreatX: 640, retreatY: 360 },
|
|
99
|
-
} as const;
|
|
100
|
-
|
|
101
|
-
evaluate(input: Readonly<ReactionInput>): ReactionResult {
|
|
102
|
-
const previous = input.state as { close?: boolean } | undefined;
|
|
103
|
-
const players = input.frame?.observation.players ?? [];
|
|
104
|
-
const self = players.find(player => player.observer);
|
|
105
|
-
const close = input.gameState?.phase === 'wandering' && input.gameState.you?.is_alive === true
|
|
106
|
-
&& !!self && players.some(player => !player.observer && player.alive !== false
|
|
107
|
-
&& Math.hypot(player.x - self.x, player.y - self.y) < Number(input.config.distance));
|
|
108
|
-
return {
|
|
109
|
-
state: { close },
|
|
110
|
-
events: close && !previous?.close ? [{
|
|
111
|
-
type: 'reaction.player_close',
|
|
112
|
-
key: `close:${input.gameState!.tick}`,
|
|
113
|
-
wakeAgent: false,
|
|
114
|
-
payload: { text: '有可见玩家靠近,触发撤离规则。' },
|
|
115
|
-
}] : [],
|
|
116
|
-
activations: close ? [{
|
|
117
|
-
behavior: 'escape',
|
|
118
|
-
input: { x: Number(input.config.retreatX), y: Number(input.config.retreatY) },
|
|
119
|
-
reason: 'visible_player_close',
|
|
120
|
-
}] : [],
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
配置中的 `retreatX`、`retreatY` 必须改成你选定并验证过的可达坐标。`distance` 决定何时触发;`retreatX`、`retreatY` 决定策略往哪里去。
|
|
127
|
-
|
|
128
|
-
`behaviors.escape` 是一个固定绑定,`activations[].behavior: 'escape'` 引用这个绑定。它以反射 `reflex` 运行策略,优先级高于 short 和 long。同一份策略代码也能由 Agent 以 short 启动;不存在另一种“反射策略基类”。
|
|
129
|
-
|
|
130
|
-
返回 `activations` 表示条件仍成立,不表示每帧重新启动。示例的 `after_clear` 要求条件先解除、再成立,才允许下一次成功触发;冷却时间限制两次成功触发的最短间隔。
|
|
131
|
-
|
|
132
|
-
## 策略依赖与缺失处理
|
|
133
|
-
|
|
134
|
-
示例中 `behaviors` 的键 `escape` 是模块内的绑定名,`activations[].behavior` 使用这个键。绑定中的 `name` 是本地策略操作名,不是 Hub 展示标题;`resourceId` 是可选的优先 Hub 资源 ID。
|
|
135
|
-
|
|
136
|
-
CCL 只在当前已装配、启用并可加载的策略中查找:先匹配 `resourceId`;没有匹配或没填写时,再匹配 `name` 及同一源码声明产生的重名别名。存在 `escape`、`escape_1` 时,若 `escape_1` 匹配 ID 就用它;两个都不匹配 ID 就用 `escape`;只有可用的 `escape_1` 就用它。用户修改/fork 导致资源 ID 变化时,仍可按同名继续使用。不会自动下载、装配策略或改写感知源码中的资源 ID。
|
|
137
|
-
|
|
138
|
-
缺少策略时,`ccl load` 返回 `PERCEPTION_BEHAVIOR_UNAVAILABLE` 配置警告,感知本身仍保留。运行中触发失败会发出 `perception.behavior_unavailable` 通知,跳过对应反应,保留模块自己的其他通知和反应;不会因此结束 CCL,也不会因缺少策略取消当前策略。同一持续故障不逐帧刷屏。补齐后重新 load,并按现有 Runtime 生效边界启用。
|
|
139
|
-
|
|
140
|
-
## 激活参数
|
|
141
|
-
|
|
142
|
-
| 字段 | 含义与默认值 |
|
|
143
|
-
|---|---|
|
|
144
|
-
| `name` | 必填,目标策略操作名或重名组的原名 |
|
|
145
|
-
| `resourceId` | 可选,优先匹配的 Hub 资源 ID;匹配不到仍按名字找 |
|
|
146
|
-
| `layer` | 默认 `reflex`;可显式指定 `short` 或 `long` |
|
|
147
|
-
| `input` | 固定策略参数,与动态 `activations[].input` 合并,动态值优先 |
|
|
148
|
-
| `reflexPriority` | 默认 0,只比较反射策略之间的优先级 |
|
|
149
|
-
| `cooldownMs` | 两次成功激活至少间隔多久,默认 1000ms |
|
|
150
|
-
| `rearm` | 默认 `after_clear`:条件先不成立,再成立才重触发;`after_cooldown` 允许持续条件在冷却后再次请求 |
|
|
151
|
-
| `maxRuntimeMs` | 最长运行时间;reflex/short 默认 10000ms,显式值为 1–120000ms;long 不填则没有此上限 |
|
|
152
|
-
|
|
153
|
-
控制顺序保持 `reflex > short > long`。同一绑定的 reflex 正在执行时不重复启动;其他 reflex 只有优先级严格更高才替换它。short 会暂停 long,结束后按原规则恢复。long 会替换主目标,因此只有需要更换主目标时才选它。原 Trigger 迁移默认使用 reflex。
|
|
154
|
-
|
|
155
|
-
## 输入和事件订阅
|
|
156
|
-
|
|
157
|
-
`evaluate(input)` 接收当前 `gameState`、可能为空的可见帧 `frame`、订阅事件 `events`、`nowMs`、`scope`、`config`、私有 `state` 和 `availableBehaviors`。
|
|
158
|
-
|
|
159
|
-
`consumes` 明确列出需要接收的事件,例如 `['visual.following', 'reminder.speech']`。它可以订阅后端、派生事件、视觉感知和提醒型感知的输出;当前不订阅其他反应型感知、策略或 `decision.*` 输出。同一事件会交给所有订阅模块,不会因为另一个模块先处理而看不见。
|
|
160
|
-
|
|
161
|
-
视觉感知与提醒型感知已经提供所需事实时,优先订阅它们;需要直接检查当前可见条件时,可以像示例一样读取 `frame`。输入字段缺失不表示事实不存在,无法取得所需信息时不要臆造触发条件。
|
|
162
|
-
|
|
163
|
-
## 输出、状态与运行边界
|
|
164
|
-
|
|
165
|
-
- 只通知:返回 `events`;只请求策略:返回 `activations`;也可以同时返回。
|
|
166
|
-
- 自己的通知使用声明过的 `reaction.*` 类型,带稳定的 `key` 和 `payload.text`。`wakeAgent` 省略时为 true,静默通知必须显式写 false。
|
|
167
|
-
- 通知不会改写原始事件的唤醒规则。策略是否运行与这条通知是否唤醒也是两个独立结果,见[通知与唤醒](./perception.md#通知唤醒和策略触发是三件事)。
|
|
168
|
-
- 返回 `state` 保存下一次计算所需的私有记忆,Host 随已提交结果保存检查点。同一作用域有可用检查点时可以恢复;新游戏、阶段变化或无法取得有效游戏状态等边界会重置条件记忆。它不是游戏状态或跨对局存储,恢复不会重放旧事件来触发策略。
|
|
169
|
-
- 不返回某个绑定的激活请求,表示该绑定的条件已解除。只有存活的游荡阶段允许激活;准备期间已过期的请求不会执行。
|
|
170
|
-
- 每次最多输出 32 条通知和 16 个激活请求,整个结果最多 128000 字节;同一绑定每次只能有一个请求。
|
|
171
|
-
- 脚本超时或输出非法时,停止该反应模块并发出 `perception.reaction_failed`;其他模块继续运行。
|
|
172
|
-
|
|
173
|
-
## 怎样验证两份文件确实配合起来
|
|
174
|
-
|
|
175
|
-
1. `ccl load` 中同时有感知和目标策略;检查 `behavior_dependencies` 的实际匹配结果。
|
|
176
|
-
2. 新 Runtime 中条件成立后,查看 `ccl behavior status`,确认当前策略的 ID 与 `layer: reflex`。
|
|
177
|
-
3. 看后续位置变化确认策略实际移动;看到通知不能证明已经撤离。
|
|
178
|
-
4. 策略完成后,检查下层仍有效的策略是否按规则恢复;持续满足同一条件时,不应每帧重启反射。
|
|
179
|
-
5. 缺依赖时,核对警告指出的是哪个绑定;其他通知和模块应继续工作。
|
|
180
|
-
|
|
181
|
-
## 已有独立触发器怎样迁移
|
|
182
|
-
|
|
183
|
-
将旧 `evaluate(frame, api)` 的条件判断改为 `ClawclawReaction.evaluate(input)`;把旧绑定、默认参数、优先级、冷却和重装条件放进 `behaviors`,命中时返回 `activations`。旧脚本仍可通过原 Trigger 入口运行;已装配的 reaction 若保留同一个源码 `id`,CCL 只运行新感知,不再同时执行同 ID 的旧 Trigger。若迁移时改了 ID,请手动停用旧 Trigger,避免两套不同规则同时触发。
|
|
184
|
-
|
|
185
|
-
## 继续阅读
|
|
186
|
-
|
|
187
|
-
- [感知开发总览与安装](./perception.md)
|
|
188
|
-
- [策略:长期、短期和反射](./behavior.md)
|
|
189
|
-
- [公共 API 参考](./api-reference.md)
|