Refactored how skills are parsed, fixes issues with bot generation and end of raid profile parsing

This commit is contained in:
Chomp
2025-06-08 09:39:14 +01:00
parent 094d83ced5
commit 89106d5448
7 changed files with 64 additions and 59 deletions
@@ -628,8 +628,8 @@ public class BotGenerator(
{ {
var skillsToReturn = new Skills var skillsToReturn = new Skills
{ {
Common = GetSkillsWithRandomisedProgressValue(botSkills.Common, true), Common = GetCommonSkillsWithRandomisedProgressValue(botSkills.Common),
Mastering = GetSkillsWithRandomisedProgressValue(botSkills.Mastering, false), Mastering = GetMasteringSkillsWithRandomisedProgressValue(botSkills.Mastering),
Points = 0 Points = 0
}; };
@@ -640,9 +640,43 @@ public class BotGenerator(
/// Randomise the progress value of passed in skills based on the min/max value /// Randomise the progress value of passed in skills based on the min/max value
/// </summary> /// </summary>
/// <param name="skills">Skills to randomise</param> /// <param name="skills">Skills to randomise</param>
/// <param name="isCommonSkills">Are the skills 'common' skills</param> /// <returns>Skills with randomised progress values as a collection</returns>
/// <returns>Skills with randomised progress values as an array</returns> public List<CommonSkill> GetCommonSkillsWithRandomisedProgressValue(Dictionary<string, MinMax<double>>? skills)
public List<BaseSkill> GetSkillsWithRandomisedProgressValue(Dictionary<string, MinMax<double>>? skills, bool isCommonSkills) {
if (skills is null)
{
return [];
}
return skills
.Select(kvp =>
{
// Get skill from dict, skip if not found
var skill = kvp.Value;
if (skill == null)
{
return null;
}
return new CommonSkill
{
Id = Enum.Parse<SkillTypes>(kvp.Key),
Progress = _randomUtil.GetDouble(skill.Min, skill.Max),
PointsEarnedDuringSession = 0,
LastAccess = 0
};
}
)
.Where(baseSkill => baseSkill != null)
.ToList();
}
/// <summary>
/// Randomise the progress value of passed in skills based on the min/max value
/// </summary>
/// <param name="skills">Skills to randomise</param>
/// <returns>Skills with randomised progress values as a collection</returns>
public List<MasterySkill> GetMasteringSkillsWithRandomisedProgressValue(Dictionary<string, MinMax<double>>? skills)
{ {
if (skills is null) if (skills is null)
{ {
@@ -660,20 +694,11 @@ public class BotGenerator(
} }
// All skills have id and progress props // All skills have id and progress props
var skillToAdd = new BaseSkill return new MasterySkill
{ {
Id = Enum.Parse<SkillTypes>(kvp.Key), Id = kvp.Key,
Progress = _randomUtil.GetDouble(skill.Min, skill.Max) Progress = _randomUtil.GetDouble(skill.Min, skill.Max)
}; };
// Common skills have additional props
if (isCommonSkills)
{
skillToAdd.PointsEarnedDuringSession = 0;
skillToAdd.LastAccess = 0;
}
return skillToAdd;
} }
) )
.Where(baseSkill => baseSkill != null) .Where(baseSkill => baseSkill != null)
@@ -1,6 +1,4 @@
using System.Text.Json; using SPTarkov.DI.Annotations;
using SPTarkov.Common.Extensions;
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Models.Eft.Common.Tables; using SPTarkov.Server.Core.Models.Eft.Common.Tables;
using SPTarkov.Server.Core.Models.Eft.Profile; using SPTarkov.Server.Core.Models.Eft.Profile;
using SPTarkov.Server.Core.Models.Enums; using SPTarkov.Server.Core.Models.Enums;
@@ -537,7 +537,7 @@ public class ProfileHelper(
/// <param name="pmcData">Player profile</param> /// <param name="pmcData">Player profile</param>
/// <param name="skill">Skill to look up and return value from</param> /// <param name="skill">Skill to look up and return value from</param>
/// <returns>Common skill object from desired profile</returns> /// <returns>Common skill object from desired profile</returns>
public BaseSkill? GetSkillFromProfile(PmcData pmcData, SkillTypes skill) public CommonSkill? GetSkillFromProfile(PmcData pmcData, SkillTypes skill)
{ {
var skillToReturn = pmcData?.Skills?.Common.FirstOrDefault(s => s.Id == skill); var skillToReturn = pmcData?.Skills?.Common.FirstOrDefault(s => s.Id == skill);
if (skillToReturn == null) if (skillToReturn == null)
@@ -123,7 +123,7 @@ public class QuestHelper(
/// <param name="profileSkill">the skill experience is being added to</param> /// <param name="profileSkill">the skill experience is being added to</param>
/// <param name="progressAmount">the amount of experience being added to the skill</param> /// <param name="progressAmount">the amount of experience being added to the skill</param>
/// <returns>the adjusted skill progress gain</returns> /// <returns>the adjusted skill progress gain</returns>
public int AdjustSkillExpForLowLevels(Models.Eft.Common.Tables.Common profileSkill, int progressAmount) public int AdjustSkillExpForLowLevels(CommonSkill profileSkill, int progressAmount)
{ {
var currentLevel = Math.Floor((double) (profileSkill.Progress / 100)); var currentLevel = Math.Floor((double) (profileSkill.Progress / 100));
@@ -931,43 +931,18 @@ public record BotBaseInventory
} }
} }
public record BaseJsonSkills
{
[JsonExtensionData]
public Dictionary<string, object> ExtensionData { get; set; }
public List<Common>? Common
{
get;
set;
}
public List<Mastering>? Mastering
{
get;
set;
}
public double? Points
{
get;
set;
}
}
public record Skills public record Skills
{ {
[JsonExtensionData] [JsonExtensionData]
public Dictionary<string, object> ExtensionData { get; set; } public Dictionary<string, object> ExtensionData { get; set; }
public List<BaseSkill>? Common public List<CommonSkill>? Common
{ {
get; get;
set; set;
} }
public List<BaseSkill>? Mastering public List<MasterySkill>? Mastering
{ {
get; get;
set; set;
@@ -980,7 +955,22 @@ public record Skills
} }
} }
public record BaseSkill public record MasterySkill
{
public string? Id
{
get;
set;
}
public double? Progress
{
get;
set;
}
}
public record CommonSkill
{ {
[JsonExtensionData] [JsonExtensionData]
public Dictionary<string, object> ExtensionData { get; set; } public Dictionary<string, object> ExtensionData { get; set; }
@@ -1024,14 +1014,6 @@ public record BaseSkill
} }
} }
public record Common : BaseSkill
{
}
public record Mastering : BaseSkill
{
}
public record Stats public record Stats
{ {
[JsonExtensionData] [JsonExtensionData]
@@ -24,7 +24,7 @@ public record WorkoutSkills
public Dictionary<string, object> ExtensionData { get; set; } public Dictionary<string, object> ExtensionData { get; set; }
[JsonPropertyName("Common")] [JsonPropertyName("Common")]
public List<BaseSkill> Common public List<CommonSkill> Common
{ {
get; get;
set; set;
@@ -1144,7 +1144,7 @@ public class LocationLifecycleService
/// Reset the skill points earned in a raid to 0, ready for next raid /// Reset the skill points earned in a raid to 0, ready for next raid
/// </summary> /// </summary>
/// <param name="commonSkills"> Profile common skills to update </param> /// <param name="commonSkills"> Profile common skills to update </param>
protected void ResetSkillPointsEarnedDuringRaid(List<BaseSkill> commonSkills) protected void ResetSkillPointsEarnedDuringRaid(List<CommonSkill> commonSkills)
{ {
foreach (var skill in commonSkills) foreach (var skill in commonSkills)
{ {