chore: handle season challenge completion in missionInventoryUpdate #1511
@ -1,10 +1,8 @@
|
|||||||
import { RequestHandler } from "express";
|
import { RequestHandler } from "express";
|
||||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
||||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
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 { 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";
|
import { IAffiliationMods } from "@/src/types/purchaseTypes";
|
||||||
|
|
||||||
export const updateChallengeProgressController: RequestHandler = async (req, res) => {
|
export const updateChallengeProgressController: RequestHandler = async (req, res) => {
|
||||||
@ -12,41 +10,19 @@ export const updateChallengeProgressController: RequestHandler = async (req, res
|
|||||||
const accountId = await getAccountIdForRequest(req);
|
const accountId = await getAccountIdForRequest(req);
|
||||||
|
|
||||||
const inventory = await getInventory(accountId, "ChallengeProgress SeasonChallengeHistory Affiliations");
|
const inventory = await getInventory(accountId, "ChallengeProgress SeasonChallengeHistory Affiliations");
|
||||||
|
let affiliationMods: IAffiliationMods[] = [];
|
||||||
if (challenges.ChallengeProgress) {
|
if (challenges.ChallengeProgress) {
|
||||||
addChallenges(inventory, challenges.ChallengeProgress);
|
affiliationMods = addChallenges(inventory, challenges.ChallengeProgress, challenges.SeasonChallengeCompletions);
|
||||||
}
|
}
|
||||||
if (challenges.SeasonChallengeHistory) {
|
if (challenges.SeasonChallengeHistory) {
|
||||||
addSeasonalChallengeHistory(inventory, challenges.SeasonChallengeHistory);
|
challenges.SeasonChallengeHistory.forEach(({ challenge, id }) => {
|
||||||
}
|
const itemIndex = inventory.SeasonChallengeHistory.findIndex(i => i.challenge === challenge);
|
||||||
const affiliationMods: IAffiliationMods[] = [];
|
if (itemIndex !== -1) {
|
||||||
if (challenges.ChallengeProgress && challenges.SeasonChallengeCompletions) {
|
inventory.SeasonChallengeHistory[itemIndex].id = id;
|
||||||
for (const challenge of challenges.SeasonChallengeCompletions) {
|
} else {
|
||||||
// Ignore challenges that weren't completed just now
|
inventory.SeasonChallengeHistory.push({ challenge, id });
|
||||||
if (!challenges.ChallengeProgress.find(x => challenge.challenge.indexOf(x.Name) != -1)) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
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();
|
await inventory.save();
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { Inventory, TInventoryDatabaseDocument } from "@/src/models/inventoryModels/inventoryModel";
|
import { Inventory, TInventoryDatabaseDocument } from "@/src/models/inventoryModels/inventoryModel";
|
||||||
import { config } from "@/src/services/configService";
|
import { config } from "@/src/services/configService";
|
||||||
import { Types } from "mongoose";
|
import { Types } from "mongoose";
|
||||||
import { SlotNames, IInventoryChanges, IBinChanges, slotNames } from "@/src/types/purchaseTypes";
|
import { SlotNames, IInventoryChanges, IBinChanges, slotNames, IAffiliationMods } from "@/src/types/purchaseTypes";
|
||||||
import {
|
import {
|
||||||
IChallengeProgress,
|
IChallengeProgress,
|
||||||
IFlavourItem,
|
IFlavourItem,
|
||||||
@ -45,6 +45,7 @@ import {
|
|||||||
ExportGear,
|
ExportGear,
|
||||||
ExportKeys,
|
ExportKeys,
|
||||||
ExportMisc,
|
ExportMisc,
|
||||||
|
ExportNightwave,
|
||||||
ExportRailjackWeapons,
|
ExportRailjackWeapons,
|
||||||
ExportRecipes,
|
ExportRecipes,
|
||||||
ExportResources,
|
ExportResources,
|
||||||
@ -1302,35 +1303,52 @@ export const addFocusXpIncreases = (inventory: TInventoryDatabaseDocument, focus
|
|||||||
inventory.DailyFocus -= focusXpPlus.reduce((a, b) => a + b, 0);
|
inventory.DailyFocus -= focusXpPlus.reduce((a, b) => a + b, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const addSeasonalChallengeHistory = (
|
export const addChallenges = (
|
||||||
inventory: TInventoryDatabaseDocument,
|
inventory: TInventoryDatabaseDocument,
|
||||||
itemsArray: ISeasonChallenge[]
|
ChallengeProgress: IChallengeProgress[],
|
||||||
): void => {
|
SeasonChallengeCompletions: ISeasonChallenge[] | undefined
|
||||||
const category = inventory.SeasonChallengeHistory;
|
): IAffiliationMods[] => {
|
||||||
|
ChallengeProgress.forEach(({ Name, Progress }) => {
|
||||||
itemsArray.forEach(({ challenge, id }) => {
|
const itemIndex = inventory.ChallengeProgress.findIndex(i => i.Name === Name);
|
||||||
const itemIndex = category.findIndex(i => i.challenge === challenge);
|
|
||||||
|
|
||||||
if (itemIndex !== -1) {
|
if (itemIndex !== -1) {
|
||||||
category[itemIndex].id = id;
|
inventory.ChallengeProgress[itemIndex].Progress = Progress;
|
||||||
} else {
|
} else {
|
||||||
category.push({ challenge, id });
|
inventory.ChallengeProgress.push({ Name, Progress });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
|
||||||
export const addChallenges = (inventory: TInventoryDatabaseDocument, itemsArray: IChallengeProgress[]): void => {
|
const affiliationMods: IAffiliationMods[] = [];
|
||||||
const category = inventory.ChallengeProgress;
|
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 meta = ExportNightwave.challenges[challenge.challenge];
|
||||||
const itemIndex = category.findIndex(i => i.Name === Name);
|
logger.debug("Completed challenge", meta);
|
||||||
|
|
||||||
if (itemIndex !== -1) {
|
let affiliation = inventory.Affiliations.find(x => x.Tag == ExportNightwave.affiliationTag);
|
||||||
category[itemIndex].Progress = Progress;
|
if (!affiliation) {
|
||||||
} else {
|
affiliation =
|
||||||
category.push({ Name, Progress });
|
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 => {
|
export const addMissionComplete = (inventory: TInventoryDatabaseDocument, { Tag, Completes }: IMission): void => {
|
||||||
|
@ -195,7 +195,7 @@ export const addMissionInventoryUpdates = async (
|
|||||||
addRecipes(inventory, value);
|
addRecipes(inventory, value);
|
||||||
break;
|
break;
|
||||||
case "ChallengeProgress":
|
case "ChallengeProgress":
|
||||||
addChallenges(inventory, value);
|
addChallenges(inventory, value, inventoryUpdates.SeasonChallengeCompletions);
|
||||||
break;
|
break;
|
||||||
case "FusionTreasures":
|
case "FusionTreasures":
|
||||||
addFusionTreasures(inventory, value);
|
addFusionTreasures(inventory, value);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user