fix: handle bundles being given to addItems (#1005)
This is needed for the Hex noggles email attachment Reviewed-on: OpenWF/SpaceNinjaServer#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 { IEquipmentClient, IEquipmentDatabase, IItemConfig } from "../types/inventoryTypes/commonInventoryTypes";
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
    ExportArcanes,
 | 
					    ExportArcanes,
 | 
				
			||||||
 | 
					    ExportBundles,
 | 
				
			||||||
    ExportCustoms,
 | 
					    ExportCustoms,
 | 
				
			||||||
    ExportDrones,
 | 
					    ExportDrones,
 | 
				
			||||||
    ExportFlavour,
 | 
					    ExportFlavour,
 | 
				
			||||||
@ -59,6 +60,7 @@ import { toOid } from "../helpers/inventoryHelpers";
 | 
				
			|||||||
import { generateRewardSeed } from "@/src/controllers/api/getNewRewardSeedController";
 | 
					import { generateRewardSeed } from "@/src/controllers/api/getNewRewardSeedController";
 | 
				
			||||||
import { addStartingGear } from "@/src/controllers/api/giveStartingGearController";
 | 
					import { addStartingGear } from "@/src/controllers/api/giveStartingGearController";
 | 
				
			||||||
import { addQuestKey, completeQuest } from "@/src/services/questService";
 | 
					import { addQuestKey, completeQuest } from "@/src/services/questService";
 | 
				
			||||||
 | 
					import { handleBundleAcqusition } from "./purchaseService";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const createInventory = async (
 | 
					export const createInventory = async (
 | 
				
			||||||
    accountOwnerId: Types.ObjectId,
 | 
					    accountOwnerId: Types.ObjectId,
 | 
				
			||||||
@ -157,6 +159,11 @@ export const addItem = async (
 | 
				
			|||||||
    typeName: string,
 | 
					    typeName: string,
 | 
				
			||||||
    quantity: number = 1
 | 
					    quantity: number = 1
 | 
				
			||||||
): Promise<{ InventoryChanges: IInventoryChanges }> => {
 | 
					): 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
 | 
					    // Strict typing
 | 
				
			||||||
    if (typeName in ExportRecipes) {
 | 
					    if (typeName in ExportRecipes) {
 | 
				
			||||||
        const recipeChanges = [
 | 
					        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 (
 | 
					export const handleStoreItemAcquisition = async (
 | 
				
			||||||
    storeItemName: string,
 | 
					    storeItemName: string,
 | 
				
			||||||
    inventory: TInventoryDatabaseDocument,
 | 
					    inventory: TInventoryDatabaseDocument,
 | 
				
			||||||
@ -212,22 +237,7 @@ export const handleStoreItemAcquisition = async (
 | 
				
			|||||||
    };
 | 
					    };
 | 
				
			||||||
    logger.debug(`handling acquision of ${storeItemName}`);
 | 
					    logger.debug(`handling acquision of ${storeItemName}`);
 | 
				
			||||||
    if (storeItemName in ExportBundles) {
 | 
					    if (storeItemName in ExportBundles) {
 | 
				
			||||||
        const bundle = ExportBundles[storeItemName];
 | 
					        await handleBundleAcqusition(storeItemName, inventory, quantity, purchaseResponse.InventoryChanges);
 | 
				
			||||||
        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
 | 
					 | 
				
			||||||
            );
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        const storeCategory = getStoreItemCategory(storeItemName);
 | 
					        const storeCategory = getStoreItemCategory(storeItemName);
 | 
				
			||||||
        const internalName = storeItemName.replace("/StoreItems", "");
 | 
					        const internalName = storeItemName.replace("/StoreItems", "");
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user