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

Commit

Permalink
fix: add an option to draw melee range.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Mar 7, 2023
1 parent 04000cd commit ddafea6
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 17 deletions.
2 changes: 1 addition & 1 deletion RotationSolver/Actions/BaseAction/BaseAction_ActionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace RotationSolver.Actions.BaseAction;

internal partial class BaseAction
{
private float Range => ActionManager.GetActionRange(ID);
public float Range => ActionManager.GetActionRange(ID);

public ActionID[] ComboIdsNot { private get; set; } = null;

Expand Down
1 change: 0 additions & 1 deletion RotationSolver/Actions/BaseAction/BaseAction_BasicInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ internal partial class BaseAction : IBaseAction
Action _action;

private bool ShouldEndSpecial { get; set; }

internal bool IsTimeline { get; } = false;

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions RotationSolver/Actions/IBaseAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ internal interface IBaseAction : IAction
/// </summary>
float CastTime { get; }

float Range { get; }

/// <summary>
/// If combo id is on this list, this aciton will not used.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions RotationSolver/Configuration/PluginConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public class PluginConfiguration : IPluginConfiguration
public bool UseAOEAction = true;
public bool UseItem = false;
public bool PositionalFeedback = true;
public bool DrawPositional = true;
public bool DrawMeleeRange = true;
public bool ShowMoveTarget = true;
public bool ShowHealthRatio = false;
public bool ShowTarget = true;
Expand Down
6 changes: 6 additions & 0 deletions RotationSolver/Helpers/IActionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,10 @@ private static ActionID[] GetIDFromActions(bool isAdjust, params IAction[] actio
{
return actions.Select(a => isAdjust ? (ActionID)a.AdjustedID : (ActionID)a.ID).ToArray();
}

internal static bool IsMeleeAction(this IAction act)
{
if (act is not IBaseAction baseAct) return false;
return baseAct.Range == 3;
}
}
2 changes: 2 additions & 0 deletions RotationSolver/Localization/Strings_Major.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ internal partial class Strings
public string Configwindow_Param_FlytextPositional { get; set; } = "Hint positional anticipation by flytext";
public string Configwindow_Param_SayPositional { get; set; } = "Hint positional anticipation by shouting";
public string Configwindow_Param_PositionalFeedback { get; set; } = "Positional error feedback";
public string Configwindow_Param_DrawPositional { get; set; } = "Draw Positional on the screen";
public string Configwindow_Param_DrawMeleeRange { get; set; } = "Draw the range of melee on the screen";
public string Configwindow_Param_ShowMoveTarget { get; set; } = "Show the pointing target of the move skill";
public string Configwindow_Param_ShowTarget { get; set; } = "Show Target";
public string Configwindow_Param_PositionalFeedbackDesc { get; set; } = "Attention: Positional anticipation is experimental, just for reference only.";
Expand Down
51 changes: 38 additions & 13 deletions RotationSolver/Windows/OverlayWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Dalamud.Interface;
using FFXIVClientStructs.FFXIV.Client.Game.Control;
using ImGuiNET;
using RotationSolver.Actions;
using RotationSolver.Actions.BaseAction;
using RotationSolver.Data;
using RotationSolver.Helpers;
Expand Down Expand Up @@ -39,7 +40,8 @@ public static void Draw()

ImGui.SetWindowSize(ImGui.GetIO().DisplaySize);

DrawPositional();
if (!DrawPositional())
DrawMeleeRange();
DrawTarget();
DrawMoveTarget();
DrawHealthRatio();
Expand Down Expand Up @@ -133,17 +135,17 @@ private static void DrawTarget(BattleChara tar, uint color, float radius, out Ve
}

const int COUNT = 20;
private static void DrawPositional()
private static bool DrawPositional()
{
if (EnemyLocationTarget == null || !Service.Configuration.PositionalFeedback) return;
if (Service.ClientState.LocalPlayer.HasStatus(true, StatusID.TrueNorth)) return;
if (ShouldPositional is EnemyPositional.None or EnemyPositional.Front) return;
if (EnemyLocationTarget == null || !Service.Configuration.DrawPositional) return false;
if (Service.ClientState.LocalPlayer.HasStatus(true, StatusID.TrueNorth)) return false;
if (ShouldPositional is EnemyPositional.None or EnemyPositional.Front) return false;

float radius = EnemyLocationTarget.HitboxRadius + 3.5f;
float radius = EnemyLocationTarget.HitboxRadius + Service.ClientState.LocalPlayer.HitboxRadius + 3;
float rotation = EnemyLocationTarget.Rotation;

Vector3 pPosition = EnemyLocationTarget.Position;
if (!Service.GameGui.WorldToScreen(pPosition, out var scrPos)) return;
if (!Service.GameGui.WorldToScreen(pPosition, out var scrPos)) return false;

List<Vector2> pts = new List<Vector2>(2 * COUNT + 2) { scrPos };
switch (ShouldPositional)
Expand All @@ -157,22 +159,45 @@ private static void DrawPositional()
SectorPlots(ref pts, pPosition, radius, Math.PI * 0.75 + rotation, COUNT);
break;
default:
return;
return false;
}
pts.Add(scrPos);

bool wrong = ShouldPositional != EnemyLocationTarget.FindEnemyPositional();
bool wrong = ShouldPositional != EnemyLocationTarget.FindEnemyPositional() || EnemyLocationTarget.DistanceToPlayer() > 3;
DrawRange(pts, wrong);
return true;
}

