Server/project/src/helpers/ProbabilityHelper.ts
Refringe 5740774a46
Apply Biome Formatting
This is the result of running `npm run format` which applies the Biome formatting rules. Rejoice!
2024-07-23 11:12:53 -04:00

22 lines
723 B
TypeScript

import { ILogger } from "@spt/models/spt/utils/ILogger";
import { RandomUtil } from "@spt/utils/RandomUtil";
import { inject, injectable } from "tsyringe";
@injectable()
export class ProbabilityHelper {
constructor(
@inject("PrimaryLogger") protected logger: ILogger,
@inject("RandomUtil") protected randomUtil: RandomUtil,
) {}
/**
* Chance to roll a number out of 100
* @param chance Percentage chance roll should success
* @param scale scale of chance to allow support of numbers > 1-100
* @returns true if success
*/
public rollChance(chance: number, scale = 1): boolean {
return this.randomUtil.getInt(1, 100 * scale) / (1 * scale) <= chance;
}
}