7a16c7e998
Item crafting: HideoutManagement skillpoints give Intellect skillpoints given Examining item: Intellect given Repairing weapon/armor Intellect given Cleanup of hideouthelper + reordering of functions Flagged rewardSkillPoints() as dupe of PlayerService.incrementSkillLevel() Flagged incrementSkillLevel() as dupe of QuestHelper.rewardsSkillPoints() Need to decide which one wins Added nullguards to incrementSkillLevel() + added optional multiplication by global skillprogression rate Made it update last access timestamp
78 lines
2.6 KiB
TypeScript
78 lines
2.6 KiB
TypeScript
import { inject, injectable } from "tsyringe";
|
|
|
|
import { IPmcData } from "../models/eft/common/IPmcData";
|
|
import { ILogger } from "../models/spt/utils/ILogger";
|
|
import { DatabaseServer } from "../servers/DatabaseServer";
|
|
import { TimeUtil } from "../utils/TimeUtil";
|
|
import { LocalisationService } from "./LocalisationService";
|
|
|
|
@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
|
|
)
|
|
{ }
|
|
|
|
/**
|
|
* Dupe of QuestHelper.rewardsSkillPoints()
|
|
* Add xp to a player skill
|
|
* @param pmcData Player profile
|
|
* @param skillName Name of skill to increment
|
|
* @param amount Amount of skill points to add to skill
|
|
* @param useSkillProgressRateMultipler Skills are multiplied by a value in globals, default is off to maintain compatibility with legacy code
|
|
*/
|
|
public incrementSkillLevel(pmcData: IPmcData, skillName: string, amount: number, useSkillProgressRateMultipler = false): void
|
|
{
|
|
if (!amount || amount < 0)
|
|
{
|
|
this.logger.error(this.localisationService.getText("player-attempt_to_increment_skill_with_negative_value", skillName));
|
|
return;
|
|
}
|
|
|
|
const profileSkill = pmcData.Skills.Common.find(skill => skill.Id === skillName);
|
|
if (!profileSkill)
|
|
{
|
|
this.logger.error(this.localisationService.getText("quest-no_skill_found", skillName));
|
|
|
|
return;
|
|
}
|
|
|
|
if (useSkillProgressRateMultipler)
|
|
{
|
|
const globals = this.databaseServer.getTables().globals;
|
|
const skillProgressRate = globals.config.SkillsSettings.SkillProgressRate;
|
|
amount = skillProgressRate * amount;
|
|
}
|
|
|
|
profileSkill.Progress += amount;
|
|
profileSkill.LastAccess = this.timeUtil.getTimestamp();
|
|
}
|
|
|
|
/**
|
|
* Get level of player
|
|
* @param pmcData Player profile
|
|
* @returns Level of player
|
|
*/
|
|
public calculateLevel(pmcData: IPmcData): number
|
|
{
|
|
let exp = 0;
|
|
|
|
for (const level in this.databaseServer.getTables().globals.config.exp.level.exp_table)
|
|
{
|
|
if (pmcData.Info.Experience < exp)
|
|
{
|
|
break;
|
|
}
|
|
|
|
pmcData.Info.Level = parseInt(level);
|
|
exp += this.databaseServer.getTables().globals.config.exp.level.exp_table[level].exp;
|
|
}
|
|
|
|
return pmcData.Info.Level;
|
|
}
|
|
} |