Skip to content

Commit 899dc11

Browse files
authored
Merge pull request #1099 from erdelf/master
reworking commands (especially for helpers)
2 parents b69ede8 + 5bcfbe0 commit 899dc11

19 files changed

+448
-353
lines changed

AutoDuty/AutoDuty.cs

Lines changed: 272 additions & 328 deletions
Large diffs are not rendered by default.

AutoDuty/Helpers/ActiveHelperBase.cs

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,57 @@ namespace AutoDuty.Helpers
88
{
99
using System;
1010
using System.Collections.Generic;
11-
using static FFXIVClientStructs.FFXIV.Client.Game.GcArmyManager.Delegates;
11+
using System.Linq;
12+
using System.Reflection;
13+
using Serilog;
1214

1315
public static class ActiveHelper
1416
{
1517
internal static HashSet<IActiveHelper> activeHelpers = [];
18+
19+
public static void InvokeAllHelpers()
20+
{
21+
Type baseType = typeof(ActiveHelperBase<>);
22+
Assembly assembly = typeof(ActiveHelper).Assembly;
23+
24+
foreach (Type type in assembly.GetTypes())
25+
{
26+
if (!type.IsClass || type.IsAbstract)
27+
continue;
28+
29+
Type? current = type;
30+
while (current != null)
31+
{
32+
if (current.IsGenericType && current.GetGenericTypeDefinition() == baseType)
33+
break;
34+
if (current.BaseType is { IsGenericType: true } && current.BaseType.GetGenericTypeDefinition() == baseType)
35+
{
36+
Svc.Log.Warning(type.FullName);
37+
Activator.CreateInstance(type);
38+
break;
39+
}
40+
current = current.BaseType;
41+
}
42+
}
43+
}
1644
}
1745

1846
internal interface IActiveHelper
1947
{
20-
internal void StopIfRunning();
48+
internal void StopIfRunning();
49+
public string[]? Commands { get; init; }
50+
public string? CommandDescription { get; init; }
51+
public void OnCommand(string[] args);
2152
}
2253

2354
internal abstract class ActiveHelperBase<T> : IActiveHelper where T : ActiveHelperBase<T>, new()
2455
{
2556
protected abstract string Name { get; }
2657
protected abstract string DisplayName { get; }
2758

59+
public virtual string[]? Commands { get; init; }
60+
public virtual string? CommandDescription { get; init; }
61+
2862
protected virtual string[] AddonsToClose { get; } = [];
2963

3064
protected virtual int TimeOut { get; set; } = 300_000;
@@ -44,6 +78,12 @@ public static T Instance
4478
}
4579
}
4680

81+
public ActiveHelperBase()
82+
{
83+
instance = (T)this;
84+
ActiveHelper.activeHelpers.Add(this);
85+
}
86+
4787

4888
internal static void Invoke()
4989
{
@@ -57,6 +97,13 @@ internal virtual void Start()
5797
this.DebugLog(this.Name + " already running");
5898
return;
5999
}
100+
if (PlayerHelper.GetGrandCompanyRank() <= 5)
101+
{
102+
Svc.Log.Info("GC Turnin requires GC Rank 6 or Higher");
103+
return;
104+
}
105+
106+
60107
this.InfoLog(this.Name + " started");
61108
State = ActionState.Running;
62109
Plugin.States |= PluginState.Other;
@@ -85,6 +132,7 @@ public void StopIfRunning()
85132
this.Stop();
86133
}
87134

135+
88136
internal virtual void Stop()
89137
{
90138
if (State == ActionState.Running)
@@ -154,6 +202,11 @@ public unsafe bool CloseAddons()
154202
return true;
155203
}
156204

