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

Commit

Permalink
feat: add auto heal ratio option to make auto heal more precise.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Sep 7, 2023
1 parent 0ab156e commit c4ceb84
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 12 deletions.
32 changes: 31 additions & 1 deletion RotationSolver.Basic/Actions/BaseAction_ActionInfo.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
using ECommons.DalamudServices;
using ECommons.ExcelServices;
using ECommons.GameHelpers;
using FFXIVClientStructs.FFXIV.Client.Game;
using RotationSolver.Basic.Configuration;

namespace RotationSolver.Basic.Actions;

public partial class BaseAction
{
/// <summary>
/// The user seted heal ratio.
/// </summary>
public float AutoHealRatio
{
get
{
return OtherConfiguration.ActionHealRatio.TryGetValue(ID, out var ratio)
? ratio : 1;
}
set
{
OtherConfiguration.ActionHealRatio[ID] = value;
OtherConfiguration.SaveActionHealRatio();
}
}

/// <summary>
/// The range of the action.
/// </summary>
Expand Down Expand Up @@ -56,6 +73,7 @@ private bool WillCooldown
}

internal static bool SkipDisable { get; set; } = false;
internal static bool AutoHealCheck { get; set; } = false;

/// <summary>
/// Can this action be used.
Expand All @@ -79,6 +97,18 @@ public unsafe virtual bool CanUse(out IAction act, CanUseOption option = CanUseO

if (!SkipDisable && !IsEnabled) return false;
if (IsDutyAction && !IsDutyActionOnSlot) return false;

if (AutoHealCheck && IsFriendly)
{
if (IsSingleTarget)
{
if (DataCenter.PartyMembersMinHP >= AutoHealRatio) return false;
}
else
{
if (DataCenter.PartyMembersAverHP >= AutoHealRatio) return false;
}
}

if (DataCenter.DisabledActionSequencer != null && DataCenter.DisabledActionSequencer.Contains(ID)) return false;

Expand Down
11 changes: 11 additions & 0 deletions RotationSolver.Basic/Actions/BaseAction_BasicInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public partial class BaseAction : IBaseAction

readonly ActionOption _option;

/// <summary>
/// Is a heal action.
/// </summary>
public bool IsHeal => _option.HasFlag(ActionOption.HealFlag);

/// <summary>
/// Is a friendly action.
/// </summary>
Expand Down Expand Up @@ -204,6 +209,12 @@ public BaseAction(ActionID actionID, ActionOption option = ActionOption.None)
CoolDownGroup = _action.GetCoolDownGroup();
}

internal static void CleanSpecial()
{
OtherOption = CanUseOption.None;
AutoHealCheck = SkipDisable = false;
}

/// <summary>
/// To string.
/// </summary>
Expand Down
8 changes: 8 additions & 0 deletions RotationSolver.Basic/Actions/IBaseAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public interface IBaseAction : IAction
[EditorBrowsable(EditorBrowsableState.Never)]
internal bool IsEot { get; }

[EditorBrowsable(EditorBrowsableState.Never)]
internal bool IsHeal { get; }

/// <summary>
/// If player has these statuses from player self, this action will not used.
/// </summary>
Expand Down Expand Up @@ -200,5 +203,10 @@ public interface IBaseAction : IAction
/// How much ttk that this action needs the targets are.
/// </summary>
float TimeToKill { get; internal set; }

/// <summary>
/// The user seted heal ratio.
/// </summary>
float AutoHealRatio { get; internal set; }
#endregion
}
11 changes: 10 additions & 1 deletion RotationSolver.Basic/Configuration/OtherConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ public class OtherConfiguration
{ (uint) ActionID.Bio, 20},
{ (uint) ActionID.EukrasianDosis, 20},
{ (uint) ActionID.Aero, 20},

};

public static Dictionary<uint, float> ActionHealRatio = new();

public static RotationSolverRecord RotationSolverRecord = new ();

public static void Init()
Expand Down Expand Up @@ -94,6 +95,8 @@ public static void Init()

Task.Run(() => InitOne(ref ActionTTK, nameof(ActionTTK)));

Task.Run(() => InitOne(ref ActionHealRatio, nameof(ActionHealRatio)));

Task.Run(() => InitOne(ref RotationSolverRecord, nameof(RotationSolverRecord), false));
}

Expand All @@ -110,6 +113,12 @@ public static void Save()
SaveNoProvokeNames();
SaveActionAOECounts();
SaveActionTTK();
SaveActionHealRatio();
}

public static void SaveActionHealRatio()
{
Task.Run(() => Save(ActionHealRatio, nameof(ActionHealRatio)));
}

public static void SaveActionTTK()
Expand Down
11 changes: 8 additions & 3 deletions RotationSolver.Basic/Data/ActionOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public enum ActionOption : byte
/// </summary>
DutyAction = 1 << 5,

/// <summary>
/// flag to check this action is heal.
/// </summary>
HealFlag = 1 << 6,

/// <summary>
/// Dot action
/// </summary>
Expand All @@ -54,12 +59,12 @@ public enum ActionOption : byte
/// <summary>
/// Heal action
/// </summary>
Heal = Friendly,
Heal = Friendly | HealFlag,

