Consolodate multiple functions (incrementSkillLevel
, rewardSkillpoints
) that do the same task into one addSkillpointsToPlayer
, make them use enum for skill type instead of string
This commit is contained in:
parent
206509359e
commit
5a60e4dcf0
@ -200,7 +200,7 @@ export class HideoutController
|
||||
}
|
||||
|
||||
// Add Skill Points Per Area Upgrade
|
||||
this.playerService.incrementSkillLevel(pmcData, SkillTypes.HIDEOUT_MANAGEMENT, db.globals.config.SkillsSettings.HideoutManagement.SkillPointsPerAreaUpgrade);
|
||||
this.profileHelper.addSkillPointsToPlayer(pmcData, SkillTypes.HIDEOUT_MANAGEMENT, db.globals.config.SkillsSettings.HideoutManagement.SkillPointsPerAreaUpgrade);
|
||||
|
||||
return output;
|
||||
}
|
||||
@ -723,12 +723,12 @@ export class HideoutController
|
||||
// manager Hideout skill
|
||||
// ? use a configuration variable for the value?
|
||||
const globals = this.databaseServer.getTables().globals;
|
||||
this.playerService.incrementSkillLevel(pmcData, SkillTypes.HIDEOUT_MANAGEMENT, globals.config.SkillsSettings.HideoutManagement.SkillPointsPerCraft, true);
|
||||
this.profileHelper.addSkillPointsToPlayer(pmcData, SkillTypes.HIDEOUT_MANAGEMENT, globals.config.SkillsSettings.HideoutManagement.SkillPointsPerCraft, true);
|
||||
//manager Crafting skill
|
||||
if (craftingExpAmount > 0)
|
||||
{
|
||||
this.playerService.incrementSkillLevel(pmcData, SkillTypes.CRAFTING, craftingExpAmount);
|
||||
this.playerService.incrementSkillLevel(pmcData, SkillTypes.INTELLECT, 0.5 * (Math.round(craftingExpAmount / 15)));
|
||||
this.profileHelper.addSkillPointsToPlayer(pmcData, SkillTypes.CRAFTING, craftingExpAmount);
|
||||
this.profileHelper.addSkillPointsToPlayer(pmcData, SkillTypes.INTELLECT, 0.5 * (Math.round(craftingExpAmount / 15)));
|
||||
}
|
||||
area.lastRecipe = request.recipeId;
|
||||
counterHoursCrafting.value = hoursCrafting;
|
||||
|
@ -599,7 +599,7 @@ export class InventoryController
|
||||
pmcData.Encyclopedia[itemId] = true;
|
||||
|
||||
// TODO: update this with correct calculation using values from globals json
|
||||
this.questHelper.rewardSkillPoints(sessionID, pmcData, SkillTypes.INTELLECT, 0.5);
|
||||
this.profileHelper.addSkillPointsToPlayer(pmcData, SkillTypes.INTELLECT, 0.5);
|
||||
}
|
||||
|
||||
return this.eventOutputHolder.getOutput(sessionID);
|
||||
|
@ -403,7 +403,7 @@ export class HideoutHelper
|
||||
//check unit consumed for increment skill point
|
||||
if (pmcData && Math.floor(pointsConsumed / 10) >= 1)
|
||||
{
|
||||
this.playerService.incrementSkillLevel(pmcData, SkillTypes.HIDEOUT_MANAGEMENT, 1);
|
||||
this.profileHelper.addSkillPointsToPlayer(pmcData, SkillTypes.HIDEOUT_MANAGEMENT, 1);
|
||||
pointsConsumed -= 10;
|
||||
}
|
||||
|
||||
@ -511,7 +511,7 @@ export class HideoutHelper
|
||||
// Check amount of units consumed for possible increment of hideout mgmt skill point
|
||||
if (pmcData && Math.floor(pointsConsumed / 10) >= 1)
|
||||
{
|
||||
this.playerService.incrementSkillLevel(pmcData, SkillTypes.HIDEOUT_MANAGEMENT, 1);
|
||||
this.profileHelper.addSkillPointsToPlayer(pmcData, SkillTypes.HIDEOUT_MANAGEMENT, 1);
|
||||
pointsConsumed -= 10;
|
||||
}
|
||||
|
||||
@ -637,7 +637,7 @@ export class HideoutHelper
|
||||
//check unit consumed for increment skill point
|
||||
if (pmcData && Math.floor(pointsConsumed / 10) >= 1)
|
||||
{
|
||||
this.playerService.incrementSkillLevel(pmcData, SkillTypes.HIDEOUT_MANAGEMENT, 1);
|
||||
this.profileHelper.addSkillPointsToPlayer(pmcData, SkillTypes.HIDEOUT_MANAGEMENT, 1);
|
||||
pointsConsumed -= 10;
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@ import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes";
|
||||
import { MessageType } from "@spt-aki/models/enums/MessageType";
|
||||
import { QuestRewardType } from "@spt-aki/models/enums/QuestRewardType";
|
||||
import { QuestStatus } from "@spt-aki/models/enums/QuestStatus";
|
||||
import { SkillTypes } from "@spt-aki/models/enums/SkillTypes";
|
||||
import { IQuestConfig } from "@spt-aki/models/spt/config/IQuestConfig";
|
||||
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
|
||||
import { EventOutputHolder } from "@spt-aki/routers/EventOutputHolder";
|
||||
@ -127,42 +128,6 @@ export class QuestHelper
|
||||
return after;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase skill points of a skill on player profile
|
||||
* Dupe of PlayerService.incrementSkillLevel()
|
||||
* @param sessionID Session id
|
||||
* @param pmcData Player profile
|
||||
* @param skillName Name of skill to increase skill points of
|
||||
* @param progressAmount Amount of skill points to add to skill
|
||||
*/
|
||||
public rewardSkillPoints(sessionID: string, pmcData: IPmcData, skillName: string, progressAmount: number, scaleToSkillLevel: boolean = false): void
|
||||
{
|
||||
const indexOfSkillToUpdate = pmcData.Skills.Common.findIndex(s => s.Id === skillName);
|
||||
if (indexOfSkillToUpdate === -1)
|
||||
{
|
||||
this.logger.error(this.localisationService.getText("quest-no_skill_found", skillName));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const profileSkill = pmcData.Skills.Common[indexOfSkillToUpdate];
|
||||
if (!profileSkill)
|
||||
{
|
||||
this.logger.error(this.localisationService.getText("quest-no_skill_found", skillName));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Tarkov has special handling of skills under level 9 to scale them to the lower XP requirement
|
||||
if (scaleToSkillLevel)
|
||||
{
|
||||
progressAmount = this.adjustSkillExpForLowLevels(profileSkill, progressAmount);
|
||||
}
|
||||
|
||||
profileSkill.Progress += progressAmount;
|
||||
profileSkill.LastAccess = this.timeUtil.getTimestamp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjust skill experience for low skill levels, mimicing the official client
|
||||
* @param profileSkill the skill experience is being added to
|
||||
@ -771,7 +736,7 @@ export class QuestHelper
|
||||
switch (reward.type)
|
||||
{
|
||||
case QuestRewardType.SKILL:
|
||||
this.rewardSkillPoints(sessionId, pmcData, reward.target, Number(reward.value));
|
||||
this.profileHelper.addSkillPointsToPlayer(pmcData, reward.target as SkillTypes, Number(reward.value));
|
||||
break;
|
||||
case QuestRewardType.EXPERIENCE:
|
||||
this.profileHelper.addExperienceToPmc(sessionId, parseInt(<string>reward.value)); // this must occur first as the output object needs to take the modified profile exp value
|
||||
@ -853,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 === "HideoutManagement");
|
||||
const hideoutManagementSkill = pmcData.Skills.Common.find(x => x.Id === 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)
|
||||
|
@ -18,41 +18,6 @@ export class PlayerService
|
||||
)
|
||||
{ }
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { inject, injectable } from "tsyringe";
|
||||
|
||||
import { ItemHelper } from "@spt-aki/helpers/ItemHelper";
|
||||
import { QuestHelper } from "@spt-aki/helpers/QuestHelper";
|
||||
import { ProfileHelper } from "@spt-aki/helpers/ProfileHelper";
|
||||
import { RepairHelper } from "@spt-aki/helpers/RepairHelper";
|
||||
import { TraderHelper } from "@spt-aki/helpers/TraderHelper";
|
||||
import { WeightedRandomHelper } from "@spt-aki/helpers/WeightedRandomHelper";
|
||||
@ -31,7 +31,7 @@ export class RepairService
|
||||
constructor(
|
||||
@inject("WinstonLogger") protected logger: ILogger,
|
||||
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
|
||||
@inject("QuestHelper") protected questHelper: QuestHelper,
|
||||
@inject("ProfileHelper") protected profileHelper: ProfileHelper,
|
||||
@inject("RandomUtil") protected randomUtil: RandomUtil,
|
||||
@inject("ItemHelper") protected itemHelper: ItemHelper,
|
||||
@inject("TraderHelper") protected traderHelper: TraderHelper,
|
||||
@ -151,7 +151,7 @@ export class RepairService
|
||||
{
|
||||
const skillPoints = this.getWeaponRepairSkillPoints(repairDetails);
|
||||
|
||||
this.questHelper.rewardSkillPoints(sessionId, pmcData, "WeaponTreatment", skillPoints, true);
|
||||
this.profileHelper.addSkillPointsToPlayer(pmcData, SkillTypes.WEAPON_TREATMENT, skillPoints, true);
|
||||
}
|
||||
|
||||
// Handle kit repairs of armor
|
||||
@ -167,10 +167,12 @@ export class RepairService
|
||||
}
|
||||
|
||||
const isHeavyArmor = itemDetails[1]._props.ArmorType === "Heavy";
|
||||
const vestSkillToLevel = (isHeavyArmor) ? "HeavyVests" : "LightVests";
|
||||
const vestSkillToLevel = (isHeavyArmor)
|
||||
? SkillTypes.HEAVY_VESTS
|
||||
: SkillTypes.LIGHT_VESTS;
|
||||
const pointsToAddToVestSkill = repairDetails.repairPoints * this.repairConfig.armorKitSkillPointGainPerRepairPointMultiplier;
|
||||
|
||||
this.questHelper.rewardSkillPoints(sessionId, pmcData, vestSkillToLevel, pointsToAddToVestSkill);
|
||||
this.profileHelper.addSkillPointsToPlayer(pmcData, vestSkillToLevel, pointsToAddToVestSkill);
|
||||
}
|
||||
|
||||
// Handle giving INT to player - differs if using kit/trader and weapon vs armor
|
||||
@ -190,7 +192,7 @@ export class RepairService
|
||||
intellectGainedFromRepair = Math.min(repairDetails.repairAmount / 10, this.repairConfig.maxIntellectGainPerRepair.trader);
|
||||
}
|
||||
|
||||
this.questHelper.rewardSkillPoints(sessionId, pmcData, SkillTypes.INTELLECT, intellectGainedFromRepair);
|
||||
this.profileHelper.addSkillPointsToPlayer(pmcData, SkillTypes.INTELLECT, intellectGainedFromRepair);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user