205+
public virtual void OnCommand(string[] args)
206+
{
207+
this.Start();
208+
}
209+
157210
protected void DebugLog(string s)
158211
{
159212
Svc.Log.Debug($"{this.Name}: {s}");

AutoDuty/Helpers/AddonHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace AutoDuty.Helpers
1111
{
12-
internal unsafe static class AddonHelper
12+
internal static unsafe class AddonHelper
1313
{
1414
internal static bool SeenAddon = false;
1515

AutoDuty/Helpers/AutoEquipHelper.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99

1010
namespace AutoDuty.Helpers
1111
{
12-
using Windows;
13-
1412
internal unsafe class AutoEquipHelper : ActiveHelperBase<AutoEquipHelper>
1513
{
14+
public override string[]? Commands { get; init; } = ["autoequip", "equiprec"];
15+
public override string? CommandDescription { get; init; } = "Equips recommended gear";
16+
1617
internal override void Start()
1718
{
1819
switch (Plugin.Configuration.AutoEquipRecommendedGearSource)

AutoDuty/Helpers/AutoRetainerHelper.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ internal class AutoRetainerHelper : ActiveHelperBase<AutoRetainerHelper>
1717
protected override string Name { get; } = nameof(AutoRetainerHelper);
1818
protected override string DisplayName { get; } = "AutoRetainer";
1919

20+
public override string[]? Commands { get; init; } = ["ar", "autoretainer"];
21+
public override string? CommandDescription { get; init; } = "Automatically manages retainers using the AutoRetainer plugin";
22+
23+
2024
protected override int TimeOut { get; set; } = 600_000;
2125

2226
protected override string[] AddonsToClose { get; } = ["RetainerList", "SelectYesno", "SelectString", "RetainerTaskAsk"];

AutoDuty/Helpers/CofferHelper.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ namespace AutoDuty.Helpers
1212

1313
internal class CofferHelper : ActiveHelperBase<CofferHelper>
1414
{
15+
public override string[]? Commands { get; init; } = ["coffer"];
16+
public override string? CommandDescription { get; init; } = "Opens coffers in your inventory";
17+
1518
private readonly Dictionary<uint, int> doneItems = [];
1619
private int initialGearset;
1720

AutoDuty/Helpers/DesynthHelper.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ internal class DesynthHelper : ActiveHelperBase<DesynthHelper>
1616
protected override string Name => nameof(DesynthHelper);
1717
protected override string DisplayName => "Desynthing";
1818

19+
public override string[]? Commands { get; init; } = ["desynth"];
20+
public override string? CommandDescription { get; init; } = "Desynth's items in your inventory";
21+
1922
protected override string[] AddonsToClose { get; } = ["Desynth", "SalvageResult", "SalvageDialog", "SalvageItemSelector"];
2023

2124
internal override void Start()

AutoDuty/Helpers/ExitDutyHelper.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ internal class ExitDutyHelper : ActiveHelperBase<ExitDutyHelper>
1111
protected override string Name => nameof(ExitDutyHelper);
1212
protected override string DisplayName => "Exiting Duty";
1313

14+
public override string[]? Commands { get; init; } = ["exitduty"];
15+
public override string? CommandDescription { get; init; } = "Exits the current duty if you are not in combat";
16+
1417
protected override int TimeOut { get; set; } = 60_000;
1518

1619
protected override string[] AddonsToClose { get; } = ["ContentsFinderMenu"];

AutoDuty/Helpers/ExtractHelper.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ internal class ExtractHelper : ActiveHelperBase<ExtractHelper>
1313
protected override string Name => nameof(ExtractHelper);
1414
protected override string DisplayName => "Extracting Materia";
1515

16+
public override string[]? Commands { get; init; } = ["extract"];
17+
public override string? CommandDescription { get; init; } = "Extract's materia from equipment";
18+
1619
protected override string[] AddonsToClose { get; } = ["Materialize", "MaterializeDialog", "SelectYesno", "SelectString"];
1720

1821
internal override void Start()

AutoDuty/Helpers/GCTurninHelper.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ internal class GCTurninHelper : ActiveHelperBase<GCTurninHelper>
1616
protected override string Name { get; } = nameof(GCTurninHelper);
1717
protected override string DisplayName { get; } = "GC Turnin";
1818

19+
public override string[]? Commands { get; init; } = ["turnin", "gcturnin"];
20+
public override string? CommandDescription { get; init; } = "Automatically turns in items into the Grand Company Supply";
21+
1922
protected override string[] AddonsToClose { get; } = ["GrandCompanySupplyReward", "SelectYesno", "SelectString", "GrandCompanySupplyList"];
2023

2124
protected override int TimeOut { get; set; } = 600_000;

0 commit comments

Comments
 (0)