diff --git a/src/controllers/api/inventorySlotsController.ts b/src/controllers/api/inventorySlotsController.ts index ad2165a9..52976e15 100644 --- a/src/controllers/api/inventorySlotsController.ts +++ b/src/controllers/api/inventorySlotsController.ts @@ -27,7 +27,7 @@ export const inventorySlotsController: RequestHandler = async (req, res) => { //TODO: check which slot was purchased because pvpBonus is also possible - const currencyChanges = await updateCurrency(-20, true, accountId); + const currencyChanges = await updateCurrency(20, true, accountId); await updateSlots(accountId, SlotNameToInventoryName.LOADOUT, 1, 1); //console.log({ InventoryChanges: currencyChanges }, " added loadout changes:"); diff --git a/src/services/inventoryService.ts b/src/services/inventoryService.ts index 4f3acc31..611cfd02 100644 --- a/src/services/inventoryService.ts +++ b/src/services/inventoryService.ts @@ -93,15 +93,19 @@ export const updateSlots = async (accountId: string, slotName: SlotNames, slotAm }; export const updateCurrency = async (price: number, usePremium: boolean, accountId: string) => { + if (config.infiniteResources) { + return {}; + } + const inventory = await getInventory(accountId); if (usePremium) { if (inventory.PremiumCreditsFree > 0) { - inventory.PremiumCreditsFree += price; + inventory.PremiumCreditsFree -= Math.min(price, inventory.PremiumCreditsFree); } - inventory.PremiumCredits += price; + inventory.PremiumCredits -= price; } else { - inventory.RegularCredits += price; + inventory.RegularCredits -= price; } const modifiedPaths = inventory.modifiedPaths(); diff --git a/src/services/purchaseService.ts b/src/services/purchaseService.ts index 7865ee00..3a0b78a8 100644 --- a/src/services/purchaseService.ts +++ b/src/services/purchaseService.ts @@ -5,12 +5,15 @@ import { addBooster, addCustomization, addMechSuit, + addMiscItems, addPowerSuit, addSentinel, addWeapon, + getInventory, updateCurrency, updateSlots } from "@/src/services/inventoryService"; +import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes"; import { IPurchaseRequest, IPurchaseResponse, SlotNameToInventoryName, SlotPurchase } from "@/src/types/purchaseTypes"; import { logger } from "@/src/utils/logger"; @@ -44,11 +47,18 @@ export const handlePurchase = async (purchaseRequest: IPurchaseRequest, accountI inventoryChanges = await handleWeaponsPurchase(internalName, accountId); break; case "Types": - inventoryChanges = await handleTypesPurchase(internalName, accountId); + inventoryChanges = await handleTypesPurchase( + internalName, + accountId, + purchaseRequest.PurchaseParams.Quantity + ); break; case "Boosters": inventoryChanges = await handleBoostersPurchase(internalName, accountId); break; + case "Interface": + inventoryChanges = await handleCustomizationPurchase(internalName, accountId); + break; default: const errorMessage = `unknown store category: ${storeCategory} not implemented or new`; logger.error(errorMessage); @@ -163,18 +173,21 @@ const handlePowersuitPurchase = async (powersuitName: string, accountId: string) }; //TODO: change to getInventory, apply changes then save at the end -const handleTypesPurchase = async (typesName: string, accountId: string) => { +const handleTypesPurchase = async (typesName: string, accountId: string, quantity: number) => { const typeCategory = getStoreItemTypesCategory(typesName); logger.debug(`type category ${typeCategory}`); switch (typeCategory) { + case "AvatarImages": case "SuitCustomizations": - return await handleSuitCustomizationsPurchase(typesName, accountId); + 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); default: throw new Error(`unknown Types category: ${typeCategory} not implemented or new`); } @@ -193,7 +206,7 @@ const handleSentinelPurchase = async (sentinelName: string, accountId: string) = }; }; -const handleSuitCustomizationsPurchase = async (customizationName: string, accountId: string) => { +const handleCustomizationPurchase = async (customizationName: string, accountId: string) => { const customization = await addCustomization(customizationName, accountId); return { @@ -228,3 +241,20 @@ const handleBoostersPurchase = async (boosterStoreName: string, accountId: strin } }; }; + +const handleMiscItemPurchase = async (uniqueName: string, accountId: string, quantity: number) => { + const inventory = await getInventory(accountId); + const miscItemChanges = [ + { + ItemType: uniqueName, + ItemCount: quantity + } satisfies IMiscItem + ]; + addMiscItems(inventory, miscItemChanges); + await inventory.save(); + return { + InventoryChanges: { + MiscItems: miscItemChanges + } + }; +};