From 043ffeecef286597e327b39d00775fe16a625a08 Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Mon, 23 Jun 2025 22:12:05 +0200 Subject: [PATCH 1/5] fix: use shared count for calendar day indecies I'm not sure if this was always this way and I was just really confused when I initially implemented this, or if this was changed in a later version, but at least now it seems to be tracking everything correctly for 38.6.0, just not entirely sure what "ActivatedChallenges" is for. --- .../api/completeCalendarEventController.ts | 33 +++++++++---------- src/services/inventoryService.ts | 15 +++++++++ src/services/missionInventoryUpdateService.ts | 21 ++++++++++-- 3 files changed, 49 insertions(+), 20 deletions(-) diff --git a/src/controllers/api/completeCalendarEventController.ts b/src/controllers/api/completeCalendarEventController.ts index 20c8abb3..d540f306 100644 --- a/src/controllers/api/completeCalendarEventController.ts +++ b/src/controllers/api/completeCalendarEventController.ts @@ -1,4 +1,4 @@ -import { getCalendarProgress, getInventory } from "@/src/services/inventoryService"; +import { checkCalendarChallengeCompletion, getCalendarProgress, getInventory } from "@/src/services/inventoryService"; import { getAccountIdForRequest } from "@/src/services/loginService"; import { handleStoreItemAcquisition } from "@/src/services/purchaseService"; import { getWorldState } from "@/src/services/worldStateService"; @@ -12,27 +12,26 @@ export const completeCalendarEventController: RequestHandler = async (req, res) const calendarProgress = getCalendarProgress(inventory); const currentSeason = getWorldState().KnownCalendarSeasons[0]; let inventoryChanges: IInventoryChanges = {}; - let dayIndex = 0; - for (const day of currentSeason.Days) { + 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 (dayIndex == calendarProgress.SeasonProgress.LastCompletedDayIdx) { - 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}`); - } + 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; } - ++dayIndex; + break; } } - calendarProgress.SeasonProgress.LastCompletedDayIdx++; + calendarProgress.SeasonProgress.LastCompletedDayIdx = dayIndex; + checkCalendarChallengeCompletion(calendarProgress, currentSeason); await inventory.save(); res.json({ InventoryChanges: inventoryChanges, diff --git a/src/services/inventoryService.ts b/src/services/inventoryService.ts index a93dbaf6..828bb665 100644 --- a/src/services/inventoryService.ts +++ b/src/services/inventoryService.ts @@ -84,6 +84,7 @@ import { getRandomElement, getRandomInt, getRandomWeightedReward, SRng } from ". import { createMessage } from "./inboxService"; import { getMaxStanding, getMinStanding } from "@/src/helpers/syndicateStandingHelper"; import { getNightwaveSyndicateTag, getWorldState } from "./worldStateService"; +import { ICalendarSeason } from "@/src/types/worldStateTypes"; import { generateNemesisProfile, INemesisProfile } from "../helpers/nemesisHelpers"; import { TAccountDocument } from "./loginService"; import { unixTimesInMs } from "../constants/timeConstants"; @@ -2029,6 +2030,20 @@ export const getCalendarProgress = (inventory: TInventoryDatabaseDocument): ICal return inventory.CalendarProgress; }; +export const checkCalendarChallengeCompletion = ( + calendarProgress: ICalendarProgress, + currentSeason: ICalendarSeason +): void => { + const dayIndex = calendarProgress.SeasonProgress.LastCompletedDayIdx + 1; + if (calendarProgress.SeasonProgress.LastCompletedChallengeDayIdx >= dayIndex) { + const day = currentSeason.Days[dayIndex]; + if (day.events.length != 0 && day.events[0].type == "CET_CHALLENGE") { + //logger.debug(`already completed the challenge, skipping ahead`); + calendarProgress.SeasonProgress.LastCompletedDayIdx++; + } + } +}; + export const giveNemesisWeaponRecipe = ( inventory: TInventoryDatabaseDocument, weaponType: string, diff --git a/src/services/missionInventoryUpdateService.ts b/src/services/missionInventoryUpdateService.ts index 7ee1b3c5..21880195 100644 --- a/src/services/missionInventoryUpdateService.ts +++ b/src/services/missionInventoryUpdateService.ts @@ -33,6 +33,7 @@ import { addSkin, addStanding, applyClientEquipmentUpdates, + checkCalendarChallengeCompletion, combineInventoryChanges, generateRewardSeed, getCalendarProgress, @@ -67,7 +68,15 @@ import { } from "@/src/helpers/nemesisHelpers"; import { Loadout } from "../models/inventoryModels/loadoutModel"; import { ILoadoutConfigDatabase } from "../types/saveLoadoutTypes"; -import { getLiteSortie, getSortie, idToBountyCycle, idToDay, idToWeek, pushClassicBounties } from "./worldStateService"; +import { + getLiteSortie, + getSortie, + getWorldState, + idToBountyCycle, + idToDay, + idToWeek, + pushClassicBounties +} from "./worldStateService"; import { config } from "./configService"; import libraryDailyTasks from "@/static/fixed_responses/libraryDailyTasks.json"; import { ISyndicateMissionInfo } from "../types/worldStateTypes"; @@ -620,12 +629,18 @@ export const addMissionInventoryUpdates = async ( } case "CalendarProgress": { const calendarProgress = getCalendarProgress(inventory); - for (const progress of value) { + const currentSeason = getWorldState().KnownCalendarSeasons[0]; + const index = currentSeason.Days.findIndex( + x => x.events[0].challenge == value[value.length - 1].challenge + ); + calendarProgress.SeasonProgress.LastCompletedChallengeDayIdx = index; + checkCalendarChallengeCompletion(calendarProgress, currentSeason); + /*for (const progress of value) { const challengeName = progress.challenge.substring(progress.challenge.lastIndexOf("/") + 1); calendarProgress.SeasonProgress.LastCompletedDayIdx++; calendarProgress.SeasonProgress.LastCompletedChallengeDayIdx++; calendarProgress.SeasonProgress.ActivatedChallenges.push(challengeName); - } + }*/ break; } case "duviriCaveOffers": { -- 2.47.2 From c4404e294296213e6716de1ac1d6048c13f55f14 Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Mon, 23 Jun 2025 22:15:48 +0200 Subject: [PATCH 2/5] remove intermediate variable --- src/services/missionInventoryUpdateService.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/services/missionInventoryUpdateService.ts b/src/services/missionInventoryUpdateService.ts index 21880195..09f64a9c 100644 --- a/src/services/missionInventoryUpdateService.ts +++ b/src/services/missionInventoryUpdateService.ts @@ -630,10 +630,9 @@ export const addMissionInventoryUpdates = async ( case "CalendarProgress": { const calendarProgress = getCalendarProgress(inventory); const currentSeason = getWorldState().KnownCalendarSeasons[0]; - const index = currentSeason.Days.findIndex( + calendarProgress.SeasonProgress.LastCompletedChallengeDayIdx = currentSeason.Days.findIndex( x => x.events[0].challenge == value[value.length - 1].challenge ); - calendarProgress.SeasonProgress.LastCompletedChallengeDayIdx = index; checkCalendarChallengeCompletion(calendarProgress, currentSeason); /*for (const progress of value) { const challengeName = progress.challenge.substring(progress.challenge.lastIndexOf("/") + 1); -- 2.47.2 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 3/5] 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; -- 2.47.2 From 917d82c70749397e7226498d960f207d56aa7f6c Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Mon, 23 Jun 2025 22:20:36 +0200 Subject: [PATCH 4/5] combine conditions --- src/controllers/api/completeCalendarEventController.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/controllers/api/completeCalendarEventController.ts b/src/controllers/api/completeCalendarEventController.ts index 1f627a9e..993b55c7 100644 --- a/src/controllers/api/completeCalendarEventController.ts +++ b/src/controllers/api/completeCalendarEventController.ts @@ -14,10 +14,10 @@ export const completeCalendarEventController: RequestHandler = async (req, res) let inventoryChanges: IInventoryChanges = {}; 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) { + if (day.events[0].type == "CET_CHALLENGE") { + throw new Error(`completeCalendarEvent should not be used for challenges`); + } const selection = day.events[parseInt(req.query.CompletedEventIdx as string)]; if (selection.type == "CET_REWARD") { inventoryChanges = (await handleStoreItemAcquisition(selection.reward!, inventory)).InventoryChanges; -- 2.47.2 From 6cd897b63a65e7bdc89f559e3cd1e1dacff81364 Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Mon, 23 Jun 2025 22:27:35 +0200 Subject: [PATCH 5/5] track season ActivatedChallenges --- src/services/inventoryService.ts | 5 +++++ src/services/missionInventoryUpdateService.ts | 6 ------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/services/inventoryService.ts b/src/services/inventoryService.ts index 828bb665..a2145d3b 100644 --- a/src/services/inventoryService.ts +++ b/src/services/inventoryService.ts @@ -88,6 +88,7 @@ import { ICalendarSeason } from "@/src/types/worldStateTypes"; import { generateNemesisProfile, INemesisProfile } from "../helpers/nemesisHelpers"; import { TAccountDocument } from "./loginService"; import { unixTimesInMs } from "../constants/timeConstants"; +import { addString } from "../helpers/stringHelpers"; export const createInventory = async ( accountOwnerId: Types.ObjectId, @@ -1784,6 +1785,10 @@ export const addChallenges = ( } else { inventory.ChallengeProgress.push({ Name, Progress }); } + + if (Name.startsWith("Calendar")) { + addString(getCalendarProgress(inventory).SeasonProgress.ActivatedChallenges, Name); + } }); const affiliationMods: IAffiliationMods[] = []; diff --git a/src/services/missionInventoryUpdateService.ts b/src/services/missionInventoryUpdateService.ts index 09f64a9c..8a14e33c 100644 --- a/src/services/missionInventoryUpdateService.ts +++ b/src/services/missionInventoryUpdateService.ts @@ -634,12 +634,6 @@ export const addMissionInventoryUpdates = async ( x => x.events[0].challenge == value[value.length - 1].challenge ); checkCalendarChallengeCompletion(calendarProgress, currentSeason); - /*for (const progress of value) { - const challengeName = progress.challenge.substring(progress.challenge.lastIndexOf("/") + 1); - calendarProgress.SeasonProgress.LastCompletedDayIdx++; - calendarProgress.SeasonProgress.LastCompletedChallengeDayIdx++; - calendarProgress.SeasonProgress.ActivatedChallenges.push(challengeName); - }*/ break; } case "duviriCaveOffers": { -- 2.47.2