2023-03-03 15:23:46 +00:00
|
|
|
import { inject, injectable } from "tsyringe";
|
|
|
|
|
2023-10-19 17:21:17 +00:00
|
|
|
import { IPmcData } from "@spt-aki/models/eft/common/IPmcData";
|
|
|
|
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
|
|
|
|
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
|
|
|
|
import { LocalisationService } from "@spt-aki/services/LocalisationService";
|
|
|
|
import { TimeUtil } from "@spt-aki/utils/TimeUtil";
|
2023-03-03 15:23:46 +00:00
|
|
|
|
|
|
|
@injectable()
|
|
|
|
export class PlayerService
|
|
|
|
{
|
|
|
|
constructor(
|
|
|
|
@inject("WinstonLogger") 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,
|
2023-11-15 20:35:05 -05:00
|
|
|
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
|
2023-03-03 15:23:46 +00:00
|
|
|
)
|
2023-11-15 20:35:05 -05: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
|
|
|
*/
|
|
|
|
public calculateLevel(pmcData: IPmcData): number
|
|
|
|
{
|
2023-11-04 14:53:08 +00:00
|
|
|
let accExp = 0;
|
2023-03-03 15:23:46 +00:00
|
|
|
|
2023-11-04 14:53:08 +00:00
|
|
|
for (const [level, { exp }] of this.databaseServer.getTables().globals.config.exp.level.exp_table.entries())
|
2023-03-03 15:23:46 +00:00
|
|
|
{
|
2023-11-04 14:53:08 +00:00
|
|
|
accExp += exp;
|
|
|
|
|
|
|
|
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
|
|
|
}
|