From 27ec7d523d06618f288d0472ab712ba606895fb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E6=B0=B4?= <1123993881@qq.com> Date: Wed, 30 Aug 2023 11:14:43 +0800 Subject: [PATCH] fix: add provoke target list. --- .../Configuration/OtherConfiguration.cs | 9 +++- RotationSolver.Basic/Helpers/TargetFilter.cs | 9 ++++ RotationSolver/Localization/Strings.cs | 2 + RotationSolver/UI/RotationConfigWindow.cs | 45 +++++++++++++++++-- 4 files changed, 61 insertions(+), 4 deletions(-) diff --git a/RotationSolver.Basic/Configuration/OtherConfiguration.cs b/RotationSolver.Basic/Configuration/OtherConfiguration.cs index ba4071ba9..6bca67440 100644 --- a/RotationSolver.Basic/Configuration/OtherConfiguration.cs +++ b/RotationSolver.Basic/Configuration/OtherConfiguration.cs @@ -13,6 +13,7 @@ public class OtherConfiguration public static SortedList AnimationLockTime = new(); public static Dictionary NoHostileNames = new(); + public static Dictionary NoProvokeNames = new(); public static Dictionary BeneficialPositions = new(); public static HashSet DangerousStatus = new(); @@ -34,6 +35,8 @@ public static void Init() Task.Run(() => InitOne(ref NoHostileNames, nameof(NoHostileNames))); + Task.Run(() => InitOne(ref NoProvokeNames, nameof(NoProvokeNames))); + Task.Run(() => InitOne(ref AnimationLockTime, nameof(AnimationLockTime))); Task.Run(() => InitOne(ref HostileCastingArea, nameof(HostileCastingArea))); @@ -55,12 +58,16 @@ public static void Save() SaveHostileCastingTank(); SaveBeneficialPositions(); SaveRotationSolverRecord(); + SaveNoProvokeNames(); } - public static void SaveRotationSolverRecord() { Task.Run(() => Save(RotationSolverRecord, nameof(RotationSolverRecord))); } + public static void SaveNoProvokeNames() + { + Task.Run(() => Save(NoProvokeNames, nameof(NoProvokeNames))); + } public static void SaveBeneficialPositions() { diff --git a/RotationSolver.Basic/Helpers/TargetFilter.cs b/RotationSolver.Basic/Helpers/TargetFilter.cs index 867d1b9fe..beaab2b0f 100644 --- a/RotationSolver.Basic/Helpers/TargetFilter.cs +++ b/RotationSolver.Basic/Helpers/TargetFilter.cs @@ -2,7 +2,9 @@ using ECommons.GameFunctions; using ECommons.GameHelpers; using Lumina.Excel.GeneratedSheets; +using RotationSolver.Basic.Configuration; using System.Data; +using System.Text.RegularExpressions; namespace RotationSolver.Basic.Helpers; @@ -175,6 +177,13 @@ internal static IEnumerable ProvokeTarget(IEnumerable var targets = inputCharas.Where(target => { + //Removed the listed names. + IEnumerable names = Array.Empty(); + if (OtherConfiguration.NoProvokeNames.TryGetValue(Svc.ClientState.TerritoryType, out var ns1)) + names = names.Union(ns1); + + if (names.Any(n => !string.IsNullOrEmpty(n) && new Regex(n).Match(target.Name.ToString()).Success)) return false; + //Target can move or two big and has a target if ((target.GetObjectNPC()?.Unknown12 == 0 || target.HitboxRadius >= 5) && (target.TargetObject?.IsValid() ?? false)) diff --git a/RotationSolver/Localization/Strings.cs b/RotationSolver/Localization/Strings.cs index 295099bae..21750f43a 100644 --- a/RotationSolver/Localization/Strings.cs +++ b/RotationSolver/Localization/Strings.cs @@ -285,6 +285,7 @@ internal partial class Strings public string ConfigWindow_List_NoHostile { get; set; } = "No Hostile"; public string ConfigWindow_List_NoHostileDesc { get; set; } = "Add names of targets that will never be attacked."; + public string ConfigWindow_List_NoProvokeDesc { get; set; } = "Add names of targets that will never be provoked."; #endregion @@ -664,6 +665,7 @@ internal partial class Strings public string ConfigWindow_List_BeneficialPositions { get; set; } = "Beneficial positions"; public string ConfigWindow_List_NoHostilesName { get; set; } = "The name of object that you don't want to attack"; + public string ConfigWindow_List_NoProvokeName { get; set; } = "The name of object that you don't want to provoke"; public string ConfigWindow_Basic_AutoSwitch { get; set; } = "Auto Switch"; diff --git a/RotationSolver/UI/RotationConfigWindow.cs b/RotationSolver/UI/RotationConfigWindow.cs index 2a9492f99..3a07df422 100644 --- a/RotationSolver/UI/RotationConfigWindow.cs +++ b/RotationSolver/UI/RotationConfigWindow.cs @@ -1875,7 +1875,7 @@ private static void DrawListTerritories() ImGui.PopStyleColor(); ImGui.PopFont(); - if (ImGui.BeginTable("Rotation Solver List Territories", 2, ImGuiTableFlags.BordersInner | ImGuiTableFlags.Resizable | ImGuiTableFlags.SizingStretchSame)) + if (ImGui.BeginTable("Rotation Solver List Territories", 3, ImGuiTableFlags.BordersInner | ImGuiTableFlags.Resizable | ImGuiTableFlags.SizingStretchSame)) { ImGui.TableSetupScrollFreeze(0, 1); ImGui.TableNextRow(ImGuiTableRowFlags.Headers); @@ -1909,14 +1909,14 @@ private static void DrawListTerritories() for (int i = 0; i < libs.Length; i++) { ImGui.SetNextItemWidth(width); - if(ImGui.InputTextWithHint($"##Rotation Solver Territory Name {i}", LocalizationManager.RightLang.ConfigWindow_List_NoHostilesName, ref libs[i], 1024)) + if(ImGui.InputTextWithHint($"##Rotation Solver Territory Target Name {i}", LocalizationManager.RightLang.ConfigWindow_List_NoHostilesName, ref libs[i], 1024)) { OtherConfiguration.NoHostileNames[territoryId] = libs; OtherConfiguration.SaveNoHostileNames(); } ImGui.SameLine(); - if (ImGuiEx.IconButton(FontAwesomeIcon.Ban, $"##Rotation Solver Remove Territory Name {i}")) + if (ImGuiEx.IconButton(FontAwesomeIcon.Ban, $"##Rotation Solver Remove Territory Target Name {i}")) { removeIndex = i; } @@ -1930,6 +1930,45 @@ private static void DrawListTerritories() } ImGui.TableNextColumn(); + ImGui.TextWrapped(LocalizationManager.RightLang.ConfigWindow_List_NoProvokeDesc); + + width = ImGui.GetColumnWidth() - ImGuiEx.CalcIconSize(FontAwesomeIcon.Ban).X - ImGui.GetStyle().ItemSpacing.X - 10 * _scale; + + if (!OtherConfiguration.NoProvokeNames.TryGetValue(territoryId, out libs)) + { + OtherConfiguration.NoProvokeNames[territoryId] = libs = Array.Empty(); + } + //Add one. + if (!libs.Any(string.IsNullOrEmpty)) + { + OtherConfiguration.NoHostileNames[territoryId] = libs.Append(string.Empty).ToArray(); + } + removeIndex = -1; + for (int i = 0; i < libs.Length; i++) + { + ImGui.SetNextItemWidth(width); + if (ImGui.InputTextWithHint($"##Rotation Solver Territory Provoke Name {i}", LocalizationManager.RightLang.ConfigWindow_List_NoProvokeName, ref libs[i], 1024)) + { + OtherConfiguration.NoProvokeNames[territoryId] = libs; + OtherConfiguration.SaveNoProvokeNames(); + } + ImGui.SameLine(); + + if (ImGuiEx.IconButton(FontAwesomeIcon.Ban, $"##Rotation Solver Remove Territory Provoke Name {i}")) + { + removeIndex = i; + } + } + if (removeIndex > -1) + { + var list = libs.ToList(); + list.RemoveAt(removeIndex); + OtherConfiguration.NoProvokeNames[territoryId] = list.ToArray(); + OtherConfiguration.SaveNoProvokeNames(); + } + + ImGui.TableNextColumn(); + if (!OtherConfiguration.BeneficialPositions.TryGetValue(territoryId, out var pts)) { OtherConfiguration.BeneficialPositions[territoryId] = pts = Array.Empty();