simplify completeCalendarEvent, codify assumption that it's not used for challenges
All checks were successful
Build / build (pull_request) Successful in 52s
All checks were successful
Build / build (pull_request) Successful in 52s
This commit is contained in:
parent
c4404e2942
commit
29a465b183
@ -12,24 +12,21 @@ export const completeCalendarEventController: RequestHandler = async (req, res)
|
|||||||
const calendarProgress = getCalendarProgress(inventory);
|
const calendarProgress = getCalendarProgress(inventory);
|
||||||
const currentSeason = getWorldState().KnownCalendarSeasons[0];
|
const currentSeason = getWorldState().KnownCalendarSeasons[0];
|
||||||
let inventoryChanges: IInventoryChanges = {};
|
let inventoryChanges: IInventoryChanges = {};
|
||||||
let dayIndex = calendarProgress.SeasonProgress.LastCompletedDayIdx + 1;
|
const dayIndex = calendarProgress.SeasonProgress.LastCompletedDayIdx + 1;
|
||||||
for (; dayIndex != currentSeason.Days.length; ++dayIndex) {
|
|
||||||
const day = currentSeason.Days[dayIndex];
|
const day = currentSeason.Days[dayIndex];
|
||||||
if (day.events.length == 0 || day.events[0].type != "CET_CHALLENGE") {
|
if (day.events.length != 0 && day.events[0].type == "CET_CHALLENGE") {
|
||||||
|
throw new Error(`completeCalendarEvent should not be used for challenges`);
|
||||||
|
}
|
||||||
if (day.events.length != 0) {
|
if (day.events.length != 0) {
|
||||||
const selection = day.events[parseInt(req.query.CompletedEventIdx as string)];
|
const selection = day.events[parseInt(req.query.CompletedEventIdx as string)];
|
||||||
if (selection.type == "CET_REWARD") {
|
if (selection.type == "CET_REWARD") {
|
||||||
inventoryChanges = (await handleStoreItemAcquisition(selection.reward!, inventory))
|
inventoryChanges = (await handleStoreItemAcquisition(selection.reward!, inventory)).InventoryChanges;
|
||||||
.InventoryChanges;
|
|
||||||
} else if (selection.type == "CET_UPGRADE") {
|
} else if (selection.type == "CET_UPGRADE") {
|
||||||
calendarProgress.YearProgress.Upgrades.push(selection.upgrade!);
|
calendarProgress.YearProgress.Upgrades.push(selection.upgrade!);
|
||||||
} else if (selection.type != "CET_PLOT") {
|
} else if (selection.type != "CET_PLOT") {
|
||||||
throw new Error(`unexpected selection type: ${selection.type}`);
|
throw new Error(`unexpected selection type: ${selection.type}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
calendarProgress.SeasonProgress.LastCompletedDayIdx = dayIndex;
|
calendarProgress.SeasonProgress.LastCompletedDayIdx = dayIndex;
|
||||||
checkCalendarChallengeCompletion(calendarProgress, currentSeason);
|
checkCalendarChallengeCompletion(calendarProgress, currentSeason);
|
||||||
await inventory.save();
|
await inventory.save();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user