feat: implement purchasing of blueprints

This commit is contained in:
Sainan 2024-05-09 15:55:35 +02:00
parent b79d0034e7
commit 9d590f4bfc
2 changed files with 25 additions and 5 deletions

View File

@ -12,7 +12,8 @@ import {
IInventoryDatabaseDocument,
IMiscItem,
IMission,
IRawUpgrade
IRawUpgrade,
ITypeCount
} from "@/src/types/inventoryTypes/inventoryTypes";
import { IGenericUpdate } from "../types/genericUpdate";
import { IArtifactsRequest, IMissionInventoryUpdateRequest, IThemeUpdateRequest } from "../types/requestTypes";
@ -260,7 +261,7 @@ const addConsumables = (inventory: IInventoryDatabaseDocument, itemsArray: ICons
});
};
const addRecipes = (inventory: IInventoryDatabaseDocument, itemsArray: IConsumable[] | undefined) => {
export const addRecipes = (inventory: IInventoryDatabaseDocument, itemsArray: ITypeCount[] | undefined) => {
const { Recipes } = inventory;
itemsArray?.forEach(({ ItemCount, ItemType }) => {

View File

@ -7,13 +7,14 @@ import {
addMechSuit,
addMiscItems,
addPowerSuit,
addRecipes,
addSentinel,
addWeapon,
getInventory,
updateCurrency,
updateSlots
} from "@/src/services/inventoryService";
import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
import { IMiscItem, ITypeCount } from "@/src/types/inventoryTypes/inventoryTypes";
import { IPurchaseRequest, IPurchaseResponse, SlotNameToInventoryName, SlotPurchase } from "@/src/types/purchaseTypes";
import { logger } from "@/src/utils/logger";
@ -180,14 +181,15 @@ const handleTypesPurchase = async (typesName: string, accountId: string, quantit
case "AvatarImages":
case "SuitCustomizations":
return await handleCustomizationPurchase(typesName, accountId);
// case "Recipes":
// break;
case "Sentinels":
return await handleSentinelPurchase(typesName, accountId);
case "SlotItems":
return await handleSlotPurchase(typesName, accountId);
case "Items":
return await handleMiscItemPurchase(typesName, accountId, quantity);
case "Recipes":
case "Consumables": // Blueprints for Ciphers, Antitoxins
return await handleRecipesPurchase(typesName, accountId, quantity);
default:
throw new Error(`unknown Types category: ${typeCategory} not implemented or new`);
}
@ -258,3 +260,20 @@ const handleMiscItemPurchase = async (uniqueName: string, accountId: string, qua
}
};
};
const handleRecipesPurchase = async (uniqueName: string, accountId: string, quantity: number) => {
const inventory = await getInventory(accountId);
const recipeChanges = [
{
ItemType: uniqueName,
ItemCount: quantity
} satisfies ITypeCount
];
addRecipes(inventory, recipeChanges);
await inventory.save();
return {
InventoryChanges: {
Recipes: recipeChanges
}
};
};