0
0
mirror of https://github.com/sp-tarkov/server.git synced 2025-02-13 09:50:43 -05:00
server/project/src/services/PlayerService.ts
Alex aee391ec1d Null checks first pass (!353)
Co-authored-by: clodan <clodan@clodan.com>
Reviewed-on: SPT/Server#353
2024-05-27 16:05:16 +00:00

43 lines
1.2 KiB
TypeScript

import { inject, injectable } from "tsyringe";
import { IPmcData } from "@spt/models/eft/common/IPmcData";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { DatabaseServer } from "@spt/servers/DatabaseServer";
import { LocalisationService } from "@spt/services/LocalisationService";
import { TimeUtil } from "@spt/utils/TimeUtil";
@injectable()
export class PlayerService
{
constructor(
@inject("WinstonLogger") protected logger: ILogger,
@inject("TimeUtil") protected timeUtil: TimeUtil,
@inject("LocalisationService") protected localisationService: LocalisationService,
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
)
{}
/**
* Get level of player
* @param pmcData Player profile
* @returns Level of player
*/
public calculateLevel(pmcData: IPmcData): number
{
let accExp = 0;
for (const [level, { exp }] of this.databaseServer.getTables().globals!.config.exp.level.exp_table.entries())
{
accExp += exp;
if (pmcData.Info.Experience < accExp)
{
break;
}
pmcData.Info.Level = level + 1;
}
return pmcData.Info.Level;
}
}