forked from ArchiDog1998/RotationSolver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRotationSolverPlugin.cs
149 lines (122 loc) · 4.88 KB
/
RotationSolverPlugin.cs
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
using Dalamud.Game.ClientState.Conditions;
using Dalamud.Game.Text.SeStringHandling.Payloads;
using Dalamud.Interface.Windowing;
using Dalamud.Plugin;
using ECommons;
using ECommons.DalamudServices;
using ECommons.GameHelpers;
using RotationSolver.Basic.Configuration;
using RotationSolver.Commands;
using RotationSolver.Data;
using RotationSolver.UI;
using RotationSolver.Updaters;
using XIVConfigUI;
namespace RotationSolver;
public sealed class RotationSolverPlugin : IDalamudPlugin, IDisposable
{
private readonly WindowSystem windowSystem;
internal static RotationConfigWindow? _rotationConfigWindow;
static ControlWindow? _controlWindow;
static NextActionWindow? _nextActionWindow;
static CooldownWindow? _cooldownWindow;
static readonly List<IDisposable> _dis = [];
public static string Name => "Rotation Solver";
public static DalamudLinkPayload OpenLinkPayload { get; private set; } = null!;
public static DalamudLinkPayload? HideWarningLinkPayload { get; private set; }
public RotationSolverPlugin(DalamudPluginInterface pluginInterface)
{
ECommonsMain.Init(pluginInterface, this, ECommons.Module.DalamudReflector, ECommons.Module.ObjectFunctions);
XIVConfigUIMain.Init(pluginInterface, Service.COMMAND, "Open config window.", RSCommands.DoOneCommand,
typeof(Configs), typeof(UiString), typeof(TargetingType), typeof(WhyActionCantUse));
XIVConfigUIMain.ShowTooltip = () => Service.Config.ShowTooltips;
_dis.Add(new Service());
_rotationConfigWindow = new();
_controlWindow = new();
_nextActionWindow = new();
_cooldownWindow = new();
windowSystem = new WindowSystem(Name);
windowSystem.AddWindow(_rotationConfigWindow);
windowSystem.AddWindow(_controlWindow);
windowSystem.AddWindow(_nextActionWindow);
windowSystem.AddWindow(_cooldownWindow);
Svc.PluginInterface.UiBuilder.OpenConfigUi += OnOpenConfigUi;
Svc.PluginInterface.UiBuilder.OpenMainUi += OnOpenConfigUi;
Svc.PluginInterface.UiBuilder.Draw += OnDraw;
PainterManager.Init();
MajorUpdater.Enable();
Watcher.Enable();
OtherConfiguration.Init();
OpenLinkPayload = pluginInterface.AddChatLinkHandler(0, (id, str) =>
{
if (id == 0) OpenConfigWindow();
});
HideWarningLinkPayload = pluginInterface.AddChatLinkHandler(1, (id, str) =>
{
if (id == 1)
{
Service.Config.HideWarning.Value = true;
Svc.Chat.Print("Warning has been hidden.");
}
});
Task.Run(async () =>
{
await DownloadHelper.DownloadAsync();
await RotationUpdater.GetAllCustomRotationsAsync(DownloadOption.Download);
});
#if DEBUG
if (Player.Available)
{
//_ = XIVPainterMain.ShowOff();
}
#endif
}
private void OnDraw()
{
if (Svc.GameGui.GameUiHidden) return;
windowSystem.Draw();
}
public async void Dispose()
{
DataCenter.RightNowDutyRotation?.Dispose();
DataCenter.RightNowRotation?.Dispose();
Watcher.Disable();
Svc.PluginInterface.UiBuilder.OpenConfigUi -= OnOpenConfigUi;
Svc.PluginInterface.UiBuilder.Draw -= OnDraw;
foreach (var item in _dis)
{
item.Dispose();
}
_dis?.Clear();
MajorUpdater.Dispose();
PainterManager.Dispose();
XIVConfigUIMain.Dispose();
await OtherConfiguration.Save();
ECommonsMain.Dispose();
Service.Config.Save();
}
private void OnOpenConfigUi()
{
_rotationConfigWindow!.IsOpen = true;
}
internal static void OpenConfigWindow()
{
_rotationConfigWindow?.Toggle();
}
static RandomDelay validDelay = new(() => (0.2f, 0.2f));
internal static void UpdateDisplayWindow()
{
var isValid = validDelay.Delay(MajorUpdater.IsValid
&& DataCenter.RightNowRotation != null
&& !Svc.Condition[ConditionFlag.OccupiedInCutSceneEvent]
&& !Svc.Condition[ConditionFlag.Occupied38] //Treasure hunt.
&& !Svc.Condition[ConditionFlag.WaitingForDuty]
&& (!Svc.Condition[ConditionFlag.UsingParasol] || Player.Object.StatusFlags.HasFlag(Dalamud.Game.ClientState.Objects.Enums.StatusFlags.WeaponOut))
&& !Svc.Condition[ConditionFlag.OccupiedInQuestEvent]);
_nextActionWindow!.IsOpen = isValid && Service.Config.ShowNextActionWindow;
isValid &= !Service.Config.OnlyShowWithHostileOrInDuty
|| Svc.Condition[ConditionFlag.BoundByDuty]
|| DataCenter.AllHostileTargets.Any(o => o.DistanceToPlayer() <= 25);
_controlWindow!.IsOpen = isValid && Service.Config.ShowControlWindow;
_cooldownWindow!.IsOpen = isValid && Service.Config.ShowCooldownWindow;
}
}