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 { getAccountIdForRequest } from "@/src/services/loginService";
 | 
				
			||||||
import { handleStoreItemAcquisition } from "@/src/services/purchaseService";
 | 
					import { handleStoreItemAcquisition } from "@/src/services/purchaseService";
 | 
				
			||||||
import { getWorldState } from "@/src/services/worldStateService";
 | 
					import { getWorldState } from "@/src/services/worldStateService";
 | 
				
			||||||
@ -12,10 +12,10 @@ 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 = 0;
 | 
					    let dayIndex = calendarProgress.SeasonProgress.LastCompletedDayIdx + 1;
 | 
				
			||||||
    for (const day of currentSeason.Days) {
 | 
					    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 || day.events[0].type != "CET_CHALLENGE") {
 | 
				
			||||||
            if (dayIndex == calendarProgress.SeasonProgress.LastCompletedDayIdx) {
 | 
					 | 
				
			||||||
            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") {
 | 
				
			||||||
@ -29,10 +29,9 @@ export const completeCalendarEventController: RequestHandler = async (req, res)
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
            ++dayIndex;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    }
 | 
					    calendarProgress.SeasonProgress.LastCompletedDayIdx = dayIndex;
 | 
				
			||||||
    calendarProgress.SeasonProgress.LastCompletedDayIdx++;
 | 
					    checkCalendarChallengeCompletion(calendarProgress, currentSeason);
 | 
				
			||||||
    await inventory.save();
 | 
					    await inventory.save();
 | 
				
			||||||
    res.json({
 | 
					    res.json({
 | 
				
			||||||
        InventoryChanges: inventoryChanges,
 | 
					        InventoryChanges: inventoryChanges,
 | 
				
			||||||
 | 
				
			|||||||
@ -84,6 +84,7 @@ import { getRandomElement, getRandomInt, getRandomWeightedReward, SRng } from ".
 | 
				
			|||||||
import { createMessage } from "./inboxService";
 | 
					import { createMessage } from "./inboxService";
 | 
				
			||||||
import { getMaxStanding, getMinStanding } from "@/src/helpers/syndicateStandingHelper";
 | 
					import { getMaxStanding, getMinStanding } from "@/src/helpers/syndicateStandingHelper";
 | 
				
			||||||
import { getNightwaveSyndicateTag, getWorldState } from "./worldStateService";
 | 
					import { getNightwaveSyndicateTag, getWorldState } from "./worldStateService";
 | 
				
			||||||
 | 
					import { ICalendarSeason } from "@/src/types/worldStateTypes";
 | 
				
			||||||
import { generateNemesisProfile, INemesisProfile } from "../helpers/nemesisHelpers";
 | 
					import { generateNemesisProfile, INemesisProfile } from "../helpers/nemesisHelpers";
 | 
				
			||||||
import { TAccountDocument } from "./loginService";
 | 
					import { TAccountDocument } from "./loginService";
 | 
				
			||||||
import { unixTimesInMs } from "../constants/timeConstants";
 | 
					import { unixTimesInMs } from "../constants/timeConstants";
 | 
				
			||||||
@ -2029,6 +2030,20 @@ export const getCalendarProgress = (inventory: TInventoryDatabaseDocument): ICal
 | 
				
			|||||||
    return inventory.CalendarProgress;
 | 
					    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 = (
 | 
					export const giveNemesisWeaponRecipe = (
 | 
				
			||||||
    inventory: TInventoryDatabaseDocument,
 | 
					    inventory: TInventoryDatabaseDocument,
 | 
				
			||||||
    weaponType: string,
 | 
					    weaponType: string,
 | 
				
			||||||
 | 
				
			|||||||
@ -33,6 +33,7 @@ import {
 | 
				
			|||||||
    addSkin,
 | 
					    addSkin,
 | 
				
			||||||
    addStanding,
 | 
					    addStanding,
 | 
				
			||||||
    applyClientEquipmentUpdates,
 | 
					    applyClientEquipmentUpdates,
 | 
				
			||||||
 | 
					    checkCalendarChallengeCompletion,
 | 
				
			||||||
    combineInventoryChanges,
 | 
					    combineInventoryChanges,
 | 
				
			||||||
    generateRewardSeed,
 | 
					    generateRewardSeed,
 | 
				
			||||||
    getCalendarProgress,
 | 
					    getCalendarProgress,
 | 
				
			||||||
@ -67,7 +68,15 @@ import {
 | 
				
			|||||||
} from "@/src/helpers/nemesisHelpers";
 | 
					} from "@/src/helpers/nemesisHelpers";
 | 
				
			||||||
import { Loadout } from "../models/inventoryModels/loadoutModel";
 | 
					import { Loadout } from "../models/inventoryModels/loadoutModel";
 | 
				
			||||||
import { ILoadoutConfigDatabase } from "../types/saveLoadoutTypes";
 | 
					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 { config } from "./configService";
 | 
				
			||||||
import libraryDailyTasks from "@/static/fixed_responses/libraryDailyTasks.json";
 | 
					import libraryDailyTasks from "@/static/fixed_responses/libraryDailyTasks.json";
 | 
				
			||||||
import { ISyndicateMissionInfo } from "../types/worldStateTypes";
 | 
					import { ISyndicateMissionInfo } from "../types/worldStateTypes";
 | 
				
			||||||
@ -620,12 +629,18 @@ export const addMissionInventoryUpdates = async (
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
            case "CalendarProgress": {
 | 
					            case "CalendarProgress": {
 | 
				
			||||||
                const calendarProgress = getCalendarProgress(inventory);
 | 
					                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);
 | 
					                    const challengeName = progress.challenge.substring(progress.challenge.lastIndexOf("/") + 1);
 | 
				
			||||||
                    calendarProgress.SeasonProgress.LastCompletedDayIdx++;
 | 
					                    calendarProgress.SeasonProgress.LastCompletedDayIdx++;
 | 
				
			||||||
                    calendarProgress.SeasonProgress.LastCompletedChallengeDayIdx++;
 | 
					                    calendarProgress.SeasonProgress.LastCompletedChallengeDayIdx++;
 | 
				
			||||||
                    calendarProgress.SeasonProgress.ActivatedChallenges.push(challengeName);
 | 
					                    calendarProgress.SeasonProgress.ActivatedChallenges.push(challengeName);
 | 
				
			||||||
                }
 | 
					                }*/
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            case "duviriCaveOffers": {
 | 
					            case "duviriCaveOffers": {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user