fix: handle quest completion via missionInventoryUpdate (#1140)
Some checks failed
Build Docker image / docker (push) Waiting to run
Build / build (22) (push) Has been cancelled
Build / build (18) (push) Has been cancelled
Build / build (20) (push) Has been cancelled

Partial fix for #1126

Reviewed-on: #1140
Co-authored-by: Sainan <sainan@calamity.inc>
Co-committed-by: Sainan <sainan@calamity.inc>
This commit is contained in:
Sainan 2025-03-10 16:22:02 -07:00 committed by OrdisPrime
parent 29275fcfdd
commit b553097fe4
4 changed files with 25 additions and 23 deletions

View File

@ -1,10 +1,8 @@
import { RequestHandler } from "express"; import { RequestHandler } from "express";
import { parseString } from "@/src/helpers/general"; import { parseString } from "@/src/helpers/general";
import { logger } from "@/src/utils/logger";
import { getJSONfromString } from "@/src/helpers/stringHelpers"; import { getJSONfromString } from "@/src/helpers/stringHelpers";
import { updateQuestKey, IUpdateQuestRequest } from "@/src/services/questService"; import { updateQuestKey, IUpdateQuestRequest } from "@/src/services/questService";
import { getQuestCompletionItems } from "@/src/services/itemDataService"; import { getInventory } from "@/src/services/inventoryService";
import { addItems, getInventory } from "@/src/services/inventoryService";
import { IInventoryChanges } from "@/src/types/purchaseTypes"; import { IInventoryChanges } from "@/src/types/purchaseTypes";
// eslint-disable-next-line @typescript-eslint/no-misused-promises // eslint-disable-next-line @typescript-eslint/no-misused-promises
@ -22,20 +20,7 @@ export const updateQuestController: RequestHandler = async (req, res) => {
const updateQuestResponse: { CustomData?: string; InventoryChanges?: IInventoryChanges; MissionRewards: [] } = { const updateQuestResponse: { CustomData?: string; InventoryChanges?: IInventoryChanges; MissionRewards: [] } = {
MissionRewards: [] MissionRewards: []
}; };
updateQuestKey(inventory, updateQuestRequest.QuestKeys); updateQuestResponse.InventoryChanges = await updateQuestKey(inventory, updateQuestRequest.QuestKeys);
if (updateQuestRequest.QuestKeys[0].Completed) {
logger.debug(`completed quest ${updateQuestRequest.QuestKeys[0].ItemType} `);
const questKeyName = updateQuestRequest.QuestKeys[0].ItemType;
const questCompletionItems = getQuestCompletionItems(questKeyName);
logger.debug(`quest completion items`, questCompletionItems);
if (questCompletionItems) {
const inventoryChanges = await addItems(inventory, questCompletionItems);
updateQuestResponse.InventoryChanges = inventoryChanges;
}
inventory.ActiveQuest = "";
}
//TODO: might need to parse the custom data and add the associated items to inventory //TODO: might need to parse the custom data and add the associated items to inventory
if (updateQuestRequest.QuestKeys[0].CustomData) { if (updateQuestRequest.QuestKeys[0].CustomData) {

View File

@ -28,7 +28,7 @@ export const manageQuestsController: RequestHandler = async (req, res) => {
switch (operation) { switch (operation) {
case "updateKey": { case "updateKey": {
//TODO: if this is intended to be used, one needs to add a updateQuestKeyMultiple, the game does never intend to do it, so it errors for multiple keys. //TODO: if this is intended to be used, one needs to add a updateQuestKeyMultiple, the game does never intend to do it, so it errors for multiple keys.
updateQuestKey(inventory, questKeyUpdate); await updateQuestKey(inventory, questKeyUpdate);
break; break;
} }
case "unlockAll": { case "unlockAll": {

View File

@ -95,7 +95,7 @@ export const addMissionInventoryUpdates = async (
inventory.RegularCredits += value; inventory.RegularCredits += value;
break; break;
case "QuestKeys": case "QuestKeys":
updateQuestKey(inventory, value); await updateQuestKey(inventory, value);
break; break;
case "AffiliationChanges": case "AffiliationChanges":
updateSyndicate(inventory, value); updateSyndicate(inventory, value);

View File

@ -2,8 +2,13 @@ import { IKeyChainRequest } from "@/src/controllers/api/giveKeyChainTriggeredIte
import { isEmptyObject } from "@/src/helpers/general"; import { isEmptyObject } from "@/src/helpers/general";
import { TInventoryDatabaseDocument } from "@/src/models/inventoryModels/inventoryModel"; import { TInventoryDatabaseDocument } from "@/src/models/inventoryModels/inventoryModel";
import { createMessage } from "@/src/services/inboxService"; import { createMessage } from "@/src/services/inboxService";
import { addItem, addKeyChainItems } from "@/src/services/inventoryService"; import { addItem, addItems, addKeyChainItems } from "@/src/services/inventoryService";
import { fromStoreItem, getKeyChainMessage, getLevelKeyRewards } from "@/src/services/itemDataService"; import {
fromStoreItem,
getKeyChainMessage,
getLevelKeyRewards,
getQuestCompletionItems
} from "@/src/services/itemDataService";
import { import {
IInventoryDatabase, IInventoryDatabase,
IQuestKeyClient, IQuestKeyClient,
@ -25,10 +30,10 @@ export interface IUpdateQuestRequest {
DoQuestReward: boolean; DoQuestReward: boolean;
} }
export const updateQuestKey = ( export const updateQuestKey = async (
inventory: HydratedDocument<IInventoryDatabase>, inventory: HydratedDocument<IInventoryDatabase>,
questKeyUpdate: IUpdateQuestRequest["QuestKeys"] questKeyUpdate: IUpdateQuestRequest["QuestKeys"]
): void => { ): Promise<IInventoryChanges> => {
if (questKeyUpdate.length > 1) { if (questKeyUpdate.length > 1) {
logger.error(`more than 1 quest key not supported`); logger.error(`more than 1 quest key not supported`);
throw new Error("more than 1 quest key not supported"); throw new Error("more than 1 quest key not supported");
@ -42,9 +47,21 @@ export const updateQuestKey = (
inventory.QuestKeys[questKeyIndex] = questKeyUpdate[0]; inventory.QuestKeys[questKeyIndex] = questKeyUpdate[0];
let inventoryChanges: IInventoryChanges = {};
if (questKeyUpdate[0].Completed) { if (questKeyUpdate[0].Completed) {
inventory.QuestKeys[questKeyIndex].CompletionDate = new Date(); inventory.QuestKeys[questKeyIndex].CompletionDate = new Date();
logger.debug(`completed quest ${questKeyUpdate[0].ItemType} `);
const questKeyName = questKeyUpdate[0].ItemType;
const questCompletionItems = getQuestCompletionItems(questKeyName);
logger.debug(`quest completion items`, questCompletionItems);
if (questCompletionItems) {
inventoryChanges = await addItems(inventory as TInventoryDatabaseDocument, questCompletionItems);
}
inventory.ActiveQuest = "";
} }
return inventoryChanges;
}; };
export const updateQuestStage = ( export const updateQuestStage = (