/// <summary>
/// Defense action (you need to change the targeting strategy.
/// Defense action (you need to change the targeting strategy.)
/// </summary>
Defense = Heal,
Defense = Friendly,

/// <summary>
/// Hot action
Expand Down
17 changes: 14 additions & 3 deletions RotationSolver.Basic/Rotations/CustomRotation_Ability.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,27 @@ private bool GeneralHealAbility(SpecialCommandType specialType, out IAction act)

if ((DataCenter.HPNotFull || ClassJob.GetJobRole() != JobRole.Healer) && InCombat)
{
if (DataCenter.SpecialType == SpecialCommandType.HealArea || CanHealAreaAbility)
if (DataCenter.SpecialType == SpecialCommandType.HealArea)
{
if (HealAreaAbility(out act)) return true;
}
if (DataCenter.SpecialType == SpecialCommandType.HealSingle || CanHealSingleAbility)
if (CanHealAreaAbility)
{
BaseAction.AutoHealCheck = true;
if (HealAreaAbility(out act)) return true;
BaseAction.AutoHealCheck = false;
}
if (DataCenter.SpecialType == SpecialCommandType.HealSingle)
{
if (HealSingleAbility(out act)) return true;
}
if (CanHealSingleAbility)
{
BaseAction.AutoHealCheck = true;
if (HealSingleAbility(out act)) return true;
BaseAction.AutoHealCheck = false;
}
}

return false;
}

Expand Down
22 changes: 20 additions & 2 deletions RotationSolver.Basic/Rotations/CustomRotation_GCD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,26 @@ private IAction GCD(bool helpDefenseAOE, bool helpDefenseSingle)
if ((DataCenter.HPNotFull || ClassJob.GetJobRole() != JobRole.Healer)
&& (DataCenter.InCombat || Service.Config.GetValue(PluginConfigBool.HealOutOfCombat)))
{
if ((specialType == SpecialCommandType.HealArea || CanHealAreaSpell) && HealAreaGCD(out act)) return act;
if ((specialType == SpecialCommandType.HealSingle || CanHealSingleSpell) && HealSingleGCD(out act)) return act;
if (specialType == SpecialCommandType.HealArea)
{
if( HealAreaGCD(out act)) return act;
}
if (CanHealAreaSpell)
{
BaseAction.AutoHealCheck = true;
if (HealAreaGCD(out act)) return act;
BaseAction.AutoHealCheck = false;
}
if (specialType == SpecialCommandType.HealSingle)
{
if (HealSingleGCD(out act)) return act;
}
if (CanHealSingleSpell)
{
BaseAction.AutoHealCheck = true;
if (HealSingleGCD(out act)) return act;
BaseAction.AutoHealCheck = false;
}
}
if (specialType == SpecialCommandType.DefenseArea && DefenseAreaGCD(out act)) return act;
if (specialType == SpecialCommandType.DefenseSingle && DefenseSingleGCD(out act)) return act;
Expand Down
1 change: 1 addition & 0 deletions RotationSolver.Basic/Rotations/CustomRotation_Invoke.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public bool TryInvoke(out IAction newAction, out IAction gcdAction)
{
UpdateInfo();
UpdateActions(ClassJob.GetJobRole());
BaseAction.CleanSpecial();

CountingOfLastUsing = CountingOfCombatTimeUsing = 0;
newAction = Invoke(out gcdAction);
Expand Down
3 changes: 2 additions & 1 deletion RotationSolver/Localization/Strings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace RotationSolver.Localization;

internal partial class Strings
internal class Strings
{
#region Commands
public string Commands_Rotation { get; set; } = "Open config window.";
Expand Down Expand Up @@ -736,4 +736,5 @@ internal partial class Strings

public string ConfigWindow_Actions_AOECount { get; set; } = "How many targets are needed to use this action.";
public string ConfigWindow_Actions_TTK { get; set; } = "TTK that this action needs the target be.";
public string ConfigWindow_Actions_HealRatio { get; set; } = "The HP ratio to auto heal";
}
13 changes: 12 additions & 1 deletion RotationSolver/UI/RotationConfigWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1243,14 +1243,25 @@ private static unsafe void DrawActions()
action.AOECount = (byte)aoeCount;
}
}

if (!action.IsFriendly)
{
var ttk = action.TimeToKill;
ImGui.SetNextItemWidth(_scale * 150);
if (ImGui.DragFloat($"{LocalizationManager.RightLang.ConfigWindow_Actions_TTK}##{action}",
ref ttk, 0.1f, 0, 120))
{
action.TimeToKill = (byte)ttk;
action.TimeToKill = ttk;
}
}
if (action.IsHeal)
{
var ratio = action.AutoHealRatio;
ImGui.SetNextItemWidth(_scale * 150);
if (ImGui.DragFloat($"{LocalizationManager.RightLang.ConfigWindow_Actions_HealRatio}##{action}",
ref ratio, 0.002f, 0, 1))
{
action.AutoHealRatio = ratio;
}
}
}
Expand Down

0 comments on commit c4ceb84

Please sign in to comment.