fix: use shared count for calendar day indecies #2265
@ -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,23 @@ 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) {
|
||||
if (day.events.length == 0 || day.events[0].type != "CET_CHALLENGE") {
|
||||
if (dayIndex == calendarProgress.SeasonProgress.LastCompletedDayIdx) {
|
||||
const dayIndex = calendarProgress.SeasonProgress.LastCompletedDayIdx + 1;
|
||||
const day = currentSeason.Days[dayIndex];
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
calendarProgress.SeasonProgress.LastCompletedDayIdx++;
|
||||
calendarProgress.SeasonProgress.LastCompletedDayIdx = dayIndex;
|
||||
checkCalendarChallengeCompletion(calendarProgress, currentSeason);
|
||||
await inventory.save();
|
||||
res.json({
|
||||
InventoryChanges: inventoryChanges,
|
||||
|
@ -84,9 +84,11 @@ 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";
|
||||
import { addString } from "../helpers/stringHelpers";
|
||||
|
||||
export const createInventory = async (
|
||||
accountOwnerId: Types.ObjectId,
|
||||
@ -1783,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[] = [];
|
||||
@ -2029,6 +2035,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,
|
||||
|
@ -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,11 @@ export const addMissionInventoryUpdates = async (
|
||||
}
|
||||
case "CalendarProgress": {
|
||||
const calendarProgress = getCalendarProgress(inventory);
|
||||
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);
|
||||
}
|
||||
const currentSeason = getWorldState().KnownCalendarSeasons[0];
|
||||
calendarProgress.SeasonProgress.LastCompletedChallengeDayIdx = currentSeason.Days.findIndex(
|
||||
x => x.events[0].challenge == value[value.length - 1].challenge
|
||||
);
|
||||
checkCalendarChallengeCompletion(calendarProgress, currentSeason);
|
||||
break;
|
||||
}
|
||||
case "duviriCaveOffers": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user