Server/project/src/helpers/ProbabilityHelper.ts

22 lines
723 B
TypeScript
Raw Normal View History

import { ILogger } from "@spt/models/spt/utils/ILogger";
import { RandomUtil } from "@spt/utils/RandomUtil";
import { inject, injectable } from "tsyringe";
2023-03-03 15:23:46 +00:00
@injectable()
export class ProbabilityHelper {
2023-03-03 15:23:46 +00:00
constructor(
@inject("PrimaryLogger") protected logger: ILogger,
2023-11-15 20:35:05 -05:00
@inject("RandomUtil") protected randomUtil: RandomUtil,
) {}
2023-03-03 15:23:46 +00:00
/**
* 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;
2023-03-03 15:23:46 +00:00
}
2023-11-15 20:35:05 -05:00
}