fix: purchasing an arcane pack does not consume vosfor (#601)

This commit is contained in:
Sainan 2024-12-22 20:35:08 +01:00 committed by GitHub
parent ac09fcec5c
commit 9fd6ed3b21
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 46 additions and 8 deletions

8
package-lock.json generated
View File

@ -12,7 +12,7 @@
"copyfiles": "^2.4.1",
"express": "^5",
"mongoose": "^8.9.2",
"warframe-public-export-plus": "^0.5.8",
"warframe-public-export-plus": "^0.5.9",
"warframe-riven-info": "^0.1.2",
"winston": "^3.17.0",
"winston-daily-rotate-file": "^5.0.0"
@ -3877,9 +3877,9 @@
}
},
"node_modules/warframe-public-export-plus": {
"version": "0.5.8",
"resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.5.8.tgz",
"integrity": "sha512-ZhHrKIkI6nhjKDlxhrNcfN8r2Yc9g+eeKLS6+9w7gzC4NscIt6TU8tH8bfjJTDeo6nRrzt88szX1/Oo3WnUY4Q=="
"version": "0.5.9",
"resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.5.9.tgz",
"integrity": "sha512-qwQVtYI7wghatg7UrJ3CFstXba5Hsks398L6ngv16auqoTVAfw/cLBqFv9DzsEpqvcVWL22IZIH+cNWiq1JXOQ=="
},
"node_modules/warframe-riven-info": {
"version": "0.1.2",

View File

@ -16,7 +16,7 @@
"copyfiles": "^2.4.1",
"express": "^5",
"mongoose": "^8.9.2",
"warframe-public-export-plus": "^0.5.8",
"warframe-public-export-plus": "^0.5.9",
"warframe-riven-info": "^0.1.2",
"winston": "^3.17.0",
"winston-daily-rotate-file": "^5.0.0"

View File

@ -1,15 +1,18 @@
import { parseSlotPurchaseName } from "@/src/helpers/purchaseHelpers";
import { getSubstringFromKeyword } from "@/src/helpers/stringHelpers";
import {
addItem,
addBooster,
addItem,
addMiscItems,
combineInventoryChanges,
getInventory,
updateCurrency,
updateSlots
} from "@/src/services/inventoryService";
import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
import { IPurchaseRequest, SlotPurchase, IInventoryChanges } from "@/src/types/purchaseTypes";
import { logger } from "@/src/utils/logger";
import { ExportBundles, ExportGear, TRarity } from "warframe-public-export-plus";
import { ExportBundles, ExportGear, ExportVendors, TRarity } from "warframe-public-export-plus";
export const getStoreItemCategory = (storeItem: string) => {
const storeItemString = getSubstringFromKeyword(storeItem, "StoreItems/");
@ -43,12 +46,46 @@ export const handlePurchase = async (purchaseRequest: IPurchaseRequest, accountI
purchaseRequest.PurchaseParams.UsePremium,
accountId
);
purchaseResponse.InventoryChanges = {
...currencyChanges,
...purchaseResponse.InventoryChanges
};
switch (purchaseRequest.PurchaseParams.Source) {
case 7:
if (!purchaseRequest.PurchaseParams.SourceId) {
throw new Error("invalid request source");
}
if (ExportVendors[purchaseRequest.PurchaseParams.SourceId]) {
const vendor = ExportVendors[purchaseRequest.PurchaseParams.SourceId];
const offer = vendor.items.find(x => x.storeItem == purchaseRequest.PurchaseParams.StoreItem);
if (offer) {
const inventory = await getInventory(accountId);
for (const item of offer.itemPrices) {
const invItem: IMiscItem = {
ItemType: item.ItemType,
ItemCount: item.ItemCount * -1
};
addMiscItems(inventory, [invItem]);
purchaseResponse.InventoryChanges.MiscItems ??= [];
const change = (purchaseResponse.InventoryChanges.MiscItems as IMiscItem[]).find(
x => x.ItemType == item.ItemType
);
if (change) {
change.ItemCount -= item.ItemCount;
} else {
(purchaseResponse.InventoryChanges.MiscItems as IMiscItem[]).push(invItem);
}
}
await inventory.save();
}
}
break;
}
return purchaseResponse;
};

View File

@ -5,6 +5,7 @@ export interface IPurchaseRequest {
export interface IPurchaseParams {
Source: number;
SourceId?: string; // for Source 7
StoreItem: string;
StorePage: string;
SearchTerm: string;