8727f6150e
Co-authored-by: clodan <clodan@clodan.com> Reviewed-on: https://dev.sp-tarkov.com/SPT/Server/pulls/355 Co-authored-by: Alex <clodan@noreply.dev.sp-tarkov.com> Co-committed-by: Alex <clodan@noreply.dev.sp-tarkov.com>
25 lines
731 B
TypeScript
25 lines
731 B
TypeScript
import { inject, injectable } from "tsyringe";
|
|
import { ILogger } from "@spt/models/spt/utils/ILogger";
|
|
import { RandomUtil } from "@spt/utils/RandomUtil";
|
|
|
|
@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;
|
|
}
|
|
}
|