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: kim counters (#3710)

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

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

代码差异

4 个文件 +47 -3
Modified src/controllers/api/clearDialogueHistoryController.ts +10 -1
@@ -8,6 +8,7 @@ export const clearDialogueHistoryController: RequestHandler = async (req, res) =
8 8 const accountId = await getAccountIdForRequest(req);
9 9 const inventory = await getInventory(accountId, "DialogueHistory");
10 10 const request = JSON.parse(String(req.body)) as IClearDialogueRequest;
11 //logger.debug(`clearDialogueHistory:`, request);
11 12 if (inventory.DialogueHistory && inventory.DialogueHistory.Dialogues) {
12 13 inventory.DialogueHistory.Resets ??= 0;
13 14 inventory.DialogueHistory.Resets += 1;
@@ -32,7 +33,15 @@ export const clearDialogueHistoryController: RequestHandler = async (req, res) =
32 33 for (const dialogueName of request.Dialogues) {
33 34 const index = inventory.DialogueHistory.Dialogues.findIndex(x => x.DialogueName == dialogueName);
34 35 if (index != -1) {
35 inventory.DialogueHistory.Dialogues.splice(index, 1);
36 if (request.ClearPersist) {
37 inventory.DialogueHistory.Dialogues.splice(index, 1);
38 } else {
39 inventory.DialogueHistory.Dialogues[index] = {
40 ...inventory.DialogueHistory.Dialogues[index],
41 Counters: inventory.DialogueHistory.Dialogues[index].Counters?.filter(x => x.Persist),
42 Completed: inventory.DialogueHistory.Dialogues[index].Completed.filter(x => x.Persist)
43 };
44 }
36 45 }
37 46 }
38 47 }
Modified src/controllers/api/saveDialogueController.ts +14 -1
@@ -1,12 +1,13 @@
1 1 import { addEmailItem, getDialogue, getInventory, updateCurrency } from "../../services/inventoryService.ts";
2 2 import { getAccountIdForRequest } from "../../services/loginService.ts";
3 import type { ICompletedDialogue } from "../../types/inventoryTypes/inventoryTypes.ts";
3 import type { ICompletedDialogue, IDialogueCounter } from "../../types/inventoryTypes/inventoryTypes.ts";
4 4 import type { IInventoryChanges } from "../../types/purchaseTypes.ts";
5 5 import type { RequestHandler } from "express";
6 6
7 7 export const saveDialogueController: RequestHandler = async (req, res) => {
8 8 const accountId = await getAccountIdForRequest(req);
9 9 const request = JSON.parse(String(req.body)) as SaveDialogueRequest;
10 //logger.debug(`saveDialogue:`, request);
10 11 if ("YearIteration" in request) {
11 12 const inventory = await getInventory(accountId, "DialogueHistory noKimCooldowns");
12 13 inventory.DialogueHistory ??= {};
@@ -39,6 +40,17 @@ export const saveDialogueController: RequestHandler = async (req, res) => {
39 40 dialogue.Booleans.splice(index, 1);
40 41 }
41 42 }
43 if (request.Counters) {
44 dialogue.Counters ??= [];
45 for (const clientCounter of request.Counters) {
46 const dbCounter = dialogue.Counters.find(x => x.Name == clientCounter.Name);
47 if (dbCounter) {
48 dbCounter.Count = clientCounter.Count;
49 } else {
50 dialogue.Counters.push(clientCounter);
51 }
52 }
53 }
42 54 for (const info of request.OtherDialogueInfos) {
43 55 const otherDialogue = getDialogue(inventory, info.Dialogue);
44 56 if (info.Tag != "") {
@@ -94,6 +106,7 @@ interface SaveCompletedDialogueRequest {
94 106 };
95 107 Booleans: string[];
96 108 ResetBooleans: string[];
109 Counters?: IDialogueCounter[];
97 110 Data?: ICompletedDialogue;
98 111 EventTriggered?: boolean; // U41
99 112 OtherDialogueInfos: IOtherDialogueInfo[];
Modified src/models/inventoryModels/inventoryModel.ts +14 -1
@@ -99,7 +99,8 @@ import type {
99 99 IFocusLoadoutDatabase,
100 100 IChallengeInstanceStateDatabase,
101 101 IChallengeInstanceStateClient,
102 IParam
102 IParam,
103 IDialogueCounter
103 104 } from "../../types/inventoryTypes/inventoryTypes.ts";
104 105 import { equipmentKeys } from "../../types/inventoryTypes/inventoryTypes.ts";
105 106 import type { IOid, ITypeCount } from "../../types/commonTypes.ts";
@@ -980,10 +981,21 @@ const dialogueGiftSchema = new Schema<IDialogueGift>(
980 981 { _id: false }
981 982 );
982 983
984 const dialogueCounterSchema = new Schema<IDialogueCounter>(
985 {
986 Name: { type: String, required: true },
987 Count: { type: Number, required: true },
988 Persist: { type: Boolean, required: true }
989 },
990 { _id: false }
991 );
992
983 993 const completedDialogueSchema = new Schema<ICompletedDialogue>(
984 994 {
985 995 Id: { type: String, required: true },
996 Persist: { type: Boolean, required: false },
986 997 Booleans: { type: [String], required: true },
998 Counters: { type: [dialogueCounterSchema], required: false },
987 999 Choices: { type: [Number], required: true }
988 1000 },
989 1001 { _id: false }
@@ -1000,6 +1012,7 @@ const dialogueSchema = new Schema<IDialogueDatabase>(
1000 1012 QueuedDialogues: { type: [String], default: [] },
1001 1013 Gifts: { type: [dialogueGiftSchema], default: [] },
1002 1014 Booleans: { type: [String], default: [] },
1015 Counters: { type: [dialogueCounterSchema], required: false },
1003 1016 Completed: { type: [completedDialogueSchema], default: [] },
1004 1017 DialogueName: String
1005 1018 },
Modified src/types/inventoryTypes/inventoryTypes.ts +9 -0
@@ -1251,6 +1251,7 @@ export interface IDialogueClient {
1251 1251 QueuedDialogues: string[];
1252 1252 Gifts: IDialogueGift[];
1253 1253 Booleans: string[];
1254 Counters?: IDialogueCounter[];
1254 1255 Completed: ICompletedDialogue[];
1255 1256 DialogueName: string;
1256 1257 }
@@ -1272,10 +1273,18 @@ export interface IDialogueGift {
1272 1273
1273 1274 export interface ICompletedDialogue {
1274 1275 Id: string;
1276 Persist?: boolean;
1275 1277 Booleans: string[];
1278 Counters?: IDialogueCounter[];
1276 1279 Choices: number[];
1277 1280 }
1278 1281
1282 export interface IDialogueCounter {
1283 Name: string;
1284 Count: number;
1285 Persist: boolean;
1286 }
1287
1279 1288 export interface ICustomMarkers {
1280 1289 tag: string;
1281 1290 markerInfos: IMarkerInfo[];