fix: handle bundles being given to addItems (#1005)
This is needed for the Hex noggles email attachment Reviewed-on: #1005 Co-authored-by: Sainan <sainan@calamity.inc> Co-committed-by: Sainan <sainan@calamity.inc>
This commit is contained in:
parent
4d9e6a35ab
commit
f672f05db9
@ -38,6 +38,7 @@ import { getExalted, getKeyChainItems } from "@/src/services/itemDataService";
|
||||
import { IEquipmentClient, IEquipmentDatabase, IItemConfig } from "../types/inventoryTypes/commonInventoryTypes";
|
||||
import {
|
||||
ExportArcanes,
|
||||
ExportBundles,
|
||||
ExportCustoms,
|
||||
ExportDrones,
|
||||
ExportFlavour,
|
||||
@ -59,6 +60,7 @@ import { toOid } from "../helpers/inventoryHelpers";
|
||||
import { generateRewardSeed } from "@/src/controllers/api/getNewRewardSeedController";
|
||||
import { addStartingGear } from "@/src/controllers/api/giveStartingGearController";
|
||||
import { addQuestKey, completeQuest } from "@/src/services/questService";
|
||||
import { handleBundleAcqusition } from "./purchaseService";
|
||||
|
||||
export const createInventory = async (
|
||||
accountOwnerId: Types.ObjectId,
|
||||
@ -157,6 +159,11 @@ export const addItem = async (
|
||||
typeName: string,
|
||||
quantity: number = 1
|
||||
): Promise<{ InventoryChanges: IInventoryChanges }> => {
|
||||
// Bundles are technically StoreItems but a) they don't have a normal counterpart, and b) they are used in non-StoreItem contexts, e.g. email attachments.
|
||||
if (typeName in ExportBundles) {
|
||||
return { InventoryChanges: await handleBundleAcqusition(typeName, inventory, quantity) };
|
||||
}
|
||||
|
||||
// Strict typing
|
||||
if (typeName in ExportRecipes) {
|
||||
const recipeChanges = [
|
||||
|
@ -200,6 +200,31 @@ const handleItemPrices = (
|
||||
}
|
||||
};
|
||||
|
||||
export const handleBundleAcqusition = async (
|
||||
storeItemName: string,
|
||||
inventory: TInventoryDatabaseDocument,
|
||||
quantity: number = 1,
|
||||
inventoryChanges: IInventoryChanges = {}
|
||||
): Promise<IInventoryChanges> => {
|
||||
const bundle = ExportBundles[storeItemName];
|
||||
logger.debug("acquiring bundle", bundle);
|
||||
for (const component of bundle.components) {
|
||||
combineInventoryChanges(
|
||||
inventoryChanges,
|
||||
(
|
||||
await handleStoreItemAcquisition(
|
||||
component.typeName,
|
||||
inventory,
|
||||
component.purchaseQuantity * quantity,
|
||||
component.durability,
|
||||
true
|
||||
)
|
||||
).InventoryChanges
|
||||
);
|
||||
}
|
||||
return inventoryChanges;
|
||||
};
|
||||
|
||||
export const handleStoreItemAcquisition = async (
|
||||
storeItemName: string,
|
||||
inventory: TInventoryDatabaseDocument,
|
||||
@ -212,22 +237,7 @@ export const handleStoreItemAcquisition = async (
|
||||
};
|
||||
logger.debug(`handling acquision of ${storeItemName}`);
|
||||
if (storeItemName in ExportBundles) {
|
||||
const bundle = ExportBundles[storeItemName];
|
||||
logger.debug("acquiring bundle", bundle);
|
||||
for (const component of bundle.components) {
|
||||
combineInventoryChanges(
|
||||
purchaseResponse.InventoryChanges,
|
||||
(
|
||||
await handleStoreItemAcquisition(
|
||||
component.typeName,
|
||||
inventory,
|
||||
component.purchaseQuantity * quantity,
|
||||
component.durability,
|
||||
true
|
||||
)
|
||||
).InventoryChanges
|
||||
);
|
||||
}
|
||||
await handleBundleAcqusition(storeItemName, inventory, quantity, purchaseResponse.InventoryChanges);
|
||||
} else {
|
||||
const storeCategory = getStoreItemCategory(storeItemName);
|
||||
const internalName = storeItemName.replace("/StoreItems", "");
|
||||
|
Loading…
x
Reference in New Issue
Block a user