@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,243 +0,0 @@
|
|
|
1
|
-
import { Action } from '../../sdk/action.js';
|
|
2
|
-
import type { GameState, PlayerInfo, Position } from '../../sdk/types.js';
|
|
3
|
-
import {
|
|
4
|
-
dist,
|
|
5
|
-
setStrategyIntent,
|
|
6
|
-
SHRIMP_KILL_RANGE,
|
|
7
|
-
strategyDecision,
|
|
8
|
-
strategyPlayerLabel,
|
|
9
|
-
} from '../game-utils.js';
|
|
10
|
-
import { assessEscapeTarget, planEscape, type EscapeOptions } from '../pathfind/escape-planner.js';
|
|
11
|
-
import { loadWalkableGrid } from '../pathfind/walkable-grid.js';
|
|
12
|
-
import type { BehaviorDecision, StrategyContext } from '../types.js';
|
|
13
|
-
import { Goal } from './goal.js';
|
|
14
|
-
|
|
15
|
-
const PANIC_RADIUS = 190;
|
|
16
|
-
const CRITICAL_RADIUS = 100;
|
|
17
|
-
const REACHED_DISTANCE = 28;
|
|
18
|
-
const MIN_USEFUL_TARGET_DISTANCE = 120;
|
|
19
|
-
const MAX_THREATS = 4;
|
|
20
|
-
const CRITICAL_REPLAN_INTERVAL_MS = 1600;
|
|
21
|
-
const PANIC_REPLAN_INTERVAL_MS = 2500;
|
|
22
|
-
const PANIC_REPLAN_TARGET_SHIFT = 220;
|
|
23
|
-
/**
|
|
24
|
-
* keep-away 逃跑推演基线参数。各档(FLEE 不覆盖;陌生人覆盖 steps:4)在此基础上合并 options.planOpts。
|
|
25
|
-
* killRange 取 SHRIMP_KILL_RANGE(160) 而非 planner 默认 80:本层威胁只有坐标、没有角色(resolver
|
|
26
|
-
* 返回可见非队友的裸位置,本游戏看不到他人身份),无法逐威胁取 killRangeFor,故统一用带刀虾兜底,
|
|
27
|
-
* 宁可对蟹/章鱼多拉开也不对带刀好人少逃;带刀好人遇到未确认对象也只复用这一层做回避,不再自卫出刀。
|
|
28
|
-
*/
|
|
29
|
-
export const KEEP_AWAY_BASE_PLAN_OPTS: EscapeOptions = {
|
|
30
|
-
killRange: SHRIMP_KILL_RANGE,
|
|
31
|
-
steps: 7,
|
|
32
|
-
beamWidth: 8,
|
|
33
|
-
directions: 16,
|
|
34
|
-
fieldRadius: 900,
|
|
35
|
-
};
|
|
36
|
-
const FALLBACK_DISTANCES = [330, 260, 200, 140];
|
|
37
|
-
const FALLBACK_ANGLE_OFFSETS = [0, Math.PI / 6, -Math.PI / 6, Math.PI / 3, -Math.PI / 3, Math.PI / 2, -Math.PI / 2, Math.PI];
|
|
38
|
-
|
|
39
|
-
export type ThreatResolver = (state: GameState, ctx: StrategyContext) => PlayerInfo[];
|
|
40
|
-
|
|
41
|
-
export interface KeepAwayGoalOptions {
|
|
42
|
-
/** 交战兼结束半径(px);Infinity = resolver 返回的全算威胁。所有调用点必须显式传,无默认值。 */
|
|
43
|
-
threatRadius: number;
|
|
44
|
-
/** 半径内无威胁时 isFinish=true,供父节点自然回收;独立 keep-away 策略作为顶层须传 false,否则每个安静 tick 被 GoalManager 清掉再重建、idle 通知刷屏。 */
|
|
45
|
-
finishWhenClear?: boolean;
|
|
46
|
-
/** 无威胁时的 idle/coast 通知;作为子目标默认关闭(父节点自有进度播报)。 */
|
|
47
|
-
idleNotices?: boolean;
|
|
48
|
-
/** 通知措辞里威胁的称呼:发现{noun}{names},{verb}到 (x, y)。传字符串则所有威胁共用一个称呼;传函数则
|
|
49
|
-
* 逐个威胁按其真实身份标注(如坏人/被怀疑者分别措辞),避免把混在一起躲的被怀疑者也一律叫成坏人。 */
|
|
50
|
-
noun?: string | ((p: PlayerInfo, ctx: StrategyContext) => string);
|
|
51
|
-
/** 覆盖 planEscape 参数(与 PLAN_OPTS 合并)。 */
|
|
52
|
-
planOpts?: EscapeOptions;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function targetKey(target: Position): string {
|
|
56
|
-
return `${Math.round(target.x)},${Math.round(target.y)}`;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function fallbackEscapeTarget(you: Position, threats: PlayerInfo[]): Position | null {
|
|
60
|
-
if (threats.length === 0) return null;
|
|
61
|
-
let vx = 0;
|
|
62
|
-
let vy = 0;
|
|
63
|
-
for (const t of threats) {
|
|
64
|
-
const dx = you.x - t.x;
|
|
65
|
-
const dy = you.y - t.y;
|
|
66
|
-
const d = Math.max(1, Math.hypot(dx, dy));
|
|
67
|
-
const weight = 1 / Math.max(80, d);
|
|
68
|
-
vx += (dx / d) * weight;
|
|
69
|
-
vy += (dy / d) * weight;
|
|
70
|
-
}
|
|
71
|
-
if (Math.hypot(vx, vy) < 0.001) {
|
|
72
|
-
vx = you.x - threats[0].x;
|
|
73
|
-
vy = you.y - threats[0].y;
|
|
74
|
-
}
|
|
75
|
-
if (Math.hypot(vx, vy) < 0.001) vx = 1;
|
|
76
|
-
|
|
77
|
-
const grid = loadWalkableGrid();
|
|
78
|
-
const baseAngle = Math.atan2(vy, vx);
|
|
79
|
-
const nearestBefore = Math.min(...threats.map(t => dist(you.x, you.y, t.x, t.y)));
|
|
80
|
-
let best: { target: Position; score: number } | null = null;
|
|
81
|
-
|
|
82
|
-
for (const distancePx of FALLBACK_DISTANCES) {
|
|
83
|
-
for (const offset of FALLBACK_ANGLE_OFFSETS) {
|
|
84
|
-
const angle = baseAngle + offset;
|
|
85
|
-
const raw = {
|
|
86
|
-
x: you.x + Math.cos(angle) * distancePx,
|
|
87
|
-
y: you.y + Math.sin(angle) * distancePx,
|
|
88
|
-
};
|
|
89
|
-
const cell = grid.snapToWalkable(grid.worldToCell(raw.x, raw.y), 10);
|
|
90
|
-
if (cell < 0) continue;
|
|
91
|
-
const target = grid.cellToWorld(cell);
|
|
92
|
-
const moveDistance = dist(you.x, you.y, target.x, target.y);
|
|
93
|
-
if (moveDistance < MIN_USEFUL_TARGET_DISTANCE) continue;
|
|
94
|
-
const nearestAfter = Math.min(...threats.map(t => dist(target.x, target.y, t.x, t.y)));
|
|
95
|
-
const score = (nearestAfter - nearestBefore) * 4 + moveDistance - Math.abs(offset) * 80;
|
|
96
|
-
if (!best || score > best.score) best = { target, score };
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return best?.target ?? null;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* 寻路躲避 Goal:用路径推演(planEscape)给出较远可走点并承诺该目标,移动中滑行,
|
|
105
|
-
* 只有路径变危险、被贴近或卡路才重规划。威胁来源、交战半径、结束条件均由构造参数定制,
|
|
106
|
-
* 供独立 keep-away 测试策略与 NormalShrimpTop 的 A/B 档共用。
|
|
107
|
-
*/
|
|
108
|
-
export class KeepAwayGoal extends Goal {
|
|
109
|
-
private committed: Position | null = null;
|
|
110
|
-
private lastNoticeKey = '';
|
|
111
|
-
private lastCommitAt = 0;
|
|
112
|
-
private lastCommitWasPanic = false;
|
|
113
|
-
private readonly threatRadius: number;
|
|
114
|
-
private readonly planOpts: EscapeOptions;
|
|
115
|
-
|
|
116
|
-
constructor(
|
|
117
|
-
public readonly key: string,
|
|
118
|
-
private readonly resolveThreats: ThreatResolver,
|
|
119
|
-
private readonly options: KeepAwayGoalOptions,
|
|
120
|
-
) {
|
|
121
|
-
super();
|
|
122
|
-
this.threatRadius = options.threatRadius;
|
|
123
|
-
this.planOpts = { ...KEEP_AWAY_BASE_PLAN_OPTS, ...options.planOpts };
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
tick(state: GameState, ctx: StrategyContext): BehaviorDecision[] {
|
|
127
|
-
const you = state.you;
|
|
128
|
-
const threats = this.threatsOf(state, ctx);
|
|
129
|
-
|
|
130
|
-
if (threats.length === 0) return this.handleNoThreat(you, ctx);
|
|
131
|
-
const threatLabels = threats.map(strategyPlayerLabel).join('、');
|
|
132
|
-
const intent = setStrategyIntent(ctx, {
|
|
133
|
-
activity: 'moving',
|
|
134
|
-
summary: `正在${state.you.room || '当前位置'}躲避${threatLabels},拉开距离。`,
|
|
135
|
-
...(state.you.room ? { room: state.you.room } : {}),
|
|
136
|
-
targetPlayer: threats[0].name,
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
const threatPoints = threats.map(p => ({ x: p.x, y: p.y }));
|
|
140
|
-
const nearestThreat = dist(threats[0].x, threats[0].y, you.x, you.y);
|
|
141
|
-
const shouldPanic = nearestThreat <= PANIC_RADIUS;
|
|
142
|
-
|
|
143
|
-
if (this.committed && (
|
|
144
|
-
dist(you.x, you.y, this.committed.x, this.committed.y) <= REACHED_DISTANCE
|
|
145
|
-
|| (ctx.blockedMoveTarget && dist(this.committed.x, this.committed.y, ctx.blockedMoveTarget.x, ctx.blockedMoveTarget.y) <= 24)
|
|
146
|
-
)) {
|
|
147
|
-
this.committed = null;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const committedAssessment = this.committed
|
|
151
|
-
? assessEscapeTarget(you, threatPoints, this.committed, this.planOpts)
|
|
152
|
-
: null;
|
|
153
|
-
const committedBad = committedAssessment
|
|
154
|
-
? committedAssessment.caught || committedAssessment.distanceToTarget === Infinity
|
|
155
|
-
: false;
|
|
156
|
-
|
|
157
|
-
if (this.committed && !shouldPanic && !committedBad) return [];
|
|
158
|
-
if (this.committed && shouldPanic) {
|
|
159
|
-
const elapsed = Date.now() - this.lastCommitAt;
|
|
160
|
-
const isCritical = nearestThreat <= CRITICAL_RADIUS;
|
|
161
|
-
if (!committedBad && isCritical && this.lastCommitWasPanic && elapsed < CRITICAL_REPLAN_INTERVAL_MS) return [];
|
|
162
|
-
if (!committedBad && !isCritical && elapsed < PANIC_REPLAN_INTERVAL_MS) return [];
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
if (!this.committed || shouldPanic || committedBad) {
|
|
166
|
-
const plan = planEscape(you, threatPoints, this.planOpts);
|
|
167
|
-
const target = plan.target;
|
|
168
|
-
const targetDistance = dist(you.x, you.y, target.x, target.y);
|
|
169
|
-
const caughtDetail = plan.caught
|
|
170
|
-
? `规划已被追上,逃点${Math.round(targetDistance)}px,最近威胁${Math.round(nearestThreat)}px,最小安全距${Math.round(plan.minCrabDistance)}px。`
|
|
171
|
-
: '';
|
|
172
|
-
if (targetDistance < MIN_USEFUL_TARGET_DISTANCE) {
|
|
173
|
-
const fallback = fallbackEscapeTarget(you, threats);
|
|
174
|
-
const detail = `规划${plan.caught ? '已被追上' : '逃点太近'},逃点${Math.round(targetDistance)}px,最近威胁${Math.round(nearestThreat)}px,最小安全距${Math.round(plan.minCrabDistance)}px。`;
|
|
175
|
-
if (!fallback) {
|
|
176
|
-
this.notice(ctx, `planner-stuck:${Math.round(nearestThreat)}:${Math.round(targetDistance)}`, `躲避规划没有可用逃点:${detail}`);
|
|
177
|
-
return [];
|
|
178
|
-
}
|
|
179
|
-
this.commit(ctx, fallback, threats, '兜底远离', true, detail);
|
|
180
|
-
} else if (!this.committed) {
|
|
181
|
-
this.commit(ctx, target, threats, plan.caught ? '挣脱' : shouldPanic ? '急避' : '远离', shouldPanic, caughtDetail);
|
|
182
|
-
} else if (dist(target.x, target.y, this.committed.x, this.committed.y) > PANIC_REPLAN_TARGET_SHIFT) {
|
|
183
|
-
this.commit(ctx, target, threats, plan.caught ? '改挣脱' : '改避', true, caughtDetail);
|
|
184
|
-
} else {
|
|
185
|
-
return [];
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const target = this.committed!;
|
|
190
|
-
return [strategyDecision(
|
|
191
|
-
Action.move(target).withThinking(`躲避${threats.map(p => p.name).join('、')},拉开距离`),
|
|
192
|
-
intent,
|
|
193
|
-
)];
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
isFinish(state: GameState, ctx: StrategyContext): boolean {
|
|
197
|
-
return (this.options.finishWhenClear ?? true) && this.threatsOf(state, ctx).length === 0;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
private threatsOf(state: GameState, ctx: StrategyContext): PlayerInfo[] {
|
|
201
|
-
const you = state.you;
|
|
202
|
-
return this.resolveThreats(state, ctx)
|
|
203
|
-
.filter(p => this.threatRadius === Infinity || dist(p.x, p.y, you.x, you.y) < this.threatRadius)
|
|
204
|
-
.sort((a, b) => dist(a.x, a.y, you.x, you.y) - dist(b.x, b.y, you.x, you.y))
|
|
205
|
-
.slice(0, MAX_THREATS);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
private handleNoThreat(you: Position & { currently_moving?: boolean }, ctx: StrategyContext): BehaviorDecision[] {
|
|
209
|
-
this.committed = null;
|
|
210
|
-
if (this.options.idleNotices) {
|
|
211
|
-
if (!you.currently_moving) this.notice(ctx, 'idle', `附近 ${this.threatRadius}px 内无人,原地待命。`);
|
|
212
|
-
else this.notice(ctx, 'coast', '威胁解除,继续完成当前移动,不再补发停步指令。');
|
|
213
|
-
}
|
|
214
|
-
if (!(this.options.finishWhenClear ?? true)) {
|
|
215
|
-
setStrategyIntent(ctx, {
|
|
216
|
-
activity: you.currently_moving ? 'moving' : 'waiting',
|
|
217
|
-
summary: you.currently_moving ? '附近威胁已解除,正在继续移动。' : '附近没有威胁,正在原地观察。',
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
return [];
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
private commit(ctx: StrategyContext, target: Position, threats: PlayerInfo[], verb: string, panic = false, detail = ''): void {
|
|
224
|
-
this.committed = target;
|
|
225
|
-
this.lastCommitAt = Date.now();
|
|
226
|
-
this.lastCommitWasPanic = panic;
|
|
227
|
-
const noun = this.options.noun;
|
|
228
|
-
const body = typeof noun === 'function'
|
|
229
|
-
? threats.map(p => `${noun(p, ctx)}${p.name}`).join('、')
|
|
230
|
-
: `${noun ?? ''}${threats.map(p => p.name).join('、')}`;
|
|
231
|
-
this.notice(
|
|
232
|
-
ctx,
|
|
233
|
-
`${verb}:${targetKey(target)}`,
|
|
234
|
-
`发现${body},${verb}到 (${Math.round(target.x)}, ${Math.round(target.y)})。${detail}`,
|
|
235
|
-
);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
private notice(ctx: StrategyContext, key: string, msg: string): void {
|
|
239
|
-
if (key === this.lastNoticeKey) return;
|
|
240
|
-
this.lastNoticeKey = key;
|
|
241
|
-
ctx.notifications.push(msg);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import type { GameState, PlayerInfo } from '../../sdk/types.js';
|
|
2
|
-
import {
|
|
3
|
-
dist,
|
|
4
|
-
killCooldownSecs,
|
|
5
|
-
killCommitRange,
|
|
6
|
-
LONE_FOLLOW_DISTANCE,
|
|
7
|
-
nearestPlayerByDistance,
|
|
8
|
-
nonTeammatesVisible,
|
|
9
|
-
patrolStep,
|
|
10
|
-
PatrolState,
|
|
11
|
-
PROGRESS_INTERVAL_MS,
|
|
12
|
-
pursueVisibleTarget,
|
|
13
|
-
setStrategyIntent,
|
|
14
|
-
strategyPlayerLabel,
|
|
15
|
-
} from '../game-utils.js';
|
|
16
|
-
import type { BehaviorDecision, StrategyContext } from '../types.js';
|
|
17
|
-
import { Goal } from './goal.js';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* 疯狂砍人:见谁杀谁(除队友外的所有可见玩家),不挑落单、不看人数、不读取玩家分类参数。
|
|
21
|
-
* 与 kill-lone 不同——周围人多也照杀,绝不因人多而暂停。
|
|
22
|
-
*
|
|
23
|
-
* 逐 tick:
|
|
24
|
-
* - 视野内有非队友 → 锁定最近那个,贴上去:出刀范围内且冷却好就出刀,
|
|
25
|
-
* 冷却中保持 LONE_FOLLOW_DISTANCE 贴身跟随等待。
|
|
26
|
-
* - 否则 → 按房间顺序巡逻找猎物。永不停手。
|
|
27
|
-
*
|
|
28
|
-
* 与 kill-target 复用同一套「锁定后追/砍/等冷却」体验(pursueVisibleTarget,
|
|
29
|
-
* kill=true、followDistance=LONE_FOLLOW_DISTANCE),仅目标选取规则不同:
|
|
30
|
-
* kill-target 追指定名单,kill-frenzy 追最近的任意非队友。
|
|
31
|
-
*/
|
|
32
|
-
export class KillFrenzyTop extends Goal {
|
|
33
|
-
private readonly patrol = new PatrolState();
|
|
34
|
-
|
|
35
|
-
tick(state: GameState, ctx: StrategyContext): BehaviorDecision[] {
|
|
36
|
-
const target = this.nearestVictim(state, ctx);
|
|
37
|
-
if (target) {
|
|
38
|
-
const decision = pursueVisibleTarget(state, target, { kill: true, followDistance: LONE_FOLLOW_DISTANCE });
|
|
39
|
-
if (decision?.action.type === 'kill') {
|
|
40
|
-
ctx.notifications.push(`发现目标${target.name}在攻击范围内,出刀!`);
|
|
41
|
-
} else {
|
|
42
|
-
const d = target.distance ?? dist(state.you.x, state.you.y, target.x, target.y);
|
|
43
|
-
if (d > killCommitRange(state.you.role)) ctx.notifications.push(`发现目标${target.name},正在靠近!`);
|
|
44
|
-
}
|
|
45
|
-
if (!decision) {
|
|
46
|
-
setStrategyIntent(ctx, {
|
|
47
|
-
activity: 'waiting',
|
|
48
|
-
summary: `正在${target.room || state.you.room || '当前位置'}贴近${strategyPlayerLabel(target)},等待击杀冷却。`,
|
|
49
|
-
...(target.room ? { room: target.room } : {}),
|
|
50
|
-
targetPlayer: target.name,
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
this.emitProgress(state, ctx);
|
|
54
|
-
return decision ? [decision] : [];
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
this.emitProgress(state, ctx);
|
|
58
|
-
return patrolStep(state, ctx, this.patrol, false, '巡逻寻找猎物');
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
private nearestVictim(state: GameState, ctx: StrategyContext): PlayerInfo | null {
|
|
62
|
-
return nearestPlayerByDistance(state, nonTeammatesVisible(state, ctx));
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
private emitProgress(state: GameState, ctx: StrategyContext): void {
|
|
66
|
-
const now = Date.now();
|
|
67
|
-
if (now - ctx.lastProgressNotifyAt < PROGRESS_INTERVAL_MS) return;
|
|
68
|
-
ctx.lastProgressNotifyAt = now;
|
|
69
|
-
|
|
70
|
-
const room = state.you.room ?? '未知';
|
|
71
|
-
const cd = killCooldownSecs(state);
|
|
72
|
-
const killsRemaining = state.you.kills_remaining;
|
|
73
|
-
const victims = nonTeammatesVisible(state, ctx);
|
|
74
|
-
|
|
75
|
-
let msg = `[进度] 当前在${room}`;
|
|
76
|
-
if (victims.length === 0) {
|
|
77
|
-
msg += ',视野内没有目标,继续巡逻寻找猎物。';
|
|
78
|
-
} else {
|
|
79
|
-
const nearest = victims.reduce((best, p) => {
|
|
80
|
-
const d = p.distance ?? dist(state.you.x, state.you.y, p.x, p.y);
|
|
81
|
-
const bestD = best.distance ?? dist(state.you.x, state.you.y, best.x, best.y);
|
|
82
|
-
return d < bestD ? p : best;
|
|
83
|
-
});
|
|
84
|
-
msg += `,视野内发现${victims.length}个目标,最近是${nearest.name}。`;
|
|
85
|
-
if (cd > 0) msg += `攻击冷却中(${cd}s)。`;
|
|
86
|
-
if (killsRemaining === 0) msg += '出刀次数已用完。';
|
|
87
|
-
}
|
|
88
|
-
ctx.notifications.push(msg);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
@@ -1,96 +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 { KillLoneTop } from './kill-lone-top.js';
|
|
5
|
-
import { KillVisibleTargetGoal } from './kill-target-goal.js';
|
|
6
|
-
|
|
7
|
-
function state(): GameState {
|
|
8
|
-
return {
|
|
9
|
-
phase: 'wandering',
|
|
10
|
-
tick: 1,
|
|
11
|
-
you: {
|
|
12
|
-
name: 'hunter',
|
|
13
|
-
x: 0,
|
|
14
|
-
y: 0,
|
|
15
|
-
room: 'control',
|
|
16
|
-
role: 'crab_generic',
|
|
17
|
-
faction: 'crab',
|
|
18
|
-
is_alive: true,
|
|
19
|
-
kill_cooldown_secs: 0,
|
|
20
|
-
},
|
|
21
|
-
your_tasks: [],
|
|
22
|
-
players: [
|
|
23
|
-
{ name: 'target', seat: 2, x: 100, y: 0, room: 'control', distance: 100 },
|
|
24
|
-
{ name: 'witness', seat: 3, x: 120, y: 0, room: 'control', distance: 120 },
|
|
25
|
-
],
|
|
26
|
-
all_players: [
|
|
27
|
-
{ name: 'target', seat: 2, role: 'unknown', is_alive: true },
|
|
28
|
-
{ name: 'witness', seat: 3, role: 'unknown', is_alive: true },
|
|
29
|
-
],
|
|
30
|
-
corpses: [],
|
|
31
|
-
stale: false,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function context(): StrategyContext {
|
|
36
|
-
return {
|
|
37
|
-
taskData: [],
|
|
38
|
-
emergency: null,
|
|
39
|
-
taskLocalBlockedUntil: 0,
|
|
40
|
-
reportCorpseTarget: null,
|
|
41
|
-
reportBlockedUntil: 0,
|
|
42
|
-
notifications: [],
|
|
43
|
-
lastProgressNotifyAt: Date.now(),
|
|
44
|
-
teammates: new Set(),
|
|
45
|
-
rooms: [{ name: 'patrol', x: 500, y: 0 }],
|
|
46
|
-
playerNamesBySeat: { '2': 'target', '3': 'witness' },
|
|
47
|
-
forcePatrolAdvance: false,
|
|
48
|
-
blockedMoveTarget: null,
|
|
49
|
-
mySeat: 1,
|
|
50
|
-
speechNotifications: [],
|
|
51
|
-
agentAlerts: [],
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
describe('KillLoneTop player-list controls', () => {
|
|
56
|
-
it('lets huntTargets bypass the lone-player condition', () => {
|
|
57
|
-
const top = new KillLoneTop([], [2]);
|
|
58
|
-
|
|
59
|
-
top.tick(state(), context());
|
|
60
|
-
|
|
61
|
-
expect(top.subGoal).toBeInstanceOf(KillVisibleTargetGoal);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('gives protectedTargets priority over huntTargets', () => {
|
|
65
|
-
const top = new KillLoneTop([2], [2]);
|
|
66
|
-
|
|
67
|
-
top.tick(state(), context());
|
|
68
|
-
|
|
69
|
-
expect(top.subGoal).not.toBeInstanceOf(KillVisibleTargetGoal);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('keeps hunting the configured seat when players share the same name', () => {
|
|
73
|
-
const top = new KillLoneTop([], [6]);
|
|
74
|
-
const current = state();
|
|
75
|
-
current.players = [
|
|
76
|
-
{ name: '木桩机器虾', seat: 2, x: 20, y: 0, room: 'control', distance: 20 },
|
|
77
|
-
{ name: '木桩机器虾', seat: 6, x: 100, y: 0, room: 'control', distance: 100 },
|
|
78
|
-
{ name: '木桩机器虾', seat: 3, x: 120, y: 0, room: 'control', distance: 120 },
|
|
79
|
-
];
|
|
80
|
-
current.all_players = current.players.map((player) => ({
|
|
81
|
-
name: player.name,
|
|
82
|
-
seat: player.seat!,
|
|
83
|
-
role: 'unknown',
|
|
84
|
-
is_alive: true,
|
|
85
|
-
}));
|
|
86
|
-
|
|
87
|
-
top.tick(current, context());
|
|
88
|
-
|
|
89
|
-
expect(top.subGoal).toBeInstanceOf(KillVisibleTargetGoal);
|
|
90
|
-
expect((top.subGoal as KillVisibleTargetGoal).targetSeat).toBe(6);
|
|
91
|
-
expect(top.subGoal?.tick(current, context())[0]?.action.payload).toMatchObject({
|
|
92
|
-
target_x: 100,
|
|
93
|
-
target_y: 0,
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
});
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import type { GameState, PlayerInfo } from '../../sdk/types.js';
|
|
2
|
-
import {
|
|
3
|
-
hasKillUseRemaining,
|
|
4
|
-
hasReachedRoomTarget,
|
|
5
|
-
killCooldownSecs,
|
|
6
|
-
LONE_IGNORE_MS,
|
|
7
|
-
matchesAnyTarget,
|
|
8
|
-
nearestPlayerByDistance,
|
|
9
|
-
nonTeammatesVisible,
|
|
10
|
-
PatrolState,
|
|
11
|
-
PROGRESS_INTERVAL_MS,
|
|
12
|
-
} from '../game-utils.js';
|
|
13
|
-
import type { BehaviorDecision, StrategyContext } from '../types.js';
|
|
14
|
-
import { Goal } from './goal.js';
|
|
15
|
-
import { KillVisibleTargetGoal } from './kill-target-goal.js';
|
|
16
|
-
import { MoveRoomGoal } from './move-room-goal.js';
|
|
17
|
-
|
|
18
|
-
const PATROL_PRIORITY = 0.2;
|
|
19
|
-
const HUNT_PRIORITY = 0.5;
|
|
20
|
-
|
|
21
|
-
export class KillLoneTop extends Goal {
|
|
22
|
-
private readonly patrol = new PatrolState();
|
|
23
|
-
private loneIgnoreUntil = 0;
|
|
24
|
-
private patrolStopOnPlayer: boolean | null = null;
|
|
25
|
-
private lastFlaggedTarget: number | null = null;
|
|
26
|
-
|
|
27
|
-
constructor(
|
|
28
|
-
private readonly protectedTargets: number[] = [],
|
|
29
|
-
private readonly huntTargets: number[] = [],
|
|
30
|
-
) {
|
|
31
|
-
super();
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
tick(state: GameState, ctx: StrategyContext): BehaviorDecision[] {
|
|
35
|
-
const now = Date.now();
|
|
36
|
-
const nonTeammates = nonTeammatesVisible(state, ctx);
|
|
37
|
-
|
|
38
|
-
if (!hasKillUseRemaining(state)) {
|
|
39
|
-
this.setPatrolGoal(state, ctx, false);
|
|
40
|
-
this.emitProgress(state, ctx);
|
|
41
|
-
return [];
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const flagged = nearestPlayerByDistance(
|
|
45
|
-
state,
|
|
46
|
-
nonTeammates.filter(p => matchesAnyTarget(p, this.huntTargets, ctx) && !this.isProtected(p, ctx)),
|
|
47
|
-
);
|
|
48
|
-
if (flagged?.seat != null) {
|
|
49
|
-
if (flagged.seat !== this.lastFlaggedTarget) {
|
|
50
|
-
ctx.notifications.push(`根据情报,${flagged.name}被标记为目标,主动出击!`);
|
|
51
|
-
this.lastFlaggedTarget = flagged.seat;
|
|
52
|
-
}
|
|
53
|
-
this.setHuntGoal(flagged.seat, true);
|
|
54
|
-
return [];
|
|
55
|
-
} else {
|
|
56
|
-
this.lastFlaggedTarget = null;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (nonTeammates.length === 0 && state.players.length > 0) {
|
|
60
|
-
this.loneIgnoreUntil = now + LONE_IGNORE_MS;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (now < this.loneIgnoreUntil || nonTeammates.length === 0) {
|
|
64
|
-
this.setPatrolGoal(state, ctx, now >= this.loneIgnoreUntil);
|
|
65
|
-
this.emitProgress(state, ctx);
|
|
66
|
-
return [];
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (nonTeammates.length > 1) {
|
|
70
|
-
this.loneIgnoreUntil = now + LONE_IGNORE_MS;
|
|
71
|
-
this.setPatrolGoal(state, ctx, false);
|
|
72
|
-
this.emitProgress(state, ctx);
|
|
73
|
-
return [];
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const target = nonTeammates[0];
|
|
77
|
-
if (this.isProtected(target, ctx)) {
|
|
78
|
-
this.loneIgnoreUntil = now + LONE_IGNORE_MS;
|
|
79
|
-
this.setPatrolGoal(state, ctx, false);
|
|
80
|
-
this.emitProgress(state, ctx);
|
|
81
|
-
return [];
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (target.seat == null) {
|
|
85
|
-
this.setPatrolGoal(state, ctx, false);
|
|
86
|
-
return [];
|
|
87
|
-
}
|
|
88
|
-
this.setHuntGoal(target.seat);
|
|
89
|
-
this.emitProgress(state, ctx);
|
|
90
|
-
return [];
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/** protectedTargets 中的玩家永不击杀;与 huntTargets 重叠时保护优先。 */
|
|
94
|
-
private isProtected(p: PlayerInfo, ctx: StrategyContext): boolean {
|
|
95
|
-
return matchesAnyTarget(p, this.protectedTargets, ctx);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
private setHuntGoal(targetSeat: number, ignoreCrowd = false): void {
|
|
99
|
-
const worker = this.subGoal;
|
|
100
|
-
if (worker instanceof KillVisibleTargetGoal && worker.targetSeat === targetSeat && worker.ignoreCrowd === ignoreCrowd) return;
|
|
101
|
-
if (this.subGoal) this.removeSubGoal();
|
|
102
|
-
this.setSubGoal(new KillVisibleTargetGoal(targetSeat, this.protectedTargets, ignoreCrowd), HUNT_PRIORITY);
|
|
103
|
-
this.patrolStopOnPlayer = null;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
private setPatrolGoal(state: GameState, ctx: StrategyContext, stopOnPlayer: boolean): void {
|
|
107
|
-
let room = this.patrol.nextRoom(ctx);
|
|
108
|
-
if (!room) {
|
|
109
|
-
this.clearGoal();
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (hasReachedRoomTarget(state, room)) {
|
|
114
|
-
this.patrol.advance(ctx);
|
|
115
|
-
room = this.patrol.nextRoom(ctx);
|
|
116
|
-
if (!room) {
|
|
117
|
-
this.clearGoal();
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const worker = this.subGoal;
|
|
123
|
-
if (worker instanceof MoveRoomGoal && worker.room === room.name && this.patrolStopOnPlayer === stopOnPlayer) return;
|
|
124
|
-
if (this.subGoal) this.removeSubGoal();
|
|
125
|
-
this.setSubGoal(new MoveRoomGoal(room.name, hasReachedRoomTarget, {
|
|
126
|
-
emitProgress: false,
|
|
127
|
-
stopOnPlayer,
|
|
128
|
-
purpose: '巡逻寻找落单目标',
|
|
129
|
-
}), PATROL_PRIORITY);
|
|
130
|
-
this.patrolStopOnPlayer = stopOnPlayer;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
private clearGoal(): void {
|
|
134
|
-
if (this.subGoal) this.removeSubGoal();
|
|
135
|
-
this.patrolStopOnPlayer = null;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
private emitProgress(state: GameState, ctx: StrategyContext): void {
|
|
139
|
-
const now = Date.now();
|
|
140
|
-
if (now - ctx.lastProgressNotifyAt < PROGRESS_INTERVAL_MS) return;
|
|
141
|
-
ctx.lastProgressNotifyAt = now;
|
|
142
|
-
|
|
143
|
-
const room = state.you.room ?? '未知';
|
|
144
|
-
const cd = killCooldownSecs(state);
|
|
145
|
-
const killsRemaining = state.you.kills_remaining;
|
|
146
|
-
const nonTeammates = nonTeammatesVisible(state, ctx);
|
|
147
|
-
|
|
148
|
-
let msg = `[进度] 当前在${room}`;
|
|
149
|
-
if (nonTeammates.length === 0) {
|
|
150
|
-
msg += ',视野内没有目标,继续巡逻寻找落单猎物。';
|
|
151
|
-
} else if (nonTeammates.length === 1) {
|
|
152
|
-
const target = nonTeammates[0];
|
|
153
|
-
if (this.isProtected(target, ctx)) {
|
|
154
|
-
msg += `,视野内发现保护目标${target.name},不动手。`;
|
|
155
|
-
} else {
|
|
156
|
-
msg += `,视野内发现落单目标${target.name}。`;
|
|
157
|
-
}
|
|
158
|
-
if (cd > 0) msg += `攻击冷却中(${cd}s)。`;
|
|
159
|
-
if (killsRemaining === 0) msg += '出刀次数已用完。';
|
|
160
|
-
} else {
|
|
161
|
-
msg += `,视野内有${nonTeammates.length}人,不适合动手,暂时回避。`;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
ctx.notifications.push(msg);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import type { GameState, PlayerInfo } from '../../sdk/types.js';
|
|
2
|
-
import { Action } from '../../sdk/action.js';
|
|
3
|
-
import {
|
|
4
|
-
canUseKill,
|
|
5
|
-
dist,
|
|
6
|
-
hasKillUseRemaining,
|
|
7
|
-
killCommitRange,
|
|
8
|
-
LONE_FOLLOW_DISTANCE,
|
|
9
|
-
matchesAnyTarget,
|
|
10
|
-
nonTeammatesVisible,
|
|
11
|
-
playerStrategyIntent,
|
|
12
|
-
setStrategyIntent,
|
|
13
|
-
strategyDecision,
|
|
14
|
-
strategyPlayerLabel,
|
|
15
|
-
} from '../game-utils.js';
|
|
16
|
-
import type { BehaviorDecision, StrategyContext } from '../types.js';
|
|
17
|
-
import { Goal } from './goal.js';
|
|
18
|
-
|
|
19
|
-
export class KillVisibleTargetGoal extends Goal {
|
|
20
|
-
constructor(
|
|
21
|
-
public readonly targetSeat: number,
|
|
22
|
-
private readonly protectedTargets: number[],
|
|
23
|
-
public readonly ignoreCrowd = false,
|
|
24
|
-
) {
|
|
25
|
-
super();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
tick(state: GameState, ctx: StrategyContext): BehaviorDecision[] {
|
|
29
|
-
const target = this.target(state, ctx);
|
|
30
|
-
if (!target) return [];
|
|
31
|
-
if (!hasKillUseRemaining(state)) return [];
|
|
32
|
-
|
|
33
|
-
const d = target.distance ?? dist(state.you.x, state.you.y, target.x, target.y);
|
|
34
|
-
|
|
35
|
-
if (d <= killCommitRange(state.you.role)) {
|
|
36
|
-
if (canUseKill(state)) {
|
|
37
|
-
if (target.seat == null || target.seat <= 0) return [];
|
|
38
|
-
ctx.notifications.push(`发现追杀目标${target.name},出刀!`);
|
|
39
|
-
return [strategyDecision(Action.kill(target.seat), playerStrategyIntent(target, '追杀', 'acting'))];
|
|
40
|
-
}
|
|
41
|
-
if (d > LONE_FOLLOW_DISTANCE) {
|
|
42
|
-
return [strategyDecision(Action.move({ x: target.x, y: target.y }), playerStrategyIntent(target, '追杀', 'moving'))];
|
|
43
|
-
}
|
|
44
|
-
setStrategyIntent(ctx, {
|
|
45
|
-
activity: 'waiting',
|
|
46
|
-
summary: `正在${target.room || state.you.room || '当前位置'}贴近${strategyPlayerLabel(target)},等待击杀冷却。`,
|
|
47
|
-
...(target.room ? { room: target.room } : {}),
|
|
48
|
-
targetPlayer: target.name,
|
|
49
|
-
});
|
|
50
|
-
return [];
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
ctx.notifications.push(`发现追杀目标${target.name},正在靠近!`);
|
|
54
|
-
return [strategyDecision(Action.move({ x: target.x, y: target.y }), playerStrategyIntent(target, '追杀', 'moving'))];
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
isFinish(state: GameState, ctx: StrategyContext): boolean {
|
|
58
|
-
return this.target(state, ctx) == null;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
private target(state: GameState, ctx: StrategyContext): PlayerInfo | null {
|
|
62
|
-
const visible = nonTeammatesVisible(state, ctx);
|
|
63
|
-
if (!this.ignoreCrowd && visible.length !== 1) return null;
|
|
64
|
-
const target = visible.find(p => p.seat === this.targetSeat) ?? null;
|
|
65
|
-
if (!target) return null;
|
|
66
|
-
if (matchesAnyTarget(target, this.protectedTargets, ctx)) return null;
|
|
67
|
-
return target;
|
|
68
|
-
}
|
|
69
|
-
}
|