74 lines
2.4 KiB
C#
74 lines
2.4 KiB
C#
using AcDream.Plugin.Abstractions;
|
|
|
|
namespace AcDream.Plugins.MossTank;
|
|
|
|
/// <summary>
|
|
/// MossTank — a self-buffing plugin, and the first consumer of acdream's
|
|
/// plugin automation surface.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Named for the mosswart, and for the Virindi Tank lineage this milestone is
|
|
/// modelled on. The buff policy lives here rather than in the host on purpose:
|
|
/// the host publishes spell data and a cast primitive, the plugin decides what
|
|
/// to cast. See <c>docs/research/2026-07-29-vtank-plugin-automation-requirements.md</c>.
|
|
/// </remarks>
|
|
public sealed class MossTankPlugin : IAcDreamPlugin
|
|
{
|
|
private IPluginHost? _host;
|
|
private MossTankPanel? _panel;
|
|
private Action<double>? _tick;
|
|
private IDisposable? _commandRegistration;
|
|
|
|
public void Initialize(IPluginHost host)
|
|
{
|
|
_host = host;
|
|
_panel = new MossTankPanel(host);
|
|
host.Log.Info("MossTank initialized");
|
|
}
|
|
|
|
public void Enable()
|
|
{
|
|
if (_host is null || _panel is null)
|
|
return;
|
|
|
|
// Markup ships beside the plugin assembly, so it is found relative to
|
|
// this DLL rather than the host's working directory -- plugins are
|
|
// loaded from their own directory and the two are not the same.
|
|
string directory =
|
|
Path.GetDirectoryName(typeof(MossTankPlugin).Assembly.Location) ?? ".";
|
|
|
|
_host.Ui.AddPanel(
|
|
new PluginPanelDescriptor("main", "MossTank")
|
|
{
|
|
IconText = "MT",
|
|
StartVisible = true,
|
|
ShowInSidePanel = true,
|
|
},
|
|
Path.Combine(directory, "mosstank.xml"),
|
|
_panel);
|
|
|
|
_commandRegistration = _host.Commands.Register(
|
|
"vt",
|
|
_panel.ExecuteVtankCommand);
|
|
|
|
_tick = _panel.OnTick;
|
|
_host.Events.Tick += _tick;
|
|
|
|
_host.Log.Info(
|
|
_host.Automation.IsAvailable
|
|
? "MossTank enabled"
|
|
: "MossTank enabled (no live session yet; the Buff button will "
|
|
+ "report 'Not in world' until one is up)");
|
|
}
|
|
|
|
public void Disable()
|
|
{
|
|
if (_host is not null && _tick is not null)
|
|
_host.Events.Tick -= _tick;
|
|
_commandRegistration?.Dispose();
|
|
_commandRegistration = null;
|
|
_tick = null;
|
|
_panel?.Disable();
|
|
_host?.Log.Info("MossTank disabled");
|
|
}
|
|
}
|