@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.
Files changed (119) hide show
  1. package/README.md +1 -1
  2. package/docs/configuration.md +2 -1
  3. package/docs/custom-modules/behavior.md +7 -18
  4. package/docs/custom-modules/trigger.md +3 -4
  5. package/docs/runtime/short-commands-and-capabilities.md +1 -1
  6. package/package.json +9 -3
  7. package/scripts/find-hide-spots.py +2 -2
  8. package/skills/clawclaw/SKILL.md +17 -13
  9. package/skills/clawclaw/references/BEHAVIORS.md +13 -9
  10. package/skills/clawclaw/references/COMMANDS.md +17 -29
  11. package/skills/clawclaw/references/TACTICS.md +1 -1
  12. package/src/commands/load.ts +245 -14
  13. package/src/commands/trigger.ts +22 -13
  14. package/src/lib/capability-load-diagnostics.ts +182 -0
  15. package/src/lib/gameplay-config.ts +10 -0
  16. package/src/lib/hub-reminder.ts +3 -5
  17. package/src/lib/trigger-config.ts +2 -10
  18. package/src/runtime/clawclaw/behavior-read-api.ts +1 -1
  19. package/src/{strategies/pathfind → runtime/clawclaw/navigation}/astar-path.ts +1 -1
  20. package/src/{strategies/pathfind → runtime/clawclaw/navigation}/escape-planner.ts +1 -1
  21. package/src/{strategies → runtime/clawclaw/navigation}/hide-spots.ts +2 -2
  22. package/src/{strategies → runtime/clawclaw/navigation}/off-route-points.ts +6 -3
  23. package/src/{strategies/pathfind → runtime/clawclaw/navigation}/walkable-grid.ts +1 -1
  24. package/src/runtime/clawclaw/owner.ts +4 -6
  25. package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.ts +1 -1
  26. package/src/runtime/framework/modules/runtime-module-loader.ts +0 -54
  27. package/src/sdk/behavior-toolkit/escape.ts +2 -2
  28. package/scripts/build-official-hub-behaviors.mjs +0 -136
  29. package/scripts/build-official-hub-behaviors.test.mjs +0 -178
  30. package/scripts/compare-perception-replays.test.ts +0 -188
  31. package/scripts/enable_ccl_permissions.test.mjs +0 -167
  32. package/scripts/enable_monitor.test.mjs +0 -201
  33. package/scripts/sync-bundled-skill.test.mjs +0 -87
  34. package/scripts/watch-perception-events.test.ts +0 -43
  35. package/src/behaviors/official-finite/do-task.ts +0 -211
  36. package/src/behaviors/official-finite/evade.ts +0 -78
  37. package/src/behaviors/official-finite/find-player.ts +0 -50
  38. package/src/behaviors/official-finite/follow-player.ts +0 -70
  39. package/src/behaviors/official-finite/go-to.ts +0 -69
  40. package/src/behaviors/official-finite/hide-temporarily.ts +0 -77
  41. package/src/behaviors/official-finite/hold-position.ts +0 -48
  42. package/src/behaviors/official-finite/hunt-player.ts +0 -47
  43. package/src/behaviors/official-finite/index.ts +0 -44
  44. package/src/behaviors/official-finite/inspect-corpse.ts +0 -64
  45. package/src/behaviors/official-finite/patrol-area.ts +0 -80
  46. package/src/behaviors/official-finite/report-corpse.ts +0 -73
  47. package/src/behaviors/official-finite/seek-kill-opportunity.ts +0 -152
  48. package/src/behaviors/official-finite/shared.ts +0 -27
  49. package/src/hub-official-behaviors/kill-lone.ts +0 -138
  50. package/src/hub-official-behaviors/patrol.ts +0 -30
  51. package/src/hub-official-behaviors/shared.ts +0 -125
  52. package/src/hub-official-behaviors/task-only.ts +0 -158
  53. package/src/runtime/clawclaw/plugins/behavior/official-goal-behavior.ts +0 -757
  54. package/src/strategies/avoid-lone.ts +0 -32
  55. package/src/strategies/avoid-players.ts +0 -43
  56. package/src/strategies/corpse-patrol.ts +0 -50
  57. package/src/strategies/crab-sabotage.ts +0 -48
  58. package/src/strategies/find-player.ts +0 -49
  59. package/src/strategies/game-utils.ts +0 -927
  60. package/src/strategies/goals/anchor-linger.ts +0 -77
  61. package/src/strategies/goals/avoid-lone-top.ts +0 -189
  62. package/src/strategies/goals/avoid-players-top.ts +0 -122
  63. package/src/strategies/goals/conversation-goal.ts +0 -51
  64. package/src/strategies/goals/corpse-patrol-top.ts +0 -120
  65. package/src/strategies/goals/crab-octopus-reflexes.ts +0 -109
  66. package/src/strategies/goals/crab-sabotage-top.ts +0 -139
  67. package/src/strategies/goals/emergency-hunt-goal.ts +0 -40
  68. package/src/strategies/goals/find-player-top.ts +0 -136
  69. package/src/strategies/goals/flee-players-goal.ts +0 -55
  70. package/src/strategies/goals/follow-companion-goal.ts +0 -130
  71. package/src/strategies/goals/goal-manager.ts +0 -41
  72. package/src/strategies/goals/goal-root-strategy.ts +0 -49
  73. package/src/strategies/goals/goal.ts +0 -28
  74. package/src/strategies/goals/hide-top.ts +0 -240
  75. package/src/strategies/goals/keep-away-goal.ts +0 -243
  76. package/src/strategies/goals/kill-frenzy-top.ts +0 -90
  77. package/src/strategies/goals/kill-lone-top.ts +0 -166
  78. package/src/strategies/goals/kill-target-goal.ts +0 -69
  79. package/src/strategies/goals/kill-target-top.ts +0 -121
  80. package/src/strategies/goals/leaf-goal.ts +0 -27
  81. package/src/strategies/goals/linger-corpse-goal.ts +0 -43
  82. package/src/strategies/goals/lone-kill-core.ts +0 -86
  83. package/src/strategies/goals/lone-kill-goal.ts +0 -24
  84. package/src/strategies/goals/lone-kill-task-top.ts +0 -133
  85. package/src/strategies/goals/move-room-goal.ts +0 -102
  86. package/src/strategies/goals/normal-shrimp-top.ts +0 -248
  87. package/src/strategies/goals/paradise-fish-top.ts +0 -234
  88. package/src/strategies/goals/patrol-top.ts +0 -68
  89. package/src/strategies/goals/report-patrol-top.ts +0 -97
  90. package/src/strategies/goals/safe-task-goal.ts +0 -130
  91. package/src/strategies/goals/social-task-top.ts +0 -192
  92. package/src/strategies/goals/task-kill-report-top.ts +0 -187
  93. package/src/strategies/goals/task-only-top.ts +0 -64
  94. package/src/strategies/goals/task-or-patrol-goal.ts +0 -59
  95. package/src/strategies/goals/task-report-top.ts +0 -57
  96. package/src/strategies/goals/wander-task-goal.ts +0 -33
  97. package/src/strategies/goals/warrior-shrimp-top.ts +0 -293
  98. package/src/strategies/greeting.ts +0 -60
  99. package/src/strategies/hide.ts +0 -51
  100. package/src/strategies/kill-frenzy.ts +0 -32
  101. package/src/strategies/kill-lone.ts +0 -52
  102. package/src/strategies/kill-target.ts +0 -48
  103. package/src/strategies/lone-kill-task.ts +0 -48
  104. package/src/strategies/meeting-gate.ts +0 -28
  105. package/src/strategies/move-room.ts +0 -46
  106. package/src/strategies/paradise-fish.ts +0 -70
  107. package/src/strategies/patrol.ts +0 -32
  108. package/src/strategies/player-targets.ts +0 -18
  109. package/src/strategies/report-patrol.ts +0 -32
  110. package/src/strategies/shrimp-memory.ts +0 -87
  111. package/src/strategies/social-task.ts +0 -67
  112. package/src/strategies/speech-module.ts +0 -123
  113. package/src/strategies/task-kill-report.ts +0 -49
  114. package/src/strategies/task-only.ts +0 -34
  115. package/src/strategies/task-report.ts +0 -50
  116. package/src/strategies/types.ts +0 -116
  117. package/src/strategies/warrior-memory.ts +0 -54
  118. /package/src/{strategies/pathfind → runtime/clawclaw/navigation}/clawclaw-walkable.bin +0 -0
  119. /package/src/{strategies/pathfind → runtime/clawclaw/navigation}/distance-field.ts +0 -0
@@ -1,97 +0,0 @@
1
- import type { GameState } from '../../sdk/types.js';
2
- import { Action } from '../../sdk/action.js';
3
- import {
4
- nearestKnownCorpse,
5
- nearestReportableCorpse,
6
- patrolStep,
7
- PatrolState,
8
- PROGRESS_INTERVAL_MS,
9
- strategyDecision,
10
- } from '../game-utils.js';
11
- import type { BehaviorDecision, StrategyContext } from '../types.js';
12
- import { Goal } from './goal.js';
13
-
14
- export class ReportPatrolTop extends Goal {
15
- private readonly patrol = new PatrolState();
16
- private lastCorpseNotified = false;
17
-
18
- tick(state: GameState, ctx: StrategyContext): BehaviorDecision[] {
19
- const reportDecision = this.tryReport(state, ctx);
20
- if (reportDecision) {
21
- this.emitProgress(state, ctx);
22
- return [reportDecision];
23
- }
24
-
25
- const decisions = this.patrolDecision(state, ctx);
26
- this.emitProgress(state, ctx);
27
- return decisions;
28
- }
29
-
30
- private tryReport(state: GameState, ctx: StrategyContext): BehaviorDecision | null {
31
- // 章鱼时间禁用报尸:不报、也不靠近尸体准备报告,落回巡逻(生存优先)。这条路径不走 reportCorpseDecision,需单独短路。
32
- if (ctx.octopusTimeActive) {
33
- this.lastCorpseNotified = false;
34
- ctx.reportCorpseTarget = null;
35
- return null;
36
- }
37
- const reportable = nearestReportableCorpse(state);
38
- if (reportable) {
39
- ctx.reportCorpseTarget = null;
40
- this.lastCorpseNotified = false;
41
- ctx.notifications.push('发现尸体,正在报告!');
42
- const room = reportable.room || state.you.room || '当前位置';
43
- return strategyDecision(Action.report(reportable.name, reportable.room), {
44
- activity: 'acting',
45
- summary: `正在报告${room}的${reportable.name ? `${reportable.name}的尸体` : '尸体'}。`,
46
- ...(reportable.room ? { room: reportable.room } : {}),
47
- });
48
- }
49
-
50
- const corpse = nearestKnownCorpse(state, ctx);
51
- if (corpse) {
52
- if (!this.lastCorpseNotified) {
53
- this.lastCorpseNotified = true;
54
- const label = corpse.name ? `${corpse.name}的尸体` : '尸体';
55
- ctx.notifications.push(`视野内发现${label},正在靠近准备报告。`);
56
- }
57
- ctx.reportCorpseTarget = corpse;
58
- const room = corpse.room || state.you.room || '当前位置';
59
- return strategyDecision(Action.move({ x: corpse.x, y: corpse.y }), {
60
- activity: 'moving',
61
- summary: `正在靠近${room}的${corpse.name ? `${corpse.name}的尸体` : '尸体'},准备报告。`,
62
- ...(corpse.room ? { room: corpse.room } : {}),
63
- });
64
- }
65
-
66
- this.lastCorpseNotified = false;
67
- ctx.reportCorpseTarget = null;
68
- return null;
69
- }
70
-
71
- private patrolDecision(state: GameState, ctx: StrategyContext): BehaviorDecision[] {
72
- if (state.you.doing_task) return [];
73
- return patrolStep(state, ctx, this.patrol, false, '巡逻寻找尸体');
74
- }
75
-
76
- private emitProgress(state: GameState, ctx: StrategyContext): void {
77
- const now = Date.now();
78
- if (now - ctx.lastProgressNotifyAt < PROGRESS_INTERVAL_MS) return;
79
- ctx.lastProgressNotifyAt = now;
80
-
81
- const room = state.you.room ?? '未知';
82
- const target = this.patrol.nextRoom(ctx);
83
-
84
- let msg = `[进度] 当前在${room}`;
85
- if (ctx.reportCorpseTarget) {
86
- const label = ctx.reportCorpseTarget.name ?? '未知';
87
- msg += `,正在靠近${label}的尸体准备报告。`;
88
- } else if (target) {
89
- msg += `,巡逻中,正在前往${target.name}寻找尸体。`;
90
- } else {
91
- msg += ',巡逻中。';
92
- }
93
- msg += ` 共${ctx.rooms.length}个房间。`;
94
-
95
- ctx.notifications.push(msg);
96
- }
97
- }
@@ -1,130 +0,0 @@
1
- import type { GameState, Position, TaskInfo } from '../../sdk/types.js';
2
- import { Action } from '../../sdk/action.js';
3
- import {
4
- dist,
5
- nearestSafeTask,
6
- patrolStrategyIntent,
7
- PATROL_REACHED_DISTANCE,
8
- PatrolState,
9
- setStrategyIntent,
10
- strategyDecision,
11
- taskMoveDecision,
12
- } from '../game-utils.js';
13
- import type { BehaviorDecision, StrategyContext } from '../types.js';
14
- import { Goal } from './goal.js';
15
-
16
- export type ThreatPointResolver = (state: GameState, ctx: StrategyContext) => Position[];
17
- const NON_CRAB = (t: TaskInfo) => t.faction !== 'crab';
18
-
19
- export interface SafeTaskPlanOptions {
20
- holdUnsafeCurrentForMs?: number;
21
- }
22
-
23
- /**
24
- * 进阶普通虾的劳作循环:与 TaskOrPatrolGoal 同构,但任务选择换成 nearestSafeTask——
25
- * 测地最近、威胁硬排除(任务点旁有威胁,或必经之路经过威胁附近都不选)、带粘性
26
- * (当前任务仍合法就不换,杜绝摇摆;路被把守时粘性失效自动换任务)。
27
- * 全部任务被排除或做完时按房间顺序巡逻。
28
- */
29
- export class SafeTaskOrPatrolGoal extends Goal {
30
- private readonly patrol = new PatrolState();
31
- private current: TaskInfo | null = null;
32
- private holdUnsafeCurrentUntil = 0;
33
-
34
- constructor(private readonly threatPoints: ThreatPointResolver) {
35
- super();
36
- }
37
-
38
- /** 当前粘住的任务,供调用方播报进度(逃跑期间也能看到将回归的任务)。 */
39
- get currentTask(): TaskInfo | null {
40
- return this.current;
41
- }
42
-
43
- /** Refresh the remembered task without issuing a task move. Safe to call while fleeing. */
44
- planTask(state: GameState, ctx: StrategyContext, opts: SafeTaskPlanOptions = {}): TaskInfo | null {
45
- if (opts.holdUnsafeCurrentForMs != null) {
46
- this.holdUnsafeCurrentUntil = Math.max(this.holdUnsafeCurrentUntil, Date.now() + opts.holdUnsafeCurrentForMs);
47
- }
48
- if (state.you.doing_task) return this.current;
49
-
50
- const task = nearestSafeTask(state, ctx.taskData, NON_CRAB, ctx.emergency, ctx.blockedMoveTarget, ctx.knownCorpses, {
51
- threatPoints: this.threatPoints(state, ctx),
52
- stickyTaskName: this.current?.task_name ?? null,
53
- routeEvidence: ctx.routeEvidence,
54
- });
55
- this.current = task;
56
- return task;
57
- }
58
-
59
- tick(state: GameState, ctx: StrategyContext): BehaviorDecision[] {
60
- if (state.you.doing_task) return [];
61
-
62
- const locked = this.current ? this.safeCurrentTask(state, ctx) : this.planTask(state, ctx);
63
- if (locked) {
64
- this.current = locked;
65
- return [taskMoveDecision(state, ctx, locked)];
66
- }
67
-
68
- if (this.current) {
69
- const remembered = this.findCurrentTask(ctx);
70
- if (remembered && this.isStillAssignable(remembered, ctx) && Date.now() < this.holdUnsafeCurrentUntil) {
71
- setStrategyIntent(ctx, {
72
- activity: 'waiting',
73
- summary: `前往${remembered.room}执行任务“${remembered.task_name}”的路线暂不安全,正在等待。`,
74
- room: remembered.room,
75
- task: remembered.task_name,
76
- });
77
- return [];
78
- }
79
- this.current = null;
80
- const replanned = this.planTask(state, ctx);
81
- if (replanned) return [taskMoveDecision(state, ctx, replanned)];
82
- }
83
-
84
- let room = this.patrol.nextRoom(ctx);
85
- if (!room) {
86
- setStrategyIntent(ctx, {
87
- activity: 'waiting',
88
- summary: `当前没有安全任务或可巡逻房间,正在${state.you.room || '当前位置'}等待。`,
89
- ...(state.you.room ? { room: state.you.room } : {}),
90
- });
91
- return [];
92
- }
93
- if (dist(state.you.x, state.you.y, room.x, room.y) <= PATROL_REACHED_DISTANCE) {
94
- this.patrol.advance(ctx);
95
- const next = this.patrol.nextRoom(ctx);
96
- if (next) room = next;
97
- }
98
- const intent = patrolStrategyIntent(room);
99
- setStrategyIntent(ctx, intent);
100
- return [strategyDecision(Action.move({ x: room.x, y: room.y }), intent)];
101
- }
102
-
103
- private safeCurrentTask(state: GameState, ctx: StrategyContext): TaskInfo | null {
104
- const current = this.findCurrentTask(ctx);
105
- if (!current) return null;
106
-
107
- const safe = nearestSafeTask(state, [current], NON_CRAB, null, ctx.blockedMoveTarget, ctx.knownCorpses, {
108
- threatPoints: this.threatPoints(state, ctx),
109
- stickyTaskName: current.task_name,
110
- routeEvidence: ctx.routeEvidence,
111
- });
112
- return safe;
113
- }
114
-
115
- private findCurrentTask(ctx: StrategyContext): TaskInfo | null {
116
- if (!this.current) return null;
117
- return ctx.taskData.find(t => t.task_id === this.current?.task_id)
118
- ?? ctx.taskData.find(t => t.task_name === this.current?.task_name)
119
- ?? null;
120
- }
121
-
122
- private isStillAssignable(task: TaskInfo, ctx: StrategyContext): boolean {
123
- return task.status !== 'completed'
124
- && task.status !== 'in_progress'
125
- && task.x != null
126
- && task.y != null
127
- && (!ctx.blockedMoveTarget || dist(task.x, task.y, ctx.blockedMoveTarget.x, ctx.blockedMoveTarget.y) > 10)
128
- && NON_CRAB(task);
129
- }
130
- }
@@ -1,192 +0,0 @@
1
- import type { GameState } from '../../sdk/types.js';
2
- import { Action } from '../../sdk/action.js';
3
- import {
4
- dist,
5
- firstAvailableTask,
6
- isTargetAlive,
7
- matchesTarget,
8
- PROGRESS_INTERVAL_MS,
9
- reportCorpseDecision,
10
- setStrategyIntent,
11
- strategyDecision,
12
- strategyPlayerLabel,
13
- taskMoveDecision,
14
- } from '../game-utils.js';
15
- import type { BehaviorDecision, StrategyContext } from '../types.js';
16
- import { Goal } from './goal.js';
17
-
18
- export interface SocialTarget {
19
- target: number;
20
- greeting: string | null;
21
- }
22
-
23
- interface SocialTargetState {
24
- greetingSent: boolean;
25
- lastSpeechTime: number;
26
- silenceNotified: boolean;
27
- }
28
-
29
- const GREETING_DISTANCE = 200;
30
- const SILENCE_TIMEOUT_MS = 10_000;
31
-
32
- export class SocialTaskTop extends Goal {
33
- private readonly socialTargets: SocialTarget[];
34
- private readonly targetStates = new Map<number, SocialTargetState>();
35
-
36
- constructor(socialTargets: SocialTarget[]) {
37
- super();
38
- this.socialTargets = socialTargets;
39
- for (const st of socialTargets) {
40
- this.targetStates.set(st.target, {
41
- greetingSent: false,
42
- lastSpeechTime: 0,
43
- silenceNotified: false,
44
- });
45
- }
46
- }
47
-
48
- tick(state: GameState, ctx: StrategyContext): BehaviorDecision[] {
49
- const decisions: BehaviorDecision[] = [];
50
- const now = Date.now();
51
-
52
- const corpseDecision = reportCorpseDecision(state, ctx);
53
- if (corpseDecision) {
54
- this.emitProgress(state, ctx);
55
- return [corpseDecision];
56
- }
57
-
58
- for (const st of this.socialTargets) {
59
- if (!isTargetAlive(state, st.target, ctx)) continue;
60
-
61
- const visiblePlayer = state.players.find(p => matchesTarget(st.target, p, ctx));
62
- if (!visiblePlayer) continue;
63
-
64
- const targetState = this.targetStates.get(st.target)!;
65
- const d = visiblePlayer.distance ?? dist(state.you.x, state.you.y, visiblePlayer.x, visiblePlayer.y);
66
- const targetName = visiblePlayer.name || `${st.target}号`;
67
- const targetLabel = strategyPlayerLabel(visiblePlayer);
68
- const targetRoom = visiblePlayer.room || state.you.room || '当前位置';
69
-
70
- const targetSpeechEvent = (state.new_events ?? []).find(
71
- evt => evt.type === 'wandering_speech' && evt.actor_name === visiblePlayer.name,
72
- );
73
-
74
- if (targetSpeechEvent) {
75
- targetState.lastSpeechTime = now;
76
- targetState.silenceNotified = false;
77
-
78
- const speechText = targetSpeechEvent.text ?? targetSpeechEvent.content ?? '';
79
- const seatNum = visiblePlayer.seat ?? st.target;
80
- ctx.notifications.push(`${seatNum}号跟我说话了:「${speechText}」`);
81
- setStrategyIntent(ctx, {
82
- activity: 'waiting',
83
- summary: `正在${targetRoom}与${targetLabel}交流,等待下一步反应。`,
84
- ...(visiblePlayer.room ? { room: visiblePlayer.room } : {}),
85
- targetPlayer: targetName,
86
- });
87
- this.emitProgress(state, ctx);
88
- return decisions;
89
- }
90
-
91
- if (st.greeting != null && !targetState.greetingSent) {
92
- if (d > GREETING_DISTANCE) {
93
- if (state.you.doing_task) {
94
- this.emitProgress(state, ctx);
95
- return decisions;
96
- }
97
- decisions.push(strategyDecision(Action.move({ x: visiblePlayer.x, y: visiblePlayer.y }), {
98
- activity: 'moving',
99
- summary: `正在前往${targetRoom}接近${targetLabel},准备交流。`,
100
- ...(visiblePlayer.room ? { room: visiblePlayer.room } : {}),
101
- targetPlayer: targetName,
102
- }));
103
- this.emitProgress(state, ctx);
104
- return decisions;
105
- }
106
- decisions.push(strategyDecision(Action.speech(st.greeting), {
107
- activity: 'acting',
108
- summary: `正在${targetRoom}向${targetLabel}打招呼。`,
109
- ...(visiblePlayer.room ? { room: visiblePlayer.room } : {}),
110
- targetPlayer: targetName,
111
- }));
112
- targetState.greetingSent = true;
113
- targetState.lastSpeechTime = now;
114
- targetState.silenceNotified = false;
115
- const seatNum = visiblePlayer.seat ?? st.target;
116
- ctx.notifications.push(`已向${seatNum}号打招呼:「${st.greeting}」`);
117
- this.emitProgress(state, ctx);
118
- return decisions;
119
- }
120
-
121
- if (targetState.greetingSent && targetState.lastSpeechTime > 0) {
122
- if (now - targetState.lastSpeechTime >= SILENCE_TIMEOUT_MS) {
123
- if (!targetState.silenceNotified) {
124
- targetState.silenceNotified = true;
125
- const seatNum = visiblePlayer.seat ?? st.target;
126
- ctx.notifications.push(`${seatNum}号没回话,放弃等待,去做任务。`);
127
- }
128
- continue;
129
- }
130
- }
131
-
132
- if (targetState.greetingSent) {
133
- setStrategyIntent(ctx, {
134
- activity: 'waiting',
135
- summary: `正在${targetRoom}等待${targetLabel}回复。`,
136
- ...(visiblePlayer.room ? { room: visiblePlayer.room } : {}),
137
- targetPlayer: targetName,
138
- });
139
- this.emitProgress(state, ctx);
140
- return decisions;
141
- }
142
-
143
- }
144
-
145
- const taskDecision = this.tryTask(state, ctx);
146
- if (taskDecision) decisions.push(taskDecision);
147
- else if (!state.you.doing_task) {
148
- setStrategyIntent(ctx, {
149
- activity: 'waiting',
150
- summary: `社交目标暂不在视野内,当前没有可执行任务,正在${state.you.room || '当前位置'}等待。`,
151
- ...(state.you.room ? { room: state.you.room } : {}),
152
- });
153
- }
154
-
155
- this.emitProgress(state, ctx);
156
- return decisions;
157
- }
158
-
159
- private tryTask(state: GameState, ctx: StrategyContext): BehaviorDecision | null {
160
- const task = firstAvailableTask(ctx.taskData, t => t.faction !== 'crab', ctx.emergency, ctx.blockedMoveTarget);
161
- if (!task) return null;
162
-
163
- const isEmergencyTask = task === ctx.emergency;
164
- if (state.you.doing_task && !isEmergencyTask) return null;
165
-
166
- return taskMoveDecision(state, ctx, task);
167
- }
168
-
169
- private emitProgress(state: GameState, ctx: StrategyContext): void {
170
- const now = Date.now();
171
- if (now - ctx.lastProgressNotifyAt < PROGRESS_INTERVAL_MS) return;
172
- ctx.lastProgressNotifyAt = now;
173
-
174
- const room = state.you.room ?? '未知';
175
- const completed = ctx.taskData.filter(t => t.status === 'completed').length;
176
- const total = ctx.taskData.filter(t => t.faction !== 'crab').length;
177
-
178
- const visibleTargetNames = this.socialTargets
179
- .filter(st => state.players.some(p => matchesTarget(st.target, p, ctx)))
180
- .map(st => st.target);
181
-
182
- let msg = `[进度] 当前在${room}。`;
183
- if (visibleTargetNames.length > 0) {
184
- msg += `社交目标在视野内: ${visibleTargetNames.join(', ')}。`;
185
- } else {
186
- msg += `社交目标不在视野内,正在做任务。`;
187
- }
188
- msg += ` 任务进度 ${completed}/${total}。`;
189
-
190
- ctx.notifications.push(msg);
191
- }
192
- }
@@ -1,187 +0,0 @@
1
- import type { GameState } from '../../sdk/types.js';
2
- import { Action } from '../../sdk/action.js';
3
- import {
4
- canUseKill,
5
- dist,
6
- firstAvailableTask,
7
- hasKillUseRemaining,
8
- isTargetAlive,
9
- killCooldownSecs,
10
- killCommitRange,
11
- LONE_FOLLOW_DISTANCE,
12
- matchesTarget,
13
- playerStrategyIntent,
14
- PROGRESS_INTERVAL_MS,
15
- reportCorpseDecision,
16
- setStrategyIntent,
17
- strategyDecision,
18
- strategyPlayerLabel,
19
- taskMoveDecision,
20
- } from '../game-utils.js';
21
- import type { BehaviorDecision, StrategyContext } from '../types.js';
22
- import { Goal } from './goal.js';
23
- import { emitLeaf, URGENT_GOAL_PRIORITY, WANDER_GOAL_PRIORITY } from './leaf-goal.js';
24
-
25
- type VisibleTargetMatch = {
26
- player: GameState['players'][number];
27
- dist: number;
28
- };
29
-
30
- export class TaskKillReportTop extends Goal {
31
- private readonly targets: number[];
32
- private readonly targetSpottedNotified = new Set<string>();
33
-
34
- constructor(targets: number[]) {
35
- super();
36
- this.targets = [...targets];
37
- }
38
-
39
- tick(state: GameState, ctx: StrategyContext): BehaviorDecision[] {
40
- const allDead = this.targets.every(t => !isTargetAlive(state, t, ctx));
41
- if (allDead) {
42
- ctx.notifications.push('所有嫌疑目标都已死亡,策略结束。');
43
- setStrategyIntent(ctx, {
44
- activity: 'idle',
45
- summary: '所有嫌疑目标都已死亡,正在等待下一步指令。',
46
- });
47
- this.emitProgress(state, ctx);
48
- this.clearSub();
49
- return [];
50
- }
51
-
52
- const visibleMatches = this.visibleTargets(state, ctx);
53
- const cd = killCooldownSecs(state);
54
- const hasKill = hasKillUseRemaining(state);
55
- const killReady = canUseKill(state);
56
-
57
- if (visibleMatches.length > 0 && hasKill) {
58
- const nearest = visibleMatches[0];
59
-
60
- if (!this.targetSpottedNotified.has(nearest.player.name)) {
61
- this.targetSpottedNotified.add(nearest.player.name);
62
- ctx.notifications.push(`发现嫌疑目标${nearest.player.name}!`);
63
- }
64
-
65
- if (nearest.dist <= killCommitRange(state.you.role) && killReady) {
66
- ctx.notifications.push(`嫌疑目标${nearest.player.name}在攻击范围内,出刀!`);
67
- if (nearest.player.seat == null || nearest.player.seat <= 0) return this.emitDecisions(state, ctx, [], URGENT_GOAL_PRIORITY);
68
- return this.emitDecisions(state, ctx, [strategyDecision(
69
- Action.kill(nearest.player.seat),
70
- playerStrategyIntent(nearest.player, '追杀', 'acting'),
71
- )], URGENT_GOAL_PRIORITY);
72
- }
73
-
74
- if (nearest.dist > killCommitRange(state.you.role) && killReady) {
75
- return this.emitDecisions(
76
- state,
77
- ctx,
78
- [strategyDecision(
79
- Action.move({ x: nearest.player.x, y: nearest.player.y }),
80
- playerStrategyIntent(nearest.player, '追杀', 'moving'),
81
- )],
82
- URGENT_GOAL_PRIORITY,
83
- );
84
- }
85
-
86
- if (!killReady) {
87
- if (nearest.dist > LONE_FOLLOW_DISTANCE) {
88
- return this.emitDecisions(
89
- state,
90
- ctx,
91
- [strategyDecision(
92
- Action.move({ x: nearest.player.x, y: nearest.player.y }),
93
- playerStrategyIntent(nearest.player, '追杀', 'moving'),
94
- )],
95
- URGENT_GOAL_PRIORITY,
96
- );
97
- }
98
- setStrategyIntent(ctx, {
99
- activity: 'waiting',
100
- summary: `正在${nearest.player.room || state.you.room || '当前位置'}贴近${strategyPlayerLabel(nearest.player)},等待击杀冷却。`,
101
- ...(nearest.player.room ? { room: nearest.player.room } : {}),
102
- targetPlayer: nearest.player.name,
103
- });
104
- this.emitProgress(state, ctx);
105
- this.clearSub();
106
- return [];
107
- }
108
- } else {
109
- this.targetSpottedNotified.clear();
110
- }
111
-
112
- const reportDecision = reportCorpseDecision(state, ctx);
113
- if (reportDecision) {
114
- return this.emitDecisions(state, ctx, [reportDecision], URGENT_GOAL_PRIORITY);
115
- }
116
-
117
- const taskDecision = this.tryTask(state, ctx);
118
- if (taskDecision) {
119
- return this.emitDecisions(state, ctx, [taskDecision], WANDER_GOAL_PRIORITY);
120
- }
121
-
122
- setStrategyIntent(ctx, {
123
- activity: 'waiting',
124
- summary: `正在${state.you.room || '当前位置'}等待嫌疑目标出现。`,
125
- ...(state.you.room ? { room: state.you.room } : {}),
126
- });
127
- this.emitProgress(state, ctx);
128
- this.clearSub();
129
- return [];
130
- }
131
-
132
- private visibleTargets(state: GameState, ctx: StrategyContext): VisibleTargetMatch[] {
133
- const aliveTargets = this.targets.filter(t => isTargetAlive(state, t, ctx));
134
- return state.players
135
- .map(player => {
136
- if (!aliveTargets.some(t => matchesTarget(t, player, ctx))) return null;
137
- const d = player.distance ?? dist(state.you.x, state.you.y, player.x, player.y);
138
- return { player, dist: d };
139
- })
140
- .filter((match): match is VisibleTargetMatch => match !== null)
141
- .sort((a, b) => a.dist - b.dist);
142
- }
143
-
144
- private tryTask(state: GameState, ctx: StrategyContext): BehaviorDecision | null {
145
- if (state.you.doing_task) return null;
146
-
147
- const task = firstAvailableTask(ctx.taskData, t => t.faction !== 'crab', ctx.emergency, ctx.blockedMoveTarget);
148
- if (!task) return null;
149
- return taskMoveDecision(state, ctx, task);
150
- }
151
-
152
- private emitDecisions(
153
- state: GameState,
154
- ctx: StrategyContext,
155
- decisions: BehaviorDecision[],
156
- priority: number,
157
- ): BehaviorDecision[] {
158
- this.emitProgress(state, ctx);
159
- return emitLeaf(this, decisions, priority);
160
- }
161
-
162
- private clearSub(): void {
163
- if (this.subGoal) this.removeSubGoal();
164
- }
165
-
166
- private emitProgress(state: GameState, ctx: StrategyContext): void {
167
- const now = Date.now();
168
- if (now - ctx.lastProgressNotifyAt < PROGRESS_INTERVAL_MS) return;
169
- ctx.lastProgressNotifyAt = now;
170
-
171
- const room = state.you.room ?? '未知';
172
- const cd = killCooldownSecs(state);
173
- const killsRemaining = state.you.kills_remaining;
174
- const targetNames = this.targets.join(', ');
175
- const aliveCount = this.targets.filter(t => isTargetAlive(state, t, ctx)).length;
176
-
177
- const completed = ctx.taskData.filter(t => t.status === 'completed').length;
178
- const total = ctx.taskData.filter(t => t.faction !== 'crab').length;
179
-
180
- let msg = `[进度] 当前在${room},嫌疑目标: ${targetNames}(存活${aliveCount}/${this.targets.length})。`;
181
- if (cd > 0) msg += `攻击冷却中(${cd}s)。`;
182
- if (killsRemaining === 0) msg += '出刀次数已用完。';
183
- msg += ` 任务进度 ${completed}/${total}。`;
184
-
185
- ctx.notifications.push(msg);
186
- }
187
- }
@@ -1,64 +0,0 @@
1
- import type { GameState } from '../../sdk/types.js';
2
- import { firstAvailableTask, PROGRESS_INTERVAL_MS, setStrategyIntent, taskMoveDecision } from '../game-utils.js';
3
- import type { BehaviorDecision, StrategyContext } from '../types.js';
4
- import { Goal } from './goal.js';
5
-
6
- export class TaskOnlyTop extends Goal {
7
- private lastEmergencyNotified = false;
8
-
9
- tick(state: GameState, ctx: StrategyContext): BehaviorDecision[] {
10
- if (state.emergency && !this.lastEmergencyNotified) {
11
- this.lastEmergencyNotified = true;
12
- ctx.notifications.push(`紧急任务出现!优先处理。`);
13
- } else if (!state.emergency) {
14
- this.lastEmergencyNotified = false;
15
- }
16
-
17
- const task = firstAvailableTask(ctx.taskData, () => true, ctx.emergency, ctx.blockedMoveTarget);
18
- if (!task) {
19
- setStrategyIntent(ctx, {
20
- activity: 'waiting',
21
- summary: `当前没有可用任务,正在${state.you.room || '当前位置'}等待。`,
22
- ...(state.you.room ? { room: state.you.room } : {}),
23
- });
24
- this.emitProgress(state, ctx);
25
- return [];
26
- }
27
-
28
- // Keep an in-flight task stable. An emergency may interrupt a different
29
- // task, but must not be resubmitted while that same repair is running.
30
- if (state.you.doing_task && (task !== ctx.emergency || state.you.task_name === task.task_name)) {
31
- this.emitProgress(state, ctx);
32
- return [];
33
- }
34
-
35
- const decisions = [taskMoveDecision(state, ctx, task)];
36
- this.emitProgress(state, ctx);
37
- return decisions;
38
- }
39
-
40
- private emitProgress(state: GameState, ctx: StrategyContext): void {
41
- const now = Date.now();
42
- if (now - ctx.lastProgressNotifyAt < PROGRESS_INTERVAL_MS) return;
43
- ctx.lastProgressNotifyAt = now;
44
-
45
- const room = state.you.room ?? '未知';
46
- const completed = ctx.taskData.filter(t => t.status === 'completed').length;
47
- const total = ctx.taskData.length;
48
- const current = firstAvailableTask(ctx.taskData, () => true, ctx.emergency);
49
-
50
- let msg = `[进度] 当前在${room}`;
51
- if (current) {
52
- msg += `,正在前往${current.room}做任务「${current.task_name}」`;
53
- } else {
54
- msg += `,没有可用任务`;
55
- }
56
- msg += `。已完成 ${completed}/${total} 个任务。`;
57
-
58
- if (state.emergency) {
59
- msg += ` 紧急任务进行中!`;
60
- }
61
-
62
- ctx.notifications.push(msg);
63
- }
64
- }