@allemandi/gacha-engine
Version:
Practical, type-safe toolkit for simulating and understanding gacha rates and rate-ups.
58 lines (55 loc) • 1.69 kB
TypeScript
interface GachaItem {
name: string;
weight: number;
rateUp?: boolean;
}
interface RarityInput {
rarity: string;
items: GachaItem[];
}
/** Weighted mode requires explicit rarityRates */
interface WeightedGachaEngineConfig {
mode: 'weighted';
rarityRates: Record<string, number>;
pools: RarityInput[];
}
/** Flat rate mode does NOT use rarityRates */
interface FlatRateGachaEngineConfig {
mode: 'flatRate';
pools: RarityInput[];
}
type GachaEngineConfig = WeightedGachaEngineConfig | FlatRateGachaEngineConfig;
declare class GachaEngine {
private static readonly SCALE;
private static readonly MAX_SAFE_SCALE;
private mode;
private pools;
private rarityRatesScaled;
private flatRateMap;
private dropRateCacheScaled;
private flatRateRateUpItems;
constructor(config: GachaEngineConfig);
private scaleRarityRates;
private toScaled;
private fromScaled;
private validateConfig;
getItemDropRate(name: string): number;
getCumulativeProbabilityForItem(name: string, rolls: number): number;
getRollsForTargetProbability(name: string, targetProbability: number): number;
getRateUpItems(): string[];
getAllItemDropRates(): {
name: string;
dropRate: number;
rarity: string;
}[];
roll(count?: number): string[];
private selectRarity;
private selectItemFromPool;
getDebugInfo(): {
scale: number;
rarityRatesScaled: Record<string, number>;
rarityRatesFloat: Record<string, number>;
};
}
export { GachaEngine };
export type { FlatRateGachaEngineConfig, GachaEngineConfig, GachaItem, RarityInput, WeightedGachaEngineConfig };