feat: handle acquisition of booster packs #452
							
								
								
									
										8
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										8
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							@ -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",
 | 
			
		||||
 | 
			
		||||
@ -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"
 | 
			
		||||
 | 
			
		||||
@ -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]) {
 | 
			
		||||
 | 
			
		||||
@ -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<TRarity, number>
 | 
			
		||||
): IRngResult | undefined => {
 | 
			
		||||
    const resultPool: IRngResult[] = [];
 | 
			
		||||
    const rarityCounts: Record<TRarity, number> = { 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);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user