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:
parent
690f21889e
commit
9d1117b923
27 changed files with 1546 additions and 10 deletions
184
src/AcDream.Plugins.MossTank/MossTankPanel.cs
Normal file
184
src/AcDream.Plugins.MossTank/MossTankPanel.cs
Normal file
|
|
@ -0,0 +1,184 @@
|
|||
using AcDream.Plugin.Abstractions;
|
||||
|
||||
namespace AcDream.Plugins.MossTank;
|
||||
|
||||
/// <summary>
|
||||
/// The panel's binding object and the buff loop's state machine.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// The markup binds <c>{Buff}</c> to <see cref="Buff"/> and its labels to the
|
||||
/// status properties. Everything here runs on the host's update thread — the
|
||||
/// button click and the tick both arrive there — so no locking is needed, and
|
||||
/// none is used, deliberately: adding a lock would imply a second thread that
|
||||
/// does not exist.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b>Pacing.</b> The loop casts one spell, then waits. There is no
|
||||
/// cast-completed event in the plugin API yet, so completion is inferred the
|
||||
/// honest way: re-evaluate the plan each pass and let landed buffs drop out of
|
||||
/// it. A fizzle simply leaves its buff missing and it gets retried on the next
|
||||
/// pass. That is self-correcting without pretending to know an outcome the
|
||||
/// host has not reported.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
internal sealed class MossTankPanel
|
||||
{
|
||||
/// <summary>Roughly a retail cast plus windup, so casts do not stack up.</summary>
|
||||
private const double CastIntervalSeconds = 3.0;
|
||||
|
||||
/// <summary>Refresh a buff already in force but nearly expired.</summary>
|
||||
private const double RefreshWhenUnderSeconds = 60.0;
|
||||
|
||||
/// <summary>Give up on a pass that stops making progress.</summary>
|
||||
private const double StallTimeoutSeconds = 20.0;
|
||||
|
||||
private readonly IPluginHost _host;
|
||||
|
||||
private List<PluginSpellInfo> _plan = new();
|
||||
private int _planIndex;
|
||||
private bool _running;
|
||||
private double _sinceLastCast;
|
||||
private double _sinceProgress;
|
||||
private int _castThisPass;
|
||||
private string _status = "Idle.";
|
||||
|
||||
public MossTankPanel(IPluginHost host) => _host = host;
|
||||
|
||||
/// <summary>Bound to the panel's Buff button.</summary>
|
||||
public Action Buff => StartOrStop;
|
||||
|
||||
public string Title => "MossTank";
|
||||
public string Status => _status;
|
||||
|
||||
public string ButtonText => _running ? "Stop" : "Buff";
|
||||
|
||||
public string Detail
|
||||
{
|
||||
get
|
||||
{
|
||||
IAutomationSurface automation = _host.Automation;
|
||||
if (!automation.IsAvailable)
|
||||
return "Not in world.";
|
||||
int known = automation.Spells.KnownSelfBuffs.Count;
|
||||
int active = automation.Character.ActiveEnchantments.Count;
|
||||
return $"{known} self-buffs known / {active} active"
|
||||
+ $" · mana {automation.Character.CurrentMana}"
|
||||
+ $"/{automation.Character.MaxMana}";
|
||||
}
|
||||
}
|
||||
|
||||
private void StartOrStop()
|
||||
{
|
||||
if (_running)
|
||||
{
|
||||
Stop("Stopped.");
|
||||
return;
|
||||
}
|
||||
|
||||
IAutomationSurface automation = _host.Automation;
|
||||
if (!automation.IsAvailable)
|
||||
{
|
||||
_status = "Not in world.";
|
||||
return;
|
||||
}
|
||||
|
||||
_plan = BuffPlan.Build(
|
||||
automation.Spells.KnownSelfBuffs,
|
||||
automation.Character.ActiveEnchantments,
|
||||
RefreshWhenUnderSeconds);
|
||||
_planIndex = 0;
|
||||
_castThisPass = 0;
|
||||
_sinceLastCast = CastIntervalSeconds; // cast the first one immediately
|
||||
_sinceProgress = 0;
|
||||
|
||||
if (_plan.Count == 0)
|
||||
{
|
||||
_status = "Already fully buffed.";
|
||||
return;
|
||||
}
|
||||
|
||||
_running = true;
|
||||
_status = $"Buffing 0/{_plan.Count}…";
|
||||
_host.Log.Info($"MossTank: buff pass started, {_plan.Count} spell(s) to cast");
|
||||
}
|
||||
|
||||
private void Stop(string status)
|
||||
{
|
||||
_running = false;
|
||||
_plan = new List<PluginSpellInfo>();
|
||||
_planIndex = 0;
|
||||
_status = status;
|
||||
}
|
||||
|
||||
/// <summary>Driven by <see cref="IEvents.Tick"/> on the host update thread.</summary>
|
||||
public void OnTick(double elapsedSeconds)
|
||||
{
|
||||
if (!_running)
|
||||
return;
|
||||
|
||||
IAutomationSurface automation = _host.Automation;
|
||||
if (!automation.IsAvailable)
|
||||
{
|
||||
Stop("Lost the session.");
|
||||
return;
|
||||
}
|
||||
|
||||
_sinceLastCast += elapsedSeconds;
|
||||
_sinceProgress += elapsedSeconds;
|
||||
|
||||
if (_sinceProgress > StallTimeoutSeconds)
|
||||
{
|
||||
Stop($"Stalled after {_castThisPass} cast(s).");
|
||||
_host.Log.Warn("MossTank: buff pass stalled; stopping");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_sinceLastCast < CastIntervalSeconds || automation.Magic.IsCasting)
|
||||
return;
|
||||
|
||||
// Re-derive against current enchantments so anything that landed since
|
||||
// the pass began drops out rather than being cast twice.
|
||||
_plan = BuffPlan.Build(
|
||||
automation.Spells.KnownSelfBuffs,
|
||||
automation.Character.ActiveEnchantments,
|
||||
RefreshWhenUnderSeconds);
|
||||
|
||||
if (_plan.Count == 0)
|
||||
{
|
||||
Stop($"Done — {_castThisPass} cast(s).");
|
||||
_host.Log.Info($"MossTank: buff pass complete ({_castThisPass} cast)");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_planIndex >= _plan.Count)
|
||||
_planIndex = 0;
|
||||
|
||||
PluginSpellInfo next = _plan[_planIndex];
|
||||
PluginCastGate gate = automation.Magic.EvaluateGate(next.SpellId);
|
||||
if (gate != PluginCastGate.Ready)
|
||||
{
|
||||
// Skip it rather than blocking the pass; the next tick tries the
|
||||
// one after. A permanently ungateable spell falls out when the
|
||||
// stall timeout fires.
|
||||
_planIndex++;
|
||||
_status = $"Skipped {next.Name} ({gate}).";
|
||||
return;
|
||||
}
|
||||
|
||||
if (automation.Magic.Cast(next.SpellId))
|
||||
{
|
||||
_castThisPass++;
|
||||
_sinceLastCast = 0;
|
||||
_sinceProgress = 0;
|
||||
_planIndex = 0;
|
||||
_status = $"Casting {next.Name} ({_castThisPass} cast)…";
|
||||
_host.Log.Info($"MossTank: casting {next.Name} (0x{next.SpellId:X4})");
|
||||
}
|
||||
else
|
||||
{
|
||||
_planIndex++;
|
||||
_status = $"Refused {next.Name}.";
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue