mirror of
https://github.com/Shu-Ying/noname-shuying.git
synced 2026-11-24 14:06:29 +08:00
fixed # 新增药水机制
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
// Candidate external coordinator. Finish callbacks return a boolean, NEVER a drain promise.
|
||||
import { getDiagnostics } from "../../diagnostics/index.js";
|
||||
import { potionSlots } from "../potions/state.js";
|
||||
const copy = value => JSON.parse(JSON.stringify(value));
|
||||
export function createBattleFlow({settlement, chooseReward, chooseDefeat, showMap, showEnding, quiesce, releaseSkills = async () => {}, releaseBattle = () => {}, presentVictory = async () => {}}) {
|
||||
let state = "map", active = null, work = null, job = null, error = null;
|
||||
@@ -37,10 +38,15 @@ export function createBattleFlow({settlement, chooseReward, chooseDefeat, showMa
|
||||
elite: job.pending.elite,
|
||||
fixedRewards: copy(job.pending.fixedRewards || []),
|
||||
rewardPackage: copy(job.pending.rewardPackage || null),
|
||||
potionChoices: copy(job.pending.potionChoices || []),
|
||||
potionSlots: potionSlots(job.pending.base.player),
|
||||
}), false);
|
||||
if (job.pending.outcome !== "defeat" && !job.pending.rewardPackage &&
|
||||
job.choiceId !== null &&
|
||||
!job.pending.choices.some(c => c.id === job.choiceId && c.kind !== "gold")) throw new Error("Invalid reward selection");
|
||||
if (job.pending.outcome !== "defeat" && !job.pending.rewardPackage) {
|
||||
const rewardId = job.pending.potionChoices?.length ? job.choiceId?.rewardId : job.choiceId;
|
||||
if (rewardId !== null && !job.pending.choices.some(c => c.id === rewardId && c.kind !== "gold")) {
|
||||
throw new Error("Invalid reward selection");
|
||||
}
|
||||
}
|
||||
job.hasChoice = true;
|
||||
}
|
||||
job.pending = await step("applyChoice", () => settlement.choose(job.input.run.runId, job.pending.id, job.choiceId));
|
||||
|
||||
@@ -9,6 +9,7 @@ import { heldRelics } from "../relics/definitions.js";
|
||||
import { getDiagnostics } from "../../diagnostics/index.js";
|
||||
import { prepareRewardPackage, applyRewardPackage }
|
||||
from "../progression/reward-package.js";
|
||||
import { applyPotionReward, rollPotionReward, samplePotions } from "../potions/state.js";
|
||||
|
||||
const copy = value => JSON.parse(JSON.stringify(value));
|
||||
const idFor = (run, node) => JSON.stringify([run.runId, run.actIndex, node.id]);
|
||||
@@ -89,6 +90,9 @@ export function createBattleSettlement({
|
||||
getRandomRewardChoices) : null;
|
||||
item = {id, state:"awaitingChoice", nodeId:node.id, base, choices:copy(choices), fixedRewards:copy(fixedRewards), victoryDialogue:copy(encounter.victoryDialogue || []), boss:!!encounter.boss, elite, outcome, relicRecovery, bondGrowth};
|
||||
item.rewardPackage = copy(rewardPackage);
|
||||
item.potionChoices = outcome !== "victory" ? []
|
||||
: encounter.rewardPackage ? samplePotions(base, encounter.rewardPackage.potionChoices ?? 0)
|
||||
: !encounter.boss && (encounter.tier === "normal" || elite) ? rollPotionReward(base, elite) : [];
|
||||
diagnostics.info("prepared", {
|
||||
outcome, choices: choices.map(choice => choice.id), fixedRewards,
|
||||
expectedRevision: snapshot.revision, actualRevision: run.revision,
|
||||
@@ -132,20 +136,26 @@ export function createBattleSettlement({
|
||||
const sameChoice = item.rewardPackage
|
||||
? item.choiceId?.cardId === choiceId?.cardId &&
|
||||
item.choiceId?.relicId === choiceId?.relicId
|
||||
: item.choiceId === choiceId;
|
||||
if (!sameChoice) throw new Error("Choice already locked");
|
||||
: item.potionChoices.length ? item.choiceId?.rewardId === choiceId?.rewardId
|
||||
: item.choiceId === choiceId;
|
||||
if (!sameChoice || item.choiceId?.potion?.id !== choiceId?.potion?.id ||
|
||||
item.choiceId?.potion?.replaceIndex !== choiceId?.potion?.replaceIndex) {
|
||||
throw new Error("Choice already locked");
|
||||
}
|
||||
return copy(item);
|
||||
}
|
||||
const result = copy(item.base);
|
||||
let route = "defeat";
|
||||
if (item.outcome === "victory") {
|
||||
applyPotionReward(result.player, item.potionChoices, choiceId?.potion);
|
||||
if (item.rewardPackage) {
|
||||
applyRewardPackage(result, item.rewardPackage, choiceId,
|
||||
applyReward);
|
||||
}
|
||||
if (!item.rewardPackage) {
|
||||
const reward = item.choices.find(c => c.id === choiceId && c.kind !== "gold");
|
||||
if (choiceId !== null && !reward) {
|
||||
const rewardId = item.potionChoices.length ? choiceId?.rewardId : choiceId;
|
||||
const reward = item.choices.find(c => c.id === rewardId && c.kind !== "gold");
|
||||
if (rewardId !== null && !reward) {
|
||||
throw new Error("Choose one pending reward or skip");
|
||||
}
|
||||
// 结果只计算一次;保存失败后的重试不再次发放金币。
|
||||
|
||||
Reference in New Issue
Block a user