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

Commit

Permalink
fix: split the stateType to state and isManual.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Jul 25, 2023
1 parent c19dd60 commit 2acf4fc
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 21 deletions.
4 changes: 2 additions & 2 deletions RotationSolver.Basic/Actions/BaseAction_Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ private static bool TargetDeath(out BattleChara target)
#region Target Hostile
private bool TargetHostile(float range, bool mustUse, int aoeCount, out BattleChara target)
{
if (DataCenter.StateType == StateCommandType.Manual)
if (DataCenter.IsManual)
{
if (Svc.Targets.Target is BattleChara b && b.IsNPCEnemy() && b.DistanceToPlayer() <= range)
{
Expand Down Expand Up @@ -355,7 +355,7 @@ private bool TargetSelf(bool mustUse, int aoeCount)
}

//not use when aoe.
if (DataCenter.StateType == StateCommandType.Manual)
if (DataCenter.IsManual)
{
if (!Service.Config.GetValue(SettingsCommand.UseAOEWhenManual) && !mustUse) return false;
}
Expand Down
4 changes: 3 additions & 1 deletion RotationSolver.Basic/DataCenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ public static float AbilityRemain
static SpecialCommandType _specialType = SpecialCommandType.EndSpecial;
public static SpecialCommandType SpecialType =>
SpecialTimeLeft < 0 ? SpecialCommandType.EndSpecial : _specialType;
public static StateCommandType StateType { get; set; } = StateCommandType.Cancel;
public static bool State { get; set; } = false;

public static bool IsManual { get; set; } = false;

public static void SetSpecialType(SpecialCommandType specialType)
{
Expand Down
13 changes: 12 additions & 1 deletion RotationSolver.Basic/Rotations/CustomRotation_OtherInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,18 @@ public abstract partial class CustomRotation
/// <summary>
///
/// </summary>
protected static StateCommandType StateType => DataCenter.StateType;
[Obsolete("Please use State or IsManual instead!", true)]
protected static StateCommandType StateType => StateCommandType.None;

/// <summary>
/// True for On, false for off.
/// </summary>
protected static bool State => DataCenter.State;

/// <summary>
/// Ture for Manual Target, false for Auto Target.
/// </summary>
protected static bool IsManual => DataCenter.IsManual;
#endregion

#region GCD
Expand Down
19 changes: 9 additions & 10 deletions RotationSolver/Commands/RSCommands_Actions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ namespace RotationSolver.Commands
public static partial class RSCommands
{
static DateTime _lastClickTime = DateTime.MinValue;
static StateCommandType _lastState;
static bool _lastState;

internal static unsafe bool CanDoAnAction(bool isGCD)
{
if (_lastState == StateCommandType.Cancel
|| DataCenter.StateType == StateCommandType.Cancel)
if (!_lastState || !DataCenter.State)
{
_lastState = DataCenter.StateType;
_lastState = DataCenter.State;
return false;
}
_lastState = DataCenter.StateType;
_lastState = DataCenter.State;

if (!Player.Available) return false;

Expand Down Expand Up @@ -76,7 +75,7 @@ public static void DoAction()
//Svc.Chat.Print($"{act}, {act.Target.Name}, {ActionUpdater.AbilityRemainCount}, {ActionUpdater.WeaponElapsed}");
#endif
//Change Target
if (act.Target != null && (Service.Config.TargetFriendly && DataCenter.StateType != StateCommandType.Manual || ((Svc.Targets.Target?.IsNPCEnemy() ?? true)
if (act.Target != null && (Service.Config.TargetFriendly && !DataCenter.IsManual || ((Svc.Targets.Target?.IsNPCEnemy() ?? true)
|| Svc.Targets.Target?.GetObjectKind() == Dalamud.Game.ClientState.Objects.Enums.ObjectKind.Treasure)
&& act.Target.IsNPCEnemy()))
{
Expand Down Expand Up @@ -113,14 +112,14 @@ static async void PulseSimulation(uint id)
internal static void ResetSpecial() => DoSpecialCommandType(SpecialCommandType.EndSpecial, false);
private static void CancelState()
{
if (DataCenter.StateType != StateCommandType.Cancel) DoStateCommandType(StateCommandType.Cancel);
if (DataCenter.State) DoStateCommandType(StateCommandType.Cancel);
}

static float _lastCountdownTime = 0;
internal static void UpdateRotationState()
{
if(ActionUpdater._cancelTime != DateTime.MinValue &&
(DataCenter.StateType == StateCommandType.Cancel || DataCenter.InCombat))
(!DataCenter.State || DataCenter.InCombat))
{
ActionUpdater._cancelTime = DateTime.MinValue;
}
Expand Down Expand Up @@ -158,7 +157,7 @@ internal static void UpdateRotationState()
else if (Service.Config.StartOnAttackedBySomeone && target != null
&& !target.IsDummy())
{
if(DataCenter.StateType == StateCommandType.Cancel)
if(!DataCenter.State)
{
DoStateCommandType(StateCommandType.Manual);
}
Expand All @@ -167,7 +166,7 @@ internal static void UpdateRotationState()
else if (Service.Config.StartOnCountdown && Service.CountDownTime > 0)
{
_lastCountdownTime = Service.CountDownTime;
if (DataCenter.StateType == StateCommandType.Cancel)
if (!DataCenter.State)
{
DoStateCommandType(StateCommandType.Auto);
}
Expand Down
23 changes: 19 additions & 4 deletions RotationSolver/Commands/RSCommands_StateSpecialCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private static void UpdateToast()

private static unsafe void DoStateCommandType(StateCommandType stateType) => DoOneCommandType(EnumTranslations.ToSayout, role =>
{
if (DataCenter.StateType == StateCommandType.Auto
if (DataCenter.State && !DataCenter.IsManual
&& stateType == StateCommandType.Auto)
{
Service.Config.TargetingIndex += 1;
Expand All @@ -32,13 +32,28 @@ private static unsafe void DoStateCommandType(StateCommandType stateType) => DoO
}

if (Service.Config.ToggleManual
&& DataCenter.StateType == StateCommandType.Manual
&& DataCenter.State && DataCenter.IsManual
&& stateType == StateCommandType.Manual)
{
stateType = StateCommandType.Cancel;
}

DataCenter.StateType = stateType;
switch (stateType)
{
case StateCommandType.Cancel:
DataCenter.State = false;
break;

case StateCommandType.Auto:
DataCenter.IsManual = false;
DataCenter.State = true;
break;

case StateCommandType.Manual:
DataCenter.IsManual = true;
DataCenter.State = true;
break;
}

UpdateStateNamePlate();

Expand All @@ -52,7 +67,7 @@ public static unsafe void UpdateStateNamePlate()
if (!Player.Available) return;

Player.Object.SetNamePlateIcon(
DataCenter.StateType == StateCommandType.Cancel ? 0u : (uint)Service.Config.NamePlateIconId);
!DataCenter.State ? 0u : (uint)Service.Config.NamePlateIconId);
}

private static void DoSpecialCommandType(SpecialCommandType specialType, bool sayout = true) => DoOneCommandType(sayout ? EnumTranslations.ToSayout : (s, r) => string.Empty, role =>
Expand Down
14 changes: 12 additions & 2 deletions RotationSolver/UI/ControlWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,17 @@ static void DrawCommandAction(uint iconId, StateCommandType command, Vector4 col

ImGui.EndGroup();

if (DataCenter.StateType == command)
bool isMatch = false;
switch (command)
{
case StateCommandType.Auto when DataCenter.State && !DataCenter.IsManual:
case StateCommandType.Manual when DataCenter.State && DataCenter.IsManual:
case StateCommandType.Cancel when !DataCenter.State:
isMatch = true;
break;
}

if (isMatch)
{
var size = ImGui.GetItemRectSize();
var winPos = ImGui.GetWindowPos();
Expand Down Expand Up @@ -451,7 +461,7 @@ internal static (Vector2, Vector2) DrawIAction(IAction action, float width, floa
var result = DrawIAction(texture.ImGuiHandle, width, action == null ? -1 : percent);
if (action != null) ImGuiHelper.HoveredString(action.Name, () =>
{
if (DataCenter.StateType == StateCommandType.Cancel)
if (!DataCenter.State)
{
bool canDoIt = false;
if(action is IBaseAction act)
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver/UI/NextActionWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public override void Draw()

var strs = new List<string>(3);
if(Service.Config.GetValue(SettingsCommand.UseAOEAction)
&& (DataCenter.StateType != StateCommandType.Manual
&& (!DataCenter.IsManual
|| Service.Config.GetValue(SettingsCommand.UseAOEWhenManual)))
{
strs.Add("AOE");
Expand Down

0 comments on commit 2acf4fc

Please sign in to comment.