From 29a465b18313847252506a77f594efbfbbdc637d Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Mon, 23 Jun 2025 22:19:51 +0200 Subject: [PATCH] simplify completeCalendarEvent, codify assumption that it's not used for challenges --- .../api/completeCalendarEventController.ts | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/controllers/api/completeCalendarEventController.ts b/src/controllers/api/completeCalendarEventController.ts index d540f306..1f627a9e 100644 --- a/src/controllers/api/completeCalendarEventController.ts +++ b/src/controllers/api/completeCalendarEventController.ts @@ -12,22 +12,19 @@ export const completeCalendarEventController: RequestHandler = async (req, res) const calendarProgress = getCalendarProgress(inventory); const currentSeason = getWorldState().KnownCalendarSeasons[0]; let inventoryChanges: IInventoryChanges = {}; - let dayIndex = calendarProgress.SeasonProgress.LastCompletedDayIdx + 1; - for (; dayIndex != currentSeason.Days.length; ++dayIndex) { - const day = currentSeason.Days[dayIndex]; - if (day.events.length == 0 || day.events[0].type != "CET_CHALLENGE") { - if (day.events.length != 0) { - const selection = day.events[parseInt(req.query.CompletedEventIdx as string)]; - if (selection.type == "CET_REWARD") { - inventoryChanges = (await handleStoreItemAcquisition(selection.reward!, inventory)) - .InventoryChanges; - } else if (selection.type == "CET_UPGRADE") { - calendarProgress.YearProgress.Upgrades.push(selection.upgrade!); - } else if (selection.type != "CET_PLOT") { - throw new Error(`unexpected selection type: ${selection.type}`); - } - } - break; + const dayIndex = calendarProgress.SeasonProgress.LastCompletedDayIdx + 1; + const day = currentSeason.Days[dayIndex]; + 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) { + const selection = day.events[parseInt(req.query.CompletedEventIdx as string)]; + if (selection.type == "CET_REWARD") { + inventoryChanges = (await handleStoreItemAcquisition(selection.reward!, inventory)).InventoryChanges; + } else if (selection.type == "CET_UPGRADE") { + calendarProgress.YearProgress.Upgrades.push(selection.upgrade!); + } else if (selection.type != "CET_PLOT") { + throw new Error(`unexpected selection type: ${selection.type}`); } } calendarProgress.SeasonProgress.LastCompletedDayIdx = dayIndex;