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

Commit

Permalink
fix: Fixed a problem with Special State passing.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Mar 18, 2023
1 parent 195ca7c commit af13b96
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 34 deletions.
14 changes: 13 additions & 1 deletion RotationSolver.Basic/DataCenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,20 @@ public static unsafe ushort FateId
#endregion
public static uint[] BluSlots { get; set; } = new uint[24];

public static SpecialCommandType SpecialType { get; set; }
static DateTime _specialStateStartTime = DateTime.MinValue;
public static double SpecialTimeLeft => Service.Config.SpecialDuration - (DateTime.Now - _specialStateStartTime).TotalSeconds;

static SpecialCommandType _specialType = SpecialCommandType.EndSpecial;
public static SpecialCommandType SpecialType =>
SpecialTimeLeft < 0 ? SpecialCommandType.EndSpecial : _specialType;
public static StateCommandType StateType { get; set; }

public static void SetSpecialType(SpecialCommandType specialType)
{
_specialType = specialType;
_specialStateStartTime = specialType == SpecialCommandType.EndSpecial ? DateTime.MinValue : DateTime.Now;
}

public static bool InCombat { get; set; }

public static float CombatTime { get; set; }
Expand Down
5 changes: 2 additions & 3 deletions RotationSolver.Basic/Rotations/CustomRotation_BasicInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ public abstract partial class CustomRotation : ICustomRotation

public string Name => Job.Abbreviation + " - " + Job.Name;

/// <summary>
/// 作者
/// </summary>
public abstract string RotationName { get; }

public bool IsEnabled
Expand Down Expand Up @@ -67,4 +64,6 @@ protected virtual IRotationConfigSet CreateConfiguration()
/// Update your customized field.
/// </summary>
protected virtual void UpdateInfo() { }

public override string ToString() => RotationName;
}
6 changes: 3 additions & 3 deletions RotationSolver/Commands/RSCommands_Actions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static partial class RSCommands
static readonly TimeSpan _fastSpan = new TimeSpan(0, 0, 0, 0, 200);
internal static unsafe void DoAnAction(bool isGCD)
{
if (StateType == StateCommandType.Cancel) return;
if (DataCenter.StateType == StateCommandType.Cancel) return;

var localPlayer = Service.Player;
if (localPlayer == null) return;
Expand Down Expand Up @@ -61,7 +61,7 @@ internal static unsafe void DoAnAction(bool isGCD)
internal static void ResetSpecial() => DoSpecialCommandType(SpecialCommandType.EndSpecial, false);
private static void CancelState()
{
if (StateType != StateCommandType.Cancel) DoStateCommandType(StateCommandType.Cancel);
if (DataCenter.StateType != StateCommandType.Cancel) DoStateCommandType(StateCommandType.Cancel);
}

internal static void UpdateRotationState()
Expand Down Expand Up @@ -89,7 +89,7 @@ internal static void UpdateRotationState()
//Auto start at count Down.
else if (Service.Config.StartOnCountdown && Service.CountDownTime > 0)
{
if (StateType == StateCommandType.Cancel)
if (DataCenter.StateType == StateCommandType.Cancel)
{
DoStateCommandType(StateCommandType.Smart);
}
Expand Down
22 changes: 5 additions & 17 deletions RotationSolver/Commands/RSCommands_StateSpecialCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,9 @@ namespace RotationSolver.Commands
{
public static partial class RSCommands
{
private static DateTime _specialStateStartTime = DateTime.MinValue;
private static double SpecialTimeLeft => Service.Config.SpecialDuration - (DateTime.Now - _specialStateStartTime).TotalSeconds;

private static SpecialCommandType _specialType = SpecialCommandType.EndSpecial;
public static SpecialCommandType SpecialType =>
SpecialTimeLeft < 0 ? SpecialCommandType.EndSpecial : _specialType;

public static StateCommandType StateType { get; private set; } = StateCommandType.Cancel;


private static string _stateString = "Off", _specialString = string.Empty;
internal static string EntryString =>
_stateString + (SpecialTimeLeft < 0 ? string.Empty : $" - {_specialString}: {SpecialTimeLeft:F2}s");
_stateString + (DataCenter.SpecialTimeLeft < 0 ? string.Empty : $" - {_specialString}: {DataCenter.SpecialTimeLeft:F2}s");

private static void UpdateToast()
{
Expand All @@ -36,14 +26,14 @@ private static void UpdateToast()

private static unsafe void DoStateCommandType(StateCommandType stateType) => DoOneCommandType(stateType, EnumTranslations.ToSayout, role =>
{
if (StateType == StateCommandType.Smart
if (DataCenter.StateType == StateCommandType.Smart
&& stateType == StateCommandType.Smart)
{
Service.Config.TargetingIndex += 1;
Service.Config.TargetingIndex %= Service.Config.TargetingTypes.Count;
}

StateType = stateType;
DataCenter.StateType = stateType;

UpdateStateNamePlate();

Expand All @@ -56,15 +46,13 @@ public static unsafe void UpdateStateNamePlate()
if (Service.Player == null) return;

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

private static void DoSpecialCommandType(SpecialCommandType specialType, bool sayout = true) => DoOneCommandType(specialType, sayout ? EnumTranslations.ToSayout : (s, r) => string.Empty, role =>
{
_specialType = specialType;
_specialString = specialType.ToSpecialString(role);

_specialStateStartTime = specialType == SpecialCommandType.EndSpecial ? DateTime.MinValue : DateTime.Now;
DataCenter.SetSpecialType(specialType);
if (sayout) UpdateToast();
});

Expand Down
13 changes: 10 additions & 3 deletions RotationSolver/RotationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,21 @@ public static bool IsDefault(this ICustomRotation rotation)
public static bool IsAllowed(this ICustomRotation rotation, out string name)
{
name = rotation.GetType().Assembly.GetName().Name;
return _allowedAssembly.Contains(rotation.GetType().Assembly.GetName().Name);
return _allowedAssembly.Contains(name);
}

public static Vector4 GetColor(this ICustomRotation rotation)
=> rotation.IsAllowed(out _) ? ImGuiColors.DalamudWhite : ImGuiColors.DalamudViolet;
=> rotation.IsAllowed(out _) ? ImGuiColors.DalamudWhite : ImGuiColors.DalamudViolet;

public static string GetAuthor(this ICustomRotation rotation)
{
return FileVersionInfo.GetVersionInfo(rotation.GetType().Assembly.Location)?.CompanyName ?? "Unnamed";
try
{
return FileVersionInfo.GetVersionInfo(rotation.GetType().Assembly.Location)?.CompanyName ?? "Unknown";
}
catch
{
return "Unknown";
}
}
}
12 changes: 6 additions & 6 deletions RotationSolver/UI/ImGuiHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -442,18 +442,18 @@ public unsafe static void Display(this ICustomRotation rotation, ICustomRotation
ImGui.TextDisabled(" - ");
ImGui.SameLine();

var isAllowed = rotation.IsAllowed(out _);
ImGui.TextColored(rotation.GetColor(),
rotation.GetAuthor());
if (!isAllowed)
ImGui.PushStyleColor(ImGuiCol.Text, rotation.GetColor());
ImGui.Text(rotation.GetAuthor());
if (!rotation.IsAllowed(out _))
{
var showStr = "This rotation is not allowed to be used in High-end Duty!"
var showStr = $"This `{rotation}` rotation is not allowed to be used in High-end Duty!"
+ string.Join("", SocialUpdater.HighEndDuties.Select(x => x.PlaceName?.Value?.Name.ToString())
.Where(s => !string.IsNullOrEmpty(s)).Select(t => "\n - " + t));

HoveredString(showStr);
}

ImGui.PopStyleColor();

ImGui.SameLine();
ImGui.TextDisabled(" - " + LocalizationManager.RightLang.ConfigWindow_Helper_GameVersion + ": ");
ImGui.SameLine();
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver/UI/RotationConfigWindow_Debug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private unsafe void DrawTargetData()
private void DrawNextAction()
{
ImGui.Text(RotationUpdater.RightNowRotation.RotationName);
ImGui.Text(RSCommands.SpecialType.ToString());
ImGui.Text(DataCenter.SpecialType.ToString());

ActionUpdater.NextAction?.Display(false);
ImGui.Text("Ability Remain: " + DataCenter.AbilityRemain.ToString());
Expand Down

0 comments on commit af13b96

Please sign in to comment.