diff --git a/RotationSolver/Helpers/ObjectHelper.cs b/RotationSolver/Helpers/ObjectHelper.cs index 73c1052a5..ac20e02a2 100644 --- a/RotationSolver/Helpers/ObjectHelper.cs +++ b/RotationSolver/Helpers/ObjectHelper.cs @@ -23,6 +23,11 @@ internal static bool HasLocationSide(this GameObject obj) return !(obj.GetObjectNPC()?.Unknown10 ?? false); } + internal static unsafe uint FateId(this GameObject obj) + => ((FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)(void*)obj.Address)->FateId; + + internal static unsafe bool IsTargetable(this GameObject obj) + => ((FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)(void*)obj.Address)->GetIsTargetable(); internal static bool IsBoss(this BattleChara obj) { if (obj == null) return false; diff --git a/RotationSolver/Updaters/TargetUpdater_Hostile.cs b/RotationSolver/Updaters/TargetUpdater_Hostile.cs index eab8b3e17..52fe346c9 100644 --- a/RotationSolver/Updaters/TargetUpdater_Hostile.cs +++ b/RotationSolver/Updaters/TargetUpdater_Hostile.cs @@ -39,9 +39,8 @@ internal static partial class TargetUpdater internal unsafe static void UpdateHostileTargets() { - var hasFate = (IntPtr)FateManager.Instance() != IntPtr.Zero; + var inFate = Service.Configuration.ChangeTargetForFate && (IntPtr)FateManager.Instance() != IntPtr.Zero && FateManager.Instance()->FateJoined > 0; - //能打的目标 AllTargets = TargetFilter.GetTargetable(TargetFilter.GetObjectInRadius(Service.ObjectTable, 30).Where(obj => { @@ -50,51 +49,23 @@ internal unsafe static void UpdateHostileTargets() if (c.StatusList.Any(status => Service.DataManager.GetExcelSheet() .GetRow(status.StatusId).Icon == 15024)) return false; - - try - { - var gameObj = (FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)(void*)c.Address; - - //不可选中 - if (!gameObj->GetIsTargetable()) return false; - - //不在fate中,不打fate怪。 - if ((!hasFate ||FateManager.Instance()->FateJoined == 0) - && gameObj->FateId > 0) return false; - } - catch - { - return false; - } + //不可选中 + if (!c.IsTargetable()) return false; if (obj.CanAttack()) return true; } return false; }).Cast()); - //Filter the fate objects. - bool inFate = Service.Configuration.ChangeTargetForFate && hasFate && FateManager.Instance()->FateJoined > 0; - uint[] ids = GetEnemies() ?? new uint[0]; + uint[] ids = GetEnemies(); if (AllTargets != null) { HostileTargets = CountDown.CountDownTime > 0 ? AllTargets : inFate ? - AllTargets.Where(t => - { - bool lowEnoughLevel = Service.ClientState.LocalPlayer.Level <= FateManager.Instance()->CurrentFate->MaxLevel; - - try - { - return t.TargetObject == Service.ClientState.LocalPlayer || - lowEnoughLevel && ((FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)(void*)t.Address)->FateId == FateManager.Instance()->CurrentFate->FateId; - } - catch - { - return false; - } - }) : - AllTargets.Where(t => t.TargetObject is BattleChara || ids.Contains(t.ObjectId)); + AllTargets.Where(t => t.FateId() == FateManager.Instance()->CurrentFate->FateId) : + AllTargets.Where(t => (t.TargetObject is BattleChara || ids.Contains(t.ObjectId)) && t.FateId() == 0 + || t.TargetObject == Service.ClientState.LocalPlayer); switch (IconReplacer.RightNowTargetToHostileType) diff --git a/RotationSolver/Windows/OverlayWindow.cs b/RotationSolver/Windows/OverlayWindow.cs index 956df26fd..77afe6730 100644 --- a/RotationSolver/Windows/OverlayWindow.cs +++ b/RotationSolver/Windows/OverlayWindow.cs @@ -80,24 +80,26 @@ private static void DrawTarget() } } - private static void DrawMoveTarget() + private unsafe static void DrawMoveTarget() { if (!Service.Configuration.ShowMoveTarget) return; var c = Service.Configuration.MovingTargetColor; var color = ImGui.GetColorU32(new Vector4(c.X, c.Y, c.Z, 1)); -//#if DEBUG -// Service.GameGui.WorldToScreen(Service.ClientState.LocalPlayer.Position, out var plp); -// var calHealth = (double)ObjectHelper.GetHealthFromMulty(1); -// foreach (var t in TargetUpdater.AllTargets) -// { -// if (Service.GameGui.WorldToScreen(t.Position, out var p)) -// { -// ImGui.GetWindowDrawList().AddText(p, color, $"Boss Ratio (Max): {t.MaxHp / calHealth:F2}\nDying Ratio (Current): {t.CurrentHp / calHealth:F2}"); -// } -// } -//#endif +#if DEBUG + Service.GameGui.WorldToScreen(Service.ClientState.LocalPlayer.Position, out var plp); + var calHealth = (double)ObjectHelper.GetHealthFromMulty(1); + foreach (var t in TargetUpdater.AllTargets) + { + if (Service.GameGui.WorldToScreen(t.Position, out var p)) + { + ImGui.GetWindowDrawList().AddText(p, color, $"FateId: {((FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)(void*)t.Address)->FateId}"); + + //ImGui.GetWindowDrawList().AddText(p, color, $"Boss Ratio (Max): {t.MaxHp / calHealth:F2}\nDying Ratio (Current): {t.CurrentHp / calHealth:F2}"); + } + } +#endif var tar = IconReplacer.RightNowRotation?.MoveTarget; if (tar == null || tar == Service.ClientState.LocalPlayer) return; diff --git a/RotationSolver/Windows/RotationConfigWindow_Debug.cs b/RotationSolver/Windows/RotationConfigWindow_Debug.cs index 34d9845dc..4a65f78e9 100644 --- a/RotationSolver/Windows/RotationConfigWindow_Debug.cs +++ b/RotationSolver/Windows/RotationConfigWindow_Debug.cs @@ -7,19 +7,22 @@ using RotationSolver.Updaters; using System.Linq; using RotationSolver.Actions.BaseAction; +using FFXIVClientStructs.FFXIV.Client.Game.Fate; namespace RotationSolver.Windows.RotationConfigWindow; #if DEBUG internal partial class RotationConfigWindow { - private void DrawDebugTab() + private unsafe void DrawDebugTab() { var str = TargetUpdater.EncryptString(Service.ClientState.LocalPlayer); ImGui.SetNextItemWidth(ImGui.CalcTextSize(str).X + 10); ImGui.InputText("That is your HASH, send to ArchiTed", ref str, 100); + ImGui.Text("All: " + TargetUpdater.AllTargets.Count().ToString()); ImGui.Text("Hostile: " + TargetUpdater.HostileTargets.Count().ToString()); ImGui.Text("Friends: " + TargetUpdater.PartyMembers.Count().ToString()); + ImGui.Text("Fate: " + FateManager.Instance()->FateJoined.ToString()); if (ImGui.CollapsingHeader("Status from self.")) {