feat: nightwave challenge completion
All checks were successful
Build / build (18) (push) Successful in 48s
Build / build (20) (push) Successful in 1m9s
Build / build (22) (push) Successful in 1m12s
Build / build (18) (pull_request) Successful in 45s
Build / build (20) (pull_request) Successful in 1m7s
Build / build (22) (pull_request) Successful in 1m13s
All checks were successful
Build / build (18) (push) Successful in 48s
Build / build (20) (push) Successful in 1m9s
Build / build (22) (push) Successful in 1m12s
Build / build (18) (pull_request) Successful in 45s
Build / build (20) (pull_request) Successful in 1m7s
Build / build (22) (pull_request) Successful in 1m13s
This commit is contained in:
parent
2ec2b0278a
commit
46fd01dbb8
@ -3,21 +3,60 @@ 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, addSeasonalChallengeHistory, 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";
|
||||||
|
|
||||||
export const updateChallengeProgressController: RequestHandler = async (req, res) => {
|
export const updateChallengeProgressController: RequestHandler = async (req, res) => {
|
||||||
const challenges = getJSONfromString<IUpdateChallengeProgressRequest>(String(req.body));
|
const challenges = getJSONfromString<IUpdateChallengeProgressRequest>(String(req.body));
|
||||||
const accountId = await getAccountIdForRequest(req);
|
const accountId = await getAccountIdForRequest(req);
|
||||||
|
|
||||||
const inventory = await getInventory(accountId, "ChallengeProgress SeasonChallengeHistory");
|
const inventory = await getInventory(accountId, "ChallengeProgress SeasonChallengeHistory Affiliations");
|
||||||
addChallenges(inventory, challenges.ChallengeProgress);
|
if (challenges.ChallengeProgress) {
|
||||||
addSeasonalChallengeHistory(inventory, challenges.SeasonChallengeHistory);
|
addChallenges(inventory, challenges.ChallengeProgress);
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
res.status(200).end();
|
res.json({
|
||||||
|
AffiliationMods: affiliationMods
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
interface IUpdateChallengeProgressRequest {
|
interface IUpdateChallengeProgressRequest {
|
||||||
ChallengeProgress: IChallengeProgress[];
|
ChallengeProgress?: IChallengeProgress[];
|
||||||
SeasonChallengeHistory: ISeasonChallenge[];
|
SeasonChallengeHistory?: ISeasonChallenge[];
|
||||||
SeasonChallengeCompletions: ISeasonChallenge[];
|
SeasonChallengeCompletions?: ISeasonChallenge[];
|
||||||
}
|
}
|
||||||
|
@ -1207,11 +1207,11 @@ export const addFocusXpIncreases = (inventory: TInventoryDatabaseDocument, focus
|
|||||||
|
|
||||||
export const addSeasonalChallengeHistory = (
|
export const addSeasonalChallengeHistory = (
|
||||||
inventory: TInventoryDatabaseDocument,
|
inventory: TInventoryDatabaseDocument,
|
||||||
itemsArray: ISeasonChallenge[] | undefined
|
itemsArray: ISeasonChallenge[]
|
||||||
): void => {
|
): void => {
|
||||||
const category = inventory.SeasonChallengeHistory;
|
const category = inventory.SeasonChallengeHistory;
|
||||||
|
|
||||||
itemsArray?.forEach(({ challenge, id }) => {
|
itemsArray.forEach(({ challenge, id }) => {
|
||||||
const itemIndex = category.findIndex(i => i.challenge === challenge);
|
const itemIndex = category.findIndex(i => i.challenge === challenge);
|
||||||
|
|
||||||
if (itemIndex !== -1) {
|
if (itemIndex !== -1) {
|
||||||
@ -1222,17 +1222,14 @@ export const addSeasonalChallengeHistory = (
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const addChallenges = (
|
export const addChallenges = (inventory: TInventoryDatabaseDocument, itemsArray: IChallengeProgress[]): void => {
|
||||||
inventory: TInventoryDatabaseDocument,
|
|
||||||
itemsArray: IChallengeProgress[] | undefined
|
|
||||||
): void => {
|
|
||||||
const category = inventory.ChallengeProgress;
|
const category = inventory.ChallengeProgress;
|
||||||
|
|
||||||
itemsArray?.forEach(({ Name, Progress }) => {
|
itemsArray.forEach(({ Name, Progress }) => {
|
||||||
const itemIndex = category.findIndex(i => i.Name === Name);
|
const itemIndex = category.findIndex(i => i.Name === Name);
|
||||||
|
|
||||||
if (itemIndex !== -1) {
|
if (itemIndex !== -1) {
|
||||||
category[itemIndex].Progress += Progress;
|
category[itemIndex].Progress = Progress;
|
||||||
} else {
|
} else {
|
||||||
category.push({ Name, Progress });
|
category.push({ Name, Progress });
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user