forked from OpenWF/SpaceNinjaServer
fix: handle saveDialogue without YearIteration having been supplied (#1774)
This is needed for The Hex rank up dialogues, which are independent of the year iterations. Fixes #1773 Reviewed-on: OpenWF/SpaceNinjaServer#1774 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
This commit is contained in:
parent
6d93ae9f2d
commit
3b20a109f6
@ -12,22 +12,17 @@ export const saveDialogueController: RequestHandler = async (req, res) => {
|
||||
const request = JSON.parse(String(req.body)) as SaveDialogueRequest;
|
||||
if ("YearIteration" in request) {
|
||||
const inventory = await getInventory(accountId, "DialogueHistory");
|
||||
if (inventory.DialogueHistory) {
|
||||
inventory.DialogueHistory.YearIteration = request.YearIteration;
|
||||
} else {
|
||||
inventory.DialogueHistory = { YearIteration: request.YearIteration };
|
||||
}
|
||||
inventory.DialogueHistory ??= {};
|
||||
inventory.DialogueHistory.YearIteration = request.YearIteration;
|
||||
await inventory.save();
|
||||
res.end();
|
||||
} else {
|
||||
const inventory = await getInventory(accountId);
|
||||
if (!inventory.DialogueHistory) {
|
||||
throw new Error("bad inventory state");
|
||||
}
|
||||
const inventoryChanges: IInventoryChanges = {};
|
||||
const tomorrowAt0Utc = config.noKimCooldowns
|
||||
? Date.now()
|
||||
: (Math.trunc(Date.now() / 86400_000) + 1) * 86400_000;
|
||||
inventory.DialogueHistory ??= {};
|
||||
inventory.DialogueHistory.Dialogues ??= [];
|
||||
const dialogue = getDialogue(inventory, request.DialogueName);
|
||||
dialogue.Rank = request.Rank;
|
||||
|
@ -909,7 +909,7 @@ dialogueSchema.set("toJSON", {
|
||||
|
||||
const dialogueHistorySchema = new Schema<IDialogueHistoryDatabase>(
|
||||
{
|
||||
YearIteration: { type: Number, required: true },
|
||||
YearIteration: Number,
|
||||
Resets: Number,
|
||||
Dialogues: { type: [dialogueSchema], required: false }
|
||||
},
|
||||
|
@ -1130,13 +1130,13 @@ export interface IEndlessXpProgress {
|
||||
}
|
||||
|
||||
export interface IDialogueHistoryClient {
|
||||
YearIteration: number;
|
||||
YearIteration?: number;
|
||||
Resets?: number; // added in 38.5.0
|
||||
Dialogues?: IDialogueClient[];
|
||||
}
|
||||
|
||||
export interface IDialogueHistoryDatabase {
|
||||
YearIteration: number;
|
||||
YearIteration?: number;
|
||||
Resets?: number;
|
||||
Dialogues?: IDialogueDatabase[];
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user