返回提交历史
Modified
src/controllers/api/saveDialogueController.ts
+36
-24
XFEstudio/SpaceNinjaServer
feat: handle OtherDialogueInfos in saveDialogue (#1542)
Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1542 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
85b5bb43
代码差异
1 个文件
+36
-24
@@ -1,6 +1,7 @@
1
import { TInventoryDatabaseDocument } from "@/src/models/inventoryModels/inventoryModel";
1
2
import { addEmailItem, getInventory, updateCurrency } from "@/src/services/inventoryService";
2
3
import { getAccountIdForRequest } from "@/src/services/loginService";
3
import { ICompletedDialogue } from "@/src/types/inventoryTypes/inventoryTypes";
4
import { ICompletedDialogue, IDialogueDatabase } from "@/src/types/inventoryTypes/inventoryTypes";
4
5
import { IInventoryChanges } from "@/src/types/purchaseTypes";
5
6
import { logger } from "@/src/utils/logger";
6
7
import { RequestHandler } from "express";
@@ -22,31 +23,10 @@ export const saveDialogueController: RequestHandler = async (req, res) => {
22
23
if (!inventory.DialogueHistory) {
23
24
throw new Error("bad inventory state");
24
25
}
25
if (request.OtherDialogueInfos.length != 0 || !(request.Data || request.Gift)) {
26
logger.error(`saveDialogue request not fully handled: ${String(req.body)}`);
27
}
28
26
const inventoryChanges: IInventoryChanges = {};
29
27
const tomorrowAt0Utc = (Math.trunc(Date.now() / 86400_000) + 1) * 86400_000;
30
28
inventory.DialogueHistory.Dialogues ??= [];
31
let dialogue = inventory.DialogueHistory.Dialogues.find(x => x.DialogueName == request.DialogueName);
32
if (!dialogue) {
33
dialogue =
34
inventory.DialogueHistory.Dialogues[
35
inventory.DialogueHistory.Dialogues.push({
36
Rank: 0,
37
Chemistry: 0,
38
AvailableDate: new Date(0),
39
AvailableGiftDate: new Date(0),
40
RankUpExpiry: new Date(0),
41
BountyChemExpiry: new Date(0),
42
QueuedDialogues: [],
43
Gifts: [],
44
Booleans: [],
45
Completed: [],
46
DialogueName: request.DialogueName
47
}) - 1
48
];
49
}
29
const dialogue = getDialogue(inventory, request.DialogueName);
50
30
dialogue.Rank = request.Rank;
51
31
dialogue.Chemistry = request.Chemistry;
52
32
if (request.Data) {
@@ -69,6 +49,13 @@ export const saveDialogueController: RequestHandler = async (req, res) => {
69
49
}
70
50
dialogue.Completed.push(request.Data);
71
51
dialogue.AvailableDate = new Date(tomorrowAt0Utc);
52
for (const info of request.OtherDialogueInfos) {
53
const otherDialogue = getDialogue(inventory, info.Dialogue);
54
if (info.Tag != "") {
55
otherDialogue.QueuedDialogues.push(info.Tag);
56
}
57
otherDialogue.Chemistry += info.Value; // unsure
58
}
72
59
await inventory.save();
73
60
res.json({
74
61
InventoryChanges: inventoryChanges,
@@ -88,6 +75,8 @@ export const saveDialogueController: RequestHandler = async (req, res) => {
88
75
InventoryChanges: inventoryChanges,
89
76
AvailableGiftDate: { $date: { $numberLong: tomorrowAt0Utc.toString() } }
90
77
});
78
} else {
79
logger.error(`saveDialogue request not fully handled: ${String(req.body)}`);
91
80
}
92
81
}
93
82
};
@@ -113,7 +102,7 @@ interface SaveCompletedDialogueRequest {
113
102
Booleans: string[];
114
103
ResetBooleans: string[];
115
104
Data?: ICompletedDialogue;
116
OtherDialogueInfos: IOtherDialogueInfo[]; // unsure
105
OtherDialogueInfos: IOtherDialogueInfo[];
117
106
}
118
107
119
108
interface IOtherDialogueInfo {
@@ -121,3 +110,26 @@ interface IOtherDialogueInfo {
121
110
Tag: string;
122
111
Value: number;
123
112
}
113
114
const getDialogue = (inventory: TInventoryDatabaseDocument, dialogueName: string): IDialogueDatabase => {
115
let dialogue = inventory.DialogueHistory!.Dialogues!.find(x => x.DialogueName == dialogueName);
116
if (!dialogue) {
117
dialogue =
118
inventory.DialogueHistory!.Dialogues![
119
inventory.DialogueHistory!.Dialogues!.push({
120
Rank: 0,
121
Chemistry: 0,
122
AvailableDate: new Date(0),
123
AvailableGiftDate: new Date(0),
124
RankUpExpiry: new Date(0),
125
BountyChemExpiry: new Date(0),
126
QueuedDialogues: [],
127
Gifts: [],
128
Booleans: [],
129
Completed: [],
130
DialogueName: dialogueName
131
}) - 1
132
];
133
}
134
return dialogue;
135
};