chore: handle season challenge completion in missionInventoryUpdate
All checks were successful
Build / build (20) (push) Successful in 44s
Build / build (22) (push) Successful in 1m18s
Build / build (18) (push) Successful in 1m16s
Build / build (18) (pull_request) Successful in 45s
Build / build (20) (pull_request) Successful in 1m16s
Build / build (22) (pull_request) Successful in 1m20s

This commit is contained in:
Sainan 2025-04-07 15:20:47 +02:00
parent 8ce86ad4fd
commit 3569a54dbd
3 changed files with 49 additions and 55 deletions

View File

@ -1,10 +1,8 @@
import { RequestHandler } from "express";
import { getJSONfromString } from "@/src/helpers/stringHelpers";
import { getAccountIdForRequest } from "@/src/services/loginService";
import { addChallenges, addSeasonalChallengeHistory, getInventory } from "@/src/services/inventoryService";
import { addChallenges, getInventory } from "@/src/services/inventoryService";
import { IChallengeProgress, ISeasonChallenge } from "@/src/types/inventoryTypes/inventoryTypes";
import { ExportNightwave } from "warframe-public-export-plus";
import { logger } from "@/src/utils/logger";
import { IAffiliationMods } from "@/src/types/purchaseTypes";
export const updateChallengeProgressController: RequestHandler = async (req, res) => {
@ -12,41 +10,19 @@ export const updateChallengeProgressController: RequestHandler = async (req, res
const accountId = await getAccountIdForRequest(req);
const inventory = await getInventory(accountId, "ChallengeProgress SeasonChallengeHistory Affiliations");
let affiliationMods: IAffiliationMods[] = [];
if (challenges.ChallengeProgress) {
addChallenges(inventory, challenges.ChallengeProgress);
affiliationMods = addChallenges(inventory, challenges.ChallengeProgress, challenges.SeasonChallengeCompletions);
}
if (challenges.SeasonChallengeHistory) {
addSeasonalChallengeHistory(inventory, challenges.SeasonChallengeHistory);
}
const affiliationMods: IAffiliationMods[] = [];
if (challenges.ChallengeProgress && challenges.SeasonChallengeCompletions) {
for (const challenge of challenges.SeasonChallengeCompletions) {
// Ignore challenges that weren't completed just now
if (!challenges.ChallengeProgress.find(x => challenge.challenge.indexOf(x.Name) != -1)) {
continue;
challenges.SeasonChallengeHistory.forEach(({ challenge, id }) => {
const itemIndex = inventory.SeasonChallengeHistory.findIndex(i => i.challenge === challenge);
if (itemIndex !== -1) {
inventory.SeasonChallengeHistory[itemIndex].id = id;
} else {
inventory.SeasonChallengeHistory.push({ challenge, id });
}
const meta = ExportNightwave.challenges[challenge.challenge];
logger.debug("Completed challenge", meta);
let affiliation = inventory.Affiliations.find(x => x.Tag == ExportNightwave.affiliationTag);
if (!affiliation) {
affiliation =
inventory.Affiliations[
inventory.Affiliations.push({
Tag: ExportNightwave.affiliationTag,
Standing: 0
}) - 1
];
}
affiliation.Standing += meta.standing;
if (affiliationMods.length == 0) {
affiliationMods.push({ Tag: ExportNightwave.affiliationTag });
}
affiliationMods[0].Standing ??= 0;
affiliationMods[0].Standing += meta.standing;
}
});
}
await inventory.save();

View File

@ -1,7 +1,7 @@
import { Inventory, TInventoryDatabaseDocument } from "@/src/models/inventoryModels/inventoryModel";
import { config } from "@/src/services/configService";
import { Types } from "mongoose";
import { SlotNames, IInventoryChanges, IBinChanges, slotNames } from "@/src/types/purchaseTypes";
import { SlotNames, IInventoryChanges, IBinChanges, slotNames, IAffiliationMods } from "@/src/types/purchaseTypes";
import {
IChallengeProgress,
IFlavourItem,
@ -45,6 +45,7 @@ import {
ExportGear,
ExportKeys,
ExportMisc,
ExportNightwave,
ExportRailjackWeapons,
ExportRecipes,
ExportResources,
@ -1302,35 +1303,52 @@ export const addFocusXpIncreases = (inventory: TInventoryDatabaseDocument, focus
inventory.DailyFocus -= focusXpPlus.reduce((a, b) => a + b, 0);
};
export const addSeasonalChallengeHistory = (
export const addChallenges = (
inventory: TInventoryDatabaseDocument,
itemsArray: ISeasonChallenge[]
): void => {
const category = inventory.SeasonChallengeHistory;
itemsArray.forEach(({ challenge, id }) => {
const itemIndex = category.findIndex(i => i.challenge === challenge);
ChallengeProgress: IChallengeProgress[],
SeasonChallengeCompletions: ISeasonChallenge[] | undefined
): IAffiliationMods[] => {
ChallengeProgress.forEach(({ Name, Progress }) => {
const itemIndex = inventory.ChallengeProgress.findIndex(i => i.Name === Name);
if (itemIndex !== -1) {
category[itemIndex].id = id;
inventory.ChallengeProgress[itemIndex].Progress = Progress;
} else {
category.push({ challenge, id });
inventory.ChallengeProgress.push({ Name, Progress });
}
});
};
export const addChallenges = (inventory: TInventoryDatabaseDocument, itemsArray: IChallengeProgress[]): void => {
const category = inventory.ChallengeProgress;
const affiliationMods: IAffiliationMods[] = [];
if (SeasonChallengeCompletions) {
for (const challenge of SeasonChallengeCompletions) {
// Ignore challenges that weren't completed just now
if (!ChallengeProgress.find(x => challenge.challenge.indexOf(x.Name) != -1)) {
continue;
}
itemsArray.forEach(({ Name, Progress }) => {
const itemIndex = category.findIndex(i => i.Name === Name);
const meta = ExportNightwave.challenges[challenge.challenge];
logger.debug("Completed challenge", meta);
if (itemIndex !== -1) {
category[itemIndex].Progress = Progress;
} else {
category.push({ Name, Progress });
let affiliation = inventory.Affiliations.find(x => x.Tag == ExportNightwave.affiliationTag);
if (!affiliation) {
affiliation =
inventory.Affiliations[
inventory.Affiliations.push({
Tag: ExportNightwave.affiliationTag,
Standing: 0
}) - 1
];
}
affiliation.Standing += meta.standing;
if (affiliationMods.length == 0) {
affiliationMods.push({ Tag: ExportNightwave.affiliationTag });
}
affiliationMods[0].Standing ??= 0;
affiliationMods[0].Standing += meta.standing;
}
});
}
return affiliationMods;
};
export const addMissionComplete = (inventory: TInventoryDatabaseDocument, { Tag, Completes }: IMission): void => {

View File

@ -195,7 +195,7 @@ export const addMissionInventoryUpdates = async (
addRecipes(inventory, value);
break;
case "ChallengeProgress":
addChallenges(inventory, value);
addChallenges(inventory, value, inventoryUpdates.SeasonChallengeCompletions);
break;
case "FusionTreasures":
addFusionTreasures(inventory, value);