@myclaw163/clawclaw-cli 0.8.4 → 0.8.5
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 +3 -2
- package/docs/configuration.md +44 -26
- package/docs/custom-modules/README.md +7 -10
- package/docs/custom-modules/behavior.md +3 -1
- package/docs/custom-modules/perception.md +1 -1
- package/docs/custom-modules/trigger.md +1 -1
- package/docs/runtime/README.md +4 -4
- package/docs/runtime/official-perception-modules.md +2 -2
- package/docs/runtime/owner-lifecycle-and-observability.md +1 -1
- package/package.json +9 -2
- package/scripts/build-official-hub-behaviors.mjs +136 -0
- package/scripts/build-official-hub-behaviors.test.mjs +178 -0
- package/scripts/enable_ccl_permissions.cjs +4 -2
- package/scripts/enable_ccl_permissions.test.mjs +8 -4
- package/scripts/postinstall.mjs +1 -4
- package/scripts/sync-bundled-skill.mjs +12 -159
- package/scripts/sync-bundled-skill.test.mjs +9 -74
- package/skills/clawclaw/SKILL.md +14 -9
- package/skills/clawclaw/references/BEHAVIORS.md +4 -4
- package/skills/clawclaw/references/COMMANDS.md +32 -16
- package/skills/clawclaw/references/HUB.md +25 -38
- package/src/commands/account.ts +58 -14
- package/src/commands/behavior.ts +116 -38
- package/src/commands/hub.ts +110 -153
- package/src/commands/load.ts +138 -33
- package/src/commands/perception.ts +55 -24
- package/src/commands/persona.ts +66 -20
- package/src/commands/skill.ts +12 -48
- package/src/commands/trigger.ts +68 -40
- package/src/hub-official-behaviors/kill-lone.ts +138 -0
- package/src/hub-official-behaviors/patrol.ts +30 -0
- package/src/hub-official-behaviors/shared.ts +125 -0
- package/src/hub-official-behaviors/task-only.ts +158 -0
- package/src/lib/account-guidance.ts +54 -9
- package/src/lib/agent-workspace-client.ts +135 -0
- package/src/lib/agent-workspace-runtime.ts +154 -0
- package/src/lib/agent-workspace-skills.ts +177 -0
- package/src/lib/agent-workspace-sync.ts +852 -0
- package/src/lib/gameplay-config.ts +29 -15
- package/src/lib/hub-client.ts +252 -34
- package/src/lib/hub-reminder.ts +22 -7
- package/src/lib/init-command.ts +0 -6
- package/src/lib/load-context.ts +12 -6
- package/src/lib/persona.ts +141 -69
- package/src/lib/server-status.ts +78 -0
- package/src/lib/skill-host.ts +160 -0
- package/src/lib/user-data.ts +197 -4
- package/src/runtime/clawclaw/owner.ts +63 -19
- package/src/runtime/clawclaw/plugins/behavior/activation-manager.ts +8 -2
- package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +2 -2
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +4 -1
- package/src/runtime/clawclaw/plugins/perception/perception-source.ts +11 -5
- package/src/runtime/clawclaw/plugins/perception/replay.ts +0 -2
- package/personas//345/217/243/346/230/257/345/277/203/351/235/236.md +0 -50
- package/personas//345/277/240/345/277/203/350/200/201/344/273/206.md +0 -51
- package/personas//346/227/240/344/272/272/350/256/276.md +0 -1
- package/personas//350/264/253/345/230/264/346/215/237/345/217/213.md +0 -48
- package/personas//350/275/257/350/220/214/350/205/271/351/273/221.md +0 -51
- package/src/behaviors/official-finite/index.test.ts +0 -249
- package/src/channel/claude-channel-server.test.ts +0 -202
- package/src/commands/account.test.ts +0 -570
- package/src/commands/behavior.test.ts +0 -158
- package/src/commands/communication.test.ts +0 -282
- package/src/commands/competition.test.ts +0 -116
- package/src/commands/data.test.ts +0 -89
- package/src/commands/events-canonical-state.test.ts +0 -406
- package/src/commands/events.test.ts +0 -58
- package/src/commands/game/index.test.ts +0 -1251
- package/src/commands/game-map.test.ts +0 -69
- package/src/commands/hub.test.ts +0 -124
- package/src/commands/load.test.ts +0 -440
- package/src/commands/perception.test.ts +0 -75
- package/src/commands/setup/hermes.test.ts +0 -96
- package/src/commands/setup/openclaw.test.ts +0 -124
- package/src/commands/trigger.test.ts +0 -140
- package/src/commands/upgrade.test.ts +0 -82
- package/src/lib/account-guidance.test.ts +0 -36
- package/src/lib/auth.test.ts +0 -151
- package/src/lib/behavior-export.test.ts +0 -326
- package/src/lib/behavior-export.ts +0 -537
- package/src/lib/clawclaw-skill-spectate-guidance.test.ts +0 -21
- package/src/lib/custom-tts.test.ts +0 -387
- package/src/lib/diagnostics-config.test.ts +0 -59
- package/src/lib/game-client-tts.test.ts +0 -151
- package/src/lib/game-client.test.ts +0 -250
- package/src/lib/gameplay-config.test.ts +0 -301
- package/src/lib/host-config-patcher.test.ts +0 -130
- package/src/lib/http-transport.test.ts +0 -124
- package/src/lib/hub-client.test.ts +0 -57
- package/src/lib/hub-install.test.ts +0 -135
- package/src/lib/hub-install.ts +0 -185
- package/src/lib/hub-unzip.test.ts +0 -69
- package/src/lib/init-command.test.ts +0 -103
- package/src/lib/load-context.test.ts +0 -62
- package/src/lib/match-state.test.ts +0 -134
- package/src/lib/official-resource-sync.test.ts +0 -199
- package/src/lib/official-resource-sync.ts +0 -221
- package/src/lib/perception-config.test.ts +0 -143
- package/src/lib/perception-export.test.ts +0 -145
- package/src/lib/perception-export.ts +0 -178
- package/src/lib/persona.test.ts +0 -84
- package/src/lib/room.test.ts +0 -88
- package/src/lib/server-registry.test.ts +0 -64
- package/src/lib/service-status.test.ts +0 -81
- package/src/lib/skill-version.test.ts +0 -48
- package/src/lib/trigger-config.test.ts +0 -102
- package/src/lib/trigger-export.test.ts +0 -80
- package/src/lib/trigger-export.ts +0 -210
- package/src/lib/user-data.test.ts +0 -121
- package/src/lib/workspace-argv.test.ts +0 -49
- package/src/pipeline/canonical-event-presentation.test.ts +0 -257
- package/src/pipeline/event-format.test.ts +0 -879
- package/src/pipeline/event-hints.test.ts +0 -337
- package/src/pipeline/game-sync-event-normalization.test.ts +0 -419
- package/src/pipeline/player-projection.test.ts +0 -247
- package/src/runtime/auto-upgrade.test.ts +0 -66
- package/src/runtime/canonical-event-emitter.test.ts +0 -70
- package/src/runtime/canonical-monitor.test.ts +0 -577
- package/src/runtime/clawclaw/agent-event-policy.test.ts +0 -60
- package/src/runtime/clawclaw/behavior-decision.test.ts +0 -43
- package/src/runtime/clawclaw/behavior-input-fields.test.ts +0 -175
- package/src/runtime/clawclaw/behavior-input.test.ts +0 -173
- package/src/runtime/clawclaw/behavior-observation-memory.test.ts +0 -59
- package/src/runtime/clawclaw/behavior-read-api.test.ts +0 -123
- package/src/runtime/clawclaw/notifications.test.ts +0 -47
- package/src/runtime/clawclaw/owner-lock.test.ts +0 -221
- package/src/runtime/clawclaw/owner.test.ts +0 -203
- package/src/runtime/clawclaw/plugins/action/action-plugin.test.ts +0 -328
- package/src/runtime/clawclaw/plugins/assembly.test.ts +0 -200
- package/src/runtime/clawclaw/plugins/behavior/activation-manager.test.ts +0 -180
- package/src/runtime/clawclaw/plugins/behavior/behavior-action.test.ts +0 -43
- package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.test.ts +0 -156
- package/src/runtime/clawclaw/plugins/behavior/behavior-module-loader.test.ts +0 -182
- package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.test.ts +0 -1094
- package/src/runtime/clawclaw/plugins/behavior/behavior-source.test.ts +0 -174
- package/src/runtime/clawclaw/plugins/behavior/control-driver.test.ts +0 -195
- package/src/runtime/clawclaw/plugins/behavior/thread-behavior-executor.test.ts +0 -283
- package/src/runtime/clawclaw/plugins/behavior-input-source.test.ts +0 -80
- package/src/runtime/clawclaw/plugins/derived-event/derived-event-plugin.test.ts +0 -267
- package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.test.ts +0 -226
- package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.test.ts +0 -239
- package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.test.ts +0 -407
- package/src/runtime/clawclaw/plugins/mailbox/desktop-event-push.integration.test.ts +0 -397
- package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.test.ts +0 -270
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-agent-event-batch.test.ts +0 -166
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-event-batch-delivery.test.ts +0 -194
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.test.ts +0 -87
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.test.ts +0 -2012
- package/src/runtime/clawclaw/plugins/perception/module-runner.test.ts +0 -214
- package/src/runtime/clawclaw/plugins/perception/modules/co-movement-module.ts +0 -347
- package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.test.ts +0 -92
- package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.ts +0 -248
- package/src/runtime/clawclaw/plugins/perception/modules/follow-module.ts +0 -389
- package/src/runtime/clawclaw/plugins/perception/modules/index.ts +0 -8
- package/src/runtime/clawclaw/plugins/perception/modules/motion-module.test.ts +0 -342
- package/src/runtime/clawclaw/plugins/perception/modules/motion-module.ts +0 -475
- package/src/runtime/clawclaw/plugins/perception/modules/parallel-module-test-helpers.ts +0 -30
- package/src/runtime/clawclaw/plugins/perception/modules/relation-stability.test.ts +0 -304
- package/src/runtime/clawclaw/plugins/perception/modules/route-module.test.ts +0 -179
- package/src/runtime/clawclaw/plugins/perception/modules/route-module.ts +0 -364
- package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.test.ts +0 -81
- package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.ts +0 -200
- package/src/runtime/clawclaw/plugins/perception/modules/stop-module.test.ts +0 -216
- package/src/runtime/clawclaw/plugins/perception/modules/stop-module.ts +0 -284
- package/src/runtime/clawclaw/plugins/perception/modules/temporal-evidence.test.ts +0 -120
- package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.test.ts +0 -105
- package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.ts +0 -269
- package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.test.ts +0 -865
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.test.ts +0 -1878
- package/src/runtime/clawclaw/plugins/perception/perception-source.test.ts +0 -278
- package/src/runtime/clawclaw/plugins/perception/replay.test.ts +0 -77
- package/src/runtime/clawclaw/plugins/runtime-plugins.test.ts +0 -853
- package/src/runtime/clawclaw/plugins/source/game-transport.test.ts +0 -287
- package/src/runtime/clawclaw/plugins/source/player-change-tracker.test.ts +0 -321
- package/src/runtime/clawclaw/plugins/source/room-transport.test.ts +0 -307
- package/src/runtime/clawclaw/plugins/source/source-plugin.test.ts +0 -2646
- package/src/runtime/clawclaw/plugins/source/task-change-tracker.test.ts +0 -212
- package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.test.ts +0 -548
- package/src/runtime/clawclaw/plugins/trigger/trigger-source.test.ts +0 -169
- package/src/runtime/clawclaw/runtime-data-export.test.ts +0 -249
- package/src/runtime/clawclaw-event-catalog.test.ts +0 -128
- package/src/runtime/framework/action-diagnostics.test.ts +0 -81
- package/src/runtime/framework/capability-registry.test.ts +0 -423
- package/src/runtime/framework/control-coordinator.test.ts +0 -675
- package/src/runtime/framework/events/event-delivery-service.test.ts +0 -84
- package/src/runtime/framework/events/event-ingress.test.ts +0 -203
- package/src/runtime/framework/events/mailbox-event-repositories.test.ts +0 -710
- package/src/runtime/framework/events/sqlite-event-repository.test.ts +0 -802
- package/src/runtime/framework/mailbox/coalescer.test.ts +0 -55
- package/src/runtime/framework/mailbox/identity.test.ts +0 -38
- package/src/runtime/framework/mailbox/mailbox-dispatcher.test.ts +0 -513
- package/src/runtime/framework/mailbox/notification-projector.test.ts +0 -77
- package/src/runtime/framework/modules/runtime-module-loader.test.ts +0 -435
- package/src/runtime/framework/participation-manager.test.ts +0 -108
- package/src/runtime/framework/plugins/runtime-input-journal.test.ts +0 -179
- package/src/runtime/framework/plugins/runtime-plugin-scheduler.test.ts +0 -2040
- package/src/runtime/framework/state/durable-agent-state-snapshot.test.ts +0 -144
- package/src/runtime/framework/state/history/sqlite-state-history-repository.test.ts +0 -157
- package/src/runtime/framework/state/history/state-history.test.ts +0 -251
- package/src/runtime/framework/state/state-core.test.ts +0 -197
- package/src/runtime/game-sync-protocol.test.ts +0 -123
- package/src/runtime/host-monitor-rate-gate.test.ts +0 -73
- package/src/runtime/mailbox-host-relay.test.ts +0 -293
- package/src/runtime/observability/observability.test.ts +0 -583
- package/src/runtime/owner-control.test.ts +0 -153
- package/src/runtime/parent-process-watch.test.ts +0 -27
- package/src/runtime/pending-event-handoff.test.ts +0 -29
- package/src/runtime/raw-ws-log.test.ts +0 -102
- package/src/runtime/runtime-logger.test.ts +0 -58
- package/src/runtime/runtime-persistence.test.ts +0 -26
- package/src/runtime/runtime.test.ts +0 -1770
- package/src/runtime/ws-client.test.ts +0 -562
- package/src/sdk/action.test.ts +0 -8
- package/src/sdk/behavior-plugin/index.test.ts +0 -74
- package/src/sdk/index.test.ts +0 -45
- package/src/sdk/module-input/index.test.ts +0 -49
- package/src/sdk/perception-plugin/index.test.ts +0 -22
- package/src/sdk/resource-metadata.test.ts +0 -40
- package/src/sdk/trigger-plugin/index.test.ts +0 -41
- package/src/short-command/classifier.test.ts +0 -107
- package/src/short-command/presenter.test.ts +0 -119
- package/src/short-command/runner.test.ts +0 -78
- package/src/short-command/sensitive-data-filter.test.ts +0 -56
- package/src/short-command/transport-response.test.ts +0 -39
- package/src/strategies/custom-module.test.ts +0 -267
- package/src/strategies/game-utils.test.ts +0 -305
- package/src/strategies/goals/avoid-players-top.test.ts +0 -95
- package/src/strategies/goals/crab-sabotage-top.test.ts +0 -131
- package/src/strategies/goals/kill-lone-top.test.ts +0 -96
- package/src/strategies/goals/kill-target-top.test.ts +0 -65
- package/src/strategies/goals/lone-kill-task-top.test.ts +0 -84
- package/src/strategies/goals/normal-shrimp-top.test.ts +0 -112
- package/src/strategies/goals/paradise-fish-top.test.ts +0 -203
- package/src/strategies/goals/task-only-top.test.ts +0 -88
- package/src/strategies/goals/warrior-shrimp-top.test.ts +0 -138
- package/src/strategies/meeting-gate.test.ts +0 -59
- package/src/strategies/official-long-behavior.test.ts +0 -89
- package/src/strategies/pathfind/astar-path.test.ts +0 -198
- package/src/strategies/pathfind/escape-planner.test.ts +0 -223
- package/src/strategies/player-targets.test.ts +0 -10
- package/src/strategies/task-only.test.ts +0 -138
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ClawclawParallelPerception,
|
|
3
|
-
type PerceptionAnalysisInput,
|
|
4
|
-
type PerceptionApi,
|
|
5
|
-
type PerceptionBoundary,
|
|
6
|
-
type PerceptionEventProposal,
|
|
7
|
-
type PerceptionFrame,
|
|
8
|
-
type VisualCorpse,
|
|
9
|
-
} from '../contracts.js';
|
|
10
|
-
import { headingDirection, round1, timeRange } from '../shared/math.js';
|
|
11
|
-
|
|
12
|
-
function isPerceptionActive(
|
|
13
|
-
frame: Readonly<PerceptionFrame> | null | undefined,
|
|
14
|
-
): frame is Readonly<PerceptionFrame> {
|
|
15
|
-
return !!frame
|
|
16
|
-
&& frame.gameState.phase === 'wandering'
|
|
17
|
-
&& frame.gameState.you?.is_alive !== false;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
type RelativeDirection = ReturnType<typeof headingDirection>;
|
|
21
|
-
|
|
22
|
-
interface CorpseVisibilityFact {
|
|
23
|
-
readonly id: string;
|
|
24
|
-
readonly place: string;
|
|
25
|
-
readonly relativeDirection: RelativeDirection | null;
|
|
26
|
-
readonly distancePx: number | null;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
interface CorpseVisibilityAnalysis {
|
|
30
|
-
readonly corpses: readonly CorpseVisibilityFact[];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function corpseLabel(corpse: VisualCorpse): string {
|
|
34
|
-
if (corpse.seat !== undefined) return `${corpse.seat}号${corpse.name ?? ''}`;
|
|
35
|
-
return corpse.name ?? corpse.id;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function directionText(direction: RelativeDirection | null): string {
|
|
39
|
-
return !direction || direction === '原地' ? '附近' : `${direction}侧`;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function distanceText(distancePx: number | null): string {
|
|
43
|
-
return distancePx === null ? '' : `,距你${distancePx}px`;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export class CorpseVisibilityModule extends ClawclawParallelPerception<CorpseVisibilityAnalysis> {
|
|
47
|
-
static readonly manifest = {
|
|
48
|
-
apiVersion: 2,
|
|
49
|
-
id: 'visual.corpse_visibility',
|
|
50
|
-
name: 'Corpse visibility changes',
|
|
51
|
-
description: 'Reports corpses entering or leaving the observer field of view.',
|
|
52
|
-
subjectScope: 'corpses',
|
|
53
|
-
produces: [
|
|
54
|
-
'visual.corpse_entered',
|
|
55
|
-
'visual.corpse_left',
|
|
56
|
-
],
|
|
57
|
-
execution: 'parallel_analysis',
|
|
58
|
-
boundaryBaseline: 'current_only',
|
|
59
|
-
} as const;
|
|
60
|
-
|
|
61
|
-
private previousTick: number | null = null;
|
|
62
|
-
private previous: PerceptionFrame | null = null;
|
|
63
|
-
private pending: PerceptionFrame | null = null;
|
|
64
|
-
private pendingAnalysis: Readonly<CorpseVisibilityAnalysis> | null = null;
|
|
65
|
-
private visibleCorpseIds: string[] = [];
|
|
66
|
-
|
|
67
|
-
analyze(input: Readonly<PerceptionAnalysisInput>, api: PerceptionApi): CorpseVisibilityAnalysis {
|
|
68
|
-
const observer = input.frame.observation.players.find((player) => player.observer);
|
|
69
|
-
return {
|
|
70
|
-
corpses: input.frame.observation.corpses.map((corpse) => ({
|
|
71
|
-
id: corpse.id,
|
|
72
|
-
place: api.spatial.placeLabel(corpse),
|
|
73
|
-
relativeDirection: observer ? headingDirection(observer, corpse, 1) : null,
|
|
74
|
-
distancePx: observer ? round1(Math.hypot(corpse.x - observer.x, corpse.y - observer.y)) : null,
|
|
75
|
-
})),
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
commit(
|
|
80
|
-
frame: PerceptionFrame,
|
|
81
|
-
analysis: Readonly<CorpseVisibilityAnalysis>,
|
|
82
|
-
api: PerceptionApi,
|
|
83
|
-
): PerceptionEventProposal[] {
|
|
84
|
-
this.previousTick = frame.tick;
|
|
85
|
-
this.visibleCorpseIds = frame.observation.corpses.map((corpse) => corpse.id);
|
|
86
|
-
if (!isPerceptionActive(frame)) {
|
|
87
|
-
const proposals = this.commitPending(api);
|
|
88
|
-
this.reset();
|
|
89
|
-
return proposals;
|
|
90
|
-
}
|
|
91
|
-
if (!this.pending) {
|
|
92
|
-
this.pending = frame;
|
|
93
|
-
this.pendingAnalysis = analysis;
|
|
94
|
-
return [];
|
|
95
|
-
}
|
|
96
|
-
if (frame.tick === this.pending.tick) {
|
|
97
|
-
this.pending = this.sameTickRevision(this.pending, frame);
|
|
98
|
-
this.pendingAnalysis = analysis;
|
|
99
|
-
return [];
|
|
100
|
-
}
|
|
101
|
-
if (frame.tick < this.pending.tick || !frame.continuousFromPrevious) {
|
|
102
|
-
this.reset();
|
|
103
|
-
this.previousTick = frame.tick;
|
|
104
|
-
this.visibleCorpseIds = frame.observation.corpses.map((corpse) => corpse.id);
|
|
105
|
-
this.pending = frame;
|
|
106
|
-
this.pendingAnalysis = analysis;
|
|
107
|
-
return [];
|
|
108
|
-
}
|
|
109
|
-
const proposals = this.commitPending(api);
|
|
110
|
-
this.pending = frame;
|
|
111
|
-
this.pendingAnalysis = analysis;
|
|
112
|
-
return proposals;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
flush(boundary: PerceptionBoundary, api: PerceptionApi): PerceptionEventProposal[] {
|
|
116
|
-
return boundary.mode === 'close' ? this.commitPending(api) : [];
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
private commitPending(api: PerceptionApi): PerceptionEventProposal[] {
|
|
120
|
-
const frame = this.pending;
|
|
121
|
-
if (!frame) return [];
|
|
122
|
-
const analysis = this.pendingAnalysis;
|
|
123
|
-
this.pending = null;
|
|
124
|
-
this.pendingAnalysis = null;
|
|
125
|
-
const previous = frame.continuousFromPrevious ? this.previous : null;
|
|
126
|
-
if (!isPerceptionActive(previous)) {
|
|
127
|
-
this.previous = frame;
|
|
128
|
-
return [];
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const proposals: PerceptionEventProposal[] = [];
|
|
132
|
-
const occurredAt = Number.isFinite(frame.timeMs)
|
|
133
|
-
? new Date(frame.timeMs).toISOString()
|
|
134
|
-
: undefined;
|
|
135
|
-
const before = new Map(previous.observation.corpses.map((corpse) => [corpse.id, corpse]));
|
|
136
|
-
const current = new Map(frame.observation.corpses.map((corpse) => [corpse.id, corpse]));
|
|
137
|
-
const observer = frame.observation.players.find((player) => player.observer);
|
|
138
|
-
const analyzed = new Map(analysis?.corpses.map((corpse) => [corpse.id, corpse]));
|
|
139
|
-
|
|
140
|
-
for (const corpse of frame.observation.corpses) {
|
|
141
|
-
if (before.has(corpse.id)) continue;
|
|
142
|
-
const fact = analyzed.get(corpse.id);
|
|
143
|
-
const relativeDirection = fact?.relativeDirection
|
|
144
|
-
?? (observer ? headingDirection(observer, corpse, 1) : null);
|
|
145
|
-
const distancePx = fact?.distancePx
|
|
146
|
-
?? (observer ? round1(Math.hypot(corpse.x - observer.x, corpse.y - observer.y)) : null);
|
|
147
|
-
const place = fact?.place ?? api.spatial.placeLabel(corpse);
|
|
148
|
-
proposals.push({
|
|
149
|
-
type: 'visual.corpse_entered',
|
|
150
|
-
dedupeKey: `corpse-entered:${corpse.id}:${frame.frameSeq}`,
|
|
151
|
-
occurredAt,
|
|
152
|
-
payload: {
|
|
153
|
-
from_tick: frame.tick,
|
|
154
|
-
to_tick: frame.tick,
|
|
155
|
-
actors: [corpse.seat ?? corpse.id],
|
|
156
|
-
text: `${timeRange(frame.tick, frame.tick)},${corpseLabel(corpse)}的尸体从${directionText(relativeDirection)}进入视野,位于${place}${distanceText(distancePx)}。`,
|
|
157
|
-
data: {
|
|
158
|
-
corpse_id: corpse.id,
|
|
159
|
-
room: corpse.room,
|
|
160
|
-
relative_direction: relativeDirection,
|
|
161
|
-
distance_px: distancePx,
|
|
162
|
-
},
|
|
163
|
-
},
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (frame.observation.visibleSetComplete) {
|
|
168
|
-
const previousObserver = previous.observation.players.find((player) => player.observer);
|
|
169
|
-
for (const corpse of previous.observation.corpses) {
|
|
170
|
-
if (current.has(corpse.id)) continue;
|
|
171
|
-
const relativeDirection = previousObserver
|
|
172
|
-
? headingDirection(previousObserver, corpse, 1)
|
|
173
|
-
: null;
|
|
174
|
-
const distancePx = previousObserver
|
|
175
|
-
? round1(Math.hypot(corpse.x - previousObserver.x, corpse.y - previousObserver.y))
|
|
176
|
-
: null;
|
|
177
|
-
const place = api.spatial.placeLabel(corpse);
|
|
178
|
-
proposals.push({
|
|
179
|
-
type: 'visual.corpse_left',
|
|
180
|
-
dedupeKey: `corpse-left:${corpse.id}:${frame.frameSeq}`,
|
|
181
|
-
occurredAt,
|
|
182
|
-
payload: {
|
|
183
|
-
from_tick: frame.tick,
|
|
184
|
-
to_tick: frame.tick,
|
|
185
|
-
actors: [corpse.seat ?? corpse.id],
|
|
186
|
-
text: `${timeRange(frame.tick, frame.tick)},${corpseLabel(corpse)}的尸体从${directionText(relativeDirection)}离开视野,最后位于${place}${distanceText(distancePx)}。`,
|
|
187
|
-
data: {
|
|
188
|
-
corpse_id: corpse.id,
|
|
189
|
-
room: corpse.room,
|
|
190
|
-
relative_direction: relativeDirection,
|
|
191
|
-
distance_px: distancePx,
|
|
192
|
-
},
|
|
193
|
-
},
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
if (frame.observation.visibleSetComplete) {
|
|
199
|
-
this.previous = frame;
|
|
200
|
-
} else {
|
|
201
|
-
const observed = new Set(frame.observation.corpses.map((corpse) => corpse.id));
|
|
202
|
-
this.previous = {
|
|
203
|
-
...frame,
|
|
204
|
-
observation: {
|
|
205
|
-
...frame.observation,
|
|
206
|
-
corpses: [
|
|
207
|
-
...frame.observation.corpses,
|
|
208
|
-
...previous.observation.corpses.filter((corpse) => !observed.has(corpse.id)),
|
|
209
|
-
],
|
|
210
|
-
},
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
return proposals;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
private sameTickRevision(previous: PerceptionFrame, frame: PerceptionFrame): PerceptionFrame {
|
|
217
|
-
if (frame.observation.visibleSetComplete) return frame;
|
|
218
|
-
const observed = new Set(frame.observation.corpses.map((corpse) => corpse.id));
|
|
219
|
-
return {
|
|
220
|
-
...frame,
|
|
221
|
-
observation: {
|
|
222
|
-
...frame.observation,
|
|
223
|
-
corpses: [
|
|
224
|
-
...frame.observation.corpses,
|
|
225
|
-
...previous.observation.corpses.filter((corpse) => !observed.has(corpse.id)),
|
|
226
|
-
],
|
|
227
|
-
visibleSetComplete: false,
|
|
228
|
-
},
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
reset(): void {
|
|
233
|
-
this.previousTick = null;
|
|
234
|
-
this.previous = null;
|
|
235
|
-
this.pending = null;
|
|
236
|
-
this.pendingAnalysis = null;
|
|
237
|
-
this.visibleCorpseIds = [];
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
debugSnapshot(): Record<string, unknown> {
|
|
241
|
-
return {
|
|
242
|
-
previous_tick: this.previousTick,
|
|
243
|
-
visible_corpse_ids: [...this.visibleCorpseIds],
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
export default CorpseVisibilityModule;
|
|
@@ -1,389 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ClawclawParallelPerception,
|
|
3
|
-
type PerceptionAnalysisInput,
|
|
4
|
-
type PerceptionApi,
|
|
5
|
-
type PerceptionBoundary,
|
|
6
|
-
type PerceptionEventProposal,
|
|
7
|
-
type VisualPlayer,
|
|
8
|
-
type PerceptionFrame,
|
|
9
|
-
} from '../contracts.js';
|
|
10
|
-
import {
|
|
11
|
-
STEP_MOVE_MIN_PX,
|
|
12
|
-
actorLabel,
|
|
13
|
-
actorValue,
|
|
14
|
-
cosine,
|
|
15
|
-
cross,
|
|
16
|
-
distance,
|
|
17
|
-
dot,
|
|
18
|
-
timeRange,
|
|
19
|
-
unit,
|
|
20
|
-
vector,
|
|
21
|
-
} from '../shared/math.js';
|
|
22
|
-
|
|
23
|
-
function isPerceptionActive(
|
|
24
|
-
frame: Readonly<PerceptionFrame> | null | undefined,
|
|
25
|
-
): frame is Readonly<PerceptionFrame> {
|
|
26
|
-
return !!frame
|
|
27
|
-
&& frame.gameState.phase === 'wandering'
|
|
28
|
-
&& frame.gameState.you?.is_alive !== false;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
interface FollowCandidate {
|
|
32
|
-
follower: VisualPlayer;
|
|
33
|
-
leader: VisualPlayer;
|
|
34
|
-
fromTick: number;
|
|
35
|
-
lastTick: number;
|
|
36
|
-
samples: number;
|
|
37
|
-
evidenceTicks: number;
|
|
38
|
-
missTicks: number;
|
|
39
|
-
active: boolean;
|
|
40
|
-
reportedThroughTick: number;
|
|
41
|
-
distanceSum: number;
|
|
42
|
-
bodyLengthPx: number;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const MAX_FOLLOW_CANDIDATES = 64;
|
|
46
|
-
/** Following is a stronger claim, so keep more than one second of evidence. */
|
|
47
|
-
const START_CONFIRM_TICKS = 12;
|
|
48
|
-
/** Do not end an active relation on a momentary turn or distance threshold miss. */
|
|
49
|
-
const ACTIVE_EXIT_CONFIRM_TICKS = 10;
|
|
50
|
-
const CANDIDATE_EXIT_CONFIRM_TICKS = 3;
|
|
51
|
-
/** Query snapshots only expose a meaningful new relation span. */
|
|
52
|
-
const SNAPSHOT_REPORT_TICKS = 30;
|
|
53
|
-
|
|
54
|
-
function keyFor(follower: string, leader: string): string {
|
|
55
|
-
return `${follower}\u001f${leader}`;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
interface FollowAnalysis {
|
|
59
|
-
readonly previousFrameSeq: number | null;
|
|
60
|
-
readonly previousPlayerIds: readonly string[];
|
|
61
|
-
readonly playerBodyLengthPx: number;
|
|
62
|
-
readonly qualifiedCandidates: readonly Readonly<{
|
|
63
|
-
key: string;
|
|
64
|
-
followerId: string;
|
|
65
|
-
leaderId: string;
|
|
66
|
-
distancePx: number;
|
|
67
|
-
}>[];
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export class FollowModule extends ClawclawParallelPerception<FollowAnalysis> {
|
|
71
|
-
static readonly manifest = {
|
|
72
|
-
apiVersion: 2,
|
|
73
|
-
id: 'visual.follow',
|
|
74
|
-
name: 'Following',
|
|
75
|
-
description: 'Reports a stable front/back following relation between visible players.',
|
|
76
|
-
localizations: {
|
|
77
|
-
'zh-CN': {
|
|
78
|
-
name: '跟随关系',
|
|
79
|
-
description: '感知同时可见玩家之间稳定的前后跟随关系。',
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
subjectScope: 'visible_pairs',
|
|
83
|
-
produces: ['visual.following', 'visual.following_ended'],
|
|
84
|
-
eventMetadata: {
|
|
85
|
-
'visual.following': {
|
|
86
|
-
name: 'Following relation',
|
|
87
|
-
description: 'Reports one visible player moving steadily behind another in the same direction.',
|
|
88
|
-
localizations: {
|
|
89
|
-
'zh-CN': { name: '跟随关系', description: '一名玩家稳定地跟在另一名玩家后方同方向移动。' },
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
'visual.following_ended': {
|
|
93
|
-
name: 'Following relation ended',
|
|
94
|
-
description: 'Reports when two players stop maintaining a confirmed front/back relation.',
|
|
95
|
-
localizations: {
|
|
96
|
-
'zh-CN': { name: '跟随关系结束', description: '两名玩家不再保持已确认的前后跟随关系。' },
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
execution: 'parallel_analysis',
|
|
101
|
-
boundaryBaseline: 'current_only',
|
|
102
|
-
} as const;
|
|
103
|
-
private previous: PerceptionFrame | null = null;
|
|
104
|
-
private readonly candidates = new Map<string, FollowCandidate>();
|
|
105
|
-
private pendingAbsenceTick: number | null = null;
|
|
106
|
-
private readonly pendingAbsences = new Set<string>();
|
|
107
|
-
|
|
108
|
-
analyze(input: Readonly<PerceptionAnalysisInput>, api: PerceptionApi): FollowAnalysis {
|
|
109
|
-
const previous = input.history.at(-1) ?? null;
|
|
110
|
-
const qualifiedCandidates: Array<{
|
|
111
|
-
key: string;
|
|
112
|
-
followerId: string;
|
|
113
|
-
leaderId: string;
|
|
114
|
-
distancePx: number;
|
|
115
|
-
}> = [];
|
|
116
|
-
if (
|
|
117
|
-
isPerceptionActive(previous)
|
|
118
|
-
&& isPerceptionActive(input.frame)
|
|
119
|
-
&& input.frame.tick !== previous.tick
|
|
120
|
-
) {
|
|
121
|
-
const before = new Map(previous.observation.players.map((player) => [player.id, player]));
|
|
122
|
-
for (let left = 0; left < input.frame.observation.players.length; left += 1) {
|
|
123
|
-
for (let right = left + 1; right < input.frame.observation.players.length; right += 1) {
|
|
124
|
-
const a = input.frame.observation.players[left]!;
|
|
125
|
-
const b = input.frame.observation.players[right]!;
|
|
126
|
-
const previousA = before.get(a.id);
|
|
127
|
-
const previousB = before.get(b.id);
|
|
128
|
-
if (!previousA || !previousB) continue;
|
|
129
|
-
const av = vector(previousA, a);
|
|
130
|
-
const bv = vector(previousB, b);
|
|
131
|
-
const pairDistance = distance(a, b);
|
|
132
|
-
if (
|
|
133
|
-
distance(previousA, a) < STEP_MOVE_MIN_PX
|
|
134
|
-
|| distance(previousB, b) < STEP_MOVE_MIN_PX
|
|
135
|
-
|| cosine(av, bv) < 0.85
|
|
136
|
-
|| pairDistance > api.spatial.playerBodyLengthPx * 3
|
|
137
|
-
) continue;
|
|
138
|
-
const movement = unit({ x: av.x + bv.x, y: av.y + bv.y });
|
|
139
|
-
const relativeA = vector(b, a);
|
|
140
|
-
const longitudinalA = dot(relativeA, movement);
|
|
141
|
-
const lateral = Math.abs(cross(relativeA, movement));
|
|
142
|
-
if (
|
|
143
|
-
lateral > api.spatial.playerBodyLengthPx * 0.8
|
|
144
|
-
|| Math.abs(longitudinalA) < 20
|
|
145
|
-
) continue;
|
|
146
|
-
const follower = longitudinalA < 0 ? a : b;
|
|
147
|
-
const leader = longitudinalA < 0 ? b : a;
|
|
148
|
-
qualifiedCandidates.push({
|
|
149
|
-
key: keyFor(follower.id, leader.id),
|
|
150
|
-
followerId: follower.id,
|
|
151
|
-
leaderId: leader.id,
|
|
152
|
-
distancePx: pairDistance,
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
return {
|
|
158
|
-
previousFrameSeq: previous?.frameSeq ?? null,
|
|
159
|
-
previousPlayerIds: previous?.observation.players.map((player) => player.id) ?? [],
|
|
160
|
-
playerBodyLengthPx: api.spatial.playerBodyLengthPx,
|
|
161
|
-
qualifiedCandidates,
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
commit(frame: PerceptionFrame, analysis: Readonly<FollowAnalysis>): PerceptionEventProposal[] {
|
|
166
|
-
const previous = this.previous;
|
|
167
|
-
if (!isPerceptionActive(frame) || !isPerceptionActive(previous)) {
|
|
168
|
-
this.previous = frame;
|
|
169
|
-
this.candidates.clear();
|
|
170
|
-
this.clearPendingAbsences();
|
|
171
|
-
return [];
|
|
172
|
-
}
|
|
173
|
-
this.commitPendingAbsencesBefore(frame.tick);
|
|
174
|
-
if (frame.tickDelta === 0) {
|
|
175
|
-
// Same-tick State revisions refine the current snapshot but provide no
|
|
176
|
-
// elapsed-time evidence. Complete-set absence remains provisional until
|
|
177
|
-
// the next distinct raw tick so a later same-tick restore wins.
|
|
178
|
-
this.revisePendingAbsences(frame);
|
|
179
|
-
this.previous = frame;
|
|
180
|
-
return [];
|
|
181
|
-
}
|
|
182
|
-
if (analysis.previousFrameSeq !== previous.frameSeq) {
|
|
183
|
-
// Do not apply independently computed formation evidence to a reducer
|
|
184
|
-
// whose baseline was reset or skipped.
|
|
185
|
-
this.previous = frame;
|
|
186
|
-
this.candidates.clear();
|
|
187
|
-
this.clearPendingAbsences();
|
|
188
|
-
return [];
|
|
189
|
-
}
|
|
190
|
-
const proposals: PerceptionEventProposal[] = [];
|
|
191
|
-
const currentPlayers = new Map(frame.observation.players.map((player) => [player.id, player]));
|
|
192
|
-
const previousPlayerIds = new Set(analysis.previousPlayerIds);
|
|
193
|
-
const visiblePlayerIds = new Set(frame.observation.players.map((player) => player.id));
|
|
194
|
-
const qualified = new Set(analysis.qualifiedCandidates.map(({ key }) => key));
|
|
195
|
-
for (const qualification of analysis.qualifiedCandidates) {
|
|
196
|
-
const { key } = qualification;
|
|
197
|
-
const follower = currentPlayers.get(qualification.followerId);
|
|
198
|
-
const leader = currentPlayers.get(qualification.leaderId);
|
|
199
|
-
if (!follower || !leader) continue;
|
|
200
|
-
const existing = this.candidates.get(key);
|
|
201
|
-
if (!existing && this.candidates.size >= MAX_FOLLOW_CANDIDATES) continue;
|
|
202
|
-
const candidate = existing ?? {
|
|
203
|
-
follower,
|
|
204
|
-
leader,
|
|
205
|
-
fromTick: previous.tick,
|
|
206
|
-
lastTick: frame.tick,
|
|
207
|
-
samples: 0,
|
|
208
|
-
evidenceTicks: 0,
|
|
209
|
-
missTicks: 0,
|
|
210
|
-
active: false,
|
|
211
|
-
reportedThroughTick: previous.tick - 1,
|
|
212
|
-
distanceSum: 0,
|
|
213
|
-
bodyLengthPx: analysis.playerBodyLengthPx,
|
|
214
|
-
};
|
|
215
|
-
candidate.follower = follower;
|
|
216
|
-
candidate.leader = leader;
|
|
217
|
-
candidate.lastTick = frame.tick;
|
|
218
|
-
candidate.samples += 1;
|
|
219
|
-
candidate.evidenceTicks += Math.max(1, frame.tick - previous.tick);
|
|
220
|
-
candidate.missTicks = 0;
|
|
221
|
-
candidate.distanceSum += qualification.distancePx;
|
|
222
|
-
candidate.bodyLengthPx = analysis.playerBodyLengthPx;
|
|
223
|
-
if (!candidate.active && candidate.evidenceTicks >= START_CONFIRM_TICKS) {
|
|
224
|
-
candidate.active = true;
|
|
225
|
-
proposals.push(this.followingProposal(candidate, 'started'));
|
|
226
|
-
}
|
|
227
|
-
this.candidates.set(key, candidate);
|
|
228
|
-
}
|
|
229
|
-
for (const [key, candidate] of this.candidates) {
|
|
230
|
-
if (qualified.has(key)) continue;
|
|
231
|
-
const bothVisible = visiblePlayerIds.has(candidate.follower.id)
|
|
232
|
-
&& visiblePlayerIds.has(candidate.leader.id);
|
|
233
|
-
if (!bothVisible) {
|
|
234
|
-
// Visibility reports player_left. Drop private relation state without
|
|
235
|
-
// inventing a visible formation break once this tick is final;
|
|
236
|
-
// incomplete sets remain unknown.
|
|
237
|
-
if (frame.observation.visibleSetComplete) this.deferAbsence(key, frame.tick);
|
|
238
|
-
continue;
|
|
239
|
-
}
|
|
240
|
-
if (
|
|
241
|
-
!previousPlayerIds.has(candidate.follower.id)
|
|
242
|
-
|| !previousPlayerIds.has(candidate.leader.id)
|
|
243
|
-
) {
|
|
244
|
-
// Reappearance after an incomplete set restores comparability on the
|
|
245
|
-
// next frame; it is not a formation miss by itself.
|
|
246
|
-
continue;
|
|
247
|
-
}
|
|
248
|
-
candidate.missTicks += Math.max(1, frame.tick - previous.tick);
|
|
249
|
-
const exitTicks = candidate.active
|
|
250
|
-
? ACTIVE_EXIT_CONFIRM_TICKS
|
|
251
|
-
: CANDIDATE_EXIT_CONFIRM_TICKS;
|
|
252
|
-
if (candidate.missTicks < exitTicks) continue;
|
|
253
|
-
if (candidate.active) {
|
|
254
|
-
proposals.push(this.endingProposal(candidate, frame));
|
|
255
|
-
}
|
|
256
|
-
this.candidates.delete(key);
|
|
257
|
-
}
|
|
258
|
-
this.previous = frame;
|
|
259
|
-
return proposals;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
flush(boundary: PerceptionBoundary): PerceptionEventProposal[] {
|
|
263
|
-
return [...this.candidates.values()]
|
|
264
|
-
.filter((candidate) => (
|
|
265
|
-
candidate.active
|
|
266
|
-
&& candidate.lastTick > candidate.reportedThroughTick
|
|
267
|
-
&& (boundary.mode === 'close' || !this.pendingAbsences.has(
|
|
268
|
-
keyFor(candidate.follower.id, candidate.leader.id),
|
|
269
|
-
))
|
|
270
|
-
&& (boundary.mode === 'close' || candidate.missTicks === 0)
|
|
271
|
-
&& (
|
|
272
|
-
boundary.mode === 'close'
|
|
273
|
-
|| candidate.lastTick - candidate.reportedThroughTick >= SNAPSHOT_REPORT_TICKS
|
|
274
|
-
)
|
|
275
|
-
))
|
|
276
|
-
.map((candidate) => this.followingProposal(
|
|
277
|
-
candidate,
|
|
278
|
-
boundary.mode === 'snapshot' ? 'ongoing' : 'closed',
|
|
279
|
-
));
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
reset(): void {
|
|
283
|
-
this.previous = null;
|
|
284
|
-
this.candidates.clear();
|
|
285
|
-
this.clearPendingAbsences();
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
debugSnapshot() {
|
|
289
|
-
return {
|
|
290
|
-
previous_tick: this.previous?.tick ?? null,
|
|
291
|
-
pending_absence_tick: this.pendingAbsenceTick,
|
|
292
|
-
pending_absences: [...this.pendingAbsences].map((key) => key.split('\u001f')),
|
|
293
|
-
candidates: [...this.candidates.values()].map((candidate) => ({
|
|
294
|
-
follower_id: candidate.follower.id,
|
|
295
|
-
leader_id: candidate.leader.id,
|
|
296
|
-
from_tick: candidate.fromTick,
|
|
297
|
-
last_tick: candidate.lastTick,
|
|
298
|
-
samples: candidate.samples,
|
|
299
|
-
evidence_ticks: candidate.evidenceTicks,
|
|
300
|
-
miss_ticks: candidate.missTicks,
|
|
301
|
-
active: candidate.active,
|
|
302
|
-
reported_through_tick: candidate.reportedThroughTick,
|
|
303
|
-
})),
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
private commitPendingAbsencesBefore(tick: number): void {
|
|
308
|
-
if (this.pendingAbsenceTick === null || this.pendingAbsenceTick === tick) return;
|
|
309
|
-
for (const key of this.pendingAbsences) this.candidates.delete(key);
|
|
310
|
-
this.clearPendingAbsences();
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
private revisePendingAbsences(frame: PerceptionFrame): void {
|
|
314
|
-
this.clearPendingAbsences();
|
|
315
|
-
if (!frame.observation.visibleSetComplete) return;
|
|
316
|
-
const present = new Set(frame.observation.players.map((player) => player.id));
|
|
317
|
-
for (const [key, candidate] of this.candidates) {
|
|
318
|
-
if (
|
|
319
|
-
!present.has(candidate.follower.id)
|
|
320
|
-
|| !present.has(candidate.leader.id)
|
|
321
|
-
) this.deferAbsence(key, frame.tick);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
private deferAbsence(key: string, tick: number): void {
|
|
326
|
-
if (this.pendingAbsenceTick !== tick) {
|
|
327
|
-
this.clearPendingAbsences();
|
|
328
|
-
this.pendingAbsenceTick = tick;
|
|
329
|
-
}
|
|
330
|
-
this.pendingAbsences.add(key);
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
private clearPendingAbsences(): void {
|
|
334
|
-
this.pendingAbsenceTick = null;
|
|
335
|
-
this.pendingAbsences.clear();
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
private followingProposal(
|
|
339
|
-
candidate: FollowCandidate,
|
|
340
|
-
status: 'started' | 'ongoing' | 'closed',
|
|
341
|
-
): PerceptionEventProposal {
|
|
342
|
-
const fromTick = Math.max(candidate.fromTick, candidate.reportedThroughTick + 1);
|
|
343
|
-
candidate.reportedThroughTick = candidate.lastTick;
|
|
344
|
-
const averageDistance = candidate.distanceSum / Math.max(1, candidate.samples);
|
|
345
|
-
const bodyLengths = Math.max(1, Math.round(averageDistance / candidate.bodyLengthPx));
|
|
346
|
-
return {
|
|
347
|
-
type: 'visual.following',
|
|
348
|
-
dedupeKey: `following:${keyFor(candidate.follower.id, candidate.leader.id)}:${fromTick}:${candidate.lastTick}`,
|
|
349
|
-
payload: {
|
|
350
|
-
from_tick: fromTick,
|
|
351
|
-
to_tick: candidate.lastTick,
|
|
352
|
-
actors: [actorValue(candidate.follower), actorValue(candidate.leader)],
|
|
353
|
-
...(status === 'started' ? {} : { status }),
|
|
354
|
-
text: `${timeRange(fromTick, candidate.lastTick)},${actorLabel(candidate.follower)}疑似跟在${actorLabel(candidate.leader)}后方约${bodyLengths}个身位同方向移动${status === 'ongoing' ? ',目前仍在继续' : status === 'closed' ? ',这段观察到此为止' : ''}。`,
|
|
355
|
-
data: {
|
|
356
|
-
follower_id: candidate.follower.id,
|
|
357
|
-
leader_id: candidate.leader.id,
|
|
358
|
-
confidence: 'medium',
|
|
359
|
-
average_distance_px: Math.round(averageDistance),
|
|
360
|
-
body_lengths: bodyLengths,
|
|
361
|
-
},
|
|
362
|
-
},
|
|
363
|
-
};
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
private endingProposal(
|
|
367
|
-
candidate: FollowCandidate,
|
|
368
|
-
frame: PerceptionFrame,
|
|
369
|
-
): PerceptionEventProposal {
|
|
370
|
-
const atTick = frame.tick;
|
|
371
|
-
return {
|
|
372
|
-
type: 'visual.following_ended',
|
|
373
|
-
dedupeKey: `following-ended:${keyFor(candidate.follower.id, candidate.leader.id)}:${frame.frameSeq}`,
|
|
374
|
-
payload: {
|
|
375
|
-
from_tick: atTick,
|
|
376
|
-
to_tick: atTick,
|
|
377
|
-
actors: [actorValue(candidate.follower), actorValue(candidate.leader)],
|
|
378
|
-
text: `${timeRange(atTick, atTick)},${actorLabel(candidate.follower)}不再保持跟在${actorLabel(candidate.leader)}后方。`,
|
|
379
|
-
data: {
|
|
380
|
-
follower_id: candidate.follower.id,
|
|
381
|
-
leader_id: candidate.leader.id,
|
|
382
|
-
reason: 'formation_lost',
|
|
383
|
-
},
|
|
384
|
-
},
|
|
385
|
-
};
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
export default FollowModule;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export * from './visibility-module.js';
|
|
2
|
-
export * from './corpse-visibility-module.js';
|
|
3
|
-
export * from './motion-module.js';
|
|
4
|
-
export * from './stop-module.js';
|
|
5
|
-
export * from './spatial-module.js';
|
|
6
|
-
export * from './route-module.js';
|
|
7
|
-
export * from './co-movement-module.js';
|
|
8
|
-
export * from './follow-module.js';
|