private static void DrawMeleeRange()
{
if (!Service.Configuration.DrawMeleeRange ||
!Service.ClientState.LocalPlayer.IsJobCategory(JobRole.Melee)) return;
if (ActionUpdater.NextAction is not IBaseAction act) return;
if (!act.IsMeleeAction()) return;

List<Vector2> pts = new List<Vector2>(4 * COUNT);

float radius = act.Target.HitboxRadius + Service.ClientState.LocalPlayer.HitboxRadius + 3;

SectorPlots(ref pts, act.Target.Position, radius, 0, 4 * COUNT, 2 * Math.PI);

DrawRange(pts, act.Target.DistanceToPlayer() > 3);
}

static void DrawRange(List<Vector2> pts, bool wrong)
{
var color = wrong ? new Vector3(0.3f, 0.8f, 0.2f) : new Vector3(1, 1, 1);

pts.ForEach(pt => ImGui.GetWindowDrawList().PathLineTo(pt));
ImGui.GetWindowDrawList().PathStroke(ImGui.GetColorU32(new Vector4(color.X, color.Y, color.Z, 1f)), ImDrawFlags.None, 3);
pts.ForEach(pt => ImGui.GetWindowDrawList().PathLineTo(pt));
ImGui.GetWindowDrawList().PathFillConvex(ImGui.GetColorU32(new Vector4(color.X, color.Y, color.Z, 0.2f)));

pts.ForEach(pt => ImGui.GetWindowDrawList().PathLineTo(pt));
ImGui.GetWindowDrawList().PathStroke(ImGui.GetColorU32(new Vector4(color.X, color.Y, color.Z, 1f)), ImDrawFlags.None, 3);
}

private static void SectorPlots(ref List<Vector2> pts, Vector3 centre, float radius, double rotation, int segments)
private static void SectorPlots(ref List<Vector2> pts, Vector3 centre, float radius, double rotation, int segments, double round = Math.PI / 2)
{
var step = Math.PI / 2 / segments;
var step = round / segments;
for (int i = 0; i <= segments; i++)
{
Service.GameGui.WorldToScreen(ChangePoint(centre, radius, rotation + i * step), out var pt);
Expand Down
11 changes: 9 additions & 2 deletions RotationSolver/Windows/RotationConfigWindow_Param.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,18 @@ private void DrawParamDisplay()
DrawCheckBox(LocalizationManager.RightLang.Configwindow_Param_FlytextPositional,
ref Service.Configuration.FlytextPositional);

DrawCheckBox(LocalizationManager.RightLang.Configwindow_Param_PositionalFeedback,
ref Service.Configuration.PositionalFeedback,
LocalizationManager.RightLang.Configwindow_Param_PositionalFeedbackDesc);

if (useOverlayWindow)
{
DrawCheckBox(LocalizationManager.RightLang.Configwindow_Param_PositionalFeedback,
ref Service.Configuration.PositionalFeedback,
DrawCheckBox(LocalizationManager.RightLang.Configwindow_Param_DrawPositional,
ref Service.Configuration.DrawPositional,
LocalizationManager.RightLang.Configwindow_Param_PositionalFeedbackDesc);

DrawCheckBox(LocalizationManager.RightLang.Configwindow_Param_DrawMeleeRange,
ref Service.Configuration.DrawMeleeRange);
}
}

Expand Down

0 comments on commit ddafea6

Please sign in to comment.