Skip to content

Commit 6b43d6f

Browse files
authored
Merge pull request #968 from FFXIV-CombatReborn/DTRfixes
Refactor DTR handling and added new /rotation Cycle command
2 parents 5013547 + e62d912 commit 6b43d6f

File tree

9 files changed

+252
-82
lines changed

9 files changed

+252
-82
lines changed

RotationSolver.Basic/Configuration/Configs.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ public const string
125125
Filter = UiInformation)]
126126
private static readonly bool _showInfoOnDtr = true;
127127

128+
[UI("DTR Behaviour", Filter = UiInformation, Parent = nameof(ShowInfoOnDtr))]
129+
public DTRType DTRType { get; set; } = DTRType.DTRNormal;
130+
128131
[ConditionBool, UI("Display plugin status in toast popup",
129132
Description = "Show a toast notification with the combat state when changed.",
130133
Filter = UiInformation)]
@@ -872,14 +875,11 @@ public const string
872875
Filter = TargetConfig)]
873876
private static readonly bool _bigHP = false;
874877

875-
[ConditionBool, UI("Change clicking the DTR bar behaviour to cycle between Off and Manual (Overrides below option).",
876-
Filter = TargetConfig)]
877-
private static readonly bool _dtrManual = false;
878-
879-
[ConditionBool, UI("Change clicking the DTR bar behaviour to cycle through each Target Type selected.",
880-
Filter = TargetConfig)]
881-
private static readonly bool _dtrCycle = false;
878+
[UI("/rotation Cycle behaviour", Filter = TargetConfig)]
879+
public CycleType CycleType { get; set; } = CycleType.CycleNormal;
882880

881+
[JobConfig, UI("Engage settings", Filter = TargetConfig, PvPFilter = JobFilterType.NoJob)]
882+
private readonly TargetHostileType _hostileType = TargetHostileType.AllTargetsWhenSoloInDuty;
883883
#endregion
884884

885885
#region Integer
@@ -1014,9 +1014,6 @@ public const string
10141014
PvEFilter = JobFilterType.Tank)]
10151015
private readonly float _healthForAutoDefense = 1;
10161016

1017-
[JobConfig, UI("Engage settings", Filter = TargetConfig, PvPFilter = JobFilterType.NoJob)]
1018-
private readonly TargetHostileType _hostileType = TargetHostileType.AllTargetsWhenSoloInDuty;
1019-
10201017
[JobConfig]
10211018
private readonly string _PvPRotationChoice = string.Empty;
10221019

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
namespace RotationSolver.Basic.Data;
2+
3+
/// <summary>
4+
/// Hostile target.
5+
/// </summary>
6+
public enum CycleType : byte
7+
{
8+
/// <summary>
9+
/// Cycle between first Auto, Manual, and Off
10+
/// </summary>
11+
[Description("Cycle between first Auto, Manual, and Off")]
12+
CycleNormal,
13+
14+
/// <summary>
15+
/// Cycle between each Auto, Manual, and Off
16+
/// </summary>
17+
[Description("Cycle between each Auto, Manual, and Off")]
18+
CycleAllAuto,
19+
20+
/// <summary>
21+
/// Cycle between Manual and Off
22+
/// </summary>
23+
[Description("Cycle between Manual and Off")]
24+
CycleManual,
25+
26+
/// <summary>
27+
/// Cycle between Manual and Auto
28+
/// </summary>
29+
[Description("Cycle between Manual and Auto")]
30+
CycleManualAuto,
31+
}

RotationSolver.Basic/Data/DTRType.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
namespace RotationSolver.Basic.Data;
2+
3+
/// <summary>
4+
/// Hostile target.
5+
/// </summary>
6+
public enum DTRType : byte
7+
{
8+
/// <summary>
9+
/// Cycle between first Auto, Manual, and Off
10+
/// </summary>
11+
[Description("Cycle between first Auto, Manual, and Off")]
12+
DTRNormal,
13+
14+
/// <summary>
15+
/// Cycle between each Auto, Manual, and Off
16+
/// </summary>
17+
[Description("Cycle between each Auto, Manual, and Off")]
18+
DTRAllAuto,
19+
20+
/// <summary>
21+
/// Cycle between Manual and Off
22+
/// </summary>
23+
[Description("Cycle between Manual and Off")]
24+
DTRManual,
25+
26+
/// <summary>
27+
/// Cycle between Manual and Auto
28+
/// </summary>
29+
[Description("Cycle between Manual and Auto")]
30+
DTRManualAuto,
31+
}

