forked from UnknownX7/ReAction
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathReAction.cs
More file actions
112 lines (91 loc) · 3.69 KB
/
ReAction.cs
File metadata and controls
112 lines (91 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System;
using System.Collections.Generic;
using System.Linq;
using Dalamud.Game;
using Dalamud.Logging;
using Dalamud.Plugin;
namespace ReAction;
public class ReAction : IDalamudPlugin
{
public string Name => "ReAction";
public static ReAction Plugin { get; private set; }
public static Configuration Config { get; private set; }
public static Dictionary<uint, Lumina.Excel.GeneratedSheets.Action> actionSheet;
public static Dictionary<uint, Lumina.Excel.GeneratedSheets.Action> mountActionsSheet;
public ReAction(DalamudPluginInterface pluginInterface)
{
Plugin = this;
DalamudApi.Initialize(this, pluginInterface);
Config = (Configuration)DalamudApi.PluginInterface.GetPluginConfig() ?? new();
Config.Initialize();
try
{
Game.Initialize();
actionSheet = DalamudApi.DataManager.GetExcelSheet<Lumina.Excel.GeneratedSheets.Action>()?.Where(i => i.ClassJobCategory.Row > 0 && i.ActionCategory.Row <= 4 && i.RowId is not 7).ToDictionary(i => i.RowId, i => i);
mountActionsSheet = DalamudApi.DataManager.GetExcelSheet<Lumina.Excel.GeneratedSheets.Action>()?.Where(i => i.ActionCategory.Row == 12).ToDictionary(i => i.RowId, i => i);
if (actionSheet == null || mountActionsSheet == null)
throw new ApplicationException("Action sheet failed to load!");
DalamudApi.Framework.Update += Update;
DalamudApi.PluginInterface.UiBuilder.Draw += Draw;
DalamudApi.PluginInterface.UiBuilder.OpenConfigUi += ToggleConfig;
}
catch (Exception e)
{
PluginLog.Error($"Failed loading ReAction\n{e}");
}
}
public void ToggleConfig() => PluginUI.isVisible ^= true;
[Command("/reaction")]
[HelpMessage("Opens / closes the config.")]
private void ToggleConfig(string command, string argument) => ToggleConfig();
[Command("/macroqueue")]
[Aliases("/mqueue")]
[HelpMessage("[on|off] - Toggles (with no argument specified), enables or disables /ac queueing in the current macro.")]
private void OnMacroQueue(string command, string argument)
{
if (!Game.IsMacroRunning)
{
PrintError("This command requires a macro to be running.");
return;
}
switch (argument)
{
case "on":
case "" when !Game.queueACCommandReplacer.IsEnabled:
Game.queueACCommandReplacer.Enable();
break;
case "off":
case "" when Game.queueACCommandReplacer.IsEnabled:
Game.queueACCommandReplacer.Disable();
break;
default:
PrintError("Invalid usage.");
break;
}
}
public static void PrintEcho(string message) => DalamudApi.ChatGui.Print($"[ReAction] {message}");
public static void PrintError(string message) => DalamudApi.ChatGui.PrintError($"[ReAction] {message}");
private void Update(Framework framework)
{
if (Game.queueACCommandReplacer.IsEnabled && !Game.IsMacroRunning)
Game.queueACCommandReplacer.Disable();
ActionStackManager.Update();
}
private void Draw() => PluginUI.Draw();
protected virtual void Dispose(bool disposing)
{
if (!disposing) return;
Config.Save();
DalamudApi.Framework.Update -= Update;
DalamudApi.PluginInterface.UiBuilder.Draw -= Draw;
DalamudApi.PluginInterface.UiBuilder.OpenConfigUi -= ToggleConfig;
DalamudApi.Dispose();
Game.Dispose();
Memory.Dispose();
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}