Centralise getting a skill from a player profile into one location profileHelper.getSkillFromProfile()

This commit is contained in:
Dev 2023-11-07 15:17:38 +00:00
parent d10c226db0
commit 203ef0c011
6 changed files with 32 additions and 35 deletions

View File

@ -18,6 +18,7 @@ import { IServerDetails } from "@spt-aki/models/eft/game/IServerDetails";
import { IAkiProfile } from "@spt-aki/models/eft/profile/IAkiProfile";
import { AccountTypes } from "@spt-aki/models/enums/AccountTypes";
import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes";
import { SkillTypes } from "@spt-aki/models/enums/SkillTypes";
import { Traders } from "@spt-aki/models/enums/Traders";
import { ICoreConfig } from "@spt-aki/models/spt/config/ICoreConfig";
import { IHttpConfig } from "@spt-aki/models/spt/config/IHttpConfig";
@ -472,7 +473,7 @@ export class GameController
*/
protected warnOnActiveBotReloadSkill(pmcProfile: IPmcData): void
{
const botReloadSkill = pmcProfile.Skills.Common.find(x => x.Id === "BotReload");
const botReloadSkill = this.profileHelper.getSkillFromProfile(pmcProfile, SkillTypes.BOT_RELOAD);
if (botReloadSkill?.Progress > 0)
{
this.logger.warning(this.localisationService.getText("server_start_player_active_botreload_skill"));

View File

@ -3,7 +3,7 @@ import { inject, injectable } from "tsyringe";
import { InventoryHelper } from "@spt-aki/helpers/InventoryHelper";
import { ProfileHelper } from "@spt-aki/helpers/ProfileHelper";
import { IPmcData } from "@spt-aki/models/eft/common/IPmcData";
import { Common, HideoutArea, IHideoutImprovement, Production, Productive } from "@spt-aki/models/eft/common/tables/IBotBase";
import { HideoutArea, IHideoutImprovement, Production, Productive } from "@spt-aki/models/eft/common/tables/IBotBase";
import { Upd } from "@spt-aki/models/eft/common/tables/IItem";
import { StageBonus } from "@spt-aki/models/eft/hideout/IHideoutArea";
import { IHideoutContinuousProductionStartRequestData } from "@spt-aki/models/eft/hideout/IHideoutContinuousProductionStartRequestData";
@ -800,16 +800,6 @@ export class HideoutHelper
return productionSlots + (hasManagementSkillSlots ? managementSlotsCount : 0);
}
/**
* Does profile have elite hideout management skill
* @param pmcData Profile to look at
* @returns True if profile has skill
*/
protected hasEliteHideoutManagementSkill(pmcData: IPmcData): boolean
{
return this.getHideoutManagementSkill(pmcData)?.Progress >= 5100; // level 51+
}
/**
* Get a count of bitcoins player miner can hold
*/
@ -818,16 +808,6 @@ export class HideoutHelper
return this.databaseServer.getTables().globals.config.SkillsSettings.HideoutManagement.EliteSlots.BitcoinFarm.Container;
}
/**
* Get the hideout management skill from player profile
* @param pmcData Profile to look at
* @returns Hideout management skill object
*/
protected getHideoutManagementSkill(pmcData: IPmcData): Common
{
return pmcData.Skills.Common.find(x => x.Id === SkillTypes.HIDEOUT_MANAGEMENT);
}
/**
* HideoutManagement skill gives a consumption bonus the higher the level
* 0.5% per level per 1-51, (25.5% at max)
@ -836,7 +816,7 @@ export class HideoutHelper
*/
protected getHideoutManagementConsumptionBonus(pmcData: IPmcData): number
{
const hideoutManagementSkill = this.getHideoutManagementSkill(pmcData);
const hideoutManagementSkill = this.profileHelper.getSkillFromProfile(pmcData, SkillTypes.HIDEOUT_MANAGEMENT);
if (!hideoutManagementSkill)
{
return 0;

View File

@ -2,7 +2,7 @@ import { inject, injectable } from "tsyringe";
import { ItemHelper } from "@spt-aki/helpers/ItemHelper";
import { IPmcData } from "@spt-aki/models/eft/common/IPmcData";
import { CounterKeyValue, Stats } from "@spt-aki/models/eft/common/tables/IBotBase";
import { Common, CounterKeyValue, Stats } from "@spt-aki/models/eft/common/tables/IBotBase";
import { IAkiProfile } from "@spt-aki/models/eft/profile/IAkiProfile";
import { IValidateNicknameRequestData } from "@spt-aki/models/eft/profile/IValidateNicknameRequestData";
import { SkillTypes } from "@spt-aki/models/enums/SkillTypes";
@ -411,4 +411,16 @@ export class ProfileHelper
profileSkill.Progress += pointsToAdd;
profileSkill.LastAccess = this.timeUtil.getTimestamp();
}
public getSkillFromProfile(pmcData: IPmcData, skill: SkillTypes): Common
{
const skillToReturn = pmcData.Skills.Common.find(x => x.Id === skill);
if (!skillToReturn)
{
this.logger.warning(`Profile ${pmcData.sessionId} does not have a skill named: ${skill}`);
return undefined;
}
return skillToReturn;
}
}

