diff --git a/package-lock.json b/package-lock.json index 8bceb7d8..10a9d206 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "copyfiles": "^2.4.1", "express": "^5.0.0-beta.3", "mongoose": "^8.1.1", - "warframe-public-export-plus": "^0.4.0", + "warframe-public-export-plus": "^0.4.1", "warframe-riven-info": "^0.1.0", "winston": "^3.11.0", "winston-daily-rotate-file": "^4.7.1" @@ -3669,9 +3669,9 @@ } }, "node_modules/warframe-public-export-plus": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.4.0.tgz", - "integrity": "sha512-8wOkh9dET4IHmHDSZ8g8RW0GlfEevHnBwEETAqy3jRhwssyF0TgQsOOpJVuhcPKedCYeudR92HJ3JoXoiTCr6A==" + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.4.1.tgz", + "integrity": "sha512-5SwnT/K/rMI0zJpdodzeEPlO/UnMlHiKv8NZGH647/5u52LZf8xfOpJHP4/yr/anjVVzDQJwY5K3CmbX0uMQdw==" }, "node_modules/warframe-riven-info": { "version": "0.1.0", diff --git a/package.json b/package.json index 522d03c4..a9ec3478 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "copyfiles": "^2.4.1", "express": "^5.0.0-beta.3", "mongoose": "^8.1.1", - "warframe-public-export-plus": "^0.4.0", + "warframe-public-export-plus": "^0.4.1", "warframe-riven-info": "^0.1.0", "winston": "^3.11.0", "winston-daily-rotate-file": "^4.7.1" diff --git a/src/services/inventoryService.ts b/src/services/inventoryService.ts index 47da3893..74e1bba0 100644 --- a/src/services/inventoryService.ts +++ b/src/services/inventoryService.ts @@ -27,9 +27,16 @@ import { } from "../types/requestTypes"; import { logger } from "@/src/utils/logger"; import { getWeaponType, getExalted } from "@/src/services/itemDataService"; +import { getRandomWeightedReward } from "@/src/services/rngService"; import { ISyndicateSacrifice, ISyndicateSacrificeResponse } from "../types/syndicateTypes"; import { IEquipmentClient } from "../types/inventoryTypes/commonInventoryTypes"; -import { ExportCustoms, ExportFlavour, ExportRecipes, ExportResources } from "warframe-public-export-plus"; +import { + ExportBoosterPacks, + ExportCustoms, + ExportFlavour, + ExportRecipes, + ExportResources +} from "warframe-public-export-plus"; export const createInventory = async ( accountOwnerId: Types.ObjectId, @@ -146,6 +153,21 @@ export const addItem = async ( } }; } + if (typeName in ExportBoosterPacks) { + const pack = ExportBoosterPacks[typeName]; + const InventoryChanges = {}; + for (const weights of pack.rarityWeightsPerRoll) { + const result = getRandomWeightedReward(pack.components, weights); + if (result) { + logger.debug(`booster pack rolled`, result); + combineInventoryChanges( + InventoryChanges, + (await addItem(accountId, result.type, result.itemCount)).InventoryChanges + ); + } + } + return { InventoryChanges }; + } // Path-based duck typing switch (typeName.substr(1).split("/")[1]) { diff --git a/src/services/rngService.ts b/src/services/rngService.ts index 9619d7eb..fad3a4ff 100644 --- a/src/services/rngService.ts +++ b/src/services/rngService.ts @@ -1,6 +1,8 @@ +import { TRarity } from "warframe-public-export-plus"; + export interface IRngResult { - type: string; - itemCount: number; + type: string; + itemCount: number; probability: number; } @@ -19,3 +21,22 @@ export const getRandomReward = (pool: IRngResult[]): IRngResult | undefined => { } throw new Error("What the fuck?"); }; + +export const getRandomWeightedReward = ( + pool: { Item: string; Rarity: TRarity }[], + weights: Record +): IRngResult | undefined => { + const resultPool: IRngResult[] = []; + const rarityCounts: Record = { COMMON: 0, UNCOMMON: 0, RARE: 0, LEGENDARY: 0 }; + for (const entry of pool) { + ++rarityCounts[entry.Rarity]; + } + for (const entry of pool) { + resultPool.push({ + type: entry.Item, + itemCount: 1, + probability: weights[entry.Rarity] / rarityCounts[entry.Rarity] + }); + } + return getRandomReward(resultPool); +};