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: digital grimoire (#3132)

Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3132 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

2eff22c0
Sainan <63328889+Sainan@users.noreply.github.com>
提交于

代码差异

5 个文件 +71 -4
Modified src/controllers/api/clearDialogueHistoryController.ts +34 -1
@@ -1,14 +1,34 @@
1 1 import { getInventory } from "../../services/inventoryService.ts";
2 2 import { getAccountIdForRequest } from "../../services/loginService.ts";
3 3 import type { RequestHandler } from "express";
4 import type { IInventoryClient, IDialogueResetDateClient } from "../../types/inventoryTypes/inventoryTypes.ts";
5 import { unixTimesInMs } from "../../constants/timeConstants.ts";
4 6
5 7 export const clearDialogueHistoryController: RequestHandler = async (req, res) => {
6 8 const accountId = await getAccountIdForRequest(req);
7 const inventory = await getInventory(accountId);
9 const inventory = await getInventory(accountId, "DialogueHistory");
8 10 const request = JSON.parse(String(req.body)) as IClearDialogueRequest;
9 11 if (inventory.DialogueHistory && inventory.DialogueHistory.Dialogues) {
10 12 inventory.DialogueHistory.Resets ??= 0;
11 13 inventory.DialogueHistory.Resets += 1;
14
15 if (request.Pack) {
16 inventory.DialogueHistory.ResetDates ??= [];
17 let resetDate = inventory.DialogueHistory.ResetDates.find(x => x.Pack == request.Pack);
18 if (!resetDate) {
19 resetDate =
20 inventory.DialogueHistory.ResetDates[
21 inventory.DialogueHistory.ResetDates.push({
22 Date: new Date(0),
23 Resets: 0,
24 Pack: request.Pack
25 }) - 1
26 ];
27 }
28 resetDate.Date = new Date(Date.now() + 28 * unixTimesInMs.day);
29 resetDate.Resets += 1;
30 }
31
12 32 for (const dialogueName of request.Dialogues) {
13 33 const index = inventory.DialogueHistory.Dialogues.findIndex(x => x.DialogueName == dialogueName);
14 34 if (index != -1) {
@@ -17,9 +37,22 @@ export const clearDialogueHistoryController: RequestHandler = async (req, res) =
17 37 }
18 38 }
19 39 await inventory.save();
40 res.json({
41 ResetDate: inventory.toJSON<IInventoryClient>().DialogueHistory?.ResetDates?.find(x => x.Pack == request.Pack),
42 Dialogues: request.Dialogues,
43 ClearPersist: request.ClearPersist
44 } satisfies IClearDialogueResponse);
20 45 res.end();
21 46 };
22 47
23 48 interface IClearDialogueRequest {
24 49 Dialogues: string[];
50 Pack?: "Hex" | "Roundtable" | "Triad"; // U41
51 ClearPersist?: boolean; // U41
52 }
53
54 interface IClearDialogueResponse {
55 ResetDate?: IDialogueResetDateClient; // U41
56 Dialogues?: string[]; // U41
57 ClearPersist?: boolean; // U41
25 58 }
Modified src/controllers/api/loginController.ts +1 -1
@@ -33,7 +33,7 @@ export const loginController: RequestHandler = async (request, response) => {
33 33 ? request.query.buildLabel.split(" ").join("+")
34 34 : buildConfig.buildLabel;
35 35
36 if (version_compare(buildLabel, "2025.10.29.12.05") > 0) {
36 if (version_compare(buildLabel, "2025.12.10.16.35") > 0) {
37 37 response.status(400).json({ error: "do you want me to change your diapers, too?" });
38 38 return;
39 39 }
Modified src/controllers/api/saveDialogueController.ts +1 -0
@@ -95,6 +95,7 @@ interface SaveCompletedDialogueRequest {
95 95 Booleans: string[];
96 96 ResetBooleans: string[];
97 97 Data?: ICompletedDialogue;
98 EventTriggered?: boolean; // U41
98 99 OtherDialogueInfos: IOtherDialogueInfo[];
99 100 }
100 101
Modified src/models/inventoryModels/inventoryModel.ts +22 -1
@@ -90,7 +90,9 @@ import type {
90 90 IKubrowPetPrintClient,
91 91 IKubrowPetPrintDatabase,
92 92 INokkoColony,
93 IJournalEntry
93 IJournalEntry,
94 IDialogueResetDateClient,
95 IDialogueResetDateDatabase
94 96 } from "../../types/inventoryTypes/inventoryTypes.ts";
95 97 import { equipmentKeys } from "../../types/inventoryTypes/inventoryTypes.ts";
96 98 import type { IOid, ITypeCount } from "../../types/commonTypes.ts";
@@ -966,10 +968,29 @@ dialogueSchema.set("toJSON", {
966 968 }
967 969 });
968 970
971 const dialogueResetDateSchema = new Schema<IDialogueResetDateDatabase>(
972 {
973 Date: Date,
974 Pack: String,
975 Resets: Number
976 },
977 { _id: false }
978 );
979 dialogueResetDateSchema.set("toJSON", {
980 virtuals: true,
981 transform(_doc, ret: Record<string, any>) {
982 const db = ret as IDialogueResetDateDatabase;
983 const client = ret as IDialogueResetDateClient;
984
985 client.Date = toMongoDate(db.Date);
986 }
987 });
988
969 989 const dialogueHistorySchema = new Schema<IDialogueHistoryDatabase>(
970 990 {
971 991 YearIteration: Number,
972 992 Resets: Number,
993 ResetDates: { type: [dialogueResetDateSchema], required: false },
973 994 Dialogues: { type: [dialogueSchema], required: false }
974 995 },
975 996 { _id: false }
Modified src/types/inventoryTypes/inventoryTypes.ts +13 -1
@@ -1131,16 +1131,28 @@ export interface IEndlessXpReward {
1131 1131
1132 1132 export interface IDialogueHistoryClient {
1133 1133 YearIteration?: number;
1134 Resets?: number; // added in 38.5.0
1134 Resets?: number; // added in 38.5.0, removed in 41.0.0
1135 ResetDates?: IDialogueResetDateClient[]; // added in 41.0.0
1135 1136 Dialogues?: IDialogueClient[];
1136 1137 }
1137 1138
1138 1139 export interface IDialogueHistoryDatabase {
1139 1140 YearIteration?: number;
1140 1141 Resets?: number;
1142 ResetDates?: IDialogueResetDateDatabase[];
1141 1143 Dialogues?: IDialogueDatabase[];
1142 1144 }
1143 1145
1146 export interface IDialogueResetDateClient {
1147 Date: IMongoDate;
1148 Pack: "Hex" | "Roundtable" | "Triad";
1149 Resets: number;
1150 }
1151
1152 export interface IDialogueResetDateDatabase extends Omit<IDialogueResetDateClient, "Date"> {
1153 Date: Date;
1154 }
1155
1144 1156 export interface IDialogueClient {
1145 1157 Rank: number;
1146 1158 Chemistry: number;