From 6eaa1d89599c68f84c54c5df584368f0f8145bcd Mon Sep 17 00:00:00 2001 From: Sainan Date: Sat, 4 May 2024 22:20:00 +0200 Subject: [PATCH 1/7] feat: purchasing glyphs & UI customisations --- src/services/purchaseService.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/services/purchaseService.ts b/src/services/purchaseService.ts index 7865ee00..508cb736 100644 --- a/src/services/purchaseService.ts +++ b/src/services/purchaseService.ts @@ -49,6 +49,9 @@ export const handlePurchase = async (purchaseRequest: IPurchaseRequest, accountI 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); @@ -167,8 +170,9 @@ const handleTypesPurchase = async (typesName: string, accountId: string) => { 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": @@ -193,7 +197,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 { -- 2.47.2 From 32160dfede5ed5987641d4907d8f382bd8150d14 Mon Sep 17 00:00:00 2001 From: Sainan Date: Sat, 4 May 2024 22:17:41 +0200 Subject: [PATCH 2/7] fix: purchases adding currency instead of subtracting --- src/controllers/api/inventorySlotsController.ts | 2 +- src/services/inventoryService.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) 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 43675663..6bfc27a3 100644 --- a/src/services/inventoryService.ts +++ b/src/services/inventoryService.ts @@ -97,11 +97,11 @@ export const updateCurrency = async (price: number, usePremium: boolean, account if (usePremium) { if (inventory.PremiumCreditsFree > 0) { - inventory.PremiumCreditsFree += price; + inventory.PremiumCreditsFree -= price; } - inventory.PremiumCredits += price; + inventory.PremiumCredits -= price; } else { - inventory.RegularCredits += price; + inventory.RegularCredits -= price; } const modifiedPaths = inventory.modifiedPaths(); -- 2.47.2 From 392f63115ec393983161eb99eccf210ff2ba112e Mon Sep 17 00:00:00 2001 From: Sainan Date: Sat, 4 May 2024 22:23:38 +0200 Subject: [PATCH 3/7] fix: PremiumCreditsFree possibly going negative --- src/services/inventoryService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/inventoryService.ts b/src/services/inventoryService.ts index 6bfc27a3..aac5a034 100644 --- a/src/services/inventoryService.ts +++ b/src/services/inventoryService.ts @@ -97,7 +97,7 @@ export const updateCurrency = async (price: number, usePremium: boolean, account if (usePremium) { if (inventory.PremiumCreditsFree > 0) { - inventory.PremiumCreditsFree -= price; + inventory.PremiumCreditsFree -= Math.min(price, inventory.PremiumCreditsFree); } inventory.PremiumCredits -= price; } else { -- 2.47.2 From 6798e09b5077c0138eb58bb93d276fc449862dcb Mon Sep 17 00:00:00 2001 From: Sainan Date: Sun, 5 May 2024 12:09:09 +0200 Subject: [PATCH 4/7] improve: don't update currency when infiniteResources is enabled --- src/services/inventoryService.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/services/inventoryService.ts b/src/services/inventoryService.ts index aac5a034..8e3a9d7a 100644 --- a/src/services/inventoryService.ts +++ b/src/services/inventoryService.ts @@ -93,6 +93,10 @@ 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) { -- 2.47.2 From 19ba136c082e15987b1d51e73fc02c10054d60ba Mon Sep 17 00:00:00 2001 From: Sainan Date: Sun, 5 May 2024 13:52:14 +0200 Subject: [PATCH 5/7] feat: implement purchasing of formas, potatoes, etc. --- src/services/purchaseService.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/services/purchaseService.ts b/src/services/purchaseService.ts index 508cb736..d042afe5 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"; @@ -179,6 +182,8 @@ const handleTypesPurchase = async (typesName: string, accountId: string) => { return await handleSentinelPurchase(typesName, accountId); case "SlotItems": return await handleSlotPurchase(typesName, accountId); + case "Items": + return await handleMiscItemPurchase(typesName, accountId); default: throw new Error(`unknown Types category: ${typeCategory} not implemented or new`); } @@ -232,3 +237,20 @@ const handleBoostersPurchase = async (boosterStoreName: string, accountId: strin } }; }; + +const handleMiscItemPurchase = async (uniqueName: string, accountId: string) => { + const inventory = await getInventory(accountId); + const miscItemChanges = [ + { + ItemType: uniqueName, + ItemCount: 1 + } satisfies IMiscItem + ]; + addMiscItems(inventory, miscItemChanges); + await inventory.save(); + return { + InventoryChanges: { + MiscItems: miscItemChanges + } + }; +}; -- 2.47.2 From a80aa0d0a0f8580e235e53712f039e535d824013 Mon Sep 17 00:00:00 2001 From: Sainan Date: Tue, 7 May 2024 11:49:42 +0200 Subject: [PATCH 6/7] feat: handle MiscItem purchase with quantity > 1 --- src/services/purchaseService.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/services/purchaseService.ts b/src/services/purchaseService.ts index d042afe5..5c02f2ed 100644 --- a/src/services/purchaseService.ts +++ b/src/services/purchaseService.ts @@ -47,7 +47,7 @@ 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); @@ -169,7 +169,7 @@ 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) { @@ -183,7 +183,7 @@ const handleTypesPurchase = async (typesName: string, accountId: string) => { case "SlotItems": return await handleSlotPurchase(typesName, accountId); case "Items": - return await handleMiscItemPurchase(typesName, accountId); + return await handleMiscItemPurchase(typesName, accountId, quantity); default: throw new Error(`unknown Types category: ${typeCategory} not implemented or new`); } @@ -238,12 +238,12 @@ const handleBoostersPurchase = async (boosterStoreName: string, accountId: strin }; }; -const handleMiscItemPurchase = async (uniqueName: string, accountId: string) => { +const handleMiscItemPurchase = async (uniqueName: string, accountId: string, quantity: number) => { const inventory = await getInventory(accountId); const miscItemChanges = [ { ItemType: uniqueName, - ItemCount: 1 + ItemCount: quantity } satisfies IMiscItem ]; addMiscItems(inventory, miscItemChanges); -- 2.47.2 From c86d080c2043b726af860c279797a0bb7b53da75 Mon Sep 17 00:00:00 2001 From: Sainan Date: Tue, 7 May 2024 09:50:04 +0000 Subject: [PATCH 7/7] Apply prettier changes --- src/services/purchaseService.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/services/purchaseService.ts b/src/services/purchaseService.ts index 5c02f2ed..3a0b78a8 100644 --- a/src/services/purchaseService.ts +++ b/src/services/purchaseService.ts @@ -47,7 +47,11 @@ export const handlePurchase = async (purchaseRequest: IPurchaseRequest, accountI inventoryChanges = await handleWeaponsPurchase(internalName, accountId); break; case "Types": - inventoryChanges = await handleTypesPurchase(internalName, accountId, purchaseRequest.PurchaseParams.Quantity); + inventoryChanges = await handleTypesPurchase( + internalName, + accountId, + purchaseRequest.PurchaseParams.Quantity + ); break; case "Boosters": inventoryChanges = await handleBoostersPurchase(internalName, accountId); -- 2.47.2