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

Commit

Permalink
fix: add the angle of sight.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Aug 28, 2023
1 parent 4654e4c commit 6713df5
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 6 deletions.
3 changes: 3 additions & 0 deletions RotationSolver.Basic/Configuration/Configs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ public enum PluginConfigBool : byte
[Default(false)] UseStopCasting,
[Default(false)] EsunaAll,
[Default(false)] OnlyAttackInView,
[Default(false)] OnlyAttackInSight,
[Default(false)] OnlyHotOnTanks,

[Default(false)] InDebug,
Expand Down Expand Up @@ -336,6 +337,8 @@ public enum PluginConfigFloat : byte
[Default(0.2f, 0.005f, 0.05f)] SampleLength,
[Default(0.1f)] KeyBoardNoiseTimeMin,
[Default(0.2f)] KeyBoardNoiseTimeMax,
[Default(45f, 0f, 90f)] AngleOfSight,


[Default(0.25f, 0f, 0.5f)] HealthDifference,
[Default(1f, 0f, 5f)] MeleeRangeOffset,
Expand Down
27 changes: 24 additions & 3 deletions RotationSolver.Basic/Helpers/ObjectHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,19 +266,40 @@ public static float GetHealthRatio(this BattleChara b)
internal static EnemyPositional FindEnemyPositional(this GameObject enemy)
{
Vector3 pPosition = enemy.Position;
float rotation = enemy.Rotation;
Vector2 faceVec = new((float)Math.Cos(rotation), (float)Math.Sin(rotation));
Vector2 faceVec = enemy.GetFaceVector();

Vector3 dir = Player.Object.Position - pPosition;
Vector2 dirVec = new(dir.Z, dir.X);

double angle = Math.Acos(Vector2.Dot(dirVec, faceVec) / dirVec.Length() / faceVec.Length());
double angle = faceVec.AngleTo(dirVec);

if (angle < Math.PI / 4) return EnemyPositional.Front;
else if (angle > Math.PI * 3 / 4) return EnemyPositional.Rear;
return EnemyPositional.Flank;
}

/// <summary>
/// Get the face vector
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public static Vector2 GetFaceVector(this GameObject obj)
{
float rotation = obj.Rotation;
return new((float)Math.Cos(rotation), (float)Math.Sin(rotation));
}

/// <summary>
/// Get two vector's angle
/// </summary>
/// <param name="vec1"></param>
/// <param name="vec2"></param>
/// <returns></returns>
public static double AngleTo(this Vector2 vec1, Vector2 vec2)
{
return Math.Acos(Vector2.Dot(vec1, vec2) / vec1.Length() / vec2.Length());
}

/// <summary>
/// The distance from <paramref name="obj"/> to the player
/// </summary>
Expand Down
5 changes: 2 additions & 3 deletions RotationSolver.Basic/Helpers/TargetFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,15 @@ internal static T FindTargetForMoving<T>(this IEnumerable<T> charas, bool mustUs
private static T FindMoveTargetFaceDirection<T>(IEnumerable<T> charas) where T : GameObject
{
Vector3 pPosition = Player.Object.Position;
float rotation = Player.Object.Rotation;
Vector2 faceVec = new((float)Math.Cos(rotation), (float)Math.Sin(rotation));
Vector2 faceVec = Player.Object.GetFaceVector();

var tars = charas.Where(t =>
{
if (t.DistanceToPlayer() < DISTANCE_TO_MOVE) return false;

Vector3 dir = t.Position - pPosition;
Vector2 dirVec = new(dir.Z, dir.X);
double angle = Math.Acos(Vector2.Dot(dirVec, faceVec) / dirVec.Length() / faceVec.Length());
double angle = faceVec.AngleTo(dirVec);
return angle <= Math.PI * Service.Config.GetValue(Configuration.PluginConfigFloat.MoveTargetAngle) / 360;
}).OrderByDescending(ObjectHelper.DistanceToPlayer);

Expand Down
2 changes: 2 additions & 0 deletions RotationSolver/Localization/ConfigTranslation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ internal static class ConfigTranslation
PluginConfigBool.TargetQuestPriority => LocalizationManager.RightLang.ConfigWindow_Param_TargetQuestPriority,
PluginConfigBool.ShowTargetDeadTime => LocalizationManager.RightLang.ConfigWindow_Param_ShowTargetDeadTime,
PluginConfigBool.ShowStateIcon => LocalizationManager.RightLang.ConfigWindow_UI_ShowStateIcon,
PluginConfigBool.OnlyAttackInSight => LocalizationManager.RightLang.ConfigWindow_Target_OnlyAttackInSight,


// extra
Expand Down Expand Up @@ -190,6 +191,7 @@ internal static class ConfigTranslation
// target
PluginConfigFloat.DeadTimeBoss => LocalizationManager.RightLang.ConfigWindow_Param_DeadTimeBoss,
PluginConfigFloat.DeadTimeDying => LocalizationManager.RightLang.ConfigWindow_Param_DeadTimeDying,
PluginConfigFloat.AngleOfSight => LocalizationManager.RightLang.ConfigWindow_Target_AngleOfSight,

_ => string.Empty,
};
Expand Down
3 changes: 3 additions & 0 deletions RotationSolver/Localization/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -720,4 +720,7 @@ internal partial class Strings
public string ConfigWindow_Auto_UseGroundBeneficialAbilityWhenMoving { get; set; } = "Use beneficial area action when moving.";
public string ConfigWindow_Auto_AutoDefenseNumber { get; set; } = "The count of hostiles who target on me. If it's larger than this, defense single.";

public string ConfigWindow_Target_OnlyAttackInSight { get; set; } = "Only attack the targets in sight";
public string ConfigWindow_Target_AngleOfSight { get; set; } = "The angle of your sight";

}
2 changes: 2 additions & 0 deletions RotationSolver/UI/RotationConfigWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2065,6 +2065,8 @@ private static unsafe void DrawParty()
ImGui.Text("CanHealAreaSpell: " + DataCenter.CanHealAreaSpell.ToString());
ImGui.Text("PartyMembersAverHP: " + DataCenter.PartyMembersAverHP.ToString());

ImGui.Text($"Your combat state: {DataCenter.InCombat}");
ImGui.Text($"Your character combat: {Player.Object.InCombat()}");
foreach (var p in Svc.Party)
{
if (p.GameObject is not BattleChara b) continue;
Expand Down
3 changes: 3 additions & 0 deletions RotationSolver/UI/RotationConfigWindow_Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,9 @@ private static void DrawTargetConfig()
new DragFloatSearchPlugin(PluginConfigFloat.DeadTimeDying, 0.02f),

new CheckBoxSearchPlugin(PluginConfigBool.OnlyAttackInView),
new CheckBoxSearchPlugin(PluginConfigBool.OnlyAttackInSight,
new DragFloatSearchPlugin(PluginConfigFloat.AngleOfSight, 0.02f)),

new CheckBoxSearchPlugin(PluginConfigBool.ChangeTargetForFate),
new CheckBoxSearchPlugin(PluginConfigBool.TargetFatePriority),
new CheckBoxSearchPlugin(PluginConfigBool.TargetHuntingRelicLevePriority),
Expand Down
11 changes: 11 additions & 0 deletions RotationSolver/Updaters/TargetUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using FFXIVClientStructs.FFXIV.Client.UI;
using Lumina.Excel.GeneratedSheets;
using RotationSolver.Basic.Configuration;
using System.Configuration;
using System.Text.RegularExpressions;
using Action = Lumina.Excel.GeneratedSheets.Action;

Expand Down Expand Up @@ -112,6 +113,16 @@ private unsafe static void UpdateHostileTargets(IEnumerable<BattleChara> allTarg
{
if (!Svc.GameGui.WorldToScreen(b.Position, out _)) return false;
}
if(Service.Config.GetValue(PluginConfigBool.OnlyAttackInSight))
{
Vector3 dir = b.Position - Player.Object.Position;
Vector2 dirVec = new(dir.Z, dir.X);
double angle = Player.Object.GetFaceVector().AngleTo(dirVec);
if (angle > Math.PI * Service.Config.GetValue(PluginConfigFloat.AngleOfSight) / 360)
{
return false;
}
}
return true;
})));

Expand Down

0 comments on commit 6713df5

Please sign in to comment.