RotationSolver.Basic/Data/RSCommandType.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,10 @@ public enum OtherCommandType : byte
161161
/// </summary>
162162
[Description("Do the next action.")]
163163
NextAction,
164+
165+
/// <summary>
166+
/// Cycles between states following settings in Target > Configuration.
167+
/// </summary>
168+
[Description("Cycles between states following settings in Target > Configuration.")]
169+
Cycle,
164170
}

RotationSolver/Commands/RSCommands_BasicInfo.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,21 @@ internal static void Disable()
2828

2929
private static void OnCommand(string command, string arguments)
3030
{
31-
DoOneCommand(arguments);
31+
DoOneCommand(arguments ?? string.Empty);
3232
}
3333

3434
private static void DoOneCommand(string command)
3535
{
36-
if (command.Equals("cancel", StringComparison.OrdinalIgnoreCase))
36+
command = (command ?? string.Empty).Trim();
37+
38+
// No args => open config
39+
if (command.Length == 0)
40+
{
41+
RotationSolverPlugin.OpenConfigWindow();
42+
return;
43+
}
44+
45+
if (string.Equals(command, "cancel", StringComparison.OrdinalIgnoreCase))
3746
{
3847
command = "off";
3948
}
@@ -90,9 +99,19 @@ private static void DoOneCommand(string command)
9099
private static bool TryGetOneEnum<T>(string command, out T type) where T : struct, Enum
91100
{
92101
type = default;
102+
103+
if (string.IsNullOrWhiteSpace(command))
104+
{
105+
return false;
106+
}
107+
108+
// Match only the first token exactly (case-insensitive).
109+
int spaceIdx = command.IndexOf(' ');
110+
string token = spaceIdx >= 0 ? command[..spaceIdx] : command;
111+
93112
foreach (T c in Enum.GetValues<T>())
94113
{
95-
if (command.StartsWith(c.ToString(), StringComparison.OrdinalIgnoreCase))
114+
if (string.Equals(token, c.ToString(), StringComparison.OrdinalIgnoreCase))
96115
{
97116
type = c;
98117
return true;

RotationSolver/Commands/RSCommands_OtherCommand.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ public static void DoOtherCommand(OtherCommandType otherType, string str)
1313
{
1414
switch (otherType)
1515
{
16+
case OtherCommandType.Cycle:
17+
ExecuteCycleCommand();
18+
break;
19+
1620
case OtherCommandType.Rotations:
1721
ExecuteRotationCommand(str);
1822
break;
@@ -39,6 +43,26 @@ public static void DoOtherCommand(OtherCommandType otherType, string str)
3943
}
4044
}
4145

46+
private static void ExecuteCycleCommand()
47+
{
48+
if (Service.Config.CycleType == CycleType.CycleNormal)
49+
{
50+
CycleStateWithOneTargetTypes();
51+
}
52+
else if (Service.Config.CycleType == CycleType.CycleAllAuto)
53+
{
54+
CycleStateWithAllTargetTypes();
55+
}
56+
else if (Service.Config.CycleType == CycleType.CycleManual)
57+
{
58+
CycleStateManual();
59+
}
60+
else if (Service.Config.CycleType == CycleType.CycleManualAuto)
61+
{
62+
CycleStateManualAuto();
63+
}
64+
}
65+
4266
private static void ExecuteRotationCommand(string str)
4367
{
4468
ICustomRotation? customCombo = DataCenter.CurrentRotation;

RotationSolver/Commands/RSCommands_StateSpecialCommand.cs

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,125 @@ private static StateCommandType AdjustStateType(StateCommandType stateType, ref
8080
return stateType;
8181
}
8282

83+
public static void CycleStateManualAuto()
84+
{
85+
// If currently Off, go to Manual
86+
if (!DataCenter.State)
87+
{
88+
DoStateCommandType(StateCommandType.Manual);
89+
return;
90+
}
91+
92+
// If currently in Manual mode, turn Off
93+
if (DataCenter.IsManual)
94+
{
95+
DoStateCommandType(StateCommandType.Auto);
96+
return;
97+
}
98+
99+
// If currently On but not Manual, switch to Manual
100+
DoStateCommandType(StateCommandType.Manual);
101+
}
102+
103+
public static void CycleStateManual()
104+
{
105+
// If currently Off, go to Manual
106+
if (!DataCenter.State)
107+
{
108+
DoStateCommandType(StateCommandType.Manual);
109+
return;
110+
}
111+
112+
// If currently in Manual mode, turn Off
113+
if (DataCenter.IsManual)
114+
{
115+
DoStateCommandType(StateCommandType.Off);
116+
return;
117+
}
118+
119+
// If currently On but not Manual, switch to Manual
120+
DoStateCommandType(StateCommandType.Manual);
121+
}
122+
123+
public static void CycleStateWithAllTargetTypes()
124+
{
125+
// If currently Off, start with the first TargetType
126+
if (!DataCenter.State)
127+
{
128+
if (Service.Config.TargetingTypes.Count > 0)
129+
{
130+
Service.Config.TargetingIndex = 0;
131+
DoStateCommandType(StateCommandType.Auto, 0);
132+
}
133+
else
134+
{
135+
// No targeting types configured, go to Manual
136+
DoStateCommandType(StateCommandType.Manual);
137+
}
138+
return;
139+
}
140+
141+
// If currently in Auto mode, cycle through all TargetTypes
142+
if (DataCenter.State && !DataCenter.IsManual)
143+
{
144+
int nextIndex = Service.Config.TargetingIndex + 1;
145+
146+
// If we've gone through all TargetTypes, switch to Manual
147+
if (nextIndex >= Service.Config.TargetingTypes.Count)
148+
{
149+
DoStateCommandType(StateCommandType.Manual);
150+
}
151+
else
152+
{
153+
// Move to next TargetType
154+
Service.Config.TargetingIndex = nextIndex;
155+
DoStateCommandType(StateCommandType.Auto, nextIndex);
156+
}
157+
return;
158+
}
159+
160+
// If currently in Manual mode, turn off
161+
if (DataCenter.State && DataCenter.IsManual)
162+
{
163+
DoStateCommandType(StateCommandType.Off);
164+
return;
165+
}
166+
}
167+
168+
public static void CycleStateWithOneTargetTypes()
169+
{
170+
// If currently Off, go to Auto using the highest TargetingIndex (last configured type)
171+
if (!DataCenter.State)
172+
{
173+
if (Service.Config.TargetingTypes.Count > 0)
174+
{
175+
int lastIdx = Service.Config.TargetingTypes.Count - Service.Config.TargetingTypes.Count;
176+
Service.Config.TargetingIndex = lastIdx;
177+
DoStateCommandType(StateCommandType.Auto, lastIdx);
178+
}
179+
else
180+
{
181+
// No targeting types configured, go to Manual
182+
DoStateCommandType(StateCommandType.Manual);
183+
}
184+
return;
185+
}
186+
187+
// If currently in Auto mode, switch to Manual
188+
if (DataCenter.State && !DataCenter.IsManual)
189+
{
190+
DoStateCommandType(StateCommandType.Manual);
191+
return;
192+
}
193+
194+
// If currently in Manual mode, turn Off
195+
if (DataCenter.State && DataCenter.IsManual)
196+
{
197+
DoStateCommandType(StateCommandType.Off);
198+
return;
199+
}
200+
}
201+
83202
private static void UpdateTargetingIndex(ref int index)
84203
{
85204
if (index == -1)

RotationSolver/UI/RotationConfigWindow.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,8 @@ private static void DrawAboutMacros()
11051105
DisplayCommandHelp(StateCommandType.Auto);
11061106
DisplayCommandHelp(StateCommandType.Manual);
11071107
DisplayCommandHelp(StateCommandType.Off);
1108+
DisplayCommandHelp(OtherCommandType.Cycle);
1109+
ImGui.NewLine();
11081110

11091111
// Display command help for other commands
11101112
DisplayCommandHelp(OtherCommandType.NextAction);

0 commit comments

Comments
 (0)