feat(plugins): MossTank — a self-buffing plugin, and the automation surface it needed

First consumer of acdream's plugin automation surface, and the first slice of
the VTank-class plugin milestone
(docs/research/2026-07-29-vtank-plugin-automation-requirements.md).

MossTank shows a panel with a Buff button; clicking it casts every self-buff
the character is missing, skips what is already in force at an equal or higher
tier, and refreshes what is nearly expired.

The host/plugin line is the load-bearing decision here. The host publishes
spell DATA -- family, tier, difficulty, mana, duration -- plus a cast
primitive with a preflight gate. The plugin owns the POLICY. That is the
architectural conclusion the requirements research reached: VTank's engine
lived in plugin-land, built on Decal's primitives, and baking "best buff for
skill X" into the host would start pulling the engine inward one convenience
at a time.

Why the plan is driven off the spellbook rather than off trained skills, which
is the obvious reading of "buff every trained and specialised skill": the
client cannot honestly make that mapping. The link between a spell and the
stat it modifies arrives from the SERVER in the enchantment message and is
absent from the client's own spell table. What the client does know is which
spells the character has learned -- and a character only learns buffs for the
skills they use, so the spellbook reaches the same set without inventing a
mapping the client has no grounds for.

Surface added, all BCL-only so Plugin.Abstractions keeps its zero project
references:

* ICharacterInfo, ISpellCatalog, IMagicCommands, grouped behind one
  IAutomationSurface so IPluginHost grows by one member rather than three.
* IEvents.Tick. Automation is sequences, not single calls -- a buff pass casts
  several spells and must wait between them. Without a host tick a plugin
  would need its own timer thread re-entering the host off its update thread.
* NoOpAutomationSurface for hosts with no live session, so a plugin keeps one
  code path and checks IsAvailable.

Markup gained <button> and <label>; it previously supported only <meter>, with
a comment promising the rest. Buttons bind onclick to an Action property and
FAIL THE PANEL LOAD if it does not resolve -- a silently dead button is worse
than a panel that refuses to load, because the user clicks and there is
nothing to diagnose. Labels bind through a Func so a status line tracks its
binding instead of freezing at build time.

Enchantment reads use EnchantmentsInEffectSnapshot rather than the raw active
set: retail leaves a weaker same-family enchantment in the registry while a
stronger one is in force, and a plugin asking "am I buffed?" means in force.

BuffPlan is a pure function of (known buffs, active enchantments) precisely so
it can be tested without a session; 9 tests cover tier supersede, the
family-0 no-stack bucket that must not be de-duplicated, expiry refresh, and
plan stability across the rebuilds the tick loop performs.

Solution builds clean; 14,421 tests pass on the standard hermetic lane filter,
0 failures.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-08-20 16:22:28 +02:00
parent 690f21889e
commit 9d1117b923
27 changed files with 1546 additions and 10 deletions

View file

@ -0,0 +1,59 @@
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;
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 markup = Path.Combine(
Path.GetDirectoryName(typeof(MossTankPlugin).Assembly.Location) ?? ".",
"mosstank.xml");
_host.Ui.AddMarkupPanel(markup, _panel);
_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;
_tick = null;
_host?.Log.Info("MossTank disabled");
}
}