From 94a215990fb7319804f61eb153732ca731813349 Mon Sep 17 00:00:00 2001 From: Xian55 <367101+Xian55@users.noreply.github.com> Date: Sat, 18 Jan 2025 01:26:07 +0100 Subject: [PATCH] Core: ClassConfiguration: GetByType returns with IEnumerable - added GetByTypeAsList as overload --- Core/ClassConfig/ClassConfiguration.cs | 21 ++++++++++------- Core/Requirement/RequirementFactory.cs | 32 +++++++++++--------------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/Core/ClassConfig/ClassConfiguration.cs b/Core/ClassConfig/ClassConfiguration.cs index f78bc7af..590e241a 100644 --- a/Core/ClassConfig/ClassConfiguration.cs +++ b/Core/ClassConfig/ClassConfiguration.cs @@ -111,7 +111,7 @@ public void Initialise(IServiceProvider sp, Dictionary overridePath SetBaseActions(Combat, Interact, Approach, AutoAttack, StopAttack, PetAttack); - var groups = GetByType(); + var groups = GetByTypeAsList(); foreach ((string name, KeyActions keyActions) in groups) { @@ -268,20 +268,25 @@ private static void SetBaseActions( } } - public List<(string name, T)> GetByType() + public IEnumerable<(string name, T)> GetByType() { return GetType() - .GetProperties(BindingFlags.Instance | - BindingFlags.Public | BindingFlags.FlattenHierarchy) + .GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy) .Where(OfType) .Select(pInfo => { return (pInfo.Name, (T)pInfo.GetValue(this)!); - }) - .ToList(); + }); - static bool OfType(PropertyInfo pInfo) => - typeof(T).IsAssignableFrom(pInfo.PropertyType); + static bool OfType(PropertyInfo pInfo) + { + return typeof(T).IsAssignableFrom(pInfo.PropertyType); + } + } + + public List<(string name, T)> GetByTypeAsList() + { + return GetByType().ToList(); } [LoggerMessage( diff --git a/Core/Requirement/RequirementFactory.cs b/Core/Requirement/RequirementFactory.cs index b84d79da..2e52d2fd 100644 --- a/Core/Requirement/RequirementFactory.cs +++ b/Core/Requirement/RequirementFactory.cs @@ -43,12 +43,6 @@ public sealed partial class RequirementFactory private readonly FrozenDictionary npcSchoolImmunity; - private static readonly string[] negateKeywords = - [ - "not ", - SymbolNegate - ]; - private readonly SearchValues negateKeywordsSpan = SearchValues.Create(['!', 'n', 'o', 't', ' ']); private readonly Dictionary> intVariables; @@ -415,22 +409,22 @@ public void InitUserDefinedIntVariables(Dictionary intKeyValues, throw new Exception($"Unable to add user defined variable to values. [{key} -> {value}]"); } - if (key.StartsWith("Buff_")) + if (key.StartsWith("Buff_", StringComparison.InvariantCultureIgnoreCase)) { int l() => playerBuffTimeReader.GetRemainingTimeMs(value); intVariables.TryAdd($"{value}", l); } - else if (key.StartsWith("Debuff_")) + else if (key.StartsWith("Debuff_", StringComparison.InvariantCultureIgnoreCase)) { int l() => targetDebuffTimeReader.GetRemainingTimeMs(value); intVariables.TryAdd($"{value}", l); } - else if (key.StartsWith("TBuff_")) + else if (key.StartsWith("TBuff_", StringComparison.InvariantCultureIgnoreCase)) { int l() => targetBuffTimeReader.GetRemainingTimeMs(value); intVariables.TryAdd($"{value}", l); } - else if (key.StartsWith("FBuff_")) + else if (key.StartsWith("FBuff_", StringComparison.InvariantCultureIgnoreCase)) { int l() => focusBuffTimeReader.GetRemainingTimeMs(value); intVariables.TryAdd($"{value}", l); @@ -706,9 +700,9 @@ public Requirement CreateRequirement(ReadOnlySpan requirement) requirement = requirement[negateLength..]; - string requirentStr = requirement.ToString(); + string requirementStr = requirement.ToString(); - string? key = requirementMap.Keys.FirstOrDefault(requirentStr.Contains); + string? key = requirementMap.Keys.FirstOrDefault(requirementStr.Contains); if (!string.IsNullOrEmpty(key) && requirementMap.TryGetValue(key, out var createRequirement)) { Requirement r = createRequirement(requirement); @@ -722,14 +716,14 @@ public Requirement CreateRequirement(ReadOnlySpan requirement) var spanLookupBool = boolVariables.GetAlternateLookup>(); if (!spanLookupBool.TryGetValue(requirement, out Func? value)) { - LogUnknown(logger, requirentStr, string.Join(", ", boolVariables.Keys)); + LogUnknown(logger, requirementStr, string.Join(", ", boolVariables.Keys)); return new Requirement { - LogMessage = () => $"UNKNOWN REQUIREMENT! {requirentStr}" + LogMessage = () => $"UNKNOWN REQUIREMENT! {requirementStr}" }; } - string s() => requirentStr; + string s() => requirementStr; Requirement req = new() { HasRequirement = value, @@ -1096,7 +1090,7 @@ private Requirement CreateUsable(ReadOnlySpan requirement) int sep = requirement.IndexOf(SEP1); ReadOnlySpan name = requirement[(sep + 1)..].Trim(); - List<(string _, KeyActions)> groups = classConfig.GetByType(); + var groups = classConfig.GetByType(); foreach ((string _, KeyActions keyActions) in groups) { @@ -1111,7 +1105,7 @@ private Requirement CreateUsable(ReadOnlySpan requirement) } throw new InvalidOperationException($"'{requirement}' " + - $"related named '{name}' {nameof(Core.KeyAction)} not found!"); + $"related named '{name}' {nameof(KeyAction)} not found!"); } private Requirement CreateCanRun(ReadOnlySpan requirement) @@ -1120,7 +1114,7 @@ private Requirement CreateCanRun(ReadOnlySpan requirement) int sep = requirement.IndexOf(SEP1); ReadOnlySpan name = requirement[(sep + 1)..].Trim(); - List<(string _, KeyActions)> groups = classConfig.GetByType(); + var groups = classConfig.GetByType(); foreach ((string _, KeyActions keyActions) in groups) { @@ -1134,7 +1128,7 @@ private Requirement CreateCanRun(ReadOnlySpan requirement) } throw new InvalidOperationException($"'{requirement}' " + - $"related named '{name}' {nameof(Core.KeyAction)} not found!"); + $"related named '{name}' {nameof(KeyAction)} not found!"); }