返回提交历史
Modified
src/controllers/api/updateChallengeProgressController.ts
+10
-34
Modified
src/services/inventoryService.ts
+38
-20
Modified
src/services/missionInventoryUpdateService.ts
+1
-1
XFEstudio/XFESpaceNinjaServer
chore: handle season challenge completion in missionInventoryUpdate (#1511)
Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1511 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
39be0958
代码差异
3 个文件
+49
-55
@@ -1,10 +1,8 @@
1
1
import { RequestHandler } from "express";
2
2
import { getJSONfromString } from "@/src/helpers/stringHelpers";
3
3
import { getAccountIdForRequest } from "@/src/services/loginService";
4
import { addChallenges, addSeasonalChallengeHistory, getInventory } from "@/src/services/inventoryService";
4
import { addChallenges, getInventory } from "@/src/services/inventoryService";
5
5
import { IChallengeProgress, ISeasonChallenge } from "@/src/types/inventoryTypes/inventoryTypes";
6
import { ExportNightwave } from "warframe-public-export-plus";
7
import { logger } from "@/src/utils/logger";
8
6
import { IAffiliationMods } from "@/src/types/purchaseTypes";
9
7
10
8
export const updateChallengeProgressController: RequestHandler = async (req, res) => {
@@ -12,41 +10,19 @@ export const updateChallengeProgressController: RequestHandler = async (req, res
12
10
const accountId = await getAccountIdForRequest(req);
13
11
14
12
const inventory = await getInventory(accountId, "ChallengeProgress SeasonChallengeHistory Affiliations");
13
let affiliationMods: IAffiliationMods[] = [];
15
14
if (challenges.ChallengeProgress) {
16
addChallenges(inventory, challenges.ChallengeProgress);
15
affiliationMods = addChallenges(inventory, challenges.ChallengeProgress, challenges.SeasonChallengeCompletions);
17
16
}
18
17
if (challenges.SeasonChallengeHistory) {
19
addSeasonalChallengeHistory(inventory, challenges.SeasonChallengeHistory);
20
}
21
const affiliationMods: IAffiliationMods[] = [];
22
if (challenges.ChallengeProgress && challenges.SeasonChallengeCompletions) {
23
for (const challenge of challenges.SeasonChallengeCompletions) {
24
// Ignore challenges that weren't completed just now
25
if (!challenges.ChallengeProgress.find(x => challenge.challenge.indexOf(x.Name) != -1)) {
26
continue;
27
}
28
29
const meta = ExportNightwave.challenges[challenge.challenge];
30
logger.debug("Completed challenge", meta);
31
32
let affiliation = inventory.Affiliations.find(x => x.Tag == ExportNightwave.affiliationTag);
33
if (!affiliation) {
34
affiliation =
35
inventory.Affiliations[
36
inventory.Affiliations.push({
37
Tag: ExportNightwave.affiliationTag,
38
Standing: 0
39
}) - 1
40
];
41
}
42
affiliation.Standing += meta.standing;
43
44
if (affiliationMods.length == 0) {
45
affiliationMods.push({ Tag: ExportNightwave.affiliationTag });
18
challenges.SeasonChallengeHistory.forEach(({ challenge, id }) => {
19
const itemIndex = inventory.SeasonChallengeHistory.findIndex(i => i.challenge === challenge);
20
if (itemIndex !== -1) {
21
inventory.SeasonChallengeHistory[itemIndex].id = id;
22
} else {
23
inventory.SeasonChallengeHistory.push({ challenge, id });
46
24
}
47
affiliationMods[0].Standing ??= 0;
48
affiliationMods[0].Standing += meta.standing;
49
}
25
});
50
26
}
51
27
await inventory.save();
52
28
@@ -1,7 +1,7 @@
1
1
import { Inventory, TInventoryDatabaseDocument } from "@/src/models/inventoryModels/inventoryModel";
2
2
import { config } from "@/src/services/configService";
3
3
import { Types } from "mongoose";
4
import { SlotNames, IInventoryChanges, IBinChanges, slotNames } from "@/src/types/purchaseTypes";
4
import { SlotNames, IInventoryChanges, IBinChanges, slotNames, IAffiliationMods } from "@/src/types/purchaseTypes";
5
5
import {
6
6
IChallengeProgress,
7
7
IFlavourItem,
@@ -45,6 +45,7 @@ import {
45
45
ExportGear,
46
46
ExportKeys,
47
47
ExportMisc,
48
ExportNightwave,
48
49
ExportRailjackWeapons,
49
50
ExportRecipes,
50
51
ExportResources,
@@ -1302,35 +1303,52 @@ export const addFocusXpIncreases = (inventory: TInventoryDatabaseDocument, focus
1302
1303
inventory.DailyFocus -= focusXpPlus.reduce((a, b) => a + b, 0);
1303
1304
};
1304
1305
1305
export const addSeasonalChallengeHistory = (
1306
export const addChallenges = (
1306
1307
inventory: TInventoryDatabaseDocument,
1307
itemsArray: ISeasonChallenge[]
1308
): void => {
1309
const category = inventory.SeasonChallengeHistory;
1310
1311
itemsArray.forEach(({ challenge, id }) => {
1312
const itemIndex = category.findIndex(i => i.challenge === challenge);
1308
ChallengeProgress: IChallengeProgress[],
1309
SeasonChallengeCompletions: ISeasonChallenge[] | undefined
1310
): IAffiliationMods[] => {
1311
ChallengeProgress.forEach(({ Name, Progress }) => {
1312
const itemIndex = inventory.ChallengeProgress.findIndex(i => i.Name === Name);
1313
1313
1314
1314
if (itemIndex !== -1) {
1315
category[itemIndex].id = id;
1315
inventory.ChallengeProgress[itemIndex].Progress = Progress;
1316
1316
} else {
1317
category.push({ challenge, id });
1317
inventory.ChallengeProgress.push({ Name, Progress });
1318
1318
}
1319
1319
});
1320
};
1321
1320
1322
export const addChallenges = (inventory: TInventoryDatabaseDocument, itemsArray: IChallengeProgress[]): void => {
1323
const category = inventory.ChallengeProgress;
1321
const affiliationMods: IAffiliationMods[] = [];
1322
if (SeasonChallengeCompletions) {
1323
for (const challenge of SeasonChallengeCompletions) {
1324
// Ignore challenges that weren't completed just now
1325
if (!ChallengeProgress.find(x => challenge.challenge.indexOf(x.Name) != -1)) {
1326
continue;
1327
}
1324
1328
1325
itemsArray.forEach(({ Name, Progress }) => {
1326
const itemIndex = category.findIndex(i => i.Name === Name);
1329
const meta = ExportNightwave.challenges[challenge.challenge];
1330
logger.debug("Completed challenge", meta);
1331
1332
let affiliation = inventory.Affiliations.find(x => x.Tag == ExportNightwave.affiliationTag);
1333
if (!affiliation) {
1334
affiliation =
1335
inventory.Affiliations[
1336
inventory.Affiliations.push({
1337
Tag: ExportNightwave.affiliationTag,
1338
Standing: 0
1339
}) - 1
1340
];
1341
}
1342
affiliation.Standing += meta.standing;
1327
1343
1328
if (itemIndex !== -1) {
1329
category[itemIndex].Progress = Progress;
1330
} else {
1331
category.push({ Name, Progress });
1344
if (affiliationMods.length == 0) {
1345
affiliationMods.push({ Tag: ExportNightwave.affiliationTag });
1346
}
1347
affiliationMods[0].Standing ??= 0;
1348
affiliationMods[0].Standing += meta.standing;
1332
1349
}
1333
});
1350
}
1351
return affiliationMods;
1334
1352
};
1335
1353
1336
1354
export const addMissionComplete = (inventory: TInventoryDatabaseDocument, { Tag, Completes }: IMission): void => {
@@ -195,7 +195,7 @@ export const addMissionInventoryUpdates = async (
195
195
addRecipes(inventory, value);
196
196
break;
197
197
case "ChallengeProgress":
198
addChallenges(inventory, value);
198
addChallenges(inventory, value, inventoryUpdates.SeasonChallengeCompletions);
199
199
break;
200
200
case "FusionTreasures":
201
201
addFusionTreasures(inventory, value);