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: updateSongChallenge (#1024)

Closes #707 untested but should be correct based on all the information I could find Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1024

bbc40d55
Sainan <sainan@calamity.inc>
提交于

代码差异

4 个文件 +71 -2
Added src/controllers/api/updateSongChallengeController.ts +50 -0
@@ -0,0 +1,50 @@
1 import { getJSONfromString } from "@/src/helpers/stringHelpers";
2 import { addShipDecorations, getInventory } from "@/src/services/inventoryService";
3 import { getAccountIdForRequest } from "@/src/services/loginService";
4 import { IInventoryChanges } from "@/src/types/purchaseTypes";
5 import { RequestHandler } from "express";
6
7 export const updateSongChallengeController: RequestHandler = async (req, res) => {
8 const accountId = await getAccountIdForRequest(req);
9 const inventory = await getInventory(accountId);
10 const request = getJSONfromString<IUpdateSongChallengeRequest>(String(req.body));
11 inventory.SongChallenges ??= [];
12 let songChallenge = inventory.SongChallenges.find(x => x.Song == request.Song);
13 if (!songChallenge) {
14 songChallenge =
15 inventory.SongChallenges[inventory.SongChallenges.push({ Song: request.Song, Difficulties: [] }) - 1];
16 }
17 songChallenge.Difficulties.push(request.Difficulty);
18
19 const response: IUpdateSongChallengeResponse = {
20 Song: request.Song,
21 Difficulty: request.Difficulty
22 };
23
24 // Handle all songs being completed on all difficulties
25 if (inventory.SongChallenges.length == 12 && !inventory.SongChallenges.find(x => x.Difficulties.length != 2)) {
26 response.Reward = "/Lotus/StoreItems/Types/Items/ShipDecos/LisetPropShawzinDuviri";
27 const shipDecorationChanges = [
28 { ItemType: "/Lotus/Types/Items/ShipDecos/LisetPropShawzinDuviri", ItemCount: 1 }
29 ];
30 response.InventoryChanges = {
31 ShipDecorations: shipDecorationChanges
32 };
33 addShipDecorations(inventory, shipDecorationChanges);
34 }
35
36 await inventory.save();
37 res.json(response);
38 };
39
40 interface IUpdateSongChallengeRequest {
41 Song: string;
42 Difficulty: number;
43 }
44
45 interface IUpdateSongChallengeResponse {
46 Song: string;
47 Difficulty: number;
48 Reward?: string;
49 InventoryChanges?: IInventoryChanges;
50 }
Modified src/models/inventoryModels/inventoryModel.ts +13 -2
@@ -73,7 +73,8 @@ import {
73 73 IDroneClient,
74 74 IAlignment,
75 75 ICollectibleEntry,
76 IIncentiveState
76 IIncentiveState,
77 ISongChallenge
77 78 } from "../../types/inventoryTypes/inventoryTypes";
78 79 import { IOid } from "../../types/commonTypes";
79 80 import {
@@ -965,6 +966,14 @@ const collectibleEntrySchema = new Schema<ICollectibleEntry>(
965 966 { _id: false }
966 967 );
967 968
969 const songChallengeSchema = new Schema<ISongChallenge>(
970 {
971 Song: String,
972 Difficulties: [Number]
973 },
974 { _id: false }
975 );
976
968 977 const pendingCouponSchema = new Schema<IPendingCouponDatabase>(
969 978 {
970 979 Expiry: { type: Date, default: new Date(0) },
@@ -1323,7 +1332,9 @@ const inventorySchema = new Schema<IInventoryDatabase, InventoryDocumentProps>(
1323 1332 EndlessXP: { type: [endlessXpProgressSchema], default: undefined },
1324 1333
1325 1334 DialogueHistory: dialogueHistorySchema,
1326 CalendarProgress: calenderProgressSchema
1335 CalendarProgress: calenderProgressSchema,
1336
1337 SongChallenges: { type: [songChallengeSchema], default: undefined }
1327 1338 },
1328 1339 { timestamps: { createdAt: "Created", updatedAt: false } }
1329 1340 );
Modified src/routes/api.ts +2 -0
@@ -92,6 +92,7 @@ import { updateAlignmentController } from "@/src/controllers/api/updateAlignment
92 92 import { updateChallengeProgressController } from "@/src/controllers/api/updateChallengeProgressController";
93 93 import { updateQuestController } from "@/src/controllers/api/updateQuestController";
94 94 import { updateSessionGetController, updateSessionPostController } from "@/src/controllers/api/updateSessionController";
95 import { updateSongChallengeController } from "@/src/controllers/api/updateSongChallengeController";
95 96 import { updateThemeController } from "@/src/controllers/api/updateThemeController";
96 97 import { upgradesController } from "@/src/controllers/api/upgradesController";
97 98
@@ -196,6 +197,7 @@ apiRouter.post("/updateChallengeProgress.php", updateChallengeProgressController
196 197 apiRouter.post("/updateNodeIntros.php", genericUpdateController);
197 198 apiRouter.post("/updateQuest.php", updateQuestController);
198 199 apiRouter.post("/updateSession.php", updateSessionPostController);
200 apiRouter.post("/updateSongChallenge.php", updateSongChallengeController);
199 201 apiRouter.post("/updateTheme.php", updateThemeController);
200 202 apiRouter.post("/upgrades.php", upgradesController);
201 203
Modified src/types/inventoryTypes/inventoryTypes.ts +6 -0
@@ -325,6 +325,7 @@ export interface IInventoryClient extends IDailyAffiliations, InventoryClientEqu
325 325 EndlessXP?: IEndlessXpProgress[];
326 326 DialogueHistory?: IDialogueHistoryClient;
327 327 CalendarProgress: ICalendarProgress;
328 SongChallenges?: ISongChallenge[];
328 329 }
329 330
330 331 export interface IAffiliation {
@@ -1079,3 +1080,8 @@ export interface ICalendarProgress {
1079 1080 YearProgress: { Upgrades: unknown[] };
1080 1081 SeasonProgress: ISeasonProgress;
1081 1082 }
1083
1084 export interface ISongChallenge {
1085 Song: string;
1086 Difficulties: number[];
1087 }