From 203ef0c0119658a34c1b76f2737183cbf1b362e2 Mon Sep 17 00:00:00 2001 From: Dev Date: Tue, 7 Nov 2023 15:17:38 +0000 Subject: [PATCH] Centralise getting a skill from a player profile into one location `profileHelper.getSkillFromProfile()` --- project/src/controllers/GameController.ts | 3 ++- project/src/helpers/HideoutHelper.ts | 24 ++--------------------- project/src/helpers/ProfileHelper.ts | 14 ++++++++++++- project/src/helpers/QuestHelper.ts | 2 +- project/src/models/enums/SkillTypes.ts | 2 ++ project/src/services/RepairService.ts | 22 +++++++++++---------- 6 files changed, 32 insertions(+), 35 deletions(-) diff --git a/project/src/controllers/GameController.ts b/project/src/controllers/GameController.ts index 58d410bf..9de0ed41 100644 --- a/project/src/controllers/GameController.ts +++ b/project/src/controllers/GameController.ts @@ -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")); diff --git a/project/src/helpers/HideoutHelper.ts b/project/src/helpers/HideoutHelper.ts index 6a76cb19..dba759df 100644 --- a/project/src/helpers/HideoutHelper.ts +++ b/project/src/helpers/HideoutHelper.ts @@ -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; diff --git a/project/src/helpers/ProfileHelper.ts b/project/src/helpers/ProfileHelper.ts index 79160688..1b06d85a 100644 --- a/project/src/helpers/ProfileHelper.ts +++ b/project/src/helpers/ProfileHelper.ts @@ -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; + } } \ No newline at end of file diff --git a/project/src/helpers/QuestHelper.ts b/project/src/helpers/QuestHelper.ts index 5bc3e932..2ea06add 100644 --- a/project/src/helpers/QuestHelper.ts +++ b/project/src/helpers/QuestHelper.ts @@ -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) diff --git a/project/src/models/enums/SkillTypes.ts b/project/src/models/enums/SkillTypes.ts index b9968d02..6ff377ba 100644 --- a/project/src/models/enums/SkillTypes.ts +++ b/project/src/models/enums/SkillTypes.ts @@ -1,5 +1,7 @@ export enum SkillTypes { + BOT_RELOAD = "BotReload", + BOT_SOUND = "BotSound", HIDEOUT_MANAGEMENT = "HideoutManagement", CRAFTING = "Crafting", METABOLISM = "Metabolism", diff --git a/project/src/services/RepairService.ts b/project/src/services/RepairService.ts index cf1b8ee5..b436400c 100644 --- a/project/src/services/RepairService.ts +++ b/project/src/services/RepairService.ts @@ -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;