feat: Quests 2 #878

Merged
OrdisPrime merged 5 commits from Quests2 into main 2025-02-01 07:26:02 -08:00
5 changed files with 17 additions and 9 deletions
Showing only changes of commit 49b702df2e - Show all commits

View File

@ -5,6 +5,7 @@ import { getJSONfromString } from "@/src/helpers/stringHelpers";
import { updateQuestKey, IUpdateQuestRequest } from "@/src/services/questService";
import { getQuestCompletionItems } from "@/src/services/itemDataService";
import { addItems, getInventory } from "@/src/services/inventoryService";
import { IInventoryChanges } from "@/src/types/purchaseTypes";
// eslint-disable-next-line @typescript-eslint/no-misused-promises
export const updateQuestController: RequestHandler = async (req, res) => {
@ -18,6 +19,9 @@ export const updateQuestController: RequestHandler = async (req, res) => {
const inventory = await getInventory(accountId);
const updateQuestResponse: { CustomData?: string; InventoryChanges?: IInventoryChanges; MissionRewards: [] } = {
MissionRewards: []
};
updateQuestKey(inventory, updateQuestRequest.QuestKeys);
if (updateQuestRequest.QuestKeys[0].Completed) {
@ -28,12 +32,15 @@ export const updateQuestController: RequestHandler = async (req, res) => {
const inventoryChanges = await addItems(inventory, questCompletionItems);
inventory.ActiveQuest = "";
await inventory.save();
res.json({ MissionRewards: [], inventoryChanges });
return;
updateQuestResponse.InventoryChanges = inventoryChanges;
}
//TODO: might need to parse the custom data and add the associated items to inventory
if (updateQuestRequest.QuestKeys[0].CustomData) {
updateQuestResponse.CustomData = updateQuestRequest.QuestKeys[0].CustomData;
}
await inventory.save();
res.send({ MissionRewards: [] });
res.send(updateQuestResponse);
};

View File

@ -494,7 +494,7 @@ const questKeysSchema = new Schema<IQuestKeyDatabase>(
Progress: { type: [questProgressSchema], default: undefined },
unlock: Boolean,
Completed: Boolean,
//CustomData: Schema.Types.Mixed,
CustomData: String,
CompletionDate: Date,
ItemType: String
},

View File

@ -28,6 +28,7 @@ export const updateQuestKey = (
throw new Error(`quest key ${questKeyUpdate[0].ItemType} not found`);
}
console.log(questKeyUpdate[0]);
inventory.QuestKeys[questKeyIndex] = questKeyUpdate[0];
if (questKeyUpdate[0].Completed) {

View File

@ -86,7 +86,7 @@ export interface IQuestKeyDatabase {
Progress?: IQuestStage[];
unlock?: boolean;
Completed?: boolean;
CustomData?: string; //TODO: check whether this actually exists
CustomData?: string;
ItemType: string;
CompletionDate?: Date;
}

View File

@ -11,8 +11,8 @@ import {
TSolarMapRegion,
TEquipmentKey,
IFusionTreasure,
IQuestKeyClient,
IPlayerSkills
IPlayerSkills,
IQuestKeyDatabase
} from "./inventoryTypes/inventoryTypes";
export interface IThemeUpdateRequest {
@ -46,7 +46,7 @@ export type IMissionInventoryUpdateRequest = {
Consumables?: ITypeCount[];
FusionTreasures?: IFusionTreasure[];
Recipes?: ITypeCount[];
QuestKeys?: IQuestKeyClient[];
QuestKeys?: Omit<IQuestKeyDatabase, "CompletionDate">[];
RegularCredits?: number;
MissionFailed: boolean;
MissionStatus: IMissionStatus;