XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFESpaceNinjaServer

feat: nightwave challenge completion (#1319)

Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1319

58508a02
Sainan <sainan@calamity.inc>
提交于

代码差异

2 个文件 +51 -15
Modified src/controllers/api/updateChallengeProgressController.ts +46 -7
@@ -3,21 +3,60 @@ import { getJSONfromString } from "@/src/helpers/stringHelpers";
3 3 import { getAccountIdForRequest } from "@/src/services/loginService";
4 4 import { addChallenges, addSeasonalChallengeHistory, 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 import { IAffiliationMods } from "@/src/types/purchaseTypes";
6 9
7 10 export const updateChallengeProgressController: RequestHandler = async (req, res) => {
8 11 const challenges = getJSONfromString<IUpdateChallengeProgressRequest>(String(req.body));
9 12 const accountId = await getAccountIdForRequest(req);
10 13
11 const inventory = await getInventory(accountId, "ChallengeProgress SeasonChallengeHistory");
12 addChallenges(inventory, challenges.ChallengeProgress);
13 addSeasonalChallengeHistory(inventory, challenges.SeasonChallengeHistory);
14 const inventory = await getInventory(accountId, "ChallengeProgress SeasonChallengeHistory Affiliations");
15 if (challenges.ChallengeProgress) {
16 addChallenges(inventory, challenges.ChallengeProgress);
17 }
18 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 });
46 }
47 affiliationMods[0].Standing ??= 0;
48 affiliationMods[0].Standing += meta.standing;
49 }
50 }
14 51 await inventory.save();
15 52
16 res.status(200).end();
53 res.json({
54 AffiliationMods: affiliationMods
55 });
17 56 };
18 57
19 58 interface IUpdateChallengeProgressRequest {
20 ChallengeProgress: IChallengeProgress[];
21 SeasonChallengeHistory: ISeasonChallenge[];
22 SeasonChallengeCompletions: ISeasonChallenge[];
59 ChallengeProgress?: IChallengeProgress[];
60 SeasonChallengeHistory?: ISeasonChallenge[];
61 SeasonChallengeCompletions?: ISeasonChallenge[];
23 62 }
Modified src/services/inventoryService.ts +5 -8
@@ -1207,11 +1207,11 @@ export const addFocusXpIncreases = (inventory: TInventoryDatabaseDocument, focus
1207 1207
1208 1208 export const addSeasonalChallengeHistory = (
1209 1209 inventory: TInventoryDatabaseDocument,
1210 itemsArray: ISeasonChallenge[] | undefined
1210 itemsArray: ISeasonChallenge[]
1211 1211 ): void => {
1212 1212 const category = inventory.SeasonChallengeHistory;
1213 1213
1214 itemsArray?.forEach(({ challenge, id }) => {
1214 itemsArray.forEach(({ challenge, id }) => {
1215 1215 const itemIndex = category.findIndex(i => i.challenge === challenge);
1216 1216
1217 1217 if (itemIndex !== -1) {
@@ -1222,17 +1222,14 @@ export const addSeasonalChallengeHistory = (
1222 1222 });
1223 1223 };
1224 1224
1225 export const addChallenges = (
1226 inventory: TInventoryDatabaseDocument,
1227 itemsArray: IChallengeProgress[] | undefined
1228 ): void => {
1225 export const addChallenges = (inventory: TInventoryDatabaseDocument, itemsArray: IChallengeProgress[]): void => {
1229 1226 const category = inventory.ChallengeProgress;
1230 1227
1231 itemsArray?.forEach(({ Name, Progress }) => {
1228 itemsArray.forEach(({ Name, Progress }) => {
1232 1229 const itemIndex = category.findIndex(i => i.Name === Name);
1233 1230
1234 1231 if (itemIndex !== -1) {
1235 category[itemIndex].Progress += Progress;
1232 category[itemIndex].Progress = Progress;
1236 1233 } else {
1237 1234 category.push({ Name, Progress });
1238 1235 }