Prevent duplicate camp rewards
This commit is contained in:
@@ -27,10 +27,13 @@ const server = await createServer({
|
|||||||
try {
|
try {
|
||||||
const {
|
const {
|
||||||
campaignStorageKey,
|
campaignStorageKey,
|
||||||
|
applyCampBondExp,
|
||||||
|
applyCampVisitReward,
|
||||||
getCampaignState,
|
getCampaignState,
|
||||||
loadCampaignState,
|
loadCampaignState,
|
||||||
normalizeCampaignSortieItemAssignments,
|
normalizeCampaignSortieItemAssignments,
|
||||||
resetCampaignState,
|
resetCampaignState,
|
||||||
|
setCampaignState,
|
||||||
setFirstBattleReport
|
setFirstBattleReport
|
||||||
} = await server.ssrLoadModule('/src/game/state/campaignState.ts');
|
} = await server.ssrLoadModule('/src/game/state/campaignState.ts');
|
||||||
const { battleScenarios } = await server.ssrLoadModule('/src/game/data/battles.ts');
|
const { battleScenarios } = await server.ssrLoadModule('/src/game/data/battles.ts');
|
||||||
@@ -99,6 +102,57 @@ try {
|
|||||||
revisedSettlement.inventory.Wine === 1,
|
revisedSettlement.inventory.Wine === 1,
|
||||||
`Expected revised battle report settlement to replace previous rewards instead of stacking: ${JSON.stringify(revisedSettlement)}`
|
`Expected revised battle report settlement to replace previous rewards instead of stacking: ${JSON.stringify(revisedSettlement)}`
|
||||||
);
|
);
|
||||||
|
applyCampVisitReward('repeat-visit', { gold: 10, itemRewards: ['Bean x2'] });
|
||||||
|
applyCampVisitReward('repeat-visit', { gold: 10, itemRewards: ['Bean x2'] });
|
||||||
|
const repeatedVisit = getCampaignState();
|
||||||
|
assert(
|
||||||
|
repeatedVisit.gold === 150 &&
|
||||||
|
repeatedVisit.inventory.Bean === 5 &&
|
||||||
|
repeatedVisit.completedCampVisits.includes('repeat-visit') &&
|
||||||
|
repeatedVisit.firstBattleReport?.completedCampVisits.includes('repeat-visit'),
|
||||||
|
`Expected repeated camp visit rewards to be applied once: ${JSON.stringify(repeatedVisit)}`
|
||||||
|
);
|
||||||
|
const visitDesynced = getCampaignState();
|
||||||
|
visitDesynced.completedCampVisits = [];
|
||||||
|
visitDesynced.firstBattleReport.completedCampVisits = ['repeat-visit'];
|
||||||
|
setCampaignState(visitDesynced);
|
||||||
|
applyCampVisitReward('repeat-visit', { gold: 10, itemRewards: ['Bean x2'] });
|
||||||
|
const visitResynced = getCampaignState();
|
||||||
|
assert(
|
||||||
|
visitResynced.gold === 150 &&
|
||||||
|
visitResynced.inventory.Bean === 5 &&
|
||||||
|
visitResynced.completedCampVisits.includes('repeat-visit') &&
|
||||||
|
visitResynced.firstBattleReport?.completedCampVisits.includes('repeat-visit'),
|
||||||
|
`Expected report-only camp visit completion to resync without duplicate rewards: ${JSON.stringify(visitResynced)}`
|
||||||
|
);
|
||||||
|
const repeatBondId = firstScenario.bonds[0].id;
|
||||||
|
applyCampBondExp('repeat-dialogue', repeatBondId, 10);
|
||||||
|
const repeatedDialogueOnce = getCampaignState();
|
||||||
|
applyCampBondExp('repeat-dialogue', repeatBondId, 10);
|
||||||
|
const repeatedDialogueTwice = getCampaignState();
|
||||||
|
const onceBond = repeatedDialogueOnce.bonds.find((bond) => bond.id === repeatBondId);
|
||||||
|
const twiceBond = repeatedDialogueTwice.bonds.find((bond) => bond.id === repeatBondId);
|
||||||
|
assert(
|
||||||
|
onceBond?.exp === twiceBond?.exp &&
|
||||||
|
onceBond?.battleExp === twiceBond?.battleExp &&
|
||||||
|
repeatedDialogueTwice.completedCampDialogues.includes('repeat-dialogue') &&
|
||||||
|
repeatedDialogueTwice.firstBattleReport?.completedCampDialogues.includes('repeat-dialogue'),
|
||||||
|
`Expected repeated camp dialogue rewards to be applied once: ${JSON.stringify(repeatedDialogueTwice)}`
|
||||||
|
);
|
||||||
|
const dialogueDesynced = getCampaignState();
|
||||||
|
dialogueDesynced.completedCampDialogues = [];
|
||||||
|
dialogueDesynced.firstBattleReport.completedCampDialogues = ['repeat-dialogue'];
|
||||||
|
setCampaignState(dialogueDesynced);
|
||||||
|
applyCampBondExp('repeat-dialogue', repeatBondId, 10);
|
||||||
|
const dialogueResynced = getCampaignState();
|
||||||
|
const resyncedBond = dialogueResynced.bonds.find((bond) => bond.id === repeatBondId);
|
||||||
|
assert(
|
||||||
|
resyncedBond?.exp === twiceBond?.exp &&
|
||||||
|
resyncedBond?.battleExp === twiceBond?.battleExp &&
|
||||||
|
dialogueResynced.completedCampDialogues.includes('repeat-dialogue') &&
|
||||||
|
dialogueResynced.firstBattleReport?.completedCampDialogues.includes('repeat-dialogue'),
|
||||||
|
`Expected report-only camp dialogue completion to resync without duplicate bond exp: ${JSON.stringify(dialogueResynced)}`
|
||||||
|
);
|
||||||
|
|
||||||
storage.clear();
|
storage.clear();
|
||||||
storage.set(
|
storage.set(
|
||||||
@@ -553,7 +607,7 @@ try {
|
|||||||
const fallback = loadCampaignState();
|
const fallback = loadCampaignState();
|
||||||
assert(fallback.step === 'second-camp' && fallback.activeSaveSlot === 2, `Expected valid slotted save fallback: ${JSON.stringify(fallback)}`);
|
assert(fallback.step === 'second-camp' && fallback.activeSaveSlot === 2, `Expected valid slotted save fallback: ${JSON.stringify(fallback)}`);
|
||||||
|
|
||||||
console.log('Verified campaign save normalization, reward resettlement, malformed-field/roster-equipment/bond-roster/report-reference/sortie-roster/latest-history/detail recovery, unknown-step/report/history recovery, unsupported-version rejection, and slotted fallback.');
|
console.log('Verified campaign save normalization, reward resettlement, camp reward idempotence, malformed-field/roster-equipment/bond-roster/report-reference/sortie-roster/latest-history/detail recovery, unknown-step/report/history recovery, unsupported-version rejection, and slotted fallback.');
|
||||||
} finally {
|
} finally {
|
||||||
await server.close();
|
await server.close();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14949,6 +14949,11 @@ export class CampScene extends Phaser.Scene {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private completeDialogue(dialogue: CampDialogue, choice: CampDialogueChoice) {
|
private completeDialogue(dialogue: CampDialogue, choice: CampDialogueChoice) {
|
||||||
|
if (this.completedCampDialogues().includes(dialogue.id)) {
|
||||||
|
this.showCampNotice('이미 완료된 대화입니다.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const rewardExp = dialogue.rewardExp + choice.rewardExp;
|
const rewardExp = dialogue.rewardExp + choice.rewardExp;
|
||||||
const updated = applyCampBondExp(dialogue.id, dialogue.bondId, rewardExp);
|
const updated = applyCampBondExp(dialogue.id, dialogue.bondId, rewardExp);
|
||||||
if (updated) {
|
if (updated) {
|
||||||
|
|||||||
@@ -677,11 +677,12 @@ export function applyCampBondExp(dialogueId: string, bondId: string, amount: num
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!state.completedCampDialogues.includes(dialogueId)) {
|
if (hasCompletionFlag(state.completedCampDialogues, state.firstBattleReport.completedCampDialogues, dialogueId)) {
|
||||||
state.completedCampDialogues.push(dialogueId);
|
if (syncCompletionFlag(state.completedCampDialogues, state.firstBattleReport.completedCampDialogues, dialogueId)) {
|
||||||
|
state.updatedAt = new Date().toISOString();
|
||||||
|
persistCampaignState(state);
|
||||||
}
|
}
|
||||||
if (!state.firstBattleReport.completedCampDialogues.includes(dialogueId)) {
|
return cloneReport(state.firstBattleReport);
|
||||||
state.firstBattleReport.completedCampDialogues.push(dialogueId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const campaignBond = state.bonds.find((candidate) => candidate.id === bondId);
|
const campaignBond = state.bonds.find((candidate) => candidate.id === bondId);
|
||||||
@@ -690,6 +691,7 @@ export function applyCampBondExp(dialogueId: string, bondId: string, amount: num
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
syncCompletionFlag(state.completedCampDialogues, state.firstBattleReport.completedCampDialogues, dialogueId);
|
||||||
advanceBond(campaignBond, amount);
|
advanceBond(campaignBond, amount);
|
||||||
reportBond.level = campaignBond.level;
|
reportBond.level = campaignBond.level;
|
||||||
reportBond.exp = campaignBond.exp;
|
reportBond.exp = campaignBond.exp;
|
||||||
@@ -709,14 +711,15 @@ export function applyCampVisitReward(
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.completedCampVisits.includes(visitId)) {
|
if (hasCompletionFlag(state.completedCampVisits, state.firstBattleReport.completedCampVisits, visitId)) {
|
||||||
|
if (syncCompletionFlag(state.completedCampVisits, state.firstBattleReport.completedCampVisits, visitId)) {
|
||||||
|
state.updatedAt = new Date().toISOString();
|
||||||
|
persistCampaignState(state);
|
||||||
|
}
|
||||||
return cloneCampaignState(state);
|
return cloneCampaignState(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
state.completedCampVisits.push(visitId);
|
syncCompletionFlag(state.completedCampVisits, state.firstBattleReport.completedCampVisits, visitId);
|
||||||
if (!state.firstBattleReport.completedCampVisits.includes(visitId)) {
|
|
||||||
state.firstBattleReport.completedCampVisits.push(visitId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (reward.bondId && reward.bondExp && reward.bondExp > 0) {
|
if (reward.bondId && reward.bondExp && reward.bondExp > 0) {
|
||||||
const campaignBond = state.bonds.find((candidate) => candidate.id === reward.bondId);
|
const campaignBond = state.bonds.find((candidate) => candidate.id === reward.bondId);
|
||||||
@@ -744,6 +747,23 @@ export function applyCampVisitReward(
|
|||||||
return cloneCampaignState(state);
|
return cloneCampaignState(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hasCompletionFlag(stateFlags: string[], reportFlags: string[], flagId: string) {
|
||||||
|
return stateFlags.includes(flagId) || reportFlags.includes(flagId);
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncCompletionFlag(stateFlags: string[], reportFlags: string[], flagId: string) {
|
||||||
|
let changed = false;
|
||||||
|
if (!stateFlags.includes(flagId)) {
|
||||||
|
stateFlags.push(flagId);
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (!reportFlags.includes(flagId)) {
|
||||||
|
reportFlags.push(flagId);
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
export function ensureCampaignRosterUnits(units: UnitData[], bonds: BattleBond[] = []) {
|
export function ensureCampaignRosterUnits(units: UnitData[], bonds: BattleBond[] = []) {
|
||||||
const state = ensureCampaignState();
|
const state = ensureCampaignState();
|
||||||
let changed = false;
|
let changed = false;
|
||||||
@@ -1451,6 +1471,7 @@ function cloneCampaignState(state: CampaignState): CampaignState {
|
|||||||
|
|
||||||
function cloneReport(report: FirstBattleReport): FirstBattleReport {
|
function cloneReport(report: FirstBattleReport): FirstBattleReport {
|
||||||
const cloned = JSON.parse(JSON.stringify(report)) as FirstBattleReport;
|
const cloned = JSON.parse(JSON.stringify(report)) as FirstBattleReport;
|
||||||
|
cloned.completedCampDialogues = [...new Set(cloned.completedCampDialogues ?? [])];
|
||||||
cloned.completedCampVisits = [...new Set(cloned.completedCampVisits ?? [])];
|
cloned.completedCampVisits = [...new Set(cloned.completedCampVisits ?? [])];
|
||||||
if (cloned.campaignRewards) {
|
if (cloned.campaignRewards) {
|
||||||
cloned.campaignRewards = cloneCampaignRewardSnapshot(cloned.campaignRewards);
|
cloned.campaignRewards = cloneCampaignRewardSnapshot(cloned.campaignRewards);
|
||||||
|
|||||||
Reference in New Issue
Block a user