Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
style: change the hostile targeting a little bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Jan 21, 2023
1 parent bb314a7 commit 1307b08
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 49 deletions.
5 changes: 5 additions & 0 deletions RotationSolver/Helpers/ObjectHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
43 changes: 7 additions & 36 deletions RotationSolver/Updaters/TargetUpdater_Hostile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
{

Expand All @@ -50,51 +49,23 @@ internal unsafe static void UpdateHostileTargets()
if (c.StatusList.Any(status => Service.DataManager.GetExcelSheet<Status>()
.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<BattleChara>());

//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)
Expand Down
26 changes: 14 additions & 12 deletions RotationSolver/Windows/OverlayWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 4 additions & 1 deletion RotationSolver/Windows/RotationConfigWindow_Debug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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."))
{
Expand Down

0 comments on commit 1307b08

Please sign in to comment.