fix: handle bundles being given to addItems
All checks were successful
Build / build (20) (push) Successful in 1m1s
Build / build (18) (push) Successful in 1m7s
Build / build (22) (push) Successful in 1m1s
Build / build (18) (pull_request) Successful in 1m4s
Build / build (20) (pull_request) Successful in 1m2s
Build / build (22) (pull_request) Successful in 1m2s

This is needed for the Hex noggles email attachment
This commit is contained in:
Sainan 2025-02-25 03:43:20 +01:00
parent 421164986a
commit cea0f25b79
2 changed files with 33 additions and 16 deletions

View File

@ -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 = [

View File

@ -199,6 +199,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,
@ -211,22 +236,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", "");