View File

@ -818,7 +818,7 @@ export class QuestHelper
let moneyRewardBonus = moneyRewardBonuses.reduce((acc, cur) => acc + cur.value, 0);
// Apply hideout management bonus to money reward (up to 51% bonus)
const hideoutManagementSkill = pmcData.Skills.Common.find(x => x.Id === SkillTypes.HIDEOUT_MANAGEMENT);
const hideoutManagementSkill = this.profileHelper.getSkillFromProfile(pmcData, SkillTypes.HIDEOUT_MANAGEMENT);
if (hideoutManagementSkill)
{
moneyRewardBonus *= (1 + (hideoutManagementSkill.Progress / 10000)); // 5100 becomes 0.51, add 1 to it, 1.51, multiply the moneyreward bonus by it (e.g. 15 x 51)

View File

@ -1,5 +1,7 @@
export enum SkillTypes
{
BOT_RELOAD = "BotReload",
BOT_SOUND = "BotSound",
HIDEOUT_MANAGEMENT = "HideoutManagement",
CRAFTING = "Crafting",
METABOLISM = "Metabolism",

View File

@ -306,7 +306,7 @@ export class RepairService
const globalRepairSettings = globals.config.RepairSettings;
const intellectRepairPointsPerLevel = globals.config.SkillsSettings.Intellect.RepairPointsCostReduction;
const profileIntellectLevel = pmcData.Skills?.Common?.find(s => s.Id === SkillTypes.INTELLECT)?.Progress ?? 0;
const profileIntellectLevel = this.profileHelper.getSkillFromProfile(pmcData, SkillTypes.INTELLECT)?.Progress ?? 0;
const intellectPointReduction = intellectRepairPointsPerLevel * Math.trunc(profileIntellectLevel / 100);
if (isArmor)
@ -448,13 +448,15 @@ export class RepairService
const itemSkillType = this.getItemSkillType(template);
if (!itemSkillType)
{
return false;
}
const commonBuffMinChanceValue = globals.config.SkillsSettings[itemSkillType].BuffSettings.CommonBuffMinChanceValue;
const commonBuffChanceLevelBonus = globals.config.SkillsSettings[itemSkillType].BuffSettings.CommonBuffChanceLevelBonus;
const receivedDurabilityMaxPercent = globals.config.SkillsSettings[itemSkillType].BuffSettings.ReceivedDurabilityMaxPercent;
const commonBuffMinChanceValue = globals.config.SkillsSettings[itemSkillType as string].BuffSettings.CommonBuffMinChanceValue;
const commonBuffChanceLevelBonus = globals.config.SkillsSettings[itemSkillType as string].BuffSettings.CommonBuffChanceLevelBonus;
const receivedDurabilityMaxPercent = globals.config.SkillsSettings[itemSkillType as string].BuffSettings.ReceivedDurabilityMaxPercent;
const skillLevel = Math.trunc((pmcData?.Skills?.Common?.find(s => s.Id === itemSkillType)?.Progress ?? 0) / 100);
const skillLevel = Math.trunc((this.profileHelper.getSkillFromProfile(pmcData, itemSkillType)?.Progress ?? 0) / 100);
const durabilityToRestorePercent = repairDetails.repairPoints / template._props.MaxDurability;
const durabilityMultiplier = this.getDurabilityMultiplier(receivedDurabilityMaxPercent, durabilityToRestorePercent);
@ -474,26 +476,26 @@ export class RepairService
* @param itemTemplate Item to check for skill
* @returns Skill name
*/
protected getItemSkillType(itemTemplate: ITemplateItem): string
protected getItemSkillType(itemTemplate: ITemplateItem): SkillTypes
{
if (this.itemHelper.isOfBaseclass(itemTemplate._id, BaseClasses.ARMOR))
{
if (itemTemplate._props.ArmorType === "Light")
{
return "LightVests";
return SkillTypes.LIGHT_VESTS;
}
else if (itemTemplate._props.ArmorType === "Heavy")
{
return "HeavyVests";
return SkillTypes.HEAVY_VESTS;
}
}
else if (this.itemHelper.isOfBaseclass(itemTemplate._id, BaseClasses.WEAPON))
{
return "WeaponTreatment";
return SkillTypes.WEAPON_TREATMENT;
}
else if (this.itemHelper.isOfBaseclass(itemTemplate._id, BaseClasses.KNIFE))
{
return "Melee";
return SkillTypes.MELEE;
}
return undefined;