2024-05-21 17:59:04 +00:00
|
|
|
import { ILogger } from "@spt/models/spt/utils/ILogger";
|
|
|
|
import { RandomUtil } from "@spt/utils/RandomUtil";
|
2024-07-23 11:12:53 -04:00
|
|
|
import { inject, injectable } from "tsyringe";
|
2023-03-03 15:23:46 +00:00
|
|
|
|
|
|
|
@injectable()
|
2024-07-23 11:12:53 -04:00
|
|
|
export class ProbabilityHelper {
|
2023-03-03 15:23:46 +00:00
|
|
|
constructor(
|
2024-05-28 14:04:20 +00:00
|
|
|
@inject("PrimaryLogger") protected logger: ILogger,
|
2023-11-15 20:35:05 -05:00
|
|
|
@inject("RandomUtil") protected randomUtil: RandomUtil,
|
2024-07-23 11:12:53 -04:00
|
|
|
) {}
|
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
|
|
|
|
*/
|
2024-07-23 11:12:53 -04:00
|
|
|
public rollChance(chance: number, scale = 1): boolean {
|
2024-05-07 23:57:08 -04:00
|
|
|
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
|
|
|
}
|