2024-05-21 17:59:04 +00:00
|
|
|
import { IPmcData } from "@spt/models/eft/common/IPmcData";
|
|
|
|
import { ILogger } from "@spt/models/spt/utils/ILogger";
|
2024-05-29 15:15:45 +01:00
|
|
|
import { DatabaseService } from "@spt/services/DatabaseService";
|
2024-05-21 17:59:04 +00:00
|
|
|
import { LocalisationService } from "@spt/services/LocalisationService";
|
|
|
|
import { TimeUtil } from "@spt/utils/TimeUtil";
|
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 PlayerService {
|
2023-03-03 15:23:46 +00:00
|
|
|
constructor(
|
2024-05-28 14:04:20 +00:00
|
|
|
@inject("PrimaryLogger") protected logger: ILogger,
|
2023-07-13 10:26:47 +01:00
|
|
|
@inject("TimeUtil") protected timeUtil: TimeUtil,
|
2023-03-03 15:23:46 +00:00
|
|
|
@inject("LocalisationService") protected localisationService: LocalisationService,
|
2024-05-29 15:15:45 +01:00
|
|
|
@inject("DatabaseService") protected databaseService: DatabaseService,
|
2024-07-23 11:12:53 -04:00
|
|
|
) {}
|
2023-03-03 15:23:46 +00:00
|
|
|
|
|
|
|
/**
|
2023-07-13 10:26:47 +01:00
|
|
|
* Get level of player
|
|
|
|
* @param pmcData Player profile
|
|
|
|
* @returns Level of player
|
2023-03-03 15:23:46 +00:00
|
|
|
*/
|
2024-07-23 11:12:53 -04:00
|
|
|
public calculateLevel(pmcData: IPmcData): number {
|
2023-11-04 14:53:08 +00:00
|
|
|
let accExp = 0;
|
2023-03-03 15:23:46 +00:00
|
|
|
|
2024-07-23 11:12:53 -04:00
|
|
|
for (const [level, { exp }] of this.databaseService.getGlobals().config.exp.level.exp_table.entries()) {
|
2023-11-04 14:53:08 +00:00
|
|
|
accExp += exp;
|
|
|
|
|
2024-07-23 11:12:53 -04:00
|
|
|
if (pmcData.Info.Experience < accExp) {
|
2023-03-03 15:23:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-11-04 14:53:08 +00:00
|
|
|
pmcData.Info.Level = level + 1;
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return pmcData.Info.Level;
|
|
|
|
}
|
2023-11-04 14:53:08 +00:00
|
|
|
}
|