feat: Implement claiming & rushing recipes
This commit is contained in:
parent
c6c5979fea
commit
9a8982c440
@ -3,11 +3,11 @@
|
||||
|
||||
import { RequestHandler } from "express";
|
||||
import { logger } from "@/src/utils/logger";
|
||||
import { getItemByBlueprint, getItemCategoryByUniqueName } from "@/src/services/itemDataService";
|
||||
import { getItemByBlueprint } from "@/src/services/itemDataService";
|
||||
import { IOid } from "@/src/types/commonTypes";
|
||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
||||
import { getInventory } from "@/src/services/inventoryService";
|
||||
import { getInventory, updateCurrency, addItem } from "@/src/services/inventoryService";
|
||||
|
||||
export interface IClaimCompletedRecipeRequest {
|
||||
RecipeIds: IOid[];
|
||||
@ -19,12 +19,10 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) =
|
||||
const accountId = await getAccountIdForRequest(req);
|
||||
if (!accountId) throw new Error("no account id");
|
||||
|
||||
console.log(claimCompletedRecipeRequest);
|
||||
const inventory = await getInventory(accountId);
|
||||
const pendingRecipe = inventory.PendingRecipes.find(
|
||||
recipe => recipe._id?.toString() === claimCompletedRecipeRequest.RecipeIds[0].$oid
|
||||
);
|
||||
console.log(pendingRecipe);
|
||||
if (!pendingRecipe) {
|
||||
logger.error(`no pending recipe found with id ${claimCompletedRecipeRequest.RecipeIds[0].$oid}`);
|
||||
throw new Error(`no pending recipe found with id ${claimCompletedRecipeRequest.RecipeIds[0].$oid}`);
|
||||
@ -36,29 +34,28 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) =
|
||||
// throw new Error(`recipe ${pendingRecipe._id} is not ready to be completed`);
|
||||
// }
|
||||
|
||||
//get completed Items
|
||||
const completedItemName = getItemByBlueprint(pendingRecipe.ItemType)?.uniqueName;
|
||||
inventory.PendingRecipes.pull(pendingRecipe._id);
|
||||
await inventory.save();
|
||||
|
||||
if (!completedItemName) {
|
||||
const buildable = getItemByBlueprint(pendingRecipe.ItemType);
|
||||
if (!buildable) {
|
||||
logger.error(`no completed item found for recipe ${pendingRecipe._id}`);
|
||||
throw new Error(`no completed item found for recipe ${pendingRecipe._id}`);
|
||||
}
|
||||
const itemCategory = getItemCategoryByUniqueName(completedItemName) as keyof typeof inventory;
|
||||
console.log(itemCategory);
|
||||
//TODO: remove all Schema.Mixed for inventory[itemCategory] not to be any
|
||||
//add item
|
||||
//inventory[itemCategory].
|
||||
|
||||
//add additional item components like mods or weapons for a sentinel.
|
||||
//const additionalItemComponents = itemComponents[uniqueName]
|
||||
//add these items to inventory
|
||||
//return changes as InventoryChanges
|
||||
|
||||
//remove pending recipe
|
||||
inventory.PendingRecipes.pull(pendingRecipe._id);
|
||||
// await inventory.save();
|
||||
|
||||
logger.debug("Claiming Completed Recipe", { completedItemName });
|
||||
|
||||
res.json({ InventoryChanges: {} });
|
||||
if (req.query.cancel) {
|
||||
// TODO: Refund items
|
||||
res.json({});
|
||||
} else {
|
||||
let currencyChanges = {};
|
||||
if (req.query.rush && buildable.skipBuildTimePrice) {
|
||||
currencyChanges = await updateCurrency(buildable.skipBuildTimePrice, true, accountId);
|
||||
}
|
||||
res.json({
|
||||
InventoryChanges: {
|
||||
...currencyChanges,
|
||||
...(await addItem(accountId, buildable.uniqueName, buildable.buildQuantity)).InventoryChanges
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -125,6 +125,7 @@ export const addItem = async (
|
||||
}
|
||||
};
|
||||
case "Sentinels":
|
||||
// TOOD: Sentinels should also grant their DefaultUpgrades & SentinelWeapon.
|
||||
const sentinel = await addSentinel(typeName, accountId);
|
||||
await updateSlots(accountId, "SentinelBin", 0, 1);
|
||||
return {
|
||||
|
Loading…
x
Reference in New Issue
Block a user