@myclaw163/clawclaw-cli 0.8.4 → 0.8.6
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 +4 -3
- package/docs/configuration.md +44 -26
- package/docs/custom-modules/README.md +7 -10
- package/docs/custom-modules/behavior.md +10 -19
- 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 +15 -2
- package/scripts/enable_ccl_permissions.cjs +4 -2
- package/scripts/find-hide-spots.py +2 -2
- package/scripts/postinstall.mjs +1 -4
- package/scripts/sync-bundled-skill.mjs +12 -159
- package/skills/clawclaw/SKILL.md +25 -18
- package/skills/clawclaw/references/BEHAVIORS.md +15 -11
- package/skills/clawclaw/references/COMMANDS.md +45 -41
- package/skills/clawclaw/references/HUB.md +25 -38
- package/skills/clawclaw/references/TACTICS.md +1 -1
- 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/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 +24 -11
- 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/behavior-read-api.ts +1 -1
- package/src/{strategies/pathfind → runtime/clawclaw/navigation}/astar-path.ts +1 -1
- package/src/{strategies/pathfind → runtime/clawclaw/navigation}/escape-planner.ts +1 -1
- package/src/{strategies → runtime/clawclaw/navigation}/hide-spots.ts +2 -2
- package/src/{strategies → runtime/clawclaw/navigation}/off-route-points.ts +6 -3
- package/src/{strategies/pathfind → runtime/clawclaw/navigation}/walkable-grid.ts +1 -1
- package/src/runtime/clawclaw/owner.ts +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/game-query/game-query-plugin.ts +1 -1
- 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/src/runtime/framework/modules/runtime-module-loader.ts +0 -54
- package/src/sdk/behavior-toolkit/escape.ts +2 -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/scripts/compare-perception-replays.test.ts +0 -188
- package/scripts/enable_ccl_permissions.test.mjs +0 -163
- package/scripts/enable_monitor.test.mjs +0 -201
- package/scripts/sync-bundled-skill.test.mjs +0 -152
- package/scripts/watch-perception-events.test.ts +0 -43
- package/src/behaviors/official-finite/do-task.ts +0 -211
- package/src/behaviors/official-finite/evade.ts +0 -78
- package/src/behaviors/official-finite/find-player.ts +0 -50
- package/src/behaviors/official-finite/follow-player.ts +0 -70
- package/src/behaviors/official-finite/go-to.ts +0 -69
- package/src/behaviors/official-finite/hide-temporarily.ts +0 -77
- package/src/behaviors/official-finite/hold-position.ts +0 -48
- package/src/behaviors/official-finite/hunt-player.ts +0 -47
- package/src/behaviors/official-finite/index.test.ts +0 -249
- package/src/behaviors/official-finite/index.ts +0 -44
- package/src/behaviors/official-finite/inspect-corpse.ts +0 -64
- package/src/behaviors/official-finite/patrol-area.ts +0 -80
- package/src/behaviors/official-finite/report-corpse.ts +0 -73
- package/src/behaviors/official-finite/seek-kill-opportunity.ts +0 -152
- package/src/behaviors/official-finite/shared.ts +0 -27
- package/src/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/official-goal-behavior.ts +0 -757
- 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/avoid-lone.ts +0 -32
- package/src/strategies/avoid-players.ts +0 -43
- package/src/strategies/corpse-patrol.ts +0 -50
- package/src/strategies/crab-sabotage.ts +0 -48
- package/src/strategies/custom-module.test.ts +0 -267
- package/src/strategies/find-player.ts +0 -49
- package/src/strategies/game-utils.test.ts +0 -305
- package/src/strategies/game-utils.ts +0 -927
- package/src/strategies/goals/anchor-linger.ts +0 -77
- package/src/strategies/goals/avoid-lone-top.ts +0 -189
- package/src/strategies/goals/avoid-players-top.test.ts +0 -95
- package/src/strategies/goals/avoid-players-top.ts +0 -122
- package/src/strategies/goals/conversation-goal.ts +0 -51
- package/src/strategies/goals/corpse-patrol-top.ts +0 -120
- package/src/strategies/goals/crab-octopus-reflexes.ts +0 -109
- package/src/strategies/goals/crab-sabotage-top.test.ts +0 -131
- package/src/strategies/goals/crab-sabotage-top.ts +0 -139
- package/src/strategies/goals/emergency-hunt-goal.ts +0 -40
- package/src/strategies/goals/find-player-top.ts +0 -136
- package/src/strategies/goals/flee-players-goal.ts +0 -55
- package/src/strategies/goals/follow-companion-goal.ts +0 -130
- package/src/strategies/goals/goal-manager.ts +0 -41
- package/src/strategies/goals/goal-root-strategy.ts +0 -49
- package/src/strategies/goals/goal.ts +0 -28
- package/src/strategies/goals/hide-top.ts +0 -240
- package/src/strategies/goals/keep-away-goal.ts +0 -243
- package/src/strategies/goals/kill-frenzy-top.ts +0 -90
- package/src/strategies/goals/kill-lone-top.test.ts +0 -96
- package/src/strategies/goals/kill-lone-top.ts +0 -166
- package/src/strategies/goals/kill-target-goal.ts +0 -69
- package/src/strategies/goals/kill-target-top.test.ts +0 -65
- package/src/strategies/goals/kill-target-top.ts +0 -121
- package/src/strategies/goals/leaf-goal.ts +0 -27
- package/src/strategies/goals/linger-corpse-goal.ts +0 -43
- package/src/strategies/goals/lone-kill-core.ts +0 -86
- package/src/strategies/goals/lone-kill-goal.ts +0 -24
- package/src/strategies/goals/lone-kill-task-top.test.ts +0 -84
- package/src/strategies/goals/lone-kill-task-top.ts +0 -133
- package/src/strategies/goals/move-room-goal.ts +0 -102
- package/src/strategies/goals/normal-shrimp-top.test.ts +0 -112
- package/src/strategies/goals/normal-shrimp-top.ts +0 -248
- package/src/strategies/goals/paradise-fish-top.test.ts +0 -203
- package/src/strategies/goals/paradise-fish-top.ts +0 -234
- package/src/strategies/goals/patrol-top.ts +0 -68
- package/src/strategies/goals/report-patrol-top.ts +0 -97
- package/src/strategies/goals/safe-task-goal.ts +0 -130
- package/src/strategies/goals/social-task-top.ts +0 -192
- package/src/strategies/goals/task-kill-report-top.ts +0 -187
- package/src/strategies/goals/task-only-top.test.ts +0 -88
- package/src/strategies/goals/task-only-top.ts +0 -64
- package/src/strategies/goals/task-or-patrol-goal.ts +0 -59
- package/src/strategies/goals/task-report-top.ts +0 -57
- package/src/strategies/goals/wander-task-goal.ts +0 -33
- package/src/strategies/goals/warrior-shrimp-top.test.ts +0 -138
- package/src/strategies/goals/warrior-shrimp-top.ts +0 -293
- package/src/strategies/greeting.ts +0 -60
- package/src/strategies/hide.ts +0 -51
- package/src/strategies/kill-frenzy.ts +0 -32
- package/src/strategies/kill-lone.ts +0 -52
- package/src/strategies/kill-target.ts +0 -48
- package/src/strategies/lone-kill-task.ts +0 -48
- package/src/strategies/meeting-gate.test.ts +0 -59
- package/src/strategies/meeting-gate.ts +0 -28
- package/src/strategies/move-room.ts +0 -46
- package/src/strategies/official-long-behavior.test.ts +0 -89
- package/src/strategies/paradise-fish.ts +0 -70
- package/src/strategies/pathfind/astar-path.test.ts +0 -198
- package/src/strategies/pathfind/escape-planner.test.ts +0 -223
- package/src/strategies/patrol.ts +0 -32
- package/src/strategies/player-targets.test.ts +0 -10
- package/src/strategies/player-targets.ts +0 -18
- package/src/strategies/report-patrol.ts +0 -32
- package/src/strategies/shrimp-memory.ts +0 -87
- package/src/strategies/social-task.ts +0 -67
- package/src/strategies/speech-module.ts +0 -123
- package/src/strategies/task-kill-report.ts +0 -49
- package/src/strategies/task-only.test.ts +0 -138
- package/src/strategies/task-only.ts +0 -34
- package/src/strategies/task-report.ts +0 -50
- package/src/strategies/types.ts +0 -116
- package/src/strategies/warrior-memory.ts +0 -54
- /package/src/{strategies/pathfind → runtime/clawclaw/navigation}/clawclaw-walkable.bin +0 -0
- /package/src/{strategies/pathfind → runtime/clawclaw/navigation}/distance-field.ts +0 -0
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import type { GameState, PlayerInfo, Position } from '../../sdk/types.js';
|
|
2
|
-
import { dist } from '../game-utils.js';
|
|
3
|
-
|
|
4
|
-
export interface AnchorLingerOptions {
|
|
5
|
-
/** 游走环最小半径(px)。 */
|
|
6
|
-
min?: number;
|
|
7
|
-
/** 游走环最大半径(px)。 */
|
|
8
|
-
max?: number;
|
|
9
|
-
/** 走到离游走点这么近就算到达、换下一个点。 */
|
|
10
|
-
reached?: number;
|
|
11
|
-
/** 单个游走点最多停留这么久就强制换点,防止点落在墙里不可达时卡死。 */
|
|
12
|
-
dwellMs?: number;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* 围绕一个锚点 min-max px 的「粘性游走」:游走点一旦选定就粘住,直到走到 / 超时 / 换了锚点,
|
|
17
|
-
* 不每 tick 重随机——否则主循环对「同一移动目标」的去重永不触发,会每轮打断上一次移动、在原地抖
|
|
18
|
-
* 而走不出一条游走腿。有 avoid 目标时偏向锚点相对最近目标的对侧。贴尸游走(LingerCorpseGoal)
|
|
19
|
-
* 与跟随同伴在其任务点假装做任务(FollowCompanionGoal)复用同一套游走机制。
|
|
20
|
-
*/
|
|
21
|
-
export class AnchorLinger {
|
|
22
|
-
private target: Position | null = null;
|
|
23
|
-
private until = 0;
|
|
24
|
-
private key = '';
|
|
25
|
-
private readonly min: number;
|
|
26
|
-
private readonly max: number;
|
|
27
|
-
private readonly reached: number;
|
|
28
|
-
private readonly dwellMs: number;
|
|
29
|
-
|
|
30
|
-
constructor(options: AnchorLingerOptions = {}) {
|
|
31
|
-
this.min = options.min ?? 40;
|
|
32
|
-
this.max = options.max ?? 100;
|
|
33
|
-
this.reached = options.reached ?? 24;
|
|
34
|
-
this.dwellMs = options.dwellMs ?? 4000;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** 丢弃当前游走点:离开锚点(尸体出视野、同伴起身走动)时调用,下次重新挑点。 */
|
|
38
|
-
reset(): void {
|
|
39
|
-
this.target = null;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/** 围绕 anchor 取下一个游走点;key 变了(换了锚点)会立即重挑。 */
|
|
43
|
-
step(state: GameState, key: string, anchor: Position, avoid: PlayerInfo[] = []): Position {
|
|
44
|
-
const now = Date.now();
|
|
45
|
-
const reached = this.target != null
|
|
46
|
-
&& dist(state.you.x, state.you.y, this.target.x, this.target.y) <= this.reached;
|
|
47
|
-
if (this.target == null || this.key !== key || reached || now >= this.until) {
|
|
48
|
-
this.key = key;
|
|
49
|
-
this.target = this.pickOffset(state, anchor, avoid);
|
|
50
|
-
this.until = now + this.dwellMs;
|
|
51
|
-
}
|
|
52
|
-
return this.target;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
private pickOffset(state: GameState, anchor: Position, avoid: PlayerInfo[]): Position {
|
|
56
|
-
return avoid.length > 0 ? this.farSideOffset(state, anchor, avoid) : this.randomOffset(anchor);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
private farSideOffset(state: GameState, anchor: Position, avoid: PlayerInfo[]): Position {
|
|
60
|
-
const nearest = avoid.reduce((best, p) => {
|
|
61
|
-
const d = p.distance ?? dist(state.you.x, state.you.y, p.x, p.y);
|
|
62
|
-
const bestD = best.distance ?? dist(state.you.x, state.you.y, best.x, best.y);
|
|
63
|
-
return d < bestD ? p : best;
|
|
64
|
-
});
|
|
65
|
-
const vx = anchor.x - nearest.x;
|
|
66
|
-
const vy = anchor.y - nearest.y;
|
|
67
|
-
const len = Math.hypot(vx, vy);
|
|
68
|
-
if (len === 0) return this.randomOffset(anchor);
|
|
69
|
-
return { x: anchor.x + (vx / len) * this.max, y: anchor.y + (vy / len) * this.max };
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
private randomOffset(anchor: Position): Position {
|
|
73
|
-
const angle = Math.random() * 2 * Math.PI;
|
|
74
|
-
const radius = this.min + Math.random() * (this.max - this.min);
|
|
75
|
-
return { x: anchor.x + Math.cos(angle) * radius, y: anchor.y + Math.sin(angle) * radius };
|
|
76
|
-
}
|
|
77
|
-
}
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import type { GameState, PlayerInfo } from '../../sdk/types.js';
|
|
2
|
-
import {
|
|
3
|
-
dist,
|
|
4
|
-
hasReachedRoomTarget,
|
|
5
|
-
PatrolState,
|
|
6
|
-
PROGRESS_INTERVAL_MS,
|
|
7
|
-
pursueVisibleTarget,
|
|
8
|
-
setStrategyIntent,
|
|
9
|
-
strategyPlayerLabel,
|
|
10
|
-
} from '../game-utils.js';
|
|
11
|
-
import type { BehaviorDecision, RoomTarget, StrategyContext } from '../types.js';
|
|
12
|
-
import { Goal } from './goal.js';
|
|
13
|
-
import { KeepAwayGoal, type ThreatResolver } from './keep-away-goal.js';
|
|
14
|
-
import { MoveRoomGoal, type RoomArrival } from './move-room-goal.js';
|
|
15
|
-
|
|
16
|
-
const PATROL_PRIORITY = 0.2;
|
|
17
|
-
const MOVE_PRIORITY = 0.5;
|
|
18
|
-
const EMPTY_GRACE_MS = 8_000;
|
|
19
|
-
// 次近玩家落在这个范围内就原地待着;超出才迈步靠近。须 < 视野半径,留边缘余量。
|
|
20
|
-
const GATHER_FOLLOW_DISTANCE = 200;
|
|
21
|
-
|
|
22
|
-
type MoveMode = 'patrol' | 'flee' | 'gather';
|
|
23
|
-
|
|
24
|
-
export class AvoidLoneTop extends Goal {
|
|
25
|
-
private readonly patrol = new PatrolState();
|
|
26
|
-
private emptySince: number | null = null;
|
|
27
|
-
private moveMode: MoveMode | null = null;
|
|
28
|
-
private lastNoticeKey = '';
|
|
29
|
-
|
|
30
|
-
tick(state: GameState, ctx: StrategyContext): BehaviorDecision[] {
|
|
31
|
-
const now = Date.now();
|
|
32
|
-
const visible = state.players;
|
|
33
|
-
|
|
34
|
-
if (visible.length === 0) {
|
|
35
|
-
if (this.emptySince == null) this.emptySince = now;
|
|
36
|
-
// 有「上一条移动」要守护时就尊重 8 秒空视野宽限:flee 靠子目标续命(KeepAwayGoal),
|
|
37
|
-
// gather 是内联返回的跟随 move(无子目标),靠 moveMode==='gather' 标记守护——
|
|
38
|
-
// 否则人短暂出视野会被立刻改判巡逻、覆盖掉刚发出的跟随移动。
|
|
39
|
-
const hasMoveToHold = this.subGoal != null || this.moveMode === 'gather';
|
|
40
|
-
if (!hasMoveToHold || now - this.emptySince >= EMPTY_GRACE_MS) {
|
|
41
|
-
this.setPatrolGoal(state, ctx);
|
|
42
|
-
this.emitProgress(state, ctx, 'patrol', null, visible);
|
|
43
|
-
} else {
|
|
44
|
-
this.emitProgress(state, ctx, this.moveMode, null, visible); // 宽限期内维持原目标
|
|
45
|
-
}
|
|
46
|
-
return [];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
this.emptySince = null;
|
|
50
|
-
|
|
51
|
-
if (visible.length === 1) {
|
|
52
|
-
const lone = visible[0].name;
|
|
53
|
-
this.setKeepAway(`single:${lone}`,
|
|
54
|
-
currentState => currentState.players.filter(player => player.name === lone));
|
|
55
|
-
if (!this.emitNotice(ctx, `flee:${lone}`,
|
|
56
|
-
`视野内只有${lone},正在寻路避免落单。`))
|
|
57
|
-
this.emitProgress(state, ctx, 'flee', null, visible);
|
|
58
|
-
return [];
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// 2+ 人:跟住「次近」的人。最近的人本就贴着、最不会掉出视野;真正卡在
|
|
62
|
-
// 「≥2 人 / 跌回 1 人独处」临界点上的是第二近的人,盯住他、保持在视野舒适范围内即可维持人数。
|
|
63
|
-
this.clearGoal();
|
|
64
|
-
this.moveMode = 'gather';
|
|
65
|
-
const anchor = [...visible].sort((a, b) => this.distOf(state, a) - this.distOf(state, b))[1]; // length>=2 必存在
|
|
66
|
-
const decision = pursueVisibleTarget(state, anchor, { kill: false, followDistance: GATHER_FOLLOW_DISTANCE });
|
|
67
|
-
if (decision) {
|
|
68
|
-
if (!this.emitNotice(ctx, `gather:follow:${anchor.name}`,
|
|
69
|
-
`视野内${visible.length}人,正在靠近${anchor.name}维持人数。`))
|
|
70
|
-
this.emitProgress(state, ctx, 'gather', null, visible);
|
|
71
|
-
return [{
|
|
72
|
-
action: decision.action.withThinking(
|
|
73
|
-
`跟住次近的${anchor.name},维持视野内至少两人,避免落单。`,
|
|
74
|
-
),
|
|
75
|
-
intent: {
|
|
76
|
-
activity: 'moving',
|
|
77
|
-
summary: `正在${anchor.room || state.you.room || '当前位置'}跟随${strategyPlayerLabel(anchor)},保持在人群中。`,
|
|
78
|
-
...(anchor.room ? { room: anchor.room } : {}),
|
|
79
|
-
targetPlayer: anchor.name,
|
|
80
|
-
},
|
|
81
|
-
}];
|
|
82
|
-
}
|
|
83
|
-
setStrategyIntent(ctx, {
|
|
84
|
-
activity: 'waiting',
|
|
85
|
-
summary: `正在${state.you.room || '当前位置'}和${strategyPlayerLabel(anchor)}保持在人群中。`,
|
|
86
|
-
...(state.you.room ? { room: state.you.room } : {}),
|
|
87
|
-
targetPlayer: anchor.name,
|
|
88
|
-
});
|
|
89
|
-
if (!this.emitNotice(ctx, `gather:hold:${visible.length}`,
|
|
90
|
-
`视野内${visible.length}人,已和大家在一起保持安全。`))
|
|
91
|
-
this.emitProgress(state, ctx, 'gather', null, visible);
|
|
92
|
-
return [];
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
private distOf(state: GameState, p: PlayerInfo): number {
|
|
96
|
-
return p.distance ?? dist(state.you.x, state.you.y, p.x, p.y);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
private setPatrolGoal(state: GameState, ctx: StrategyContext): void {
|
|
100
|
-
let room = this.patrol.nextRoom(ctx);
|
|
101
|
-
if (!room) {
|
|
102
|
-
this.clearGoal();
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (hasReachedRoomTarget(state, room)) {
|
|
107
|
-
this.patrol.advance(ctx);
|
|
108
|
-
room = this.patrol.nextRoom(ctx);
|
|
109
|
-
if (!room) {
|
|
110
|
-
this.clearGoal();
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
this.setMoveGoal(room, 'patrol', true, PATROL_PRIORITY);
|
|
116
|
-
this.lastNoticeKey = '';
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* 寻路躲避:用 KeepAwayGoal 推演逃点远离这个唯一可见的人(不限距离,避免落单)。
|
|
121
|
-
* finishWhenClear:false——人短暂丢失视野时子目标不自我结束,交由父层 8 秒空视野宽限
|
|
122
|
-
* 决定何时转巡逻,否则一丢视野就同轮被清、下一 tick 立刻 patrol,宽限只剩一帧会来回摇摆。
|
|
123
|
-
*/
|
|
124
|
-
private setKeepAway(key: string, resolveThreats: ThreatResolver): void {
|
|
125
|
-
const worker = this.subGoal;
|
|
126
|
-
if (worker instanceof KeepAwayGoal && worker.key === key) {
|
|
127
|
-
this.moveMode = 'flee';
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
if (this.subGoal) this.removeSubGoal();
|
|
131
|
-
this.setSubGoal(new KeepAwayGoal(key, resolveThreats, {
|
|
132
|
-
threatRadius: Infinity,
|
|
133
|
-
finishWhenClear: false,
|
|
134
|
-
noun: '',
|
|
135
|
-
}), MOVE_PRIORITY);
|
|
136
|
-
this.moveMode = 'flee';
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
private setMoveGoal(
|
|
140
|
-
room: RoomTarget,
|
|
141
|
-
mode: MoveMode,
|
|
142
|
-
stopOnPlayer: boolean,
|
|
143
|
-
priority = MOVE_PRIORITY,
|
|
144
|
-
hasArrived: RoomArrival = hasReachedRoomTarget,
|
|
145
|
-
): void {
|
|
146
|
-
const worker = this.subGoal;
|
|
147
|
-
if (worker instanceof MoveRoomGoal && worker.room === room.name && this.moveMode === mode) return;
|
|
148
|
-
if (this.subGoal) this.removeSubGoal();
|
|
149
|
-
this.setSubGoal(new MoveRoomGoal(room.name, hasArrived, {
|
|
150
|
-
emitProgress: false,
|
|
151
|
-
stopOnPlayer,
|
|
152
|
-
purpose: mode === 'patrol' ? '巡逻寻找人群' : '靠近人群',
|
|
153
|
-
}), priority);
|
|
154
|
-
this.moveMode = mode;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
private clearGoal(): void {
|
|
158
|
-
if (this.subGoal) this.removeSubGoal();
|
|
159
|
-
this.moveMode = null;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
private emitNotice(ctx: StrategyContext, key: string, message: string): boolean {
|
|
163
|
-
if (key === this.lastNoticeKey) return false;
|
|
164
|
-
this.lastNoticeKey = key;
|
|
165
|
-
ctx.notifications.push(message);
|
|
166
|
-
return true;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
private emitProgress(
|
|
170
|
-
state: GameState,
|
|
171
|
-
ctx: StrategyContext,
|
|
172
|
-
mode: MoveMode | null,
|
|
173
|
-
target: RoomTarget | null,
|
|
174
|
-
visible: PlayerInfo[],
|
|
175
|
-
): void {
|
|
176
|
-
const now = Date.now();
|
|
177
|
-
if (now - ctx.lastProgressNotifyAt < PROGRESS_INTERVAL_MS) return;
|
|
178
|
-
ctx.lastProgressNotifyAt = now;
|
|
179
|
-
|
|
180
|
-
const room = state.you.room ?? '未知';
|
|
181
|
-
let msg = `[进度] 当前在${room},视野内${visible.length}人`;
|
|
182
|
-
if (mode === 'gather') msg += ',正在跟随人群';
|
|
183
|
-
else if (mode === 'flee') msg += ',正在避免落单风险';
|
|
184
|
-
else msg += ',正在巡逻寻找人群';
|
|
185
|
-
if (target) msg += `,前往${target.name}`;
|
|
186
|
-
msg += '。';
|
|
187
|
-
ctx.notifications.push(msg);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import type { GameState } from '../../sdk/types.js';
|
|
3
|
-
import type { StrategyContext } from '../types.js';
|
|
4
|
-
import { KeepAwayGoal } from './keep-away-goal.js';
|
|
5
|
-
import { AvoidPlayersTop } from './avoid-players-top.js';
|
|
6
|
-
|
|
7
|
-
function state(overrides: Partial<GameState> = {}): GameState {
|
|
8
|
-
return {
|
|
9
|
-
phase: 'wandering',
|
|
10
|
-
tick: 1,
|
|
11
|
-
you: {
|
|
12
|
-
name: 'self',
|
|
13
|
-
x: 0,
|
|
14
|
-
y: 0,
|
|
15
|
-
room: 'start',
|
|
16
|
-
role: 'neutral_octopus',
|
|
17
|
-
faction: 'neutral',
|
|
18
|
-
is_alive: true,
|
|
19
|
-
},
|
|
20
|
-
your_tasks: [],
|
|
21
|
-
players: [],
|
|
22
|
-
corpses: [],
|
|
23
|
-
stale: false,
|
|
24
|
-
...overrides,
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function context(overrides: Partial<StrategyContext> = {}): StrategyContext {
|
|
29
|
-
return {
|
|
30
|
-
taskData: [],
|
|
31
|
-
emergency: null,
|
|
32
|
-
taskLocalBlockedUntil: 0,
|
|
33
|
-
reportCorpseTarget: null,
|
|
34
|
-
reportBlockedUntil: 0,
|
|
35
|
-
notifications: [],
|
|
36
|
-
lastProgressNotifyAt: Date.now(),
|
|
37
|
-
teammates: new Set(),
|
|
38
|
-
rooms: [{ name: 'patrol', x: 500, y: 0 }],
|
|
39
|
-
playerNamesBySeat: {},
|
|
40
|
-
forcePatrolAdvance: false,
|
|
41
|
-
blockedMoveTarget: null,
|
|
42
|
-
mySeat: 1,
|
|
43
|
-
speechNotifications: [],
|
|
44
|
-
agentAlerts: [],
|
|
45
|
-
...overrides,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
describe('AvoidPlayersTop', () => {
|
|
50
|
-
it('patrols without stop_on_player when the avoid list has no active threat', () => {
|
|
51
|
-
const top = new AvoidPlayersTop([]);
|
|
52
|
-
const ctx = context();
|
|
53
|
-
const current = state({
|
|
54
|
-
players: [{ name: 'roadie', x: 200, y: 0, room: 'start' }],
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
top.tick(current, ctx);
|
|
58
|
-
const decisions = top.subGoal?.tick(current, ctx) ?? [];
|
|
59
|
-
|
|
60
|
-
expect(decisions).toHaveLength(1);
|
|
61
|
-
expect(decisions[0].action.type).toBe('move');
|
|
62
|
-
expect(decisions[0].action.payload).toMatchObject({ target_x: 500, target_y: 0 });
|
|
63
|
-
expect(decisions[0].action.payload).not.toHaveProperty('stop_on_player');
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('patrols without stop_on_player when the configured avoid target is dead', () => {
|
|
67
|
-
const top = new AvoidPlayersTop([2]);
|
|
68
|
-
const ctx = context();
|
|
69
|
-
const current = state({
|
|
70
|
-
players: [{ name: 'roadie', x: 200, y: 0, room: 'start' }],
|
|
71
|
-
all_players: [
|
|
72
|
-
{ name: 'dead-target', role: 'lobster', is_alive: false, seat: 2 },
|
|
73
|
-
{ name: 'roadie', role: 'lobster', is_alive: true, seat: 3 },
|
|
74
|
-
],
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
top.tick(current, ctx);
|
|
78
|
-
const decisions = top.subGoal?.tick(current, ctx) ?? [];
|
|
79
|
-
|
|
80
|
-
expect(decisions).toHaveLength(1);
|
|
81
|
-
expect(decisions[0].action.payload).not.toHaveProperty('stop_on_player');
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('uses targets as the complete active avoid list', () => {
|
|
85
|
-
const top = new AvoidPlayersTop([2]);
|
|
86
|
-
const current = state({
|
|
87
|
-
players: [{ name: 'danger', seat: 2, x: 200, y: 0, room: 'start' }],
|
|
88
|
-
all_players: [{ name: 'danger', seat: 2, role: 'unknown', is_alive: true }],
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
top.tick(current, context({ playerNamesBySeat: { '2': 'danger' } }));
|
|
92
|
-
|
|
93
|
-
expect(top.subGoal).toBeInstanceOf(KeepAwayGoal);
|
|
94
|
-
});
|
|
95
|
-
});
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import type { GameState, PlayerInfo } from '../../sdk/types.js';
|
|
2
|
-
import { hasReachedRoomTarget, isTargetAlive, matchesAnyTarget, PatrolState, PROGRESS_INTERVAL_MS } from '../game-utils.js';
|
|
3
|
-
import type { BehaviorDecision, RoomTarget, StrategyContext } from '../types.js';
|
|
4
|
-
import { Goal } from './goal.js';
|
|
5
|
-
import { KeepAwayGoal, type KeepAwayGoalOptions, type ThreatResolver } from './keep-away-goal.js';
|
|
6
|
-
import { MoveRoomGoal } from './move-room-goal.js';
|
|
7
|
-
|
|
8
|
-
const PATROL_PRIORITY = 0.2;
|
|
9
|
-
const FLEE_PRIORITY = 0.5;
|
|
10
|
-
|
|
11
|
-
export class AvoidPlayersTop extends Goal {
|
|
12
|
-
private readonly patrol = new PatrolState();
|
|
13
|
-
private moveMode: 'patrol' | 'flee' | null = null;
|
|
14
|
-
private lastAvoidNoticeKey = '';
|
|
15
|
-
|
|
16
|
-
constructor(private readonly targets: number[]) {
|
|
17
|
-
super();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
tick(state: GameState, ctx: StrategyContext): BehaviorDecision[] {
|
|
21
|
-
const threats = this.threats(state, ctx);
|
|
22
|
-
|
|
23
|
-
if (threats.length > 0) {
|
|
24
|
-
this.setKeepAway();
|
|
25
|
-
if (!this.emitAvoidNotice(ctx, threats)) this.emitAvoidProgress(state, ctx, threats);
|
|
26
|
-
return [];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
this.lastAvoidNoticeKey = '';
|
|
30
|
-
let room = this.patrol.nextRoom(ctx);
|
|
31
|
-
if (!room) {
|
|
32
|
-
this.emitPatrolProgress(state, ctx, null);
|
|
33
|
-
return [];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (hasReachedRoomTarget(state, room)) {
|
|
37
|
-
this.patrol.advance(ctx);
|
|
38
|
-
room = this.patrol.nextRoom(ctx);
|
|
39
|
-
if (!room) {
|
|
40
|
-
this.emitPatrolProgress(state, ctx, null);
|
|
41
|
-
return [];
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
this.setMoveGoal(room, PATROL_PRIORITY, 'patrol', false);
|
|
46
|
-
this.emitPatrolProgress(state, ctx, room);
|
|
47
|
-
return [];
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/** 寻路躲避:用 KeepAwayGoal 推演逃点远离回避目标(不限距离,名单上的人始终要躲)。 */
|
|
51
|
-
private setKeepAway(): void {
|
|
52
|
-
const key = this.targets.join('|');
|
|
53
|
-
const resolve: ThreatResolver = (state, ctx) => this.threats(state, ctx);
|
|
54
|
-
const options: KeepAwayGoalOptions = { threatRadius: Infinity, noun: '回避目标' };
|
|
55
|
-
const worker = this.subGoal;
|
|
56
|
-
if (worker instanceof KeepAwayGoal && worker.key === key) {
|
|
57
|
-
this.moveMode = 'flee';
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
if (this.subGoal) this.removeSubGoal();
|
|
61
|
-
this.setSubGoal(new KeepAwayGoal(key, resolve, options), FLEE_PRIORITY);
|
|
62
|
-
this.moveMode = 'flee';
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** targets 中仍存活的玩家;空名单表示只巡逻。 */
|
|
66
|
-
private threats(state: GameState, ctx: StrategyContext): PlayerInfo[] {
|
|
67
|
-
const validTargets = this.targets.filter(target => isTargetAlive(state, target, ctx));
|
|
68
|
-
return state.players.filter(p => matchesAnyTarget(p, validTargets, ctx));
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
private setMoveGoal(room: RoomTarget, priority: number, mode: 'patrol' | 'flee', stopOnPlayer: boolean): void {
|
|
72
|
-
const worker = this.subGoal;
|
|
73
|
-
if (worker instanceof MoveRoomGoal && worker.room === room.name && this.moveMode === mode) return;
|
|
74
|
-
if (this.subGoal) this.removeSubGoal();
|
|
75
|
-
this.setSubGoal(new MoveRoomGoal(room.name, hasReachedRoomTarget, {
|
|
76
|
-
emitProgress: false,
|
|
77
|
-
stopOnPlayer,
|
|
78
|
-
purpose: '巡逻并避开指定玩家',
|
|
79
|
-
}), priority);
|
|
80
|
-
this.moveMode = mode;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
private emitAvoidNotice(ctx: StrategyContext, threats: PlayerInfo[]): boolean {
|
|
84
|
-
const names = threats.map(p => p.name).join('、');
|
|
85
|
-
const key = threats.map(p => p.name).sort().join('|');
|
|
86
|
-
if (key === this.lastAvoidNoticeKey) return false;
|
|
87
|
-
this.lastAvoidNoticeKey = key;
|
|
88
|
-
|
|
89
|
-
ctx.notifications.push(`发现回避目标${names},正在寻路躲避。`);
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
private emitPatrolProgress(state: GameState, ctx: StrategyContext, target: RoomTarget | null): void {
|
|
94
|
-
const now = Date.now();
|
|
95
|
-
if (now - ctx.lastProgressNotifyAt < PROGRESS_INTERVAL_MS) return;
|
|
96
|
-
ctx.lastProgressNotifyAt = now;
|
|
97
|
-
|
|
98
|
-
const room = state.you.room ?? '未知';
|
|
99
|
-
const targetNames = this.targets.length > 0 ? this.targets.join(', ') : '(未配置)';
|
|
100
|
-
|
|
101
|
-
let msg = `[进度] 当前在${room},巡逻中,回避名单: ${targetNames}`;
|
|
102
|
-
if (target) {
|
|
103
|
-
msg += `,正在前往${target.name}`;
|
|
104
|
-
}
|
|
105
|
-
msg += '。';
|
|
106
|
-
ctx.notifications.push(msg);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
private emitAvoidProgress(
|
|
110
|
-
state: GameState,
|
|
111
|
-
ctx: StrategyContext,
|
|
112
|
-
threats: PlayerInfo[],
|
|
113
|
-
): void {
|
|
114
|
-
const now = Date.now();
|
|
115
|
-
if (now - ctx.lastProgressNotifyAt < PROGRESS_INTERVAL_MS) return;
|
|
116
|
-
ctx.lastProgressNotifyAt = now;
|
|
117
|
-
|
|
118
|
-
const here = state.you.room ?? '未知';
|
|
119
|
-
const names = threats.map(p => p.name).join('、');
|
|
120
|
-
ctx.notifications.push(`[进度] 当前在${here},发现${names},正在寻路躲避。`);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { GameState } from '../../sdk/types.js';
|
|
2
|
-
import type { BehaviorDecision, StrategyContext } from '../types.js';
|
|
3
|
-
import { Goal } from './goal.js';
|
|
4
|
-
import { GoalManager } from './goal-manager.js';
|
|
5
|
-
import { URGENT_GOAL_PRIORITY } from './leaf-goal.js';
|
|
6
|
-
import type { SpeechModule } from '../speech-module.js';
|
|
7
|
-
|
|
8
|
-
export class ConversationGoal extends Goal {
|
|
9
|
-
private readonly innerMgr = new GoalManager();
|
|
10
|
-
|
|
11
|
-
constructor(
|
|
12
|
-
private readonly makeInner: () => Goal,
|
|
13
|
-
private readonly speech: SpeechModule,
|
|
14
|
-
) {
|
|
15
|
-
super();
|
|
16
|
-
this.innerMgr.setTop(makeInner());
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
tick(state: GameState, ctx: StrategyContext): BehaviorDecision[] {
|
|
20
|
-
if (this.innerMgr.getTop() === null) this.innerMgr.setTop(this.makeInner());
|
|
21
|
-
const innerDecisions = this.innerMgr.tick(state, ctx);
|
|
22
|
-
|
|
23
|
-
const interruptible = this.innerLeafPriority() < URGENT_GOAL_PRIORITY;
|
|
24
|
-
const primaryIsMove = innerDecisions[0]?.action.type === 'move';
|
|
25
|
-
const result = this.speech.evaluate(state, ctx, {
|
|
26
|
-
allowAutoGreet: interruptible && primaryIsMove,
|
|
27
|
-
});
|
|
28
|
-
for (const msg of result.notifications) ctx.speechNotifications.push(msg);
|
|
29
|
-
|
|
30
|
-
return innerDecisions;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
onMeetingResume(): void {
|
|
34
|
-
this.speech.resetMeetingState();
|
|
35
|
-
this.innerMgr.getTop()?.onMeetingResume();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
updateConfig(role: string): void {
|
|
39
|
-
this.speech.updateConfig(role);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
private innerLeafPriority(): number {
|
|
43
|
-
let node: Goal | null = this.innerMgr.getTop();
|
|
44
|
-
let priority = 0;
|
|
45
|
-
while (node) {
|
|
46
|
-
priority = node.priority;
|
|
47
|
-
node = node.subGoal;
|
|
48
|
-
}
|
|
49
|
-
return priority;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import type { GameState } from '../../sdk/types.js';
|
|
2
|
-
import { Action } from '../../sdk/action.js';
|
|
3
|
-
import {
|
|
4
|
-
corpseAtScene,
|
|
5
|
-
emergencyRushDecision,
|
|
6
|
-
nearestKnownCorpseNav,
|
|
7
|
-
patrolStep,
|
|
8
|
-
PatrolState,
|
|
9
|
-
PROGRESS_INTERVAL_MS,
|
|
10
|
-
} from '../game-utils.js';
|
|
11
|
-
import type { BehaviorDecision, CorpseTarget, StrategyContext } from '../types.js';
|
|
12
|
-
import { Goal } from './goal.js';
|
|
13
|
-
import { LingerCorpseGoal } from './linger-corpse-goal.js';
|
|
14
|
-
|
|
15
|
-
const GREETING_COOLDOWN_MS = 120_000;
|
|
16
|
-
|
|
17
|
-
export class CorpsePatrolTop extends Goal {
|
|
18
|
-
private readonly patrol = new PatrolState();
|
|
19
|
-
private readonly linger = new LingerCorpseGoal();
|
|
20
|
-
private lastCorpseNotified = false;
|
|
21
|
-
private lastGreetingAt: number | null = null;
|
|
22
|
-
|
|
23
|
-
constructor(private readonly greetingPhrases: string[]) {
|
|
24
|
-
super();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
tick(state: GameState, ctx: StrategyContext): BehaviorDecision[] {
|
|
28
|
-
// 残局抢修紧急任务(已知存活≤6):天堂鱼最高优先级,先于贴尸/巡逻/打招呼——
|
|
29
|
-
// 紧急任务超时则蟹直接获胜;天堂鱼要拖到第二轮及以后被投出,故残局抢着把维修做掉、掐断蟹的破坏取胜线。
|
|
30
|
-
const emergency = emergencyRushDecision(state, ctx);
|
|
31
|
-
if (emergency) {
|
|
32
|
-
this.emitProgress(state, ctx, null, true);
|
|
33
|
-
return [emergency];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const decisions: BehaviorDecision[] = [];
|
|
37
|
-
|
|
38
|
-
const greetingDecision = this.tryGreeting(state);
|
|
39
|
-
if (greetingDecision) decisions.push(greetingDecision);
|
|
40
|
-
|
|
41
|
-
const corpse = nearestKnownCorpseNav(state, ctx);
|
|
42
|
-
const canMove = !state.you.doing_task;
|
|
43
|
-
|
|
44
|
-
if (corpse) {
|
|
45
|
-
if (!this.lastCorpseNotified) {
|
|
46
|
-
this.lastCorpseNotified = true;
|
|
47
|
-
const label = corpse.name ? `${corpse.name}的尸体` : '尸体';
|
|
48
|
-
// corpseAtScene=已站在尸体旁(≤150px);仅凭记忆/房间锚点导航过去时人还没到,别谎报「在附近徘徊」。
|
|
49
|
-
ctx.notifications.push(
|
|
50
|
-
corpseAtScene(state) ? `发现${label}!在附近徘徊观察。` : `发现${label}!正前往查看。`,
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
if (canMove) decisions.push(...this.linger.tick(state, ctx));
|
|
54
|
-
} else {
|
|
55
|
-
this.lastCorpseNotified = false;
|
|
56
|
-
if (canMove) decisions.push(...patrolStep(state, ctx, this.patrol, false, '巡逻寻找尸体'));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
this.emitProgress(state, ctx, corpse);
|
|
60
|
-
return decisions;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
private tryGreeting(state: GameState): BehaviorDecision | null {
|
|
64
|
-
if (this.greetingPhrases.length === 0) return null;
|
|
65
|
-
if (state.players.length === 0) return null;
|
|
66
|
-
|
|
67
|
-
const now = Date.now();
|
|
68
|
-
if (this.lastGreetingAt !== null && now - this.lastGreetingAt < GREETING_COOLDOWN_MS) return null;
|
|
69
|
-
|
|
70
|
-
const text = this.greetingPhrases[Math.floor(Math.random() * this.greetingPhrases.length)];
|
|
71
|
-
this.lastGreetingAt = now;
|
|
72
|
-
return {
|
|
73
|
-
action: Action.speech(text),
|
|
74
|
-
intent: {
|
|
75
|
-
activity: 'acting',
|
|
76
|
-
summary: `正在${state.you.room || '当前位置'}向附近玩家打招呼。`,
|
|
77
|
-
...(state.you.room ? { room: state.you.room } : {}),
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
private emitProgress(
|
|
83
|
-
state: GameState,
|
|
84
|
-
ctx: StrategyContext,
|
|
85
|
-
corpse: CorpseTarget | null,
|
|
86
|
-
emergencyRush = false,
|
|
87
|
-
): void {
|
|
88
|
-
const now = Date.now();
|
|
89
|
-
if (now - ctx.lastProgressNotifyAt < PROGRESS_INTERVAL_MS) return;
|
|
90
|
-
ctx.lastProgressNotifyAt = now;
|
|
91
|
-
|
|
92
|
-
const room = state.you.room ?? '未知';
|
|
93
|
-
|
|
94
|
-
if (emergencyRush) {
|
|
95
|
-
const name = ctx.emergency?.task_name ?? '紧急维修';
|
|
96
|
-
ctx.notifications.push(
|
|
97
|
-
`[进度] 当前在${room},残局仅剩${state.alive_count}人,抢着去做紧急任务「${name}」,阻止蟹靠破坏倒计时取胜。`,
|
|
98
|
-
);
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
let msg = `[进度] 当前在${room}`;
|
|
103
|
-
if (corpse) {
|
|
104
|
-
const label = corpse.name ?? '未知';
|
|
105
|
-
msg += corpseAtScene(state)
|
|
106
|
-
? `,在${label}的尸体附近徘徊。`
|
|
107
|
-
: `,正前往${label}的尸体所在位置。`;
|
|
108
|
-
} else {
|
|
109
|
-
const target = this.patrol.nextRoom(ctx);
|
|
110
|
-
if (target) {
|
|
111
|
-
msg += `,巡逻中,正在前往${target.name}。`;
|
|
112
|
-
} else {
|
|
113
|
-
msg += `,巡逻中。`;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
msg += ` 共${ctx.rooms.length}个房间。`;
|
|
117
|
-
|
|
118
|
-
ctx.notifications.push(msg);
|
|
119
|
-
}
|
|
120
|
-
}
|