feat: implement purchasing of blueprints & gear items (#208)
This commit is contained in:
		
							parent
							
								
									b79d0034e7
								
							
						
					
					
						commit
						b9c7daf4f6
					
				@ -12,7 +12,8 @@ import {
 | 
				
			|||||||
    IInventoryDatabaseDocument,
 | 
					    IInventoryDatabaseDocument,
 | 
				
			||||||
    IMiscItem,
 | 
					    IMiscItem,
 | 
				
			||||||
    IMission,
 | 
					    IMission,
 | 
				
			||||||
    IRawUpgrade
 | 
					    IRawUpgrade,
 | 
				
			||||||
 | 
					    ITypeCount
 | 
				
			||||||
} from "@/src/types/inventoryTypes/inventoryTypes";
 | 
					} from "@/src/types/inventoryTypes/inventoryTypes";
 | 
				
			||||||
import { IGenericUpdate } from "../types/genericUpdate";
 | 
					import { IGenericUpdate } from "../types/genericUpdate";
 | 
				
			||||||
import { IArtifactsRequest, IMissionInventoryUpdateRequest, IThemeUpdateRequest } from "../types/requestTypes";
 | 
					import { IArtifactsRequest, IMissionInventoryUpdateRequest, IThemeUpdateRequest } from "../types/requestTypes";
 | 
				
			||||||
@ -245,7 +246,7 @@ export const addMiscItems = (inventory: IInventoryDatabaseDocument, itemsArray:
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const addConsumables = (inventory: IInventoryDatabaseDocument, itemsArray: IConsumable[] | undefined) => {
 | 
					export const addConsumables = (inventory: IInventoryDatabaseDocument, itemsArray: IConsumable[] | undefined) => {
 | 
				
			||||||
    const { Consumables } = inventory;
 | 
					    const { Consumables } = inventory;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    itemsArray?.forEach(({ ItemCount, ItemType }) => {
 | 
					    itemsArray?.forEach(({ ItemCount, ItemType }) => {
 | 
				
			||||||
@ -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;
 | 
					    const { Recipes } = inventory;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    itemsArray?.forEach(({ ItemCount, ItemType }) => {
 | 
					    itemsArray?.forEach(({ ItemCount, ItemType }) => {
 | 
				
			||||||
 | 
				
			|||||||
@ -3,17 +3,19 @@ import { getWeaponType } from "@/src/services/itemDataService";
 | 
				
			|||||||
import { getSubstringFromKeyword } from "@/src/helpers/stringHelpers";
 | 
					import { getSubstringFromKeyword } from "@/src/helpers/stringHelpers";
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
    addBooster,
 | 
					    addBooster,
 | 
				
			||||||
 | 
					    addConsumables,
 | 
				
			||||||
    addCustomization,
 | 
					    addCustomization,
 | 
				
			||||||
    addMechSuit,
 | 
					    addMechSuit,
 | 
				
			||||||
    addMiscItems,
 | 
					    addMiscItems,
 | 
				
			||||||
    addPowerSuit,
 | 
					    addPowerSuit,
 | 
				
			||||||
 | 
					    addRecipes,
 | 
				
			||||||
    addSentinel,
 | 
					    addSentinel,
 | 
				
			||||||
    addWeapon,
 | 
					    addWeapon,
 | 
				
			||||||
    getInventory,
 | 
					    getInventory,
 | 
				
			||||||
    updateCurrency,
 | 
					    updateCurrency,
 | 
				
			||||||
    updateSlots
 | 
					    updateSlots
 | 
				
			||||||
} from "@/src/services/inventoryService";
 | 
					} from "@/src/services/inventoryService";
 | 
				
			||||||
import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
					import { IConsumable, IMiscItem, ITypeCount } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
				
			||||||
import { IPurchaseRequest, IPurchaseResponse, SlotNameToInventoryName, SlotPurchase } from "@/src/types/purchaseTypes";
 | 
					import { IPurchaseRequest, IPurchaseResponse, SlotNameToInventoryName, SlotPurchase } from "@/src/types/purchaseTypes";
 | 
				
			||||||
import { logger } from "@/src/utils/logger";
 | 
					import { logger } from "@/src/utils/logger";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -180,14 +182,18 @@ const handleTypesPurchase = async (typesName: string, accountId: string, quantit
 | 
				
			|||||||
        case "AvatarImages":
 | 
					        case "AvatarImages":
 | 
				
			||||||
        case "SuitCustomizations":
 | 
					        case "SuitCustomizations":
 | 
				
			||||||
            return await handleCustomizationPurchase(typesName, accountId);
 | 
					            return await handleCustomizationPurchase(typesName, accountId);
 | 
				
			||||||
        // case "Recipes":
 | 
					 | 
				
			||||||
        //     break;
 | 
					 | 
				
			||||||
        case "Sentinels":
 | 
					        case "Sentinels":
 | 
				
			||||||
            return await handleSentinelPurchase(typesName, accountId);
 | 
					            return await handleSentinelPurchase(typesName, accountId);
 | 
				
			||||||
        case "SlotItems":
 | 
					        case "SlotItems":
 | 
				
			||||||
            return await handleSlotPurchase(typesName, accountId);
 | 
					            return await handleSlotPurchase(typesName, accountId);
 | 
				
			||||||
        case "Items":
 | 
					        case "Items":
 | 
				
			||||||
            return await handleMiscItemPurchase(typesName, accountId, quantity);
 | 
					            return await handleMiscItemPurchase(typesName, accountId, quantity);
 | 
				
			||||||
 | 
					        case "Recipes":
 | 
				
			||||||
 | 
					        case "Consumables": // Blueprints for Ciphers, Antitoxins
 | 
				
			||||||
 | 
					            return await handleRecipesPurchase(typesName, accountId, quantity);
 | 
				
			||||||
 | 
					        case "Restoratives": // Codex Scanner, Remote Observer, Starburst
 | 
				
			||||||
 | 
					            return await handleRestorativesPurchase(typesName, accountId, quantity);
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
        default:
 | 
					        default:
 | 
				
			||||||
            throw new Error(`unknown Types category: ${typeCategory} not implemented or new`);
 | 
					            throw new Error(`unknown Types category: ${typeCategory} not implemented or new`);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -258,3 +264,37 @@ 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
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const handleRestorativesPurchase = async (uniqueName: string, accountId: string, quantity: number) => {
 | 
				
			||||||
 | 
					    const inventory = await getInventory(accountId);
 | 
				
			||||||
 | 
					    const consumablesChanges = [
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            ItemType: uniqueName,
 | 
				
			||||||
 | 
					            ItemCount: quantity
 | 
				
			||||||
 | 
					        } satisfies IConsumable
 | 
				
			||||||
 | 
					    ];
 | 
				
			||||||
 | 
					    addConsumables(inventory, consumablesChanges);
 | 
				
			||||||
 | 
					    await inventory.save();
 | 
				
			||||||
 | 
					    return {
 | 
				
			||||||
 | 
					        InventoryChanges: {
 | 
				
			||||||
 | 
					            Consumables: consumablesChanges
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user