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

Commit

Permalink
feat: add an control window.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Mar 18, 2023
1 parent 5df63d2 commit f172d0e
Show file tree
Hide file tree
Showing 20 changed files with 406 additions and 111 deletions.
27 changes: 0 additions & 27 deletions RotationSolver.Basic/Actions/BaseAction/BaseAction_BasicInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,6 @@ public partial class BaseAction : IBaseAction

public string Description => string.Empty;

//public string CateName
//{
// get
// {
// string result;

// if (_isFriendly)
// {
// result = LocalizationManager.RightLang.Action_Friendly;
// if (_isEot)
// {
// result += "Hot";
// }
// }
// else
// {
// result = LocalizationManager.RightLang.Action_Attack;

// if (_isEot)
// {
// result += "Dot";
// }
// }
// result += "-" + (IsRealGCD ? "GCD" : LocalizationManager.RightLang.Timeline_Ability);
// return result;
// }
//}
public bool IsEnabled
{
get => !Service.Config.DisabledActions.Contains(ID);
Expand Down
5 changes: 5 additions & 0 deletions RotationSolver.Basic/Configuration/PluginConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ public class PluginConfiguration : IPluginConfiguration

public bool ShowControlWindow = false;
public bool IsControlWindowLock = true;
public Vector4 ControlWindowLockBg = new Vector4(0, 0, 0, 0.5f);
public Vector4 ControlWindowUnlockBg = new Vector4(0, 0, 0, 1);
public float ControlWindowGCDSize = 40;
public float ControlWindow0GCDSize = 30;
public float ControlWindowNextSizeRatio = 1.5f;

public void Save()
{
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver.Basic/Data/IconSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static class IconSet
{
private static readonly Dictionary<uint, TextureWrap> _textures = new Dictionary<uint, TextureWrap>();

public static TextureWrap GetTexture(this ITexture text) => GetTexture(text.IconID);
public static TextureWrap GetTexture(this ITexture text) => GetTexture(text?.IconID ?? 0);

public static TextureWrap GetTexture(uint id)
{
Expand Down
4 changes: 2 additions & 2 deletions RotationSolver.Basic/Helpers/ActionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace RotationSolver.Basic.Helpers;

internal static class ActionHelper
public static class ActionHelper
{
internal const byte GCDCooldownGroup = 58;
public const byte GCDCooldownGroup = 58;

internal static ActionCate GetActionType(this Action action) => (ActionCate)action.ActionCategory.Value.RowId;
internal static bool IsGeneralGCD(this Action action) => action.CooldownGroup == GCDCooldownGroup;
Expand Down
3 changes: 2 additions & 1 deletion RotationSolver.Basic/Rotations/CustomRotation_Ability.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ private bool AntiKnockback(JobRole role, SpecialCommandType specialType, out IAc
private bool GeneralHealAbility(byte abilitiesRemaining, SpecialCommandType specialType, out IAction act)
{
act = null;

switch (specialType)
{
case SpecialCommandType.DefenseArea:
Expand All @@ -142,7 +143,7 @@ private bool GeneralHealAbility(byte abilitiesRemaining, SpecialCommandType spec
break;
}

if ((DataCenter.HPNotFull || Job.RowId == (uint)ClassJobID.BlackMage) && InCombat)
if ((DataCenter.HPNotFull || Job.GetJobRole() != JobRole.Healer) && InCombat)
{
if ((DataCenter.SpecialType == SpecialCommandType.HealArea || CanHealAreaAbility) && HealAreaAbility(abilitiesRemaining, out act)) return true;
if ((DataCenter.SpecialType == SpecialCommandType.HealSingle || CanHealSingleAbility) && HealSingleAbility(abilitiesRemaining, out act)) return true;
Expand Down
33 changes: 33 additions & 0 deletions RotationSolver.Basic/Rotations/CustomRotation_BasicInfo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Dalamud.Game.ClientState.Objects.Types;
using Lumina.Excel.GeneratedSheets;
using RotationSolver.Basic;
using RotationSolver.Basic.Actions;
using RotationSolver.Basic.Attributes;
using RotationSolver.Basic.Configuration.RotationConfig;
using RotationSolver.Basic.Data;
Expand Down Expand Up @@ -44,6 +45,38 @@ public bool IsEnabled

public virtual string Description { get; } = string.Empty;

public IAction ActionHealAreaGCD { get; private set; }

public IAction ActionHealAreaAbility { get; private set; }

public IAction ActionHealSingleGCD { get; private set; }

public IAction ActionHealSingleAbility { get; private set; }

public IAction ActionDefenseAreaGCD { get; private set; }

public IAction ActionDefenseAreaAbility { get; private set; }

public IAction ActionDefenseSingleGCD { get; private set; }

public IAction ActionDefenseSingleAbility { get; private set; }

public IAction ActionMoveForwardGCD { get; private set; }

public IAction ActionMoveForwardAbility { get; private set; }

public IAction ActionMoveBackAbility { get; private set; }

public IAction EsunaStanceNorthGCD { get; private set; }

public IAction EsunaStanceNorthAbility { get; private set; }

public IAction RaiseShirkGCD { get; private set; }

public IAction RaiseShirkAbility { get; private set; }

public IAction AntiKnockbackAbility { get; private set; }

/// <summary>
/// Description about the actions.
/// </summary>
Expand Down
7 changes: 5 additions & 2 deletions RotationSolver.Basic/Rotations/CustomRotation_GCD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ private IAction GCD(byte abilityRemain, bool helpDefenseAOE, bool helpDefenseSin
}

//General Heal
if (DataCenter.HPNotFull && (DataCenter.InCombat || Service.Config.HealOutOfCombat))
if ((DataCenter.HPNotFull || Job.GetJobRole() != JobRole.Healer)
&& (DataCenter.InCombat || Service.Config.HealOutOfCombat))
{
if ((specialType == SpecialCommandType.HealArea || CanHealAreaSpell) && HealAreaGCD(out act)) return act;
if ((specialType == SpecialCommandType.HealSingle || CanHealSingleSpell) && HealSingleGCD(out act)) return act;
Expand Down Expand Up @@ -58,10 +59,12 @@ private bool RaiseSpell(SpecialCommandType specialType, out IAction act, byte ac
if (Raise == null) return false;
if (Player.CurrentMp <= Service.Config.LessMPNoRaise) return false;

if (specialType == SpecialCommandType.RaiseShirk && DataCenter.DeathPeopleAll.Any()) return true;

if ((Service.Config.RaiseAll ? DataCenter.DeathPeopleAll.Any() : DataCenter.DeathPeopleParty.Any())
&& Raise.CanUse(out act))
{
if (specialType == SpecialCommandType.RaiseShirk || HasSwift)
if (HasSwift)
{
return true;
}
Expand Down
42 changes: 41 additions & 1 deletion RotationSolver.Basic/Rotations/CustomRotation_Invoke.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,47 @@ public bool TryInvoke(out IAction newAction, out IAction gcdAction)
return false;
}

MoveTarget = (MoveForwardAbility(1, out var act, recordTarget: false) && act is BaseAction a) ? a.Target : null;
ActionMoveForwardGCD = MoveForwardGCD(out var act) ? act : null;
ActionMoveForwardAbility = MoveForwardAbility(DataCenter.AbilityRemainCount, out act, recordTarget: false) ? act : null;
MoveTarget = act is IBaseAction a ? a.Target : null;

ActionMoveBackAbility = MoveBackAbility(DataCenter.AbilityRemainCount, out act) ? act : null;

ActionHealAreaGCD = HealAreaGCD(out act) ? act : null;
ActionHealAreaAbility = HealAreaAbility(DataCenter.AbilityRemainCount, out act) ? act : null;

ActionHealSingleGCD = HealSingleGCD(out act) ? act : null;
ActionHealSingleAbility = HealSingleAbility(DataCenter.AbilityRemainCount, out act) ? act : null;

ActionDefenseAreaGCD = DefenseAreaGCD(out act) ? act : null;
ActionDefenseAreaAbility = DefenseAreaAbility(DataCenter.AbilityRemainCount, out act) ? act : null;

ActionDefenseSingleGCD = DefenseSingleGCD(out act) ? act : null;
ActionDefenseSingleAbility = DefenseSingleAbility(DataCenter.AbilityRemainCount, out act) ? act : null;

var role = Job.GetJobRole();
EsunaStanceNorthGCD = role switch
{
JobRole.Healer => DataCenter.WeakenPeople.Any() && Esuna.CanUse(out act, mustUse: true) ? act : null,
_ => null,
};
EsunaStanceNorthAbility = role switch
{
JobRole.Melee => TrueNorth.CanUse(out act) ? act : null,
JobRole.Tank => Shield.CanUse(out act) ? act : null,
_ => null,
};
RaiseShirkGCD = role switch
{
JobRole.Healer => DataCenter.DeathPeopleAll.Any() && Raise.CanUse(out act) ? act : null,
_ => null,
};
RaiseShirkAbility = role switch
{
JobRole.Tank => Shirk.CanUse(out act) ? act : null,
_ => null,
};
AntiKnockbackAbility = AntiKnockback(role, SpecialCommandType.AntiKnockback, out act) ? act : null;
UpdateInfo();

newAction = Invoke(out gcdAction);
Expand Down
16 changes: 16 additions & 0 deletions RotationSolver.Basic/Rotations/ICustomRotation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,21 @@ public interface ICustomRotation : ITexture
MethodInfo[] AllLast { get; }
MethodInfo[] AllGCDs { get; }

IAction ActionHealAreaGCD { get; }
IAction ActionHealAreaAbility { get; }
IAction ActionHealSingleGCD { get; }
IAction ActionHealSingleAbility { get; }
IAction ActionDefenseAreaGCD { get; }
IAction ActionDefenseAreaAbility { get; }
IAction ActionDefenseSingleGCD { get; }
IAction ActionDefenseSingleAbility { get; }
IAction ActionMoveForwardGCD { get; }
IAction ActionMoveForwardAbility { get; }
IAction ActionMoveBackAbility { get; }
IAction EsunaStanceNorthGCD { get; }
IAction EsunaStanceNorthAbility { get; }
IAction RaiseShirkGCD { get; }
IAction RaiseShirkAbility { get; }
IAction AntiKnockbackAbility { get; }
bool TryInvoke(out IAction newAction, out IAction gcdAction);
}
109 changes: 60 additions & 49 deletions RotationSolver/Commands/RSCommands_BasicInfo.cs
Original file line number Diff line number Diff line change
@@ -1,76 +1,87 @@
using Dalamud.Game.Command;
using FFXIVClientStructs.FFXIV.Client.Game.UI;
using Lumina.Excel.GeneratedSheets;
using RotationSolver.Basic;
using RotationSolver.Basic.Data;
using RotationSolver.Localization;
using System;
using System.Linq;

namespace RotationSolver.Commands
namespace RotationSolver.Commands;

public static partial class RSCommands
{
public static partial class RSCommands
internal static TargetingType TargetingType
{
internal static TargetingType TargetingType
get
{
get
if (Service.Config.TargetingTypes.Count == 0)
{
if (Service.Config.TargetingTypes.Count == 0)
{
Service.Config.TargetingTypes.Add(TargetingType.Big);
Service.Config.TargetingTypes.Add(TargetingType.Small);
Service.Config.Save();
}

return Service.Config.TargetingTypes[Service.Config.TargetingIndex %= Service.Config.TargetingTypes.Count];
Service.Config.TargetingTypes.Add(TargetingType.Big);
Service.Config.TargetingTypes.Add(TargetingType.Small);
Service.Config.Save();
}

return Service.Config.TargetingTypes[Service.Config.TargetingIndex %= Service.Config.TargetingTypes.Count];
}
}

internal static void Enable()
=> Service.CommandManager.AddHandler(Service.Command, new CommandInfo(OnCommand)
{
HelpMessage = LocalizationManager.RightLang.Commands_Rotation,
ShowInHelp = true,
});
internal static void Enable()
=> Service.CommandManager.AddHandler(Service.Command, new CommandInfo(OnCommand)
{
HelpMessage = LocalizationManager.RightLang.Commands_Rotation,
ShowInHelp = true,
});

internal static void Disable() => Service.CommandManager.RemoveHandler(Service.Command);

internal static void Disable() => Service.CommandManager.RemoveHandler(Service.Command);
private static void OnCommand(string command, string arguments)
{
DoOneCommand(arguments);
}

private static void OnCommand(string command, string arguments)
private static void DoOneCommand(string str)
{
if (TryGetOneEnum<StateCommandType>(str, out var stateType))
{
DoStateCommandType(stateType);
}
else if (TryGetOneEnum<SpecialCommandType>(str, out var specialType))
{
DoSpecialCommandType(specialType);
}
else if (TryGetOneEnum<OtherCommandType>(str, out var otherType))
{
DoOtherCommand(otherType, str.Substring(otherType.ToString().Length).Trim());
}
else
{
DoOneCommand(arguments);
RotationSolverPlugin.OpenConfigWindow();
}
}

private static void DoOneCommand(string str)
private static bool TryGetOneEnum<T>(string str, out T type) where T : struct, Enum
{
type = default;
try
{
if (TryGetOneEnum<StateCommandType>(str, out var stateType))
{
DoStateCommandType(stateType);
}
else if (TryGetOneEnum<SpecialCommandType>(str, out var specialType))
{
DoSpecialCommandType(specialType);
}
else if (TryGetOneEnum<OtherCommandType>(str, out var otherType))
{
DoOtherCommand(otherType, str.Substring(otherType.ToString().Length).Trim());
}
else
{
RotationSolverPlugin.OpenConfigWindow();
}
type = Enum.GetValues<T>().First(c => str.StartsWith(c.ToString(), StringComparison.OrdinalIgnoreCase));
return true;
}
catch
{
return false;
}
}

private static bool TryGetOneEnum<T>(string str, out T type) where T : struct, Enum
internal static string GetCommandStr<T>(this T command, string extraCommand = "")
where T : struct, Enum
{
var cmdStr = Service.Command + " " + command.ToString();
if (!string.IsNullOrEmpty(extraCommand))
{
type = default;
try
{
type = Enum.GetValues<T>().First(c => str.StartsWith(c.ToString(), StringComparison.OrdinalIgnoreCase));
return true;
}
catch
{
return false;
}
cmdStr += " " + extraCommand;
}
return cmdStr;
}
}
5 changes: 5 additions & 0 deletions RotationSolver/Localization/Localization.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"ConfigWindow_HelpItem_MoveBack": "Open a window to move back.",
"ConfigWindow_HelpItem_EndSpecial": "Close special window.",
"ConfigWindow_Helper_SwitchRotation": "Click to switch authors",
"ConfigWindow_Helper_HighEndWarning": "This `{0}` rotation is not allowed to be used in High-end Duty!",
"ConfigWindow_Helper_GameVersion": "Game Version",
"ConfigWindow_Helper_OpenSource": "Open the source code URL",
"ConfigWindow_Helper_RunCommand": "Click to execute the command",
Expand Down Expand Up @@ -172,6 +173,10 @@
"ConfigWindow_Param_ConditionDelete": "Delete",
"ConfigWindow_Control_ShowControlWindow": "Show Control Window",
"ConfigWindow_Control_IsControlWindowLock": "Lock Control Window",
"ConfigWindow_Control_BackgroundColor": "Control Window's Background",
"ConfigWindow_Control_ControlWindowGCDSize": "GCD icon size",
"ConfigWindow_Control_ControlWindow0GCDSize": "0GCD icon size",
"ConfigWindow_Control_ControlWindowNextSizeRatio": "Next Action Size Ratio",
"Timeline_DragdropDescription": "Drag&drop to move,Ctrl+Alt+RightClick to delete.",
"Timeline_SearchBar": "Search Bar",
"Timeline_MustUse": "MustUse",
Expand Down
Loading

0 comments on commit f172d0e

Please sign in to comment.