fix: not being able to purchase boosters (#316)

This commit is contained in:
Sainan 2024-06-17 16:38:26 +02:00 committed by GitHub
parent 92e12a6d03
commit 77c2761a97
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 18 deletions

8
package-lock.json generated
View File

@ -13,7 +13,7 @@
"express": "^5.0.0-beta.3", "express": "^5.0.0-beta.3",
"mongoose": "^8.1.1", "mongoose": "^8.1.1",
"warframe-items": "^1.1262.74", "warframe-items": "^1.1262.74",
"warframe-public-export-plus": "^0.2.3", "warframe-public-export-plus": "^0.2.4",
"warframe-riven-info": "^0.1.0", "warframe-riven-info": "^0.1.0",
"winston": "^3.11.0", "winston": "^3.11.0",
"winston-daily-rotate-file": "^4.7.1" "winston-daily-rotate-file": "^4.7.1"
@ -3909,9 +3909,9 @@
} }
}, },
"node_modules/warframe-public-export-plus": { "node_modules/warframe-public-export-plus": {
"version": "0.2.3", "version": "0.2.4",
"resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.2.3.tgz", "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.2.4.tgz",
"integrity": "sha512-Bl4gb3f1LIdGXLEOJg2XTIFYqrialdTIvVhDqDzVJIRfii0PKsy9jsr9vqM14tWz7oVpQMeCUyvisDkkXijTSg==" "integrity": "sha512-Kh2+4p0qirTNUfHLr/nUJ1y/kH9mKnig28dwgpPaWt41ZfGzA+/qrpqI3DHYUvpd4wTCii/HItIy6tZtpTsy4Q=="
}, },
"node_modules/warframe-riven-info": { "node_modules/warframe-riven-info": {
"version": "0.1.0", "version": "0.1.0",

View File

@ -17,7 +17,7 @@
"express": "^5.0.0-beta.3", "express": "^5.0.0-beta.3",
"mongoose": "^8.1.1", "mongoose": "^8.1.1",
"warframe-items": "^1.1262.74", "warframe-items": "^1.1262.74",
"warframe-public-export-plus": "^0.2.3", "warframe-public-export-plus": "^0.2.4",
"warframe-riven-info": "^0.1.0", "warframe-riven-info": "^0.1.0",
"winston": "^3.11.0", "winston": "^3.11.0",
"winston-daily-rotate-file": "^4.7.1" "winston-daily-rotate-file": "^4.7.1"

View File

@ -3,7 +3,7 @@ import { getSubstringFromKeyword } from "@/src/helpers/stringHelpers";
import { addItem, addBooster, updateCurrency, updateSlots } from "@/src/services/inventoryService"; import { addItem, addBooster, updateCurrency, updateSlots } from "@/src/services/inventoryService";
import { IPurchaseRequest, SlotPurchase } from "@/src/types/purchaseTypes"; import { IPurchaseRequest, SlotPurchase } from "@/src/types/purchaseTypes";
import { logger } from "@/src/utils/logger"; import { logger } from "@/src/utils/logger";
import { ExportBundles } from "warframe-public-export-plus"; import { ExportBundles, TRarity } from "warframe-public-export-plus";
export const getStoreItemCategory = (storeItem: string) => { export const getStoreItemCategory = (storeItem: string) => {
const storeItemString = getSubstringFromKeyword(storeItem, "StoreItems/"); const storeItemString = getSubstringFromKeyword(storeItem, "StoreItems/");
@ -26,7 +26,8 @@ export const handlePurchase = async (purchaseRequest: IPurchaseRequest, accountI
const purchaseResponse = await handleStoreItemAcquisition( const purchaseResponse = await handleStoreItemAcquisition(
purchaseRequest.PurchaseParams.StoreItem, purchaseRequest.PurchaseParams.StoreItem,
accountId, accountId,
purchaseRequest.PurchaseParams.Quantity purchaseRequest.PurchaseParams.Quantity,
"COMMON"
); );
if (!purchaseResponse) throw new Error("purchase response was undefined"); if (!purchaseResponse) throw new Error("purchase response was undefined");
@ -48,7 +49,8 @@ export const handlePurchase = async (purchaseRequest: IPurchaseRequest, accountI
const handleStoreItemAcquisition = async ( const handleStoreItemAcquisition = async (
storeItemName: string, storeItemName: string,
accountId: string, accountId: string,
quantity: number quantity: number,
durability: TRarity
): Promise<{ InventoryChanges: object }> => { ): Promise<{ InventoryChanges: object }> => {
let purchaseResponse = { let purchaseResponse = {
InventoryChanges: {} InventoryChanges: {}
@ -60,7 +62,12 @@ const handleStoreItemAcquisition = async (
for (const component of bundle.components) { for (const component of bundle.components) {
purchaseResponse = { purchaseResponse = {
...purchaseResponse, ...purchaseResponse,
...(await handleStoreItemAcquisition(component.typeName, accountId, component.purchaseQuantity)) ...(await handleStoreItemAcquisition(
component.typeName,
accountId,
component.purchaseQuantity,
component.durability
))
}; };
} }
} else { } else {
@ -75,7 +82,7 @@ const handleStoreItemAcquisition = async (
purchaseResponse = await handleTypesPurchase(internalName, accountId, quantity); purchaseResponse = await handleTypesPurchase(internalName, accountId, quantity);
break; break;
case "Boosters": case "Boosters":
purchaseResponse = await handleBoostersPurchase(internalName, accountId); purchaseResponse = await handleBoostersPurchase(internalName, accountId, durability);
break; break;
} }
} }
@ -144,17 +151,21 @@ const boosterCollection = [
"/Lotus/Types/Boosters/CreditBooster" "/Lotus/Types/Boosters/CreditBooster"
]; ];
const handleBoostersPurchase = async (boosterStoreName: string, accountId: string) => { const boosterDuration: Record<TRarity, number> = {
const match = boosterStoreName.match(/(\d+)Day/); COMMON: 3 * 86400,
if (!match) { UNCOMMON: 7 * 86400,
RARE: 30 * 86400,
LEGENDARY: 90 * 86400
};
const handleBoostersPurchase = async (boosterStoreName: string, accountId: string, durability: TRarity) => {
const ItemType = boosterStoreName.replace("StoreItem", "");
if (!boosterCollection.find(x => x == ItemType)) {
logger.error(`unknown booster type: ${ItemType}`);
return { InventoryChanges: {} }; return { InventoryChanges: {} };
} }
const extractedDigit = Number(match[1]); const ExpiryDate = boosterDuration[durability];
const ItemType = boosterCollection.find(i =>
boosterStoreName.includes(i.split("/").pop()!.replace("Booster", ""))
)!;
const ExpiryDate = extractedDigit * 86400;
await addBooster(ItemType, ExpiryDate, accountId); await addBooster(ItemType, ExpiryDate, accountId);