From 02dc5ed8821703211184d0632c4bb1d6b4cf688b Mon Sep 17 00:00:00 2001 From: Chomp Date: Sat, 18 Jan 2025 12:00:49 +0000 Subject: [PATCH 1/2] Further repeatable quest improvements --- Core/Models/Spt/Repeatable/QuestTypePool.cs | 6 +++++- Core/Utils/Collections/ProbabilityObjectArray.cs | 9 ++++----- Core/Utils/Extensions/EliminationTargetPoolExtensions.cs | 4 ++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Core/Models/Spt/Repeatable/QuestTypePool.cs b/Core/Models/Spt/Repeatable/QuestTypePool.cs index 25a34a87..ccee6fb1 100644 --- a/Core/Models/Spt/Repeatable/QuestTypePool.cs +++ b/Core/Models/Spt/Repeatable/QuestTypePool.cs @@ -74,12 +74,16 @@ public record EliminationTargetPool [JsonPropertyName("bossBoarSniper")] public TargetLocation? BossBoarSniper { get; set; } - public EliminationTargetPool this[string toLower] + public EliminationTargetPool? this[string toLower] { get { return (EliminationTargetPool?)GetType().GetProperties().SingleOrDefault(p => p.GetJsonName() == toLower)?.GetValue(this); } + set + { + // Implement + } } } diff --git a/Core/Utils/Collections/ProbabilityObjectArray.cs b/Core/Utils/Collections/ProbabilityObjectArray.cs index 74ada0fb..e8e496fe 100644 --- a/Core/Utils/Collections/ProbabilityObjectArray.cs +++ b/Core/Utils/Collections/ProbabilityObjectArray.cs @@ -133,13 +133,12 @@ public class ProbabilityObjectArray : List where T : ProbabilityObje * Drawing can be with or without replacement * @param count The number of times we want to draw * @param replacement Draw with or without replacement from the input dict (true = dont remove after drawing) - * @param locklist list keys which shall be replaced even if drawing without replacement + * @param lockList list keys which shall be replaced even if drawing without replacement * @returns Array consisting of N random keys for this ProbabilityObjectArray */ - public List Draw(int count = 1, bool replacement = true, List? locklist = null) + public List Draw(int count = 1, bool replacement = true, List? lockList = null) { - if (locklist == null) - locklist = new List(); + lockList ??= []; if (Count == 0) { return []; @@ -163,7 +162,7 @@ public class ProbabilityObjectArray : List where T : ProbabilityObje var rand = Random.Shared.NextDouble(); var randomIndex = (int)probCumsum.First((x) => x > rand); // We cannot put Math.random() directly in the findIndex because then it draws anew for each of its iteration - if (replacement || locklist.Contains(totals.keyArray[randomIndex])) + if (replacement || lockList.Contains(totals.keyArray[randomIndex])) { // Add random item from possible value into return array drawnKeys.Add(totals.keyArray[randomIndex]); diff --git a/Core/Utils/Extensions/EliminationTargetPoolExtensions.cs b/Core/Utils/Extensions/EliminationTargetPoolExtensions.cs index 82c56e8b..c9c003dc 100644 --- a/Core/Utils/Extensions/EliminationTargetPoolExtensions.cs +++ b/Core/Utils/Extensions/EliminationTargetPoolExtensions.cs @@ -4,9 +4,9 @@ namespace Core.Utils.Extensions { public static class EliminationTargetPoolExtensions { - public static void Remove(this EliminationTargetPool pool, T key) + public static void Remove(this EliminationTargetPool pool, string key) { - // TODO: Implement + pool[key] = null; } } } From 051c8a5a288d228ade0d592c7a962efeb923b2e3 Mon Sep 17 00:00:00 2001 From: Chomp Date: Sat, 18 Jan 2025 12:08:29 +0000 Subject: [PATCH 2/2] Replaced `EliminationTarget` with a dictionary --- Core/Controllers/RepeatableQuestController.cs | 6 +-- Core/Generators/RepeatableQuestGenerator.cs | 1 + Core/Models/Spt/Repeatable/QuestTypePool.cs | 50 +------------------ .../EliminationTargetPoolExtensions.cs | 12 ----- 4 files changed, 5 insertions(+), 64 deletions(-) delete mode 100644 Core/Utils/Extensions/EliminationTargetPoolExtensions.cs diff --git a/Core/Controllers/RepeatableQuestController.cs b/Core/Controllers/RepeatableQuestController.cs index 695d7e3a..0865a056 100644 --- a/Core/Controllers/RepeatableQuestController.cs +++ b/Core/Controllers/RepeatableQuestController.cs @@ -323,7 +323,7 @@ public class RepeatableQuestController // Target is boss if (targetKvP.Data.IsBoss.GetValueOrDefault(false)) { - var targets = questPool.Pool.Elimination.Targets.Get(targetKvP.Key); + questPool.Pool.Elimination.Targets.TryGetValue(targetKvP.Key, out var targets); targets.Locations.Clear(); targets.Locations.Add("any"); } @@ -332,7 +332,7 @@ public class RepeatableQuestController // Non-boss targets var possibleLocations = locations; - var targets = questPool.Pool.Elimination.Targets.Get(targetKvP.Key); + questPool.Pool.Elimination.Targets.TryGetValue(targetKvP.Key, out var targets); var targetsClone = _cloner.Clone(targets); var allowedLocations = targetKvP.Key == "Savage" ? targetsClone.Locations.Where((location) => location != "laboratory") // Exclude labs for Savage targets. @@ -360,7 +360,7 @@ public class RepeatableQuestController }, Elimination = new EliminationPool { - Targets = new EliminationTargetPool() + Targets = new Dictionary() }, Pickup = new ExplorationPool { diff --git a/Core/Generators/RepeatableQuestGenerator.cs b/Core/Generators/RepeatableQuestGenerator.cs index abdd0c09..ada78075 100644 --- a/Core/Generators/RepeatableQuestGenerator.cs +++ b/Core/Generators/RepeatableQuestGenerator.cs @@ -150,6 +150,7 @@ public class RepeatableQuestGenerator var maxKillDifficulty = eliminationConfig.MaxKills; + var targetPool = questTypePool.Pool.Elimination; targetsConfig = (ProbabilityObjectArray)targetsConfig.Where((x) => questTypePool.Pool.Elimination.Targets.Contains(x.Key)); if (targetsConfig.Count == 0 || targetsConfig.All((x) => x.Data.IsBoss.GetValueOrDefault(false))) { diff --git a/Core/Models/Spt/Repeatable/QuestTypePool.cs b/Core/Models/Spt/Repeatable/QuestTypePool.cs index ccee6fb1..17bcd918 100644 --- a/Core/Models/Spt/Repeatable/QuestTypePool.cs +++ b/Core/Models/Spt/Repeatable/QuestTypePool.cs @@ -36,55 +36,7 @@ public record ExplorationPool public record EliminationPool { [JsonPropertyName("targets")] - public EliminationTargetPool? Targets { get; set; } -} - -public record EliminationTargetPool -{ - [JsonPropertyName("Savage")] - public TargetLocation? Savage { get; set; } - - [JsonPropertyName("AnyPmc")] - public TargetLocation? AnyPmc { get; set; } - - [JsonPropertyName("bossBully")] - public TargetLocation? BossBully { get; set; } - - [JsonPropertyName("bossGluhar")] - public TargetLocation? BossGluhar { get; set; } - - [JsonPropertyName("bossKilla")] - public TargetLocation? BossKilla { get; set; } - - [JsonPropertyName("bossSanitar")] - public TargetLocation? BossSanitar { get; set; } - - [JsonPropertyName("bossTagilla")] - public TargetLocation? BossTagilla { get; set; } - - [JsonPropertyName("bossKnight")] - public TargetLocation? BossKnight { get; set; } - - [JsonPropertyName("bossZryachiy")] - public TargetLocation? BossZryachiy { get; set; } - - [JsonPropertyName("bossBoar")] - public TargetLocation? BossBoar { get; set; } - - [JsonPropertyName("bossBoarSniper")] - public TargetLocation? BossBoarSniper { get; set; } - - public EliminationTargetPool? this[string toLower] - { - get - { - return (EliminationTargetPool?)GetType().GetProperties().SingleOrDefault(p => p.GetJsonName() == toLower)?.GetValue(this); - } - set - { - // Implement - } - } + public Dictionary? Targets { get; set; } } public record TargetLocation diff --git a/Core/Utils/Extensions/EliminationTargetPoolExtensions.cs b/Core/Utils/Extensions/EliminationTargetPoolExtensions.cs deleted file mode 100644 index c9c003dc..00000000 --- a/Core/Utils/Extensions/EliminationTargetPoolExtensions.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Core.Models.Spt.Repeatable; - -namespace Core.Utils.Extensions -{ - public static class EliminationTargetPoolExtensions - { - public static void Remove(this EliminationTargetPool pool, string key) - { - pool[key] = null; - } - } -}