@myclaw163/clawclaw-cli 0.8.5 → 0.8.7
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/README.md +1 -1
- package/docs/configuration.md +2 -1
- package/docs/custom-modules/behavior.md +7 -18
- package/docs/custom-modules/trigger.md +3 -4
- package/docs/runtime/short-commands-and-capabilities.md +1 -1
- package/package.json +9 -3
- package/scripts/find-hide-spots.py +2 -2
- package/skills/clawclaw/SKILL.md +17 -13
- package/skills/clawclaw/references/BEHAVIORS.md +13 -9
- package/skills/clawclaw/references/COMMANDS.md +17 -29
- package/skills/clawclaw/references/TACTICS.md +1 -1
- package/src/commands/load.ts +245 -14
- package/src/commands/trigger.ts +22 -13
- package/src/lib/capability-load-diagnostics.ts +182 -0
- package/src/lib/gameplay-config.ts +10 -0
- package/src/lib/hub-reminder.ts +3 -5
- package/src/lib/trigger-config.ts +2 -10
- package/src/runtime/clawclaw/behavior-read-api.ts +1 -1
- package/src/{strategies/pathfind → runtime/clawclaw/navigation}/astar-path.ts +1 -1
- package/src/{strategies/pathfind → runtime/clawclaw/navigation}/escape-planner.ts +1 -1
- package/src/{strategies → runtime/clawclaw/navigation}/hide-spots.ts +2 -2
- package/src/{strategies → runtime/clawclaw/navigation}/off-route-points.ts +6 -3
- package/src/{strategies/pathfind → runtime/clawclaw/navigation}/walkable-grid.ts +1 -1
- package/src/runtime/clawclaw/owner.ts +4 -6
- package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.ts +1 -1
- package/src/runtime/framework/modules/runtime-module-loader.ts +0 -54
- package/src/sdk/behavior-toolkit/escape.ts +2 -2
- package/scripts/build-official-hub-behaviors.mjs +0 -136
- package/scripts/build-official-hub-behaviors.test.mjs +0 -178
- package/scripts/compare-perception-replays.test.ts +0 -188
- package/scripts/enable_ccl_permissions.test.mjs +0 -167
- package/scripts/enable_monitor.test.mjs +0 -201
- package/scripts/sync-bundled-skill.test.mjs +0 -87
- package/scripts/watch-perception-events.test.ts +0 -43
- package/src/behaviors/official-finite/do-task.ts +0 -211
- package/src/behaviors/official-finite/evade.ts +0 -78
- package/src/behaviors/official-finite/find-player.ts +0 -50
- package/src/behaviors/official-finite/follow-player.ts +0 -70
- package/src/behaviors/official-finite/go-to.ts +0 -69
- package/src/behaviors/official-finite/hide-temporarily.ts +0 -77
- package/src/behaviors/official-finite/hold-position.ts +0 -48
- package/src/behaviors/official-finite/hunt-player.ts +0 -47
- package/src/behaviors/official-finite/index.ts +0 -44
- package/src/behaviors/official-finite/inspect-corpse.ts +0 -64
- package/src/behaviors/official-finite/patrol-area.ts +0 -80
- package/src/behaviors/official-finite/report-corpse.ts +0 -73
- package/src/behaviors/official-finite/seek-kill-opportunity.ts +0 -152
- package/src/behaviors/official-finite/shared.ts +0 -27
- package/src/hub-official-behaviors/kill-lone.ts +0 -138
- package/src/hub-official-behaviors/patrol.ts +0 -30
- package/src/hub-official-behaviors/shared.ts +0 -125
- package/src/hub-official-behaviors/task-only.ts +0 -158
- package/src/runtime/clawclaw/plugins/behavior/official-goal-behavior.ts +0 -757
- package/src/strategies/avoid-lone.ts +0 -32
- package/src/strategies/avoid-players.ts +0 -43
- package/src/strategies/corpse-patrol.ts +0 -50
- package/src/strategies/crab-sabotage.ts +0 -48
- package/src/strategies/find-player.ts +0 -49
- package/src/strategies/game-utils.ts +0 -927
- package/src/strategies/goals/anchor-linger.ts +0 -77
- package/src/strategies/goals/avoid-lone-top.ts +0 -189
- package/src/strategies/goals/avoid-players-top.ts +0 -122
- package/src/strategies/goals/conversation-goal.ts +0 -51
- package/src/strategies/goals/corpse-patrol-top.ts +0 -120
- package/src/strategies/goals/crab-octopus-reflexes.ts +0 -109
- package/src/strategies/goals/crab-sabotage-top.ts +0 -139
- package/src/strategies/goals/emergency-hunt-goal.ts +0 -40
- package/src/strategies/goals/find-player-top.ts +0 -136
- package/src/strategies/goals/flee-players-goal.ts +0 -55
- package/src/strategies/goals/follow-companion-goal.ts +0 -130
- package/src/strategies/goals/goal-manager.ts +0 -41
- package/src/strategies/goals/goal-root-strategy.ts +0 -49
- package/src/strategies/goals/goal.ts +0 -28
- package/src/strategies/goals/hide-top.ts +0 -240
- package/src/strategies/goals/keep-away-goal.ts +0 -243
- package/src/strategies/goals/kill-frenzy-top.ts +0 -90
- package/src/strategies/goals/kill-lone-top.ts +0 -166
- package/src/strategies/goals/kill-target-goal.ts +0 -69
- package/src/strategies/goals/kill-target-top.ts +0 -121
- package/src/strategies/goals/leaf-goal.ts +0 -27
- package/src/strategies/goals/linger-corpse-goal.ts +0 -43
- package/src/strategies/goals/lone-kill-core.ts +0 -86
- package/src/strategies/goals/lone-kill-goal.ts +0 -24
- package/src/strategies/goals/lone-kill-task-top.ts +0 -133
- package/src/strategies/goals/move-room-goal.ts +0 -102
- package/src/strategies/goals/normal-shrimp-top.ts +0 -248
- package/src/strategies/goals/paradise-fish-top.ts +0 -234
- package/src/strategies/goals/patrol-top.ts +0 -68
- package/src/strategies/goals/report-patrol-top.ts +0 -97
- package/src/strategies/goals/safe-task-goal.ts +0 -130
- package/src/strategies/goals/social-task-top.ts +0 -192
- package/src/strategies/goals/task-kill-report-top.ts +0 -187
- package/src/strategies/goals/task-only-top.ts +0 -64
- package/src/strategies/goals/task-or-patrol-goal.ts +0 -59
- package/src/strategies/goals/task-report-top.ts +0 -57
- package/src/strategies/goals/wander-task-goal.ts +0 -33
- package/src/strategies/goals/warrior-shrimp-top.ts +0 -293
- package/src/strategies/greeting.ts +0 -60
- package/src/strategies/hide.ts +0 -51
- package/src/strategies/kill-frenzy.ts +0 -32
- package/src/strategies/kill-lone.ts +0 -52
- package/src/strategies/kill-target.ts +0 -48
- package/src/strategies/lone-kill-task.ts +0 -48
- package/src/strategies/meeting-gate.ts +0 -28
- package/src/strategies/move-room.ts +0 -46
- package/src/strategies/paradise-fish.ts +0 -70
- package/src/strategies/patrol.ts +0 -32
- package/src/strategies/player-targets.ts +0 -18
- package/src/strategies/report-patrol.ts +0 -32
- package/src/strategies/shrimp-memory.ts +0 -87
- package/src/strategies/social-task.ts +0 -67
- package/src/strategies/speech-module.ts +0 -123
- package/src/strategies/task-kill-report.ts +0 -49
- package/src/strategies/task-only.ts +0 -34
- package/src/strategies/task-report.ts +0 -50
- package/src/strategies/types.ts +0 -116
- package/src/strategies/warrior-memory.ts +0 -54
- /package/src/{strategies/pathfind → runtime/clawclaw/navigation}/clawclaw-walkable.bin +0 -0
- /package/src/{strategies/pathfind → runtime/clawclaw/navigation}/distance-field.ts +0 -0
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import type { GameState, TaskInfo } from '../../sdk/types.js';
|
|
2
|
-
import {
|
|
3
|
-
approachOrDoTaskStep,
|
|
4
|
-
firstAvailableTask,
|
|
5
|
-
killCooldownSecs,
|
|
6
|
-
nonTeammatesVisible,
|
|
7
|
-
PatrolState,
|
|
8
|
-
PROGRESS_INTERVAL_MS,
|
|
9
|
-
} from '../game-utils.js';
|
|
10
|
-
import type { BehaviorDecision, StrategyContext } from '../types.js';
|
|
11
|
-
import { Goal } from './goal.js';
|
|
12
|
-
import { LoneKillCore } from './lone-kill-core.js';
|
|
13
|
-
import { LoneKillGoal } from './lone-kill-goal.js';
|
|
14
|
-
import { WanderTaskGoal } from './wander-task-goal.js';
|
|
15
|
-
import { EmergencyHuntGoal } from './emergency-hunt-goal.js';
|
|
16
|
-
import { emitLeaf, setBehavior, URGENT_GOAL_PRIORITY, WANDER_GOAL_PRIORITY } from './leaf-goal.js';
|
|
17
|
-
import { corpseReportWithNonTeammate, immediateLoneKillDecision } from './crab-octopus-reflexes.js';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* 蟹的「破坏 + 落单猎杀 + 任务伪装」编排 top。本身不产决策,每 tick 自上而下判定该走哪条分支、
|
|
21
|
-
* 把对应**叶子子目标**挂为唯一子目标(产出动作的是叶子;URGENT/WANDER 优先级供 ConversationGoal 判断):
|
|
22
|
-
*
|
|
23
|
-
* 0a. 反射·立刻出刀(crab-octopus-reflexes,URGENT):落单非队友贴脸(出刀范围内)且刀好 → 立刻出刀,
|
|
24
|
-
* 无视暂停窗口、不管自己是否正在做破坏任务。
|
|
25
|
-
* 0b. 反射·报尸(crab-octopus-reflexes,URGENT):有尸体且附近有非队友 → 报警/靠近报警,不管尸体是谁造成的。
|
|
26
|
-
* 1a. 服务端状态 ready → 去做真实破坏任务;完成后服务端自动触发一一对应的紧急任务。
|
|
27
|
-
* 1b. 正在做任务(doing_task)→ 本 tick 不产决策,不撇下任务去猎杀(0a 的贴脸反射刀仍生效)。
|
|
28
|
-
* 2. 落单猎杀(LoneKillGoal,URGENT):assess 判 hunt(刀好且有落单目标)→ 叶子 pursue;
|
|
29
|
-
* 刀在冷却时 assess 返回 idle,不追不等,直接下沉到破坏/任务/巡逻。
|
|
30
|
-
* 3. 紧急期搜猎(EmergencyHuntGoal,URGENT):往人少处找真正落单的,永远有动作(不在人前乱杀)。
|
|
31
|
-
* 4. 任务伪装 / 巡逻(WanderTaskGoal,WANDER):先真实任务再虾的伪装任务,跳过紧挨已知尸体的任务,没任务就巡逻。
|
|
32
|
-
*/
|
|
33
|
-
export class CrabSabotageTop extends Goal {
|
|
34
|
-
private readonly killCore = new LoneKillCore();
|
|
35
|
-
private readonly patrol = new PatrolState();
|
|
36
|
-
private readonly loneKillGoal = new LoneKillGoal(this.killCore);
|
|
37
|
-
private readonly emergencyHuntGoal = new EmergencyHuntGoal(this.killCore, this.patrol);
|
|
38
|
-
private readonly wanderGoal = new WanderTaskGoal(
|
|
39
|
-
(state, ctx) => {
|
|
40
|
-
const sabotageTask = this.shouldPrepareSabotage(state)
|
|
41
|
-
? firstAvailableTask(ctx.taskData, t => this.isWorkableTask(t) && !t.is_fake_shrimp, undefined, ctx.blockedMoveTarget, ctx.knownCorpses)
|
|
42
|
-
: null;
|
|
43
|
-
return sabotageTask
|
|
44
|
-
?? firstAvailableTask(ctx.taskData, t => this.isWorkableTask(t) && !!t.is_fake_shrimp, undefined, ctx.blockedMoveTarget, ctx.knownCorpses);
|
|
45
|
-
},
|
|
46
|
-
() => this.killCore.patrolStopOnPlayer(),
|
|
47
|
-
this.patrol,
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
onMeetingResume(): void {
|
|
51
|
-
this.killCore.reset();
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
tick(state: GameState, ctx: StrategyContext): BehaviorDecision[] {
|
|
55
|
-
this.emitProgress(state, ctx);
|
|
56
|
-
|
|
57
|
-
const immediateKill = immediateLoneKillDecision(state, ctx);
|
|
58
|
-
if (immediateKill) return emitLeaf(this, immediateKill, URGENT_GOAL_PRIORITY);
|
|
59
|
-
|
|
60
|
-
const corpseReport = corpseReportWithNonTeammate(state, ctx);
|
|
61
|
-
if (corpseReport) return emitLeaf(this, corpseReport, URGENT_GOAL_PRIORITY);
|
|
62
|
-
|
|
63
|
-
// 1a. ready 表示当前可执行蟹破坏任务;任务完成后服务端自动触发紧急任务。
|
|
64
|
-
const crabTask = this.tryCrabTask(state, ctx);
|
|
65
|
-
if (crabTask) return emitLeaf(this, crabTask, WANDER_GOAL_PRIORITY);
|
|
66
|
-
|
|
67
|
-
if (state.you.doing_task) {
|
|
68
|
-
if (this.subGoal) this.removeSubGoal();
|
|
69
|
-
return [];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// 2. 落单猎杀(紧急;紧急期 bypass 暂停窗口持续盯防)
|
|
73
|
-
const target = this.killCore.assess(state, ctx, { bypassIgnoreWindow: !!ctx.emergency });
|
|
74
|
-
if (target.kind === 'hunt') {
|
|
75
|
-
this.loneKillGoal.setTarget(target.target);
|
|
76
|
-
return setBehavior(this, this.loneKillGoal, URGENT_GOAL_PRIORITY);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// 3. 紧急期搜猎(紧急):虾群涌向维修点,蟹不做任务,往人少处找真正落单的(警报期照样会被举报,不在人前乱杀)
|
|
80
|
-
if (ctx.emergency) return setBehavior(this, this.emergencyHuntGoal, URGENT_GOAL_PRIORITY);
|
|
81
|
-
|
|
82
|
-
// 4. 任务伪装 / 巡逻(游走)
|
|
83
|
-
return setBehavior(this, this.wanderGoal, WANDER_GOAL_PRIORITY);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// ── 1a. 去做真实破坏任务(破坏点紧挨已知尸体时跳过;到点遇阻返回 null,让上层回退去猎杀)──
|
|
87
|
-
private tryCrabTask(state: GameState, ctx: StrategyContext): BehaviorDecision[] | null {
|
|
88
|
-
if (state.you.faction !== 'crab') return null;
|
|
89
|
-
if (ctx.emergency) return null;
|
|
90
|
-
if (state.you.doing_task) return null;
|
|
91
|
-
if (!this.shouldPrepareSabotage(state)) return null;
|
|
92
|
-
|
|
93
|
-
const task = firstAvailableTask(
|
|
94
|
-
ctx.taskData,
|
|
95
|
-
t => t.faction === 'crab' && !t.is_fake_shrimp,
|
|
96
|
-
undefined,
|
|
97
|
-
ctx.blockedMoveTarget,
|
|
98
|
-
ctx.knownCorpses,
|
|
99
|
-
);
|
|
100
|
-
if (task) return approachOrDoTaskStep(state, ctx, task, false);
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
private isWorkableTask(task: TaskInfo): boolean {
|
|
105
|
-
return task.status !== 'emergency';
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
private shouldPrepareSabotage(state: GameState): boolean {
|
|
109
|
-
return state.crab_sabotage?.status === 'ready';
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
private emitProgress(state: GameState, ctx: StrategyContext): void {
|
|
113
|
-
const now = Date.now();
|
|
114
|
-
if (now - ctx.lastProgressNotifyAt < PROGRESS_INTERVAL_MS) return;
|
|
115
|
-
ctx.lastProgressNotifyAt = now;
|
|
116
|
-
|
|
117
|
-
const room = state.you.room ?? '未知';
|
|
118
|
-
const cd = killCooldownSecs(state);
|
|
119
|
-
const killsRemaining = state.you.kills_remaining;
|
|
120
|
-
const nonTeammates = nonTeammatesVisible(state, ctx);
|
|
121
|
-
|
|
122
|
-
let msg = `[进度] 当前在${room}`;
|
|
123
|
-
if (nonTeammates.length === 0) {
|
|
124
|
-
msg += ',视野内没有落单目标,继续巡逻做任务。';
|
|
125
|
-
} else if (nonTeammates.length === 1) {
|
|
126
|
-
msg += `,视野内发现落单目标${nonTeammates[0].name}。`;
|
|
127
|
-
if (cd > 0) msg += `攻击冷却中(${cd}s),先做任务、冷却好再下手。`;
|
|
128
|
-
if (killsRemaining === 0) msg += '出刀次数已用完,继续巡逻做任务。';
|
|
129
|
-
} else {
|
|
130
|
-
msg += `,视野内有${nonTeammates.length}人,不适合动手。`;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (state.emergency) {
|
|
134
|
-
msg += ' 紧急警报进行中,往人少处找真正落单的目标,别在人前动手。';
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
ctx.notifications.push(msg);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { GameState } from '../../sdk/types.js';
|
|
2
|
-
import { Action } from '../../sdk/action.js';
|
|
3
|
-
import {
|
|
4
|
-
nonTeammatesVisible,
|
|
5
|
-
patrolStep,
|
|
6
|
-
PatrolState,
|
|
7
|
-
patrolStrategyIntent,
|
|
8
|
-
roomAwayFromPlayers,
|
|
9
|
-
strategyDecision,
|
|
10
|
-
} from '../game-utils.js';
|
|
11
|
-
import type { BehaviorDecision, StrategyContext } from '../types.js';
|
|
12
|
-
import { Goal } from './goal.js';
|
|
13
|
-
import type { LoneKillCore } from './lone-kill-core.js';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* 紧急(自己触发破坏警报)期间的搜猎子目标(叶子,由上层以 URGENT 优先级挂载):虾群涌向维修点,
|
|
17
|
-
* 蟹不做任务,朝人少方向走去抓真正掉队的——警报期杀人照样会被举报,所以不在人前乱杀、只清落单;
|
|
18
|
-
* 看不到非队友就按房间游走搜寻。永远有动作。
|
|
19
|
-
* stop_on_player 复用 core.patrolStopOnPlayer()(身边只有队友时别撞着队友停下)。
|
|
20
|
-
*/
|
|
21
|
-
export class EmergencyHuntGoal extends Goal {
|
|
22
|
-
constructor(
|
|
23
|
-
private readonly core: LoneKillCore,
|
|
24
|
-
private readonly patrol: PatrolState,
|
|
25
|
-
) {
|
|
26
|
-
super();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
tick(state: GameState, ctx: StrategyContext): BehaviorDecision[] {
|
|
30
|
-
const crowd = nonTeammatesVisible(state, ctx);
|
|
31
|
-
const room = roomAwayFromPlayers(state, ctx, crowd);
|
|
32
|
-
if (room) {
|
|
33
|
-
return [strategyDecision(
|
|
34
|
-
Action.move({ x: room.x, y: room.y }, false),
|
|
35
|
-
patrolStrategyIntent(room, '寻找落单目标'),
|
|
36
|
-
)];
|
|
37
|
-
}
|
|
38
|
-
return patrolStep(state, ctx, this.patrol, this.core.patrolStopOnPlayer(), '巡逻寻找落单目标');
|
|
39
|
-
}
|
|
40
|
-
}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import type { GameState } from '../../sdk/types.js';
|
|
2
|
-
import { Action } from '../../sdk/action.js';
|
|
3
|
-
import {
|
|
4
|
-
dist,
|
|
5
|
-
isTargetAlive,
|
|
6
|
-
nearestVisibleTarget,
|
|
7
|
-
PatrolState,
|
|
8
|
-
PATROL_REACHED_DISTANCE,
|
|
9
|
-
PROGRESS_INTERVAL_MS,
|
|
10
|
-
pursueVisibleTarget,
|
|
11
|
-
patrolStrategyIntent,
|
|
12
|
-
setStrategyIntent,
|
|
13
|
-
strategyDecision,
|
|
14
|
-
strategyPlayerLabel,
|
|
15
|
-
} from '../game-utils.js';
|
|
16
|
-
import type { BehaviorDecision, StrategyContext } from '../types.js';
|
|
17
|
-
import { Goal } from './goal.js';
|
|
18
|
-
|
|
19
|
-
const DEFAULT_TRACK_DISTANCE = 40;
|
|
20
|
-
const LAST_SEEN_ARRIVE = 20;
|
|
21
|
-
|
|
22
|
-
export class FindPlayerTop extends Goal {
|
|
23
|
-
private readonly patrol = new PatrolState();
|
|
24
|
-
private lastSeenX: number | null = null;
|
|
25
|
-
private lastSeenY: number | null = null;
|
|
26
|
-
private lastSeenRoom: string | null = null;
|
|
27
|
-
private foundNotified = false;
|
|
28
|
-
|
|
29
|
-
constructor(
|
|
30
|
-
private readonly target: number,
|
|
31
|
-
private readonly trackDistance: number = DEFAULT_TRACK_DISTANCE,
|
|
32
|
-
) {
|
|
33
|
-
super();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
tick(state: GameState, ctx: StrategyContext): BehaviorDecision[] {
|
|
37
|
-
if (!isTargetAlive(state, this.target, ctx)) {
|
|
38
|
-
ctx.notifications.push('目标已死亡');
|
|
39
|
-
setStrategyIntent(ctx, {
|
|
40
|
-
activity: 'idle',
|
|
41
|
-
summary: `${this.targetLabel(ctx)}已死亡,正在等待下一步指令。`,
|
|
42
|
-
targetPlayer: this.targetLabel(ctx),
|
|
43
|
-
});
|
|
44
|
-
this.emitProgress(state, ctx);
|
|
45
|
-
return [];
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const target = nearestVisibleTarget(state, ctx, [this.target]);
|
|
49
|
-
if (target) {
|
|
50
|
-
this.lastSeenX = target.x;
|
|
51
|
-
this.lastSeenY = target.y;
|
|
52
|
-
this.lastSeenRoom = target.room || null;
|
|
53
|
-
if (!this.foundNotified) {
|
|
54
|
-
this.foundNotified = true;
|
|
55
|
-
ctx.notifications.push('我已经牢牢跟住他了!');
|
|
56
|
-
}
|
|
57
|
-
const decision = pursueVisibleTarget(state, target, { kill: false, followDistance: this.trackDistance });
|
|
58
|
-
if (!decision) {
|
|
59
|
-
setStrategyIntent(ctx, {
|
|
60
|
-
activity: 'waiting',
|
|
61
|
-
summary: `正在${target.room || state.you.room || '当前位置'}贴近跟踪${strategyPlayerLabel(target)}。`,
|
|
62
|
-
...(target.room ? { room: target.room } : {}),
|
|
63
|
-
targetPlayer: target.name,
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
this.emitProgress(state, ctx);
|
|
67
|
-
return decision ? [decision] : [];
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
this.foundNotified = false;
|
|
71
|
-
|
|
72
|
-
if (this.lastSeenX != null && this.lastSeenY != null) {
|
|
73
|
-
if (dist(state.you.x, state.you.y, this.lastSeenX, this.lastSeenY) > LAST_SEEN_ARRIVE) {
|
|
74
|
-
this.emitProgress(state, ctx);
|
|
75
|
-
return [strategyDecision(Action.move({ x: this.lastSeenX, y: this.lastSeenY }), {
|
|
76
|
-
activity: 'moving',
|
|
77
|
-
summary: `正在前往${this.lastSeenRoom || '最后目击区域'}寻找${this.targetLabel(ctx)}。`,
|
|
78
|
-
...(this.lastSeenRoom ? { room: this.lastSeenRoom } : {}),
|
|
79
|
-
targetPlayer: this.targetLabel(ctx),
|
|
80
|
-
})];
|
|
81
|
-
}
|
|
82
|
-
this.lastSeenX = null;
|
|
83
|
-
this.lastSeenY = null;
|
|
84
|
-
this.lastSeenRoom = null;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
this.emitProgress(state, ctx);
|
|
88
|
-
return this.patrolDecision(state, ctx);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
private patrolDecision(state: GameState, ctx: StrategyContext): BehaviorDecision[] {
|
|
92
|
-
let room = this.patrol.nextRoom(ctx);
|
|
93
|
-
if (!room) {
|
|
94
|
-
setStrategyIntent(ctx, {
|
|
95
|
-
activity: 'waiting',
|
|
96
|
-
summary: `暂无可巡逻房间,正在等待${this.targetLabel(ctx)}出现。`,
|
|
97
|
-
targetPlayer: this.targetLabel(ctx),
|
|
98
|
-
});
|
|
99
|
-
return [];
|
|
100
|
-
}
|
|
101
|
-
if (dist(state.you.x, state.you.y, room.x, room.y) <= PATROL_REACHED_DISTANCE) {
|
|
102
|
-
this.patrol.advance(ctx);
|
|
103
|
-
const next = this.patrol.nextRoom(ctx);
|
|
104
|
-
if (next) room = next;
|
|
105
|
-
}
|
|
106
|
-
return [strategyDecision(
|
|
107
|
-
Action.move({ x: room.x, y: room.y }),
|
|
108
|
-
{
|
|
109
|
-
...patrolStrategyIntent(room, `巡逻寻找${this.targetLabel(ctx)}`),
|
|
110
|
-
targetPlayer: this.targetLabel(ctx),
|
|
111
|
-
},
|
|
112
|
-
)];
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
private targetLabel(ctx: StrategyContext): string {
|
|
116
|
-
const name = ctx.playerNamesBySeat[String(this.target)];
|
|
117
|
-
return name ? `${this.target}号${name}` : `${this.target}号`;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
private emitProgress(state: GameState, ctx: StrategyContext): void {
|
|
121
|
-
const now = Date.now();
|
|
122
|
-
if (now - ctx.lastProgressNotifyAt < PROGRESS_INTERVAL_MS) return;
|
|
123
|
-
ctx.lastProgressNotifyAt = now;
|
|
124
|
-
|
|
125
|
-
const room = state.you.room ?? '未知';
|
|
126
|
-
if (this.foundNotified) {
|
|
127
|
-
const t = nearestVisibleTarget(state, ctx, [this.target]);
|
|
128
|
-
const d = t ? (t.distance ?? dist(state.you.x, state.you.y, t.x, t.y)) : 0;
|
|
129
|
-
ctx.notifications.push(`[进度] 当前在${room},正在跟踪目标${this.target},距离${Math.round(d)}px。`);
|
|
130
|
-
} else if (this.lastSeenX != null) {
|
|
131
|
-
ctx.notifications.push(`[进度] 当前在${room},跟丢了,正赶往${this.target}最后出现的位置。`);
|
|
132
|
-
} else {
|
|
133
|
-
ctx.notifications.push(`[进度] 当前在${room},正在巡逻寻找${this.target}。`);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import type { GameState, PlayerInfo } from '../../sdk/types.js';
|
|
2
|
-
import { dist, hasReachedRoomTarget, resolveRoom, roomAwayFromPlayers } from '../game-utils.js';
|
|
3
|
-
import type { BehaviorDecision, StrategyContext } from '../types.js';
|
|
4
|
-
import { Goal } from './goal.js';
|
|
5
|
-
import { MoveRoomGoal } from './move-room-goal.js';
|
|
6
|
-
|
|
7
|
-
export type FleePlayerResolver = (state: GameState, ctx: StrategyContext) => PlayerInfo[];
|
|
8
|
-
|
|
9
|
-
export interface FleePlayersGoalOptions {
|
|
10
|
-
emitProgress?: boolean;
|
|
11
|
-
finishWhenEmpty?: boolean;
|
|
12
|
-
stopOnPlayer?: boolean;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export class FleePlayersGoal extends Goal {
|
|
16
|
-
constructor(
|
|
17
|
-
public readonly key: string,
|
|
18
|
-
private readonly resolvePlayers: FleePlayerResolver,
|
|
19
|
-
private readonly options: FleePlayersGoalOptions = {},
|
|
20
|
-
) {
|
|
21
|
-
super();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
tick(state: GameState, ctx: StrategyContext): BehaviorDecision[] {
|
|
25
|
-
const players = this.resolvePlayers(state, ctx);
|
|
26
|
-
const worker = this.subGoal;
|
|
27
|
-
if (worker instanceof MoveRoomGoal && this.canKeepTarget(worker, state, ctx, players)) return [];
|
|
28
|
-
|
|
29
|
-
const room = roomAwayFromPlayers(state, ctx, players);
|
|
30
|
-
if (!room) return [];
|
|
31
|
-
|
|
32
|
-
if (!(worker instanceof MoveRoomGoal) || worker.room !== room.name) {
|
|
33
|
-
if (this.subGoal) this.removeSubGoal();
|
|
34
|
-
const names = players.map(player => player.seat != null ? `${player.seat}号${player.name}` : player.name).join('、');
|
|
35
|
-
this.setSubGoal(new MoveRoomGoal(room.name, hasReachedRoomTarget, {
|
|
36
|
-
emitProgress: this.options.emitProgress ?? false,
|
|
37
|
-
stopOnPlayer: this.options.stopOnPlayer ?? false,
|
|
38
|
-
purpose: names ? `躲避${names}` : '躲避附近玩家',
|
|
39
|
-
}), 0.2);
|
|
40
|
-
}
|
|
41
|
-
return [];
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
isFinish(state: GameState, ctx: StrategyContext): boolean {
|
|
45
|
-
return (this.options.finishWhenEmpty ?? true) && this.resolvePlayers(state, ctx).length === 0;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
private canKeepTarget(worker: MoveRoomGoal, state: GameState, ctx: StrategyContext, players: PlayerInfo[]): boolean {
|
|
49
|
-
const target = resolveRoom(worker.room, ctx);
|
|
50
|
-
if (!target) return false;
|
|
51
|
-
if (hasReachedRoomTarget(state, target)) return true;
|
|
52
|
-
if (ctx.blockedMoveTarget && dist(target.x, target.y, ctx.blockedMoveTarget.x, ctx.blockedMoveTarget.y) <= 10) return false;
|
|
53
|
-
return !players.some(player => player.room?.toLowerCase() === target.name.toLowerCase());
|
|
54
|
-
}
|
|
55
|
-
}
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import type { GameState, PlayerInfo, Position } from '../../sdk/types.js';
|
|
2
|
-
import { Action } from '../../sdk/action.js';
|
|
3
|
-
import {
|
|
4
|
-
dist,
|
|
5
|
-
nearestPlayerByDistance,
|
|
6
|
-
playerStrategyIntent,
|
|
7
|
-
setStrategyIntent,
|
|
8
|
-
strategyDecision,
|
|
9
|
-
strategyPlayerLabel,
|
|
10
|
-
} from '../game-utils.js';
|
|
11
|
-
import type { BehaviorDecision, StrategyContext } from '../types.js';
|
|
12
|
-
import { AnchorLinger } from './anchor-linger.js';
|
|
13
|
-
import { Goal } from './goal.js';
|
|
14
|
-
|
|
15
|
-
/** 同伴移动时跟到这么近(px)就停手,不再补发移动,免得贴身打转;停住后改在锚点附近 40-100 游走。 */
|
|
16
|
-
const FOLLOW_STOP = 80;
|
|
17
|
-
/** 同伴本帧位置离上次记下的停留点小于这么多(px)就算「没动」。走路一步上百 px,远大于此。 */
|
|
18
|
-
const STILL_EPS = 30;
|
|
19
|
-
/** 同伴「没动」持续这么久(ms)就当作在做任务,切到在其停留点假装做任务(≈ 一个轮询间隔的余量)。 */
|
|
20
|
-
const PARKED_MS = 1500;
|
|
21
|
-
/** 距上次 tick 超过这么久(ms,被开会/高优先级行为打断)就重置跟踪,避免拿陈旧停留点误判同伴已停住。 */
|
|
22
|
-
const STALE_MS = 5000;
|
|
23
|
-
/** 同伴停留点离某个真实任务站点这么近(px)就以站点为晃荡中心,否则就地在停留点附近晃。 */
|
|
24
|
-
const TASK_ANCHOR_RANGE = 100;
|
|
25
|
-
|
|
26
|
-
type CompanionResolver = (state: GameState, ctx: StrategyContext) => PlayerInfo[];
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* 跟随可信同伴:同伴走动时跟在其身后,同伴停下(推断在做任务)时就在其停留点附近 40-100 px 游走
|
|
30
|
-
* 「假装做任务」,融入人群躲投票——天堂鱼无刀、不做任务,靠贴着可信同伴显得正常。无法直接观测他人
|
|
31
|
-
* 是否在做任务(PlayerInfo 不含 doing_task),故以「同伴位置连续 PARKED_MS 没动」作为代理判据。
|
|
32
|
-
* 任务点游走复用 AnchorLinger(与贴尸 LingerCorpseGoal 同一套粘性游走)。优先级由调用方(天堂鱼
|
|
33
|
-
* tick 的 if 链顺序)控制:排在贴尸游走之后,故跟随天然低于在尸体上晃荡。
|
|
34
|
-
*/
|
|
35
|
-
export class FollowCompanionGoal extends Goal {
|
|
36
|
-
private readonly wander = new AnchorLinger();
|
|
37
|
-
private mateKey = '';
|
|
38
|
-
private mateAnchor: Position | null = null;
|
|
39
|
-
private stillSince = 0;
|
|
40
|
-
private lastTickAt = 0;
|
|
41
|
-
|
|
42
|
-
constructor(
|
|
43
|
-
private readonly resolveCompanions: CompanionResolver,
|
|
44
|
-
private readonly resolveAvoid?: CompanionResolver,
|
|
45
|
-
) {
|
|
46
|
-
super();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
tick(state: GameState, ctx: StrategyContext): BehaviorDecision[] {
|
|
50
|
-
const now = Date.now();
|
|
51
|
-
const stale = now - this.lastTickAt > STALE_MS;
|
|
52
|
-
this.lastTickAt = now;
|
|
53
|
-
|
|
54
|
-
const mate = nearestPlayerByDistance(state, this.resolveCompanions(state, ctx));
|
|
55
|
-
if (!mate) {
|
|
56
|
-
this.resetTracking();
|
|
57
|
-
return [];
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const key = this.mateKeyOf(mate);
|
|
61
|
-
const moved = this.mateAnchor == null
|
|
62
|
-
|| dist(mate.x, mate.y, this.mateAnchor.x, this.mateAnchor.y) > STILL_EPS;
|
|
63
|
-
if (stale || this.mateKey !== key || moved) {
|
|
64
|
-
this.mateKey = key;
|
|
65
|
-
this.mateAnchor = { x: mate.x, y: mate.y };
|
|
66
|
-
this.stillSince = now;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (now - this.stillSince >= PARKED_MS) {
|
|
70
|
-
// 同伴停住够久(多半在做任务):优先以其附近真实任务站点为晃荡中心——更像在做任务、坐标也比同伴
|
|
71
|
-
// 上报位置稳;附近没有任务站点(如只是站着闲聊)就退回在停留点附近晃。旁边有要避开的人就偏到对侧。
|
|
72
|
-
const avoid = this.resolveAvoid?.(state, ctx) ?? [];
|
|
73
|
-
const spot = this.taskAnchorNear(ctx, this.mateAnchor!)
|
|
74
|
-
?? { x: this.mateAnchor!.x, y: this.mateAnchor!.y, key: `mate:${key}` };
|
|
75
|
-
return [strategyDecision(Action.move(this.wander.step(state, spot.key, spot, avoid)), {
|
|
76
|
-
activity: 'moving',
|
|
77
|
-
summary: `正在${mate.room || state.you.room || '当前位置'}陪同${strategyPlayerLabel(mate)}并伪装做任务。`,
|
|
78
|
-
...(mate.room ? { room: mate.room } : {}),
|
|
79
|
-
targetPlayer: mate.name,
|
|
80
|
-
})];
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// 同伴在移动:跟上去,跟到 FOLLOW_STOP 内就不再补发移动。
|
|
84
|
-
this.wander.reset();
|
|
85
|
-
const d = mate.distance ?? dist(state.you.x, state.you.y, mate.x, mate.y);
|
|
86
|
-
if (d > FOLLOW_STOP) {
|
|
87
|
-
return [strategyDecision(
|
|
88
|
-
Action.move({ x: mate.x, y: mate.y }),
|
|
89
|
-
playerStrategyIntent(mate, '跟随', 'moving'),
|
|
90
|
-
)];
|
|
91
|
-
}
|
|
92
|
-
setStrategyIntent(ctx, {
|
|
93
|
-
activity: 'waiting',
|
|
94
|
-
summary: `正在${mate.room || state.you.room || '当前位置'}陪同${strategyPlayerLabel(mate)}。`,
|
|
95
|
-
...(mate.room ? { room: mate.room } : {}),
|
|
96
|
-
targetPlayer: mate.name,
|
|
97
|
-
});
|
|
98
|
-
return [];
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
isFinish(state: GameState, ctx: StrategyContext): boolean {
|
|
102
|
-
return this.resolveCompanions(state, ctx).length === 0;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
private mateKeyOf(mate: PlayerInfo): string {
|
|
106
|
-
return mate.name || (mate.seat != null ? String(mate.seat) : `${Math.round(mate.x)},${Math.round(mate.y)}`);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/** 同伴停留点附近最近的真实任务站点(蟹的破坏点除外),带稳定 key 供 AnchorLinger 粘住游走。 */
|
|
110
|
-
private taskAnchorNear(ctx: StrategyContext, near: Position): { x: number; y: number; key: string } | null {
|
|
111
|
-
let best: { x: number; y: number; key: string } | null = null;
|
|
112
|
-
let bestD = TASK_ANCHOR_RANGE;
|
|
113
|
-
for (const t of ctx.taskLocations ?? []) {
|
|
114
|
-
if (t.faction === 'crab') continue;
|
|
115
|
-
const d = dist(near.x, near.y, t.x, t.y);
|
|
116
|
-
if (d <= bestD) {
|
|
117
|
-
best = { x: t.x, y: t.y, key: `task:${t.name}` };
|
|
118
|
-
bestD = d;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return best;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
private resetTracking(): void {
|
|
125
|
-
this.wander.reset();
|
|
126
|
-
this.mateKey = '';
|
|
127
|
-
this.mateAnchor = null;
|
|
128
|
-
this.stillSince = 0;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { GameState } from '../../sdk/types.js';
|
|
2
|
-
import type { BehaviorDecision, StrategyContext } from '../types.js';
|
|
3
|
-
import { Goal } from './goal.js';
|
|
4
|
-
|
|
5
|
-
export class GoalManager {
|
|
6
|
-
private top: Goal | null = null;
|
|
7
|
-
|
|
8
|
-
setTop(goal: Goal): void {
|
|
9
|
-
this.top = goal;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
getTop(): Goal | null {
|
|
13
|
-
return this.top;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
clear(): void {
|
|
17
|
-
this.top = null;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
tick(state: GameState, ctx: StrategyContext): BehaviorDecision[] {
|
|
21
|
-
const decisions: BehaviorDecision[] = [];
|
|
22
|
-
let parent: Goal | null = null;
|
|
23
|
-
let node: Goal | null = this.top;
|
|
24
|
-
|
|
25
|
-
while (node !== null) {
|
|
26
|
-
if (node.isFinish(state, ctx)) {
|
|
27
|
-
if (parent === null) {
|
|
28
|
-
this.top = null;
|
|
29
|
-
} else {
|
|
30
|
-
parent.removeSubGoal();
|
|
31
|
-
}
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
decisions.push(...node.tick(state, ctx));
|
|
35
|
-
parent = node;
|
|
36
|
-
node = node.subGoal;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return decisions;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { GameState } from '../../sdk/types.js';
|
|
2
|
-
import type { BehaviorDecision, CustomModule, Strategy, StrategyContext } from '../types.js';
|
|
3
|
-
import type { Goal } from './goal.js';
|
|
4
|
-
import { GoalManager } from './goal-manager.js';
|
|
5
|
-
|
|
6
|
-
export interface GoalRootStrategyOptions {
|
|
7
|
-
resetOnMeetingResume?: boolean;
|
|
8
|
-
customModules?: CustomModule[];
|
|
9
|
-
onUpdateRole?: (role: string) => void;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export class GoalRootStrategy implements Strategy {
|
|
13
|
-
readonly name: string;
|
|
14
|
-
private readonly mgr = new GoalManager();
|
|
15
|
-
private readonly makeTop: () => Goal;
|
|
16
|
-
private readonly resetOnMeetingResume: boolean;
|
|
17
|
-
private readonly modules: CustomModule[];
|
|
18
|
-
private readonly onUpdateRole?: (role: string) => void;
|
|
19
|
-
|
|
20
|
-
constructor(name: string, makeTop: () => Goal, options?: GoalRootStrategyOptions) {
|
|
21
|
-
this.name = name;
|
|
22
|
-
this.makeTop = makeTop;
|
|
23
|
-
this.resetOnMeetingResume = options?.resetOnMeetingResume ?? true;
|
|
24
|
-
this.modules = options?.customModules ?? [];
|
|
25
|
-
this.onUpdateRole = options?.onUpdateRole;
|
|
26
|
-
this.mgr.setTop(makeTop());
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
decide(state: GameState, ctx: StrategyContext): BehaviorDecision[] {
|
|
30
|
-
if (this.mgr.getTop() === null) this.mgr.setTop(this.makeTop());
|
|
31
|
-
return this.mgr.tick(state, ctx);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
onMeetingResume(): void {
|
|
35
|
-
if (this.resetOnMeetingResume) {
|
|
36
|
-
this.mgr.setTop(this.makeTop());
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
this.mgr.getTop()?.onMeetingResume();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
customModules(): CustomModule[] {
|
|
43
|
-
return this.modules;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
updateRole(role: string): void {
|
|
47
|
-
this.onUpdateRole?.(role);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { GameState } from '../../sdk/types.js';
|
|
2
|
-
import type { BehaviorDecision, StrategyContext } from '../types.js';
|
|
3
|
-
|
|
4
|
-
export abstract class Goal {
|
|
5
|
-
subGoal: Goal | null = null;
|
|
6
|
-
priority = 0;
|
|
7
|
-
|
|
8
|
-
abstract tick(state: GameState, ctx: StrategyContext): BehaviorDecision[];
|
|
9
|
-
|
|
10
|
-
isFinish(_state: GameState, _ctx: StrategyContext): boolean {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
onMeetingResume(): void {}
|
|
15
|
-
|
|
16
|
-
setSubGoal(child: Goal, priority: number): boolean {
|
|
17
|
-
if (this.subGoal !== null && this.subGoal.priority >= priority) {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
child.priority = priority;
|
|
21
|
-
this.subGoal = child;
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
removeSubGoal(): void {
|
|
26
|
-
this.subGoal = null;
|
|
27
|
-
}
|
|
28
|
-
}
|