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
|
|
@ -30,6 +30,21 @@ internal sealed class ScopedPluginHost : IPluginHost, IDisposable
|
|||
public ISelectionService Selection => _selection;
|
||||
public IUiRegistry Ui => _ui;
|
||||
|
||||
/// <summary>
|
||||
/// Delegated rather than scoped, unlike <see cref="Events"/>,
|
||||
/// <see cref="Selection"/> and <see cref="Ui"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Automation has no registrations to roll back — it is reads plus a cast
|
||||
/// call. What actually stops a disabled plugin acting is that its
|
||||
/// <c>Events.Tick</c> subscription is revoked with the scoped event source,
|
||||
/// so its buff loop stops being driven. A plugin that cached the surface
|
||||
/// could still issue a cast from some other callback; that is acceptable
|
||||
/// while plugins are first-party and trusted, and the fix if that changes
|
||||
/// is a revocable wrapper here, not a change at the call site.
|
||||
/// </remarks>
|
||||
public IAutomationSurface Automation => _inner.Automation;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_disposed)
|
||||
|
|
@ -142,8 +157,60 @@ internal sealed class ScopedPluginHost : IPluginHost, IDisposable
|
|||
{
|
||||
private readonly object _gate = new();
|
||||
private readonly List<Action<WorldEntitySnapshot>> _registrations = [];
|
||||
private readonly List<Action<double>> _tickRegistrations = [];
|
||||
private bool _disposed;
|
||||
|
||||
/// <summary>
|
||||
/// Same transactional revoke contract as <see cref="EntitySpawned"/>.
|
||||
/// Revoking this on teardown is what actually stops a disabled plugin
|
||||
/// acting on the world: no tick, no automation loop.
|
||||
/// </summary>
|
||||
public event Action<double> Tick
|
||||
{
|
||||
add
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(value);
|
||||
try
|
||||
{
|
||||
inner.Tick += value;
|
||||
}
|
||||
catch
|
||||
{
|
||||
try { inner.Tick -= value; }
|
||||
catch { }
|
||||
throw;
|
||||
}
|
||||
lock (_gate)
|
||||
{
|
||||
if (!_disposed)
|
||||
{
|
||||
_tickRegistrations.Add(value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try { inner.Tick -= value; }
|
||||
catch { }
|
||||
throw new ObjectDisposedException(nameof(ScopedEvents));
|
||||
}
|
||||
remove
|
||||
{
|
||||
if (value is null)
|
||||
return;
|
||||
inner.Tick -= value;
|
||||
lock (_gate)
|
||||
{
|
||||
for (int index = _tickRegistrations.Count - 1; index >= 0; index--)
|
||||
{
|
||||
if (_tickRegistrations[index] != value)
|
||||
continue;
|
||||
_tickRegistrations.RemoveAt(index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public event Action<WorldEntitySnapshot> EntitySpawned
|
||||
{
|
||||
add
|
||||
|
|
@ -190,6 +257,7 @@ internal sealed class ScopedPluginHost : IPluginHost, IDisposable
|
|||
public void Dispose()
|
||||
{
|
||||
Action<WorldEntitySnapshot>[] registrations;
|
||||
Action<double>[] tickRegistrations;
|
||||
lock (_gate)
|
||||
{
|
||||
if (_disposed)
|
||||
|
|
@ -197,6 +265,8 @@ internal sealed class ScopedPluginHost : IPluginHost, IDisposable
|
|||
_disposed = true;
|
||||
registrations = _registrations.ToArray();
|
||||
_registrations.Clear();
|
||||
tickRegistrations = _tickRegistrations.ToArray();
|
||||
_tickRegistrations.Clear();
|
||||
}
|
||||
|
||||
for (int index = registrations.Length - 1; index >= 0; index--)
|
||||
|
|
@ -204,6 +274,12 @@ internal sealed class ScopedPluginHost : IPluginHost, IDisposable
|
|||
try { inner.EntitySpawned -= registrations[index]; }
|
||||
catch { }
|
||||
}
|
||||
|
||||
for (int index = tickRegistrations.Length - 1; index >= 0; index--)
|
||||
{
|
||||
try { inner.Tick -= tickRegistrations[index]; }
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoveLast(Action<WorldEntitySnapshot> handler)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ public sealed class WorldEvents : IEvents
|
|||
private readonly Dictionary<uint, WorldEntitySnapshot> _current = new();
|
||||
private readonly List<Subscription> _subscriptions = new();
|
||||
private Subscription[] _liveSnapshot = Array.Empty<Subscription>();
|
||||
private Action<double>? _tick;
|
||||
|
||||
private sealed class Subscription(Action<WorldEntitySnapshot> handler)
|
||||
{
|
||||
|
|
@ -77,6 +78,46 @@ public sealed class WorldEvents : IEvents
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised by the host once per update. Unlike <see cref="EntitySpawned"/>
|
||||
/// there is no replay: a tick is a moment, not a fact about the world, and
|
||||
/// replaying one to a late subscriber would be meaningless.
|
||||
/// </summary>
|
||||
public event Action<double> Tick
|
||||
{
|
||||
add
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(value);
|
||||
lock (_lock)
|
||||
_tick += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
if (value is null)
|
||||
return;
|
||||
lock (_lock)
|
||||
_tick -= value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Called by the host on its update thread.</summary>
|
||||
public void FireTick(double elapsedSeconds)
|
||||
{
|
||||
Action<double>? handlers;
|
||||
lock (_lock)
|
||||
handlers = _tick;
|
||||
if (handlers is null)
|
||||
return;
|
||||
|
||||
// Invoked per subscriber rather than as one multicast call so a single
|
||||
// throwing plugin cannot suppress every later subscriber's tick.
|
||||
foreach (Delegate handler in handlers.GetInvocationList())
|
||||
{
|
||||
try { ((Action<double>)handler)(elapsedSeconds); }
|
||||
catch { /* plugin errors don't propagate out of event dispatch */ }
|
||||
}
|
||||
}
|
||||
|
||||
public event Action<WorldEntitySnapshot> EntitySpawned
|
||||
{
|
||||
add
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue