Prevent duplicate camp rewards
This commit is contained in:
@@ -27,10 +27,13 @@ const server = await createServer({
|
||||
try {
|
||||
const {
|
||||
campaignStorageKey,
|
||||
applyCampBondExp,
|
||||
applyCampVisitReward,
|
||||
getCampaignState,
|
||||
loadCampaignState,
|
||||
normalizeCampaignSortieItemAssignments,
|
||||
resetCampaignState,
|
||||
setCampaignState,
|
||||
setFirstBattleReport
|
||||
} = await server.ssrLoadModule('/src/game/state/campaignState.ts');
|
||||
const { battleScenarios } = await server.ssrLoadModule('/src/game/data/battles.ts');
|
||||
@@ -99,6 +102,57 @@ try {
|
||||
revisedSettlement.inventory.Wine === 1,
|
||||
`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.set(
|
||||
@@ -553,7 +607,7 @@ try {
|
||||
const fallback = loadCampaignState();
|
||||
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 {
|
||||
await server.close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user