@myclaw163/clawclaw-cli 0.7.13 → 0.7.15

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 (47) hide show
  1. package/docs/runtime/strategy-runtime.md +1 -1
  2. package/docs//350/207/252/345/256/232/344/271/211/347/255/226/347/225/245.md +4 -4
  3. package/package.json +1 -1
  4. package/skills/clawclaw/SKILL.md +5 -5
  5. package/skills/clawclaw/references/COMMANDS.md +2 -2
  6. package/skills/clawclaw/references/STRATEGIES.md +4 -4
  7. package/skills/clawclaw/references/STREAM.md +1 -1
  8. package/src/lib/strategy-export.test.ts +13 -0
  9. package/src/pipeline/canonical-event-presentation.test.ts +59 -0
  10. package/src/pipeline/canonical-event-presentation.ts +54 -0
  11. package/src/runtime/clawclaw/owner.ts +7 -2
  12. package/src/runtime/clawclaw/plugins/mailbox/desktop-event-push.integration.test.ts +26 -4
  13. package/src/runtime/clawclaw/plugins/strategy/strategy-module-loader.ts +1 -1
  14. package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.test.ts +22 -0
  15. package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.ts +14 -5
  16. package/src/sdk/index.ts +2 -2
  17. package/src/sdk/strategy-plugin/index.test.ts +10 -4
  18. package/src/sdk/strategy-plugin/index.ts +13 -2
  19. package/src/strategies/avoid-players.ts +4 -5
  20. package/src/strategies/find-player.ts +5 -6
  21. package/src/strategies/game-utils.test.ts +22 -0
  22. package/src/strategies/game-utils.ts +12 -39
  23. package/src/strategies/goals/avoid-players-top.test.ts +2 -2
  24. package/src/strategies/goals/avoid-players-top.ts +1 -1
  25. package/src/strategies/goals/crab-octopus-reflexes.ts +10 -10
  26. package/src/strategies/goals/find-player-top.ts +7 -8
  27. package/src/strategies/goals/kill-lone-top.test.ts +27 -2
  28. package/src/strategies/goals/kill-lone-top.ts +16 -12
  29. package/src/strategies/goals/kill-target-goal.ts +3 -3
  30. package/src/strategies/goals/kill-target-top.test.ts +66 -0
  31. package/src/strategies/goals/kill-target-top.ts +4 -6
  32. package/src/strategies/goals/normal-shrimp-top.test.ts +2 -2
  33. package/src/strategies/goals/normal-shrimp-top.ts +3 -3
  34. package/src/strategies/goals/paradise-fish-top.test.ts +3 -3
  35. package/src/strategies/goals/paradise-fish-top.ts +2 -2
  36. package/src/strategies/goals/social-task-top.ts +3 -3
  37. package/src/strategies/goals/task-kill-report-top.ts +2 -2
  38. package/src/strategies/goals/warrior-shrimp-top.test.ts +3 -3
  39. package/src/strategies/goals/warrior-shrimp-top.ts +11 -7
  40. package/src/strategies/kill-lone.ts +7 -12
  41. package/src/strategies/kill-target.ts +5 -6
  42. package/src/strategies/paradise-fish.ts +8 -8
  43. package/src/strategies/player-targets.ts +0 -8
  44. package/src/strategies/shrimp-memory.ts +13 -13
  45. package/src/strategies/social-task.ts +4 -4
  46. package/src/strategies/task-kill-report.ts +5 -5
  47. package/src/strategies/warrior-memory.ts +7 -12
@@ -1,10 +1,9 @@
1
1
  import {
2
2
  ClawclawGoalStrategy,
3
- clawclawStrategyStringList,
3
+ clawclawStrategySeatList,
4
4
  } from '../sdk/strategy-plugin/index.js';
5
5
  import { GoalRootStrategy } from './goals/goal-root-strategy.js';
6
6
  import { AvoidPlayersTop } from './goals/avoid-players-top.js';
7
- import { parseTargetArgs } from './player-targets.js';
8
7
 
9
8
  export default class AvoidPlayersStrategy extends ClawclawGoalStrategy {
10
9
  static readonly manifest = {
@@ -14,8 +13,8 @@ export default class AvoidPlayersStrategy extends ClawclawGoalStrategy {
14
13
  execution: 'parallel_analyze',
15
14
  controls: [{
16
15
  id: 'targets',
17
- type: 'player_refs',
18
- description: '需要回避的座位号或玩家名列表。',
16
+ type: 'player_seats',
17
+ description: '需要回避的玩家座位号列表。',
19
18
  default: [],
20
19
  }],
21
20
  } as const;
@@ -24,7 +23,7 @@ export default class AvoidPlayersStrategy extends ClawclawGoalStrategy {
24
23
  super(parameters, {
25
24
  id: 'avoid-players',
26
25
  create: (values) => {
27
- const targets = parseTargetArgs(clawclawStrategyStringList(values, 'targets'));
26
+ const targets = clawclawStrategySeatList(values, 'targets');
28
27
  return new GoalRootStrategy('avoid-players', () => new AvoidPlayersTop(targets), {
29
28
  resetOnMeetingResume: false,
30
29
  });
@@ -1,10 +1,9 @@
1
1
  import {
2
2
  ClawclawGoalStrategy,
3
- clawclawStrategyStringList,
3
+ clawclawStrategySeatList,
4
4
  } from '../sdk/strategy-plugin/index.js';
5
5
  import { GoalRootStrategy } from './goals/goal-root-strategy.js';
6
6
  import { FindPlayerTop } from './goals/find-player-top.js';
7
- import { parseTargetArgs } from './player-targets.js';
8
7
 
9
8
  export default class FindPlayerStrategy extends ClawclawGoalStrategy {
10
9
  static readonly manifest = {
@@ -14,8 +13,8 @@ export default class FindPlayerStrategy extends ClawclawGoalStrategy {
14
13
  execution: 'parallel_analyze',
15
14
  controls: [{
16
15
  id: 'targets',
17
- type: 'player_refs',
18
- description: '要寻找并跟踪的单个玩家。',
16
+ type: 'player_seats',
17
+ description: '要寻找并跟踪的单个玩家座位号。',
19
18
  }],
20
19
  } as const;
21
20
 
@@ -23,12 +22,12 @@ export default class FindPlayerStrategy extends ClawclawGoalStrategy {
23
22
  super(parameters, {
24
23
  id: 'find-player',
25
24
  validateParameters: (values) => (
26
- parseTargetArgs(clawclawStrategyStringList(values, 'targets')).length === 1
25
+ clawclawStrategySeatList(values, 'targets').length === 1
27
26
  ? undefined
28
27
  : '盯人策略必须配置且只能配置一个目标玩家。'
29
28
  ),
30
29
  create: (values) => {
31
- const targets = parseTargetArgs(clawclawStrategyStringList(values, 'targets'));
30
+ const targets = clawclawStrategySeatList(values, 'targets');
32
31
  return new GoalRootStrategy('find-player', () => new FindPlayerTop(targets[0]), {
33
32
  resetOnMeetingResume: false,
34
33
  });
@@ -6,6 +6,8 @@ import {
6
6
  emergencyRushDecision,
7
7
  firstAvailableTask,
8
8
  killYieldsToEmergencyRepair,
9
+ matchesTarget,
10
+ nearestVisibleTarget,
9
11
  nearestSafeTask,
10
12
  PatrolState,
11
13
  safePatrolStep,
@@ -66,6 +68,26 @@ function context(overrides: Partial<StrategyContext> = {}): StrategyContext {
66
68
  };
67
69
  }
68
70
 
71
+ describe('seat-only player targets', () => {
72
+ it('selects only the configured seat when multiple players share one name', () => {
73
+ const ctx = context({
74
+ playerNamesBySeat: {
75
+ '2': '木桩机器虾',
76
+ '6': '木桩机器虾',
77
+ },
78
+ });
79
+ const sameNamePlayers = [
80
+ { name: '木桩机器虾', seat: 2, room: '居住区', x: 10, y: 0, distance: 10 },
81
+ { name: '木桩机器虾', seat: 6, room: '居住区', x: 20, y: 0, distance: 20 },
82
+ ];
83
+ const current = state({ players: sameNamePlayers });
84
+
85
+ expect(matchesTarget(6, sameNamePlayers[0], ctx)).toBe(false);
86
+ expect(matchesTarget(6, sameNamePlayers[1], ctx)).toBe(true);
87
+ expect(nearestVisibleTarget(current, ctx, [6])?.seat).toBe(6);
88
+ });
89
+ });
90
+
69
91
  describe('CorpseMemory', () => {
70
92
  it('uses the last visible position immediately after a confirmed kill', () => {
71
93
  const memory = new CorpseMemory();
@@ -758,42 +758,17 @@ export function nonTeammatesVisible(state: GameState, ctx: StrategyContext): Pla
758
758
  : players;
759
759
  }
760
760
 
761
- /**
762
- * Resolve a target string (seat number or player name) to a seat number.
763
- * Names are resolved through `ctx.playerNamesBySeat` (seat → name). Returns
764
- * null when the target cannot be resolved to a seat (unknown name, empty input).
765
- */
766
- export function targetSeat(target: string, ctx: StrategyContext): number | null {
767
- const trimmed = target.trim();
768
- if (!trimmed) return null;
769
- if (/^\d+$/.test(trimmed)) return Number(trimmed);
770
- const folded = trimmed.toLowerCase();
771
- for (const [seat, name] of Object.entries(ctx.playerNamesBySeat)) {
772
- if (name && name.toLowerCase() === folded) return Number(seat);
773
- }
774
- return null;
775
- }
776
-
777
761
  export function matchesTarget(
778
- target: string,
762
+ targetSeat: number,
779
763
  player: { name?: string; seat?: number },
780
- ctx: StrategyContext,
764
+ _ctx: StrategyContext,
781
765
  ): boolean {
782
- const trimmed = target.trim();
783
- const seat = targetSeat(trimmed, ctx);
784
- if (seat != null && player.seat != null && player.seat === seat) return true;
785
- if (seat != null) {
786
- // 座位号参数对无名/缺 seat 的条目(如只有名字的尸体):经 seat→name 反查命中。
787
- const nameFromSeat = ctx.playerNamesBySeat[String(seat)];
788
- if (nameFromSeat && player.name && player.name.toLowerCase() === nameFromSeat.toLowerCase()) return true;
789
- }
790
- const normalized = trimmed.toLowerCase();
791
- return player.name != null && player.name.toLowerCase() === normalized;
766
+ return Number.isInteger(targetSeat) && player.seat === targetSeat;
792
767
  }
793
768
 
794
769
  export function matchesAnyTarget(
795
770
  player: { name?: string; seat?: number },
796
- targets: string[],
771
+ targets: number[],
797
772
  ctx: StrategyContext,
798
773
  ): boolean {
799
774
  return targets.some(target => matchesTarget(target, player, ctx));
@@ -801,26 +776,24 @@ export function matchesAnyTarget(
801
776
 
802
777
  export function isTargetAlive(
803
778
  state: GameState,
804
- target: string,
779
+ targetSeat: number,
805
780
  ctx: StrategyContext,
806
781
  ): boolean {
807
- if (isRecentlyKilledTarget(target, ctx)) return false;
808
- const player = state.all_players?.find(p => matchesTarget(target, p, ctx));
782
+ if (isRecentlyKilledTarget(targetSeat, ctx)) return false;
783
+ const player = state.all_players?.find(p => matchesTarget(targetSeat, p, ctx));
809
784
  return player ? player.is_alive !== false : true;
810
785
  }
811
786
 
812
- export function isRecentlyKilledTarget(target: string, ctx: StrategyContext): boolean {
813
- const seat = targetSeat(target, ctx);
814
- if (seat == null) return false;
815
- const until = ctx.recentlyKilledTargets?.get(String(seat));
787
+ export function isRecentlyKilledTarget(targetSeat: number, ctx: StrategyContext): boolean {
788
+ const until = ctx.recentlyKilledTargets?.get(String(targetSeat));
816
789
  if (until == null) return false;
817
790
  if (until > Date.now()) return true;
818
- ctx.recentlyKilledTargets?.delete(String(seat));
791
+ ctx.recentlyKilledTargets?.delete(String(targetSeat));
819
792
  return false;
820
793
  }
821
794
 
822
795
  export function visibleLivePlayers(state: GameState, ctx: StrategyContext): PlayerInfo[] {
823
- return state.players.filter(p => isTargetAlive(state, p.name, ctx));
796
+ return state.players.filter(p => p.seat == null || isTargetAlive(state, p.seat, ctx));
824
797
  }
825
798
 
826
799
  export function nearestPlayerByDistance(state: GameState, players: PlayerInfo[]): PlayerInfo | null {
@@ -832,7 +805,7 @@ export function nearestPlayerByDistance(state: GameState, players: PlayerInfo[])
832
805
  export function nearestVisibleTarget(
833
806
  state: GameState,
834
807
  ctx: StrategyContext,
835
- targets: string[],
808
+ targets: number[],
836
809
  ): PlayerInfo | null {
837
810
  return nearestPlayerByDistance(
838
811
  state,
@@ -65,7 +65,7 @@ describe('AvoidPlayersTop', () => {
65
65
  });
66
66
 
67
67
  it('patrols without stop_on_player when the configured avoid target is dead', () => {
68
- const top = new AvoidPlayersTop(['dead-target']);
68
+ const top = new AvoidPlayersTop([2]);
69
69
  const ctx = context();
70
70
  const current = state({
71
71
  players: [{ name: 'roadie', x: 200, y: 0, room: 'start' }],
@@ -83,7 +83,7 @@ describe('AvoidPlayersTop', () => {
83
83
  });
84
84
 
85
85
  it('uses targets as the complete active avoid list', () => {
86
- const top = new AvoidPlayersTop(['danger']);
86
+ const top = new AvoidPlayersTop([2]);
87
87
  const current = state({
88
88
  players: [{ name: 'danger', seat: 2, x: 200, y: 0, room: 'start' }],
89
89
  all_players: [{ name: 'danger', seat: 2, role: 'unknown', is_alive: true }],
@@ -13,7 +13,7 @@ export class AvoidPlayersTop extends Goal {
13
13
  private moveMode: 'patrol' | 'flee' | null = null;
14
14
  private lastAvoidNoticeKey = '';
15
15
 
16
- constructor(private readonly targets: string[]) {
16
+ constructor(private readonly targets: number[]) {
17
17
  super();
18
18
  }
19
19
 
@@ -10,7 +10,6 @@ import {
10
10
  reportCorpseDecision,
11
11
  playerStrategyIntent,
12
12
  strategyDecision,
13
- targetSeat,
14
13
  } from '../game-utils.js';
15
14
  import type { BehaviorDecision, StrategyContext } from '../types.js';
16
15
 
@@ -43,9 +42,10 @@ export function corpseReportWithNonTeammate(state: GameState, ctx: StrategyConte
43
42
  if (report.action.type === 'report') {
44
43
  // 实时给 Agent 一条「为什么是我报的尸」简报:报尸=召集会议,是高风险自证动作。
45
44
  // 若尸体很可能是自己刚才下的那一刀,必须显式提醒,免得 Agent 之后发言露馅。
46
- const corpseName = nearestReportableCorpse(state)?.name ?? '';
45
+ const corpse = nearestReportableCorpse(state);
46
+ const corpseName = corpse?.name ?? '';
47
47
  ctx.agentAlerts.push(
48
- isRecentOwnKill(ctx, corpseName)
48
+ isRecentOwnKill(ctx, corpse)
49
49
  ? `我刚下手的目标${corpseName ? `(${corpseName})` : ''}尸体被${witnessNames}撞见,我抢先报尸召集会议、把自己装成发现者并把嫌疑引向在场者。接下来发言/投票要顺着「我是主动报告的人」走,绝不能承认是自己动的手。`
50
50
  : `尸体旁有${witnessNames}在场,我抢先报尸召集会议、伪装成主动报告的好人。发言时按「主动报告的发现者」立场走。`,
51
51
  );
@@ -91,16 +91,16 @@ export function immediateLoneKillDecision(
91
91
  * 这具尸体是不是「自己刚才下的那一刀」。先按尸体座位号精确匹配 recentlyKilledTargets(刚杀过且未过期),
92
92
  * 座位对不上但近期确实杀过人时,冒出的尸体大概率也是自己造成的,按 true 处理(宁可多提醒一次)。
93
93
  */
94
- function isRecentOwnKill(ctx: StrategyContext, corpseName: string): boolean {
94
+ function isRecentOwnKill(
95
+ ctx: StrategyContext,
96
+ corpse: { seat?: number } | null,
97
+ ): boolean {
95
98
  const map = ctx.recentlyKilledTargets;
96
99
  if (!map || map.size === 0) return false;
97
100
  const now = Date.now();
98
- if (corpseName) {
99
- const seat = targetSeat(corpseName, ctx);
100
- if (seat != null) {
101
- const until = map.get(String(seat));
102
- if (until != null && until > now) return true;
103
- }
101
+ if (corpse?.seat != null) {
102
+ const until = map.get(String(corpse.seat));
103
+ if (until != null && until > now) return true;
104
104
  }
105
105
  for (const until of map.values()) {
106
106
  if (until > now) return true;
@@ -27,7 +27,7 @@ export class FindPlayerTop extends Goal {
27
27
  private foundNotified = false;
28
28
 
29
29
  constructor(
30
- private readonly target: string,
30
+ private readonly target: number,
31
31
  private readonly trackDistance: number = DEFAULT_TRACK_DISTANCE,
32
32
  ) {
33
33
  super();
@@ -39,7 +39,7 @@ export class FindPlayerTop extends Goal {
39
39
  setStrategyIntent(ctx, {
40
40
  activity: 'idle',
41
41
  summary: `${this.targetLabel(ctx)}已死亡,正在等待下一步指令。`,
42
- targetPlayer: this.target,
42
+ targetPlayer: this.targetLabel(ctx),
43
43
  });
44
44
  this.emitProgress(state, ctx);
45
45
  return [];
@@ -76,7 +76,7 @@ export class FindPlayerTop extends Goal {
76
76
  activity: 'moving',
77
77
  summary: `正在前往${this.lastSeenRoom || '最后目击区域'}寻找${this.targetLabel(ctx)}。`,
78
78
  ...(this.lastSeenRoom ? { room: this.lastSeenRoom } : {}),
79
- targetPlayer: this.target,
79
+ targetPlayer: this.targetLabel(ctx),
80
80
  })];
81
81
  }
82
82
  this.lastSeenX = null;
@@ -94,7 +94,7 @@ export class FindPlayerTop extends Goal {
94
94
  setStrategyIntent(ctx, {
95
95
  activity: 'waiting',
96
96
  summary: `暂无可巡逻房间,正在等待${this.targetLabel(ctx)}出现。`,
97
- targetPlayer: this.target,
97
+ targetPlayer: this.targetLabel(ctx),
98
98
  });
99
99
  return [];
100
100
  }
@@ -107,15 +107,14 @@ export class FindPlayerTop extends Goal {
107
107
  Action.move({ x: room.x, y: room.y }),
108
108
  {
109
109
  ...patrolStrategyIntent(room, `巡逻寻找${this.targetLabel(ctx)}`),
110
- targetPlayer: this.target,
110
+ targetPlayer: this.targetLabel(ctx),
111
111
  },
112
112
  )];
113
113
  }
114
114
 
115
115
  private targetLabel(ctx: StrategyContext): string {
116
- const seat = this.target.trim();
117
- const name = /^\d+$/.test(seat) ? ctx.playerNamesBySeat[seat] : undefined;
118
- return name ? `${seat}号${name}` : this.target;
116
+ const name = ctx.playerNamesBySeat[String(this.target)];
117
+ return name ? `${this.target}号${name}` : `${this.target}号`;
119
118
  }
120
119
 
121
120
  private emitProgress(state: GameState, ctx: StrategyContext): void {
@@ -55,7 +55,7 @@ function context(): StrategyContext {
55
55
 
56
56
  describe('KillLoneTop player-list controls', () => {
57
57
  it('lets huntTargets bypass the lone-player condition', () => {
58
- const top = new KillLoneTop([], ['target']);
58
+ const top = new KillLoneTop([], [2]);
59
59
 
60
60
  top.tick(state(), context());
61
61
 
@@ -63,10 +63,35 @@ describe('KillLoneTop player-list controls', () => {
63
63
  });
64
64
 
65
65
  it('gives protectedTargets priority over huntTargets', () => {
66
- const top = new KillLoneTop(['target'], ['target']);
66
+ const top = new KillLoneTop([2], [2]);
67
67
 
68
68
  top.tick(state(), context());
69
69
 
70
70
  expect(top.subGoal).not.toBeInstanceOf(KillVisibleTargetGoal);
71
71
  });
72
+
73
+ it('keeps hunting the configured seat when players share the same name', () => {
74
+ const top = new KillLoneTop([], [6]);
75
+ const current = state();
76
+ current.players = [
77
+ { name: '木桩机器虾', seat: 2, x: 20, y: 0, room: 'control', distance: 20 },
78
+ { name: '木桩机器虾', seat: 6, x: 100, y: 0, room: 'control', distance: 100 },
79
+ { name: '木桩机器虾', seat: 3, x: 120, y: 0, room: 'control', distance: 120 },
80
+ ];
81
+ current.all_players = current.players.map((player) => ({
82
+ name: player.name,
83
+ seat: player.seat!,
84
+ role: 'unknown',
85
+ is_alive: true,
86
+ }));
87
+
88
+ top.tick(current, context());
89
+
90
+ expect(top.subGoal).toBeInstanceOf(KillVisibleTargetGoal);
91
+ expect((top.subGoal as KillVisibleTargetGoal).targetSeat).toBe(6);
92
+ expect(top.subGoal?.tick(current, context())[0]?.action.payload).toMatchObject({
93
+ target_x: 100,
94
+ target_y: 0,
95
+ });
96
+ });
72
97
  });
@@ -22,11 +22,11 @@ export class KillLoneTop extends Goal {
22
22
  private readonly patrol = new PatrolState();
23
23
  private loneIgnoreUntil = 0;
24
24
  private patrolStopOnPlayer: boolean | null = null;
25
- private lastFlaggedTarget = '';
25
+ private lastFlaggedTarget: number | null = null;
26
26
 
27
27
  constructor(
28
- private readonly protectedTargets: string[] = [],
29
- private readonly huntTargets: string[] = [],
28
+ private readonly protectedTargets: number[] = [],
29
+ private readonly huntTargets: number[] = [],
30
30
  ) {
31
31
  super();
32
32
  }
@@ -45,15 +45,15 @@ export class KillLoneTop extends Goal {
45
45
  state,
46
46
  nonTeammates.filter(p => matchesAnyTarget(p, this.huntTargets, ctx) && !this.isProtected(p, ctx)),
47
47
  );
48
- if (flagged) {
49
- if (flagged.name !== this.lastFlaggedTarget) {
48
+ if (flagged?.seat != null) {
49
+ if (flagged.seat !== this.lastFlaggedTarget) {
50
50
  ctx.notifications.push(`根据情报,${flagged.name}被标记为目标,主动出击!`);
51
- this.lastFlaggedTarget = flagged.name;
51
+ this.lastFlaggedTarget = flagged.seat;
52
52
  }
53
- this.setHuntGoal(flagged.name, true);
53
+ this.setHuntGoal(flagged.seat, true);
54
54
  return [];
55
55
  } else {
56
- this.lastFlaggedTarget = '';
56
+ this.lastFlaggedTarget = null;
57
57
  }
58
58
 
59
59
  if (nonTeammates.length === 0 && state.players.length > 0) {
@@ -81,7 +81,11 @@ export class KillLoneTop extends Goal {
81
81
  return [];
82
82
  }
83
83
 
84
- this.setHuntGoal(target.name);
84
+ if (target.seat == null) {
85
+ this.setPatrolGoal(state, ctx, false);
86
+ return [];
87
+ }
88
+ this.setHuntGoal(target.seat);
85
89
  this.emitProgress(state, ctx);
86
90
  return [];
87
91
  }
@@ -91,11 +95,11 @@ export class KillLoneTop extends Goal {
91
95
  return matchesAnyTarget(p, this.protectedTargets, ctx);
92
96
  }
93
97
 
94
- private setHuntGoal(targetName: string, ignoreCrowd = false): void {
98
+ private setHuntGoal(targetSeat: number, ignoreCrowd = false): void {
95
99
  const worker = this.subGoal;
96
- if (worker instanceof KillVisibleTargetGoal && worker.targetName === targetName && worker.ignoreCrowd === ignoreCrowd) return;
100
+ if (worker instanceof KillVisibleTargetGoal && worker.targetSeat === targetSeat && worker.ignoreCrowd === ignoreCrowd) return;
97
101
  if (this.subGoal) this.removeSubGoal();
98
- this.setSubGoal(new KillVisibleTargetGoal(targetName, this.protectedTargets, ignoreCrowd), HUNT_PRIORITY);
102
+ this.setSubGoal(new KillVisibleTargetGoal(targetSeat, this.protectedTargets, ignoreCrowd), HUNT_PRIORITY);
99
103
  this.patrolStopOnPlayer = null;
100
104
  }
101
105
 
@@ -18,8 +18,8 @@ import { Goal } from './goal.js';
18
18
 
19
19
  export class KillVisibleTargetGoal extends Goal {
20
20
  constructor(
21
- public readonly targetName: string,
22
- private readonly protectedTargets: string[],
21
+ public readonly targetSeat: number,
22
+ private readonly protectedTargets: number[],
23
23
  public readonly ignoreCrowd = false,
24
24
  ) {
25
25
  super();
@@ -61,7 +61,7 @@ export class KillVisibleTargetGoal extends Goal {
61
61
  private target(state: GameState, ctx: StrategyContext): PlayerInfo | null {
62
62
  const visible = nonTeammatesVisible(state, ctx);
63
63
  if (!this.ignoreCrowd && visible.length !== 1) return null;
64
- const target = visible.find(p => p.name === this.targetName) ?? null;
64
+ const target = visible.find(p => p.seat === this.targetSeat) ?? null;
65
65
  if (!target) return null;
66
66
  if (matchesAnyTarget(target, this.protectedTargets, ctx)) return null;
67
67
  return target;
@@ -0,0 +1,66 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import type { GameState } from '../../sdk/types.js';
3
+ import type { StrategyContext } from '../types.js';
4
+ import { KillTargetTop } from './kill-target-top.js';
5
+
6
+ function state(): GameState {
7
+ return {
8
+ phase: 'wandering',
9
+ tick: 1,
10
+ you: {
11
+ name: 'hunter',
12
+ x: 0,
13
+ y: 0,
14
+ room: 'control',
15
+ role: 'neutral_octopus',
16
+ faction: 'neutral',
17
+ is_alive: true,
18
+ kill_cooldown_secs: 0,
19
+ },
20
+ your_tasks: [],
21
+ players: [],
22
+ all_players: [
23
+ { name: '木桩机器虾', seat: 1, role: 'unknown', is_alive: false },
24
+ { name: '木桩机器虾', seat: 3, role: 'unknown', is_alive: true },
25
+ ],
26
+ corpses: [],
27
+ stale: false,
28
+ };
29
+ }
30
+
31
+ function context(): StrategyContext {
32
+ return {
33
+ taskData: [],
34
+ emergency: null,
35
+ taskLocalBlockedUntil: 0,
36
+ reportCorpseTarget: null,
37
+ reportBlockedUntil: 0,
38
+ notifications: [],
39
+ lastProgressNotifyAt: Date.now(),
40
+ teammates: new Set(),
41
+ alarmDone: false,
42
+ rooms: [{ name: 'patrol', x: 500, y: 0 }],
43
+ playerNamesBySeat: {
44
+ '1': '木桩机器虾',
45
+ '3': '木桩机器虾',
46
+ },
47
+ forcePatrolAdvance: false,
48
+ blockedMoveTarget: null,
49
+ mySeat: 4,
50
+ speechNotifications: [],
51
+ agentAlerts: [],
52
+ };
53
+ }
54
+
55
+ describe('KillTargetTop seat targeting', () => {
56
+ it('does not complete seat 3 when a different player with the same name is dead', () => {
57
+ const top = new KillTargetTop([3]);
58
+ const ctx = context();
59
+
60
+ const decisions = top.tick(state(), ctx);
61
+
62
+ expect(decisions[0]?.intent?.summary).toContain('巡逻寻找追杀目标');
63
+ expect(decisions[0]?.intent?.summary).not.toContain('离开现场巡逻');
64
+ expect(ctx.notifications).not.toContain('击杀目标已完成,切换巡逻离开现场。');
65
+ });
66
+ });
@@ -15,7 +15,6 @@ import {
15
15
  pursueVisibleTarget,
16
16
  setStrategyIntent,
17
17
  strategyPlayerLabel,
18
- targetSeat,
19
18
  } from '../game-utils.js';
20
19
  import type { BehaviorDecision, StrategyContext } from '../types.js';
21
20
  import { Goal } from './goal.js';
@@ -26,7 +25,7 @@ export class KillTargetTop extends Goal {
26
25
  private completedAfterKill = false;
27
26
  private completedNotified = false;
28
27
 
29
- constructor(private readonly targets: string[]) {
28
+ constructor(private readonly targets: number[]) {
30
29
  super();
31
30
  }
32
31
 
@@ -91,17 +90,16 @@ export class KillTargetTop extends Goal {
91
90
  return patrolStep(state, ctx, this.patrol, false, '离开现场巡逻');
92
91
  }
93
92
 
94
- private isValidTarget(t: string, state: GameState, ctx: StrategyContext): boolean {
93
+ private isValidTarget(t: number, state: GameState, ctx: StrategyContext): boolean {
95
94
  if (!isTargetAlive(state, t, ctx)) return false;
96
- const seat = targetSeat(t, ctx);
97
- return !(seat != null && ctx.teammates.has(String(seat)));
95
+ return !ctx.teammates.has(String(t));
98
96
  }
99
97
 
100
98
  private allTargetsDeadInState(state: GameState, ctx: StrategyContext): boolean {
101
99
  return this.targets.length > 0 && this.targets.every(target => this.targetDeadInState(target, state, ctx));
102
100
  }
103
101
 
104
- private targetDeadInState(target: string, state: GameState, ctx: StrategyContext): boolean {
102
+ private targetDeadInState(target: number, state: GameState, ctx: StrategyContext): boolean {
105
103
  const player = state.all_players?.find(p => matchesTarget(target, p, ctx));
106
104
  if (player) return player.is_alive === false;
107
105
  return (ctx.knownCorpses ?? []).some(corpse => matchesTarget(target, corpse, ctx));
@@ -96,7 +96,7 @@ describe('NormalShrimpTop vision thresholds', () => {
96
96
  });
97
97
 
98
98
  it('hard-avoids hostileTargets even outside the normal stranger enter range', () => {
99
- const top = new NormalShrimpTop([], ['stranger']);
99
+ const top = new NormalShrimpTop([], [2]);
100
100
 
101
101
  top.tick(stateWithStranger(500), context());
102
102
 
@@ -104,7 +104,7 @@ describe('NormalShrimpTop vision thresholds', () => {
104
104
  });
105
105
 
106
106
  it('gives trustedTargets priority over hostileTargets', () => {
107
- const top = new NormalShrimpTop([], ['stranger'], ['stranger']);
107
+ const top = new NormalShrimpTop([], [2], [2]);
108
108
 
109
109
  top.tick(stateWithStranger(100), context());
110
110
 
@@ -63,9 +63,9 @@ export class NormalShrimpTop extends Goal {
63
63
 
64
64
  constructor(
65
65
  greetingPhrases: string[] = [],
66
- private readonly hostileTargets: string[] = [],
67
- private readonly trustedTargets: string[] = [],
68
- private readonly paradiseFishTargets: string[] = [],
66
+ private readonly hostileTargets: number[] = [],
67
+ private readonly trustedTargets: number[] = [],
68
+ private readonly paradiseFishTargets: number[] = [],
69
69
  ) {
70
70
  super();
71
71
  this.greeting = new GreetingTracker(greetingPhrases);
@@ -125,7 +125,7 @@ describe('ParadiseFishTop patrol routing', () => {
125
125
  });
126
126
 
127
127
  it('hard-avoids hostileTargets', () => {
128
- const top = new ParadiseFishTop([], ['danger']);
128
+ const top = new ParadiseFishTop([], [2]);
129
129
 
130
130
  top.tick(state({
131
131
  players: [{ name: 'danger', seat: 2, x: 1986, y: 994, room: 'control', distance: 591 }],
@@ -135,7 +135,7 @@ describe('ParadiseFishTop patrol routing', () => {
135
135
  });
136
136
 
137
137
  it('gives trustedTargets priority over hostileTargets', () => {
138
- const top = new ParadiseFishTop([], ['friend'], ['friend']);
138
+ const top = new ParadiseFishTop([], [2], [2]);
139
139
 
140
140
  top.tick(state({
141
141
  players: [{ name: 'friend', seat: 2, x: 1986, y: 994, room: 'control', distance: 591 }],
@@ -190,7 +190,7 @@ describe('ParadiseFishTop patrol routing', () => {
190
190
  });
191
191
 
192
192
  it('still escapes an explicitly hostile player while a task is running', () => {
193
- const top = new ParadiseFishTop([], ['danger']);
193
+ const top = new ParadiseFishTop([], [2]);
194
194
  const ctx = context({ playerNamesBySeat: { '2': 'danger' } });
195
195
  const current = state({
196
196
  you: { ...state().you, doing_task: true, task_name: '解除毒药' },
@@ -34,8 +34,8 @@ export class ParadiseFishTop extends Goal {
34
34
 
35
35
  constructor(
36
36
  greetingPhrases: string[] = [],
37
- private readonly hostileTargets: string[] = [],
38
- private readonly trustedTargets: string[] = [],
37
+ private readonly hostileTargets: number[] = [],
38
+ private readonly trustedTargets: number[] = [],
39
39
  ) {
40
40
  super();
41
41
  this.greeting = new GreetingTracker(greetingPhrases);
@@ -16,7 +16,7 @@ import type { BehaviorDecision, StrategyContext } from '../types.js';
16
16
  import { Goal } from './goal.js';
17
17
 
18
18
  export interface SocialTarget {
19
- target: string;
19
+ target: number;
20
20
  greeting: string | null;
21
21
  }
22
22
 
@@ -31,7 +31,7 @@ const SILENCE_TIMEOUT_MS = 10_000;
31
31
 
32
32
  export class SocialTaskTop extends Goal {
33
33
  private readonly socialTargets: SocialTarget[];
34
- private readonly targetStates = new Map<string, SocialTargetState>();
34
+ private readonly targetStates = new Map<number, SocialTargetState>();
35
35
 
36
36
  constructor(socialTargets: SocialTarget[]) {
37
37
  super();
@@ -63,7 +63,7 @@ export class SocialTaskTop extends Goal {
63
63
 
64
64
  const targetState = this.targetStates.get(st.target)!;
65
65
  const d = visiblePlayer.distance ?? dist(state.you.x, state.you.y, visiblePlayer.x, visiblePlayer.y);
66
- const targetName = visiblePlayer.name || st.target;
66
+ const targetName = visiblePlayer.name || `${st.target}号`;
67
67
  const targetLabel = strategyPlayerLabel(visiblePlayer);
68
68
  const targetRoom = visiblePlayer.room || state.you.room || '当前位置';
69
69