poi-plugin-kca-next 1.0.3 → 1.0.4
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/dist/index.js +129 -23
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -873,7 +873,9 @@ function createDefaultSettings() {
|
|
|
873
873
|
minLevel: 0,
|
|
874
874
|
reservedDocks: 1,
|
|
875
875
|
sortOrder: "shortest",
|
|
876
|
-
batchAllFreeDocks: true
|
|
876
|
+
batchAllFreeDocks: true,
|
|
877
|
+
damageThreshold: "light",
|
|
878
|
+
avoidSortieConflict: true
|
|
877
879
|
},
|
|
878
880
|
develop: {
|
|
879
881
|
remainingCount: 0,
|
|
@@ -4313,42 +4315,98 @@ async function executeRepair(bridge, actions, logger, shipIds, bucketThresholdSe
|
|
|
4313
4315
|
);
|
|
4314
4316
|
return repairedCount;
|
|
4315
4317
|
}
|
|
4318
|
+
function planAutoRepair(state, settings, ctx) {
|
|
4319
|
+
const cfg = settings.repair;
|
|
4320
|
+
const avoidConflict = cfg.avoidSortieConflict !== false;
|
|
4321
|
+
const damageThreshold = cfg.damageThreshold ?? "light";
|
|
4322
|
+
const freeDocks = getFreeRepairDocks(state, settings.general.operationAdvanceSec);
|
|
4323
|
+
const effectiveReservedDocks = avoidConflict && ctx.isSortieEnabled ? Math.max(cfg.reservedDocks, 1) : cfg.reservedDocks;
|
|
4324
|
+
const usableCount = Math.max(0, freeDocks.length - effectiveReservedDocks);
|
|
4325
|
+
const excludedShipIds = /* @__PURE__ */ new Set();
|
|
4326
|
+
for (const f of Object.values(state.fleets)) {
|
|
4327
|
+
for (const sid of f.shipIds) excludedShipIds.add(sid);
|
|
4328
|
+
}
|
|
4329
|
+
if (avoidConflict && ctx.isSortieEnabled) {
|
|
4330
|
+
const activeProfile = settings.sortie.profiles.find((p) => p.id === settings.sortie.activeProfileId) ?? settings.sortie.profiles[0];
|
|
4331
|
+
if (activeProfile?.autoChangeShip) {
|
|
4332
|
+
for (const slotList of activeProfile.candidateShips) {
|
|
4333
|
+
for (const sid of slotList ?? []) {
|
|
4334
|
+
if (sid > 0) excludedShipIds.add(sid);
|
|
4335
|
+
}
|
|
4336
|
+
}
|
|
4337
|
+
}
|
|
4338
|
+
}
|
|
4339
|
+
const candidates = Object.values(state.ships).filter(
|
|
4340
|
+
(s) => s.hp < s.maxHp && matchesDamageThreshold(s, damageThreshold) && !s.isRepairing && s.level >= cfg.minLevel && !excludedShipIds.has(s.id) && !ctx.isShipReservedByKira(s.id)
|
|
4341
|
+
).sort(
|
|
4342
|
+
(a, b) => cfg.sortOrder === "shortest" ? a.repairTimeMs - b.repairTimeMs : b.repairTimeMs - a.repairTimeMs
|
|
4343
|
+
);
|
|
4344
|
+
return {
|
|
4345
|
+
usableCount,
|
|
4346
|
+
effectiveReservedDocks,
|
|
4347
|
+
freeDockCount: freeDocks.length,
|
|
4348
|
+
candidates
|
|
4349
|
+
};
|
|
4350
|
+
}
|
|
4351
|
+
var REPAIR_ERROR_BACKOFF_MS = 6e4;
|
|
4316
4352
|
var AutoRepairModule = class extends AutomationModule {
|
|
4317
|
-
constructor(runtime,
|
|
4353
|
+
constructor(runtime, hooks) {
|
|
4318
4354
|
super(runtime);
|
|
4319
|
-
this.
|
|
4355
|
+
this.hooks = hooks;
|
|
4320
4356
|
}
|
|
4321
4357
|
id = "repair";
|
|
4322
4358
|
category = "repair";
|
|
4323
4359
|
displayName = "\u81EA\u52A8\u5165\u6E20";
|
|
4360
|
+
backoffUntilMs = 0;
|
|
4361
|
+
onEnabled() {
|
|
4362
|
+
this.backoffUntilMs = 0;
|
|
4363
|
+
}
|
|
4364
|
+
/**
|
|
4365
|
+
* Returns true when AutoRepair has both spare docks (beyond sortie reserve) and eligible
|
|
4366
|
+
* damaged standby ships ready to dock at Homeport. Used by AutoSortie to yield cleanly
|
|
4367
|
+
* between sorties so both modules work side-by-side without conflict.
|
|
4368
|
+
*/
|
|
4369
|
+
needsAction() {
|
|
4370
|
+
if (!this.enabled) return false;
|
|
4371
|
+
if (Date.now() < this.backoffUntilMs) return false;
|
|
4372
|
+
const state = this.runtime.bridge.getState();
|
|
4373
|
+
if (!state.loaded || state.inSortie) return false;
|
|
4374
|
+
if (this.runtime.scheduler.isSortieClickLockActive) return false;
|
|
4375
|
+
if (this.hooks.hasHigherPriorityWork?.()) return false;
|
|
4376
|
+
const settings = this.runtime.getSettings();
|
|
4377
|
+
const plan = planAutoRepair(state, settings, {
|
|
4378
|
+
isSortieEnabled: this.runtime.isModuleEnabled("sortie"),
|
|
4379
|
+
isShipReservedByKira: this.hooks.isShipReservedByKira
|
|
4380
|
+
});
|
|
4381
|
+
return plan.usableCount > 0 && plan.candidates.length > 0;
|
|
4382
|
+
}
|
|
4324
4383
|
async tick() {
|
|
4325
4384
|
if (!this.enabled || !this.runtime.scheduler.canAcquire(this.id)) return;
|
|
4385
|
+
if (Date.now() < this.backoffUntilMs) return;
|
|
4326
4386
|
const state = this.runtime.bridge.getState();
|
|
4327
4387
|
if (!state.loaded || state.inSortie) return;
|
|
4388
|
+
if (this.runtime.scheduler.isSortieClickLockActive) return;
|
|
4389
|
+
if (this.hooks.hasHigherPriorityWork?.()) return;
|
|
4328
4390
|
const settings = this.runtime.getSettings();
|
|
4329
4391
|
const cfg = settings.repair;
|
|
4330
|
-
const
|
|
4331
|
-
|
|
4332
|
-
|
|
4333
|
-
|
|
4392
|
+
const plan = planAutoRepair(state, settings, {
|
|
4393
|
+
isSortieEnabled: this.runtime.isModuleEnabled("sortie"),
|
|
4394
|
+
isShipReservedByKira: this.hooks.isShipReservedByKira
|
|
4395
|
+
});
|
|
4396
|
+
if (plan.usableCount <= 0) {
|
|
4397
|
+
this.setStatus(
|
|
4398
|
+
`\u7B49\u5F85\u7A7A\u6E20\u4F4D (\u7A7A\u95F2 ${plan.freeDockCount} / \u4FDD\u7559 ${plan.effectiveReservedDocks})`,
|
|
4399
|
+
"idle"
|
|
4400
|
+
);
|
|
4334
4401
|
return;
|
|
4335
4402
|
}
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
for (const sid of f.shipIds) inFleetIds.add(sid);
|
|
4339
|
-
}
|
|
4340
|
-
const candidates = Object.values(state.ships).filter(
|
|
4341
|
-
(s) => s.hp < s.maxHp && !s.isRepairing && s.level >= cfg.minLevel && !inFleetIds.has(s.id) && !this.isShipReservedByKira(s.id)
|
|
4342
|
-
).sort(
|
|
4343
|
-
(a, b) => cfg.sortOrder === "shortest" ? a.repairTimeMs - b.repairTimeMs : b.repairTimeMs - a.repairTimeMs
|
|
4344
|
-
);
|
|
4345
|
-
if (candidates.length === 0) {
|
|
4346
|
-
this.setStatus("\u6682\u65E0\u9700\u8981\u4FEE\u7406\u7684\u5F85\u547D\u8230\u5A18", "idle");
|
|
4403
|
+
if (plan.candidates.length === 0) {
|
|
4404
|
+
this.setStatus("\u6682\u65E0\u7B26\u5408\u635F\u4F24\u6761\u4EF6\u7684\u5F85\u547D\u8230\u5A18", "idle");
|
|
4347
4405
|
return;
|
|
4348
4406
|
}
|
|
4349
|
-
const batchSize = cfg.batchAllFreeDocks ? usableCount : 1;
|
|
4350
|
-
const shipIds = candidates.slice(0, batchSize).map((s) => s.id);
|
|
4351
|
-
await this.runLocked(async (ctx) => {
|
|
4407
|
+
const batchSize = cfg.batchAllFreeDocks ? plan.usableCount : 1;
|
|
4408
|
+
const shipIds = plan.candidates.slice(0, batchSize).map((s) => s.id);
|
|
4409
|
+
const ok = await this.runLocked(async (ctx) => {
|
|
4352
4410
|
this.setStatus(`\u6B63\u5728\u5B89\u6392\u5165\u6E20 (${shipIds.length} \u8258)`);
|
|
4353
4411
|
await executeRepair(
|
|
4354
4412
|
this.runtime.bridge,
|
|
@@ -4361,6 +4419,9 @@ var AutoRepairModule = class extends AutomationModule {
|
|
|
4361
4419
|
);
|
|
4362
4420
|
this.setStatus("\u5165\u6E20\u5B8C\u6210", "idle");
|
|
4363
4421
|
});
|
|
4422
|
+
if (!ok && this.lastError) {
|
|
4423
|
+
this.backoffUntilMs = Date.now() + REPAIR_ERROR_BACKOFF_MS;
|
|
4424
|
+
}
|
|
4364
4425
|
}
|
|
4365
4426
|
};
|
|
4366
4427
|
|
|
@@ -8875,6 +8936,9 @@ var AutoSortieModule = class extends AutomationModule {
|
|
|
8875
8936
|
return;
|
|
8876
8937
|
}
|
|
8877
8938
|
}
|
|
8939
|
+
if (this.hooks.repairNeedsAction?.()) {
|
|
8940
|
+
return;
|
|
8941
|
+
}
|
|
8878
8942
|
if (profile.limitType !== "none" && profile.limitRemaining <= 0) {
|
|
8879
8943
|
this.runtime.logger.success("sortie", `\u51FA\u51FB\u914D\u7F6E [${profile.name}] \u5DF2\u8FBE\u6210\u6B21\u6570/\u76EE\u6807\u9650\u5236\uFF0C\u81EA\u52A8\u505C\u6B62`);
|
|
8880
8944
|
this.setEnabled(false);
|
|
@@ -9705,17 +9769,21 @@ var KcaAssistantCoordinator = class {
|
|
|
9705
9769
|
}
|
|
9706
9770
|
);
|
|
9707
9771
|
this.organization = new AutoOrganizationModule(runtime, () => this.practice.needsAction());
|
|
9772
|
+
this.repair = new AutoRepairModule(runtime, {
|
|
9773
|
+
isShipReservedByKira: (id) => this.kira.isShipReserved(id),
|
|
9774
|
+
hasHigherPriorityWork: () => this.practice.needsAction() || this.expedition.needsAction() || this.kira.needsAction()
|
|
9775
|
+
});
|
|
9708
9776
|
this.sortie = new AutoSortieModule(runtime, {
|
|
9709
9777
|
practiceNeedsAction: () => this.practice.needsAction(),
|
|
9710
9778
|
expeditionNeedsAction: () => this.expedition.needsAction(),
|
|
9711
9779
|
kiraNeedsAction: () => this.kira.needsAction(),
|
|
9780
|
+
repairNeedsAction: () => this.repair.needsAction(),
|
|
9712
9781
|
isShipReservedByKira: (id) => this.kira.isShipReserved(id),
|
|
9713
9782
|
getPendingSupportExpeditions: () => this.expedition.getPendingSupportDispatches(),
|
|
9714
9783
|
clearPendingSupportExpeditions: () => this.expedition.clearPendingSupportDispatches(),
|
|
9715
9784
|
onBattleResultForQuests: (params) => this.quests.onBattleResult(params),
|
|
9716
9785
|
onSortieCompletedForQuests: () => this.quests.onSortieCompleted()
|
|
9717
9786
|
});
|
|
9718
|
-
this.repair = new AutoRepairModule(runtime, (id) => this.kira.isShipReserved(id));
|
|
9719
9787
|
this.develop = new AutoDevelopModule(runtime);
|
|
9720
9788
|
this.plan = new AutoPlanModule(runtime, {
|
|
9721
9789
|
isAnyFleetInSortie: () => this.bridge.getState().inSortie,
|
|
@@ -13796,6 +13864,12 @@ var PERIOD_LABELS = {
|
|
|
13796
13864
|
monthly: "\u6708\u5E38",
|
|
13797
13865
|
other: "\u5176\u4ED6"
|
|
13798
13866
|
};
|
|
13867
|
+
var REPAIR_DAMAGE_LABELS = {
|
|
13868
|
+
light: "\u5C0F\u7834\u53CA\u4EE5\u4E0A",
|
|
13869
|
+
moderate: "\u4E2D\u7834\u53CA\u4EE5\u4E0A",
|
|
13870
|
+
heavy: "\u4EC5\u5927\u7834",
|
|
13871
|
+
scratch: "\u5168\u90E8\u635F\u4F24(\u542B\u64E6\u4F24)"
|
|
13872
|
+
};
|
|
13799
13873
|
var OrgPracticeQuestsTab = ({ coordinator, settings }) => {
|
|
13800
13874
|
const [recordFleet, setRecordFleet] = (0, import_react4.useState)(1);
|
|
13801
13875
|
const [recordName, setRecordName] = (0, import_react4.useState)("");
|
|
@@ -14278,8 +14352,22 @@ var OrgPracticeQuestsTab = ({ coordinator, settings }) => {
|
|
|
14278
14352
|
storageKey: "modules.repair",
|
|
14279
14353
|
title: "\u81EA\u52A8\u5165\u6E20 (\u5F85\u547D\u8230\u5A18)",
|
|
14280
14354
|
defaultOpen: true,
|
|
14281
|
-
summary: /* @__PURE__ */ import_react4.default.createElement("span", null, "Lv\u2265", rep.minLevel, " \xB7 \u7559", rep.reservedDocks, "\u6E20
|
|
14355
|
+
summary: /* @__PURE__ */ import_react4.default.createElement(import_react4.default.Fragment, null, /* @__PURE__ */ import_react4.default.createElement("span", null, REPAIR_DAMAGE_LABELS[rep.damageThreshold ?? "light"], " \xB7 Lv\u2265", rep.minLevel, " \xB7 \u7559", rep.reservedDocks, "\u6E20"), rep.avoidSortieConflict !== false && /* @__PURE__ */ import_react4.default.createElement("span", { className: "kca-badge kca-badge-ok" }, "\u9632\u51FA\u51FB\u51B2\u7A81"))
|
|
14282
14356
|
},
|
|
14357
|
+
/* @__PURE__ */ import_react4.default.createElement("div", { className: "kca-row" }, /* @__PURE__ */ import_react4.default.createElement("span", null, "\u635F\u4F24\u6761\u4EF6"), /* @__PURE__ */ import_react4.default.createElement(
|
|
14358
|
+
"select",
|
|
14359
|
+
{
|
|
14360
|
+
className: "kca-select",
|
|
14361
|
+
value: rep.damageThreshold ?? "light",
|
|
14362
|
+
onChange: (e) => coordinator.updateSettings((s) => {
|
|
14363
|
+
s.repair.damageThreshold = e.target.value;
|
|
14364
|
+
})
|
|
14365
|
+
},
|
|
14366
|
+
/* @__PURE__ */ import_react4.default.createElement("option", { value: "light" }, "\u5C0F\u7834\u53CA\u4EE5\u4E0A (\u5C0F\u7834/\u4E2D\u7834/\u5927\u7834\uFF0C\u8DF3\u8FC7\u64E6\u4F24)"),
|
|
14367
|
+
/* @__PURE__ */ import_react4.default.createElement("option", { value: "moderate" }, "\u4E2D\u7834\u53CA\u4EE5\u4E0A (\u4E2D\u7834/\u5927\u7834)"),
|
|
14368
|
+
/* @__PURE__ */ import_react4.default.createElement("option", { value: "heavy" }, "\u4EC5\u5927\u7834 (HP \u2264 25%)"),
|
|
14369
|
+
/* @__PURE__ */ import_react4.default.createElement("option", { value: "scratch" }, "\u5168\u90E8\u635F\u4F24 (\u542B\u64E6\u4F24)")
|
|
14370
|
+
)),
|
|
14283
14371
|
/* @__PURE__ */ import_react4.default.createElement("div", { className: "kca-row" }, /* @__PURE__ */ import_react4.default.createElement("span", null, "\u6700\u4F4E\u7B49\u7EA7"), /* @__PURE__ */ import_react4.default.createElement(
|
|
14284
14372
|
"input",
|
|
14285
14373
|
{
|
|
@@ -14313,6 +14401,24 @@ var OrgPracticeQuestsTab = ({ coordinator, settings }) => {
|
|
|
14313
14401
|
/* @__PURE__ */ import_react4.default.createElement("option", { value: "shortest" }, "\u77ED\u65F6\u4F18\u5148"),
|
|
14314
14402
|
/* @__PURE__ */ import_react4.default.createElement("option", { value: "longest" }, "\u957F\u65F6\u4F18\u5148")
|
|
14315
14403
|
)),
|
|
14404
|
+
/* @__PURE__ */ import_react4.default.createElement(
|
|
14405
|
+
"label",
|
|
14406
|
+
{
|
|
14407
|
+
className: "kca-switch",
|
|
14408
|
+
title: "\u5F00\u542F\u540E\uFF1A1) \u8DF3\u8FC7\u5F53\u524D\u6FC0\u6D3B\u51FA\u51FB\u65B9\u6848\u5019\u9009\u6C60\u4E2D\u7684\u8F6E\u6362\u8230\u5A18\uFF1B2) \u81EA\u52A8\u51FA\u51FB\u5F00\u542F\u65F6\u81F3\u5C11\u4FDD\u7559 1 \u4E2A\u7A7A\u6E20\u7ED9\u51FA\u51FB\u4FEE\u8239/\u6CFC\u6876\uFF1B3) \u51FA\u51FB\u95F4\u6B47\u5728\u6BCD\u6E2F\u5B89\u5168\u534F\u540C\u5165\u6E20\uFF0C\u4E0D\u62A2\u5360\u6218\u6597\u6216\u51FA\u51FB\u524D\u4FEE\u8239"
|
|
14409
|
+
},
|
|
14410
|
+
/* @__PURE__ */ import_react4.default.createElement(
|
|
14411
|
+
"input",
|
|
14412
|
+
{
|
|
14413
|
+
type: "checkbox",
|
|
14414
|
+
checked: rep.avoidSortieConflict !== false,
|
|
14415
|
+
onChange: (e) => coordinator.updateSettings((s) => {
|
|
14416
|
+
s.repair.avoidSortieConflict = e.target.checked;
|
|
14417
|
+
})
|
|
14418
|
+
}
|
|
14419
|
+
),
|
|
14420
|
+
/* @__PURE__ */ import_react4.default.createElement("strong", null, "\u4E0E\u81EA\u52A8\u51FA\u51FB\u9632\u51B2\u7A81 (\u907F\u5F00\u51FA\u51FB\u5019\u9009\u8239 \xB7 \u81EA\u52A8\u7559\u22651\u7A7A\u6E20)")
|
|
14421
|
+
),
|
|
14316
14422
|
/* @__PURE__ */ import_react4.default.createElement("label", { className: "kca-switch" }, /* @__PURE__ */ import_react4.default.createElement(
|
|
14317
14423
|
"input",
|
|
14318
14424
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "poi-plugin-kca-next",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "High-performance native poi KanColle automation replacement for (非)提助手 — zero DRM, zero extra browser, event-driven in-process engine",
|
|
5
5
|
"author": "machilus",
|
|
6
6
|
"main": "dist/index.js",
|