forked from OpenWF/SpaceNinjaServer
chore: handle CalendarProgress in updateChallengeProgress
This commit is contained in:
parent
d8ff601be7
commit
4acd87aae6
@ -1,7 +1,7 @@
|
||||
import { RequestHandler } from "express";
|
||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
||||
import { getAccountForRequest } from "@/src/services/loginService";
|
||||
import { addChallenges, getInventory } from "@/src/services/inventoryService";
|
||||
import { addCalendarProgress, addChallenges, getInventory } from "@/src/services/inventoryService";
|
||||
import { IChallengeProgress, ISeasonChallenge } from "@/src/types/inventoryTypes/inventoryTypes";
|
||||
import { IAffiliationMods } from "@/src/types/purchaseTypes";
|
||||
import { getEntriesUnsafe } from "@/src/utils/ts-utils";
|
||||
@ -25,13 +25,17 @@ export const updateChallengeProgressController: RequestHandler = async (req, res
|
||||
);
|
||||
}
|
||||
for (const [key, value] of getEntriesUnsafe(challenges)) {
|
||||
if (value === undefined) {
|
||||
logger.error(`Challenge progress update key ${key} has no value`);
|
||||
continue;
|
||||
}
|
||||
switch (key) {
|
||||
case "ChallengesFixVersion":
|
||||
inventory.ChallengesFixVersion = value;
|
||||
break;
|
||||
|
||||
case "SeasonChallengeHistory":
|
||||
value!.forEach(({ challenge, id }) => {
|
||||
value.forEach(({ challenge, id }) => {
|
||||
const itemIndex = inventory.SeasonChallengeHistory.findIndex(i => i.challenge === challenge);
|
||||
if (itemIndex !== -1) {
|
||||
inventory.SeasonChallengeHistory[itemIndex].id = id;
|
||||
@ -41,6 +45,10 @@ export const updateChallengeProgressController: RequestHandler = async (req, res
|
||||
});
|
||||
break;
|
||||
|
||||
case "CalendarProgress":
|
||||
addCalendarProgress(inventory, value);
|
||||
break;
|
||||
|
||||
case "ChallengeProgress":
|
||||
case "SeasonChallengeCompletions":
|
||||
case "ChallengePTS":
|
||||
@ -63,5 +71,6 @@ interface IUpdateChallengeProgressRequest {
|
||||
ChallengeProgress?: IChallengeProgress[];
|
||||
SeasonChallengeHistory?: ISeasonChallenge[];
|
||||
SeasonChallengeCompletions?: ISeasonChallenge[];
|
||||
CalendarProgress?: { challenge: string }[];
|
||||
crossPlaySetting?: string;
|
||||
}
|
||||
|
@ -1832,6 +1832,15 @@ export const addChallenges = (
|
||||
return affiliationMods;
|
||||
};
|
||||
|
||||
export const addCalendarProgress = (inventory: TInventoryDatabaseDocument, value: { challenge: string }[]): void => {
|
||||
const calendarProgress = getCalendarProgress(inventory);
|
||||
const currentSeason = getWorldState().KnownCalendarSeasons[0];
|
||||
calendarProgress.SeasonProgress.LastCompletedChallengeDayIdx = currentSeason.Days.findIndex(
|
||||
day => day.events.length != 0 && day.events[0].challenge == value[value.length - 1].challenge
|
||||
);
|
||||
checkCalendarChallengeCompletion(calendarProgress, currentSeason);
|
||||
};
|
||||
|
||||
export const addMissionComplete = (inventory: TInventoryDatabaseDocument, { Tag, Completes, Tier }: IMission): void => {
|
||||
const { Missions } = inventory;
|
||||
const itemIndex = Missions.findIndex(item => item.Tag === Tag);
|
||||
|
@ -14,6 +14,7 @@ import { IRngResult, SRng, getRandomElement, getRandomReward } from "@/src/servi
|
||||
import { equipmentKeys, IMission, ITypeCount, TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes";
|
||||
import {
|
||||
addBooster,
|
||||
addCalendarProgress,
|
||||
addChallenges,
|
||||
addConsumables,
|
||||
addCrewShipAmmo,
|
||||
@ -33,10 +34,8 @@ import {
|
||||
addSkin,
|
||||
addStanding,
|
||||
applyClientEquipmentUpdates,
|
||||
checkCalendarChallengeCompletion,
|
||||
combineInventoryChanges,
|
||||
generateRewardSeed,
|
||||
getCalendarProgress,
|
||||
getDialogue,
|
||||
giveNemesisPetRecipe,
|
||||
giveNemesisWeaponRecipe,
|
||||
@ -671,12 +670,7 @@ export const addMissionInventoryUpdates = async (
|
||||
break;
|
||||
}
|
||||
case "CalendarProgress": {
|
||||
const calendarProgress = getCalendarProgress(inventory);
|
||||
const currentSeason = getWorldState().KnownCalendarSeasons[0];
|
||||
calendarProgress.SeasonProgress.LastCompletedChallengeDayIdx = currentSeason.Days.findIndex(
|
||||
day => day.events.length != 0 && day.events[0].challenge == value[value.length - 1].challenge
|
||||
);
|
||||
checkCalendarChallengeCompletion(calendarProgress, currentSeason);
|
||||
addCalendarProgress(inventory, value);
|
||||
break;
|
||||
}
|
||||
case "duviriCaveOffers": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user