chore: fix code duplication for quest completion
All checks were successful
Build / build (20) (push) Successful in 40s
Build / build (22) (push) Successful in 1m13s
Build / build (18) (push) Successful in 1m16s
Build / build (18) (pull_request) Successful in 41s
Build / build (20) (pull_request) Successful in 1m13s
Build / build (22) (pull_request) Successful in 1m18s
All checks were successful
Build / build (20) (push) Successful in 40s
Build / build (22) (push) Successful in 1m13s
Build / build (18) (push) Successful in 1m16s
Build / build (18) (pull_request) Successful in 41s
Build / build (20) (pull_request) Successful in 1m13s
Build / build (22) (pull_request) Successful in 1m18s
This commit is contained in:
parent
5702ab5f3b
commit
027f58a79b
@ -1,7 +1,5 @@
|
|||||||
import { IKeyChainRequest } from "@/src/types/requestTypes";
|
import { IKeyChainRequest } from "@/src/types/requestTypes";
|
||||||
import { getIndexAfter } from "@/src/helpers/stringHelpers";
|
import { getIndexAfter } from "@/src/helpers/stringHelpers";
|
||||||
import { ITypeCount } from "@/src/types/inventoryTypes/inventoryTypes";
|
|
||||||
import { logger } from "@/src/utils/logger";
|
|
||||||
import {
|
import {
|
||||||
dict_de,
|
dict_de,
|
||||||
dict_en,
|
dict_en,
|
||||||
@ -34,7 +32,6 @@ import {
|
|||||||
IRecipe,
|
IRecipe,
|
||||||
TReward
|
TReward
|
||||||
} from "warframe-public-export-plus";
|
} from "warframe-public-export-plus";
|
||||||
import questCompletionItems from "@/static/fixed_responses/questCompletionRewards.json";
|
|
||||||
import { IMessage } from "../models/inboxModel";
|
import { IMessage } from "../models/inboxModel";
|
||||||
|
|
||||||
export type WeaponTypeInternal =
|
export type WeaponTypeInternal =
|
||||||
@ -181,32 +178,6 @@ export const getLevelKeyRewards = (
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getQuestCompletionItems = (questKey: string): ITypeCount[] | undefined => {
|
|
||||||
if (questKey in questCompletionItems) {
|
|
||||||
return questCompletionItems[questKey as keyof typeof questCompletionItems];
|
|
||||||
}
|
|
||||||
logger.warn(`Quest ${questKey} not found in questCompletionItems`);
|
|
||||||
|
|
||||||
const items: ITypeCount[] = [];
|
|
||||||
const meta = ExportKeys[questKey];
|
|
||||||
if (meta.rewards) {
|
|
||||||
for (const reward of meta.rewards) {
|
|
||||||
if (reward.rewardType == "RT_STORE_ITEM") {
|
|
||||||
items.push({
|
|
||||||
ItemType: fromStoreItem(reward.itemType),
|
|
||||||
ItemCount: 1
|
|
||||||
});
|
|
||||||
} else if (reward.rewardType == "RT_RESOURCE" || reward.rewardType == "RT_RECIPE") {
|
|
||||||
items.push({
|
|
||||||
ItemType: reward.itemType,
|
|
||||||
ItemCount: reward.amount
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return items;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getKeyChainMessage = ({ KeyChain, ChainStage }: IKeyChainRequest): IMessage => {
|
export const getKeyChainMessage = ({ KeyChain, ChainStage }: IKeyChainRequest): IMessage => {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||||
const chainStages = ExportKeys[KeyChain]?.chainStages;
|
const chainStages = ExportKeys[KeyChain]?.chainStages;
|
||||||
|
@ -3,18 +3,14 @@ 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, addItems, addKeyChainItems, setupKahlSyndicate } from "@/src/services/inventoryService";
|
import { addItem, addItems, addKeyChainItems, setupKahlSyndicate } from "@/src/services/inventoryService";
|
||||||
import {
|
import { fromStoreItem, getKeyChainMessage, getLevelKeyRewards } from "@/src/services/itemDataService";
|
||||||
fromStoreItem,
|
import { IQuestKeyClient, IQuestKeyDatabase, IQuestStage, ITypeCount } from "@/src/types/inventoryTypes/inventoryTypes";
|
||||||
getKeyChainMessage,
|
|
||||||
getLevelKeyRewards,
|
|
||||||
getQuestCompletionItems
|
|
||||||
} from "@/src/services/itemDataService";
|
|
||||||
import { IQuestKeyClient, IQuestKeyDatabase, IQuestStage } from "@/src/types/inventoryTypes/inventoryTypes";
|
|
||||||
import { logger } from "@/src/utils/logger";
|
import { logger } from "@/src/utils/logger";
|
||||||
import { Types } from "mongoose";
|
import { Types } from "mongoose";
|
||||||
import { ExportKeys } from "warframe-public-export-plus";
|
import { ExportKeys } from "warframe-public-export-plus";
|
||||||
import { addFixedLevelRewards } from "./missionInventoryUpdateService";
|
import { addFixedLevelRewards } from "./missionInventoryUpdateService";
|
||||||
import { IInventoryChanges } from "../types/purchaseTypes";
|
import { IInventoryChanges } from "../types/purchaseTypes";
|
||||||
|
import questCompletionItems from "@/static/fixed_responses/questCompletionRewards.json";
|
||||||
|
|
||||||
export interface IUpdateQuestRequest {
|
export interface IUpdateQuestRequest {
|
||||||
QuestKeys: Omit<IQuestKeyDatabase, "CompletionDate">[];
|
QuestKeys: Omit<IQuestKeyDatabase, "CompletionDate">[];
|
||||||
@ -42,23 +38,12 @@ export const updateQuestKey = async (
|
|||||||
|
|
||||||
inventory.QuestKeys[questKeyIndex].overwrite(questKeyUpdate[0]);
|
inventory.QuestKeys[questKeyIndex].overwrite(questKeyUpdate[0]);
|
||||||
|
|
||||||
let inventoryChanges: IInventoryChanges = {};
|
const 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 questKey = questKeyUpdate[0].ItemType;
|
||||||
const questKeyName = questKeyUpdate[0].ItemType;
|
await handleQuestCompletion(inventory, questKey, inventoryChanges);
|
||||||
const questCompletionItems = getQuestCompletionItems(questKeyName);
|
|
||||||
logger.debug(`quest completion items`, questCompletionItems);
|
|
||||||
|
|
||||||
if (questCompletionItems) {
|
|
||||||
inventoryChanges = await addItems(inventory, questCompletionItems);
|
|
||||||
}
|
|
||||||
inventory.ActiveQuest = "";
|
|
||||||
|
|
||||||
if (questKeyUpdate[0].ItemType == "/Lotus/Types/Keys/NewWarQuest/NewWarQuestKeyChain") {
|
|
||||||
setupKahlSyndicate(inventory);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return inventoryChanges;
|
return inventoryChanges;
|
||||||
};
|
};
|
||||||
@ -177,10 +162,46 @@ export const completeQuest = async (inventory: TInventoryDatabaseDocument, quest
|
|||||||
await giveKeyChainMissionReward(inventory, { KeyChain: questKey, ChainStage: i });
|
await giveKeyChainMissionReward(inventory, { KeyChain: questKey, ChainStage: i });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await handleQuestCompletion(inventory, questKey);
|
||||||
|
};
|
||||||
|
|
||||||
|
const getQuestCompletionItems = (questKey: string): ITypeCount[] | undefined => {
|
||||||
|
if (questKey in questCompletionItems) {
|
||||||
|
return questCompletionItems[questKey as keyof typeof questCompletionItems];
|
||||||
|
}
|
||||||
|
logger.warn(`Quest ${questKey} not found in questCompletionItems`);
|
||||||
|
|
||||||
|
const items: ITypeCount[] = [];
|
||||||
|
const meta = ExportKeys[questKey];
|
||||||
|
if (meta.rewards) {
|
||||||
|
for (const reward of meta.rewards) {
|
||||||
|
if (reward.rewardType == "RT_STORE_ITEM") {
|
||||||
|
items.push({
|
||||||
|
ItemType: fromStoreItem(reward.itemType),
|
||||||
|
ItemCount: 1
|
||||||
|
});
|
||||||
|
} else if (reward.rewardType == "RT_RESOURCE" || reward.rewardType == "RT_RECIPE") {
|
||||||
|
items.push({
|
||||||
|
ItemType: reward.itemType,
|
||||||
|
ItemCount: reward.amount
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return items;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleQuestCompletion = async (
|
||||||
|
inventory: TInventoryDatabaseDocument,
|
||||||
|
questKey: string,
|
||||||
|
inventoryChanges: IInventoryChanges = {}
|
||||||
|
): Promise<void> => {
|
||||||
|
logger.debug(`completed quest ${questKey}`);
|
||||||
|
|
||||||
const questCompletionItems = getQuestCompletionItems(questKey);
|
const questCompletionItems = getQuestCompletionItems(questKey);
|
||||||
logger.debug(`quest completion items`, questCompletionItems);
|
logger.debug(`quest completion items`, questCompletionItems);
|
||||||
if (questCompletionItems) {
|
if (questCompletionItems) {
|
||||||
await addItems(inventory, questCompletionItems);
|
await addItems(inventory, questCompletionItems, inventoryChanges);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inventory.ActiveQuest == questKey) inventory.ActiveQuest = "";
|
if (inventory.ActiveQuest == questKey) inventory.ActiveQuest = "";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user