Skip to content

Runtime and Presentation

mewcodex edited this page Sep 2, 2026 · 2 revisions

Runtime and Presentation

English | 简体中文

Custom opcodes need a runtime handler. Register all routes during initialization, before any generated operation executes.

Runtime package

using AutoAnthony;

ComponentRuntimeApi.RegisterPackage(
    "my_watcher:autoanthony:runtime",
    [
        new ComponentRuntimeRoute(
            "watcher_stance",
            "enter_calm",
            new EnterCalmHandler())
    ]);

sealed class EnterCalmHandler : IComponentRuntimeHandler
{
    public async Task<bool> ExecuteAsync(ComponentRuntimeContext context)
    {
        await WatcherActions.EnterCalm(context.Card.Owner, context.Amount);
        return true;
    }
}

WatcherActions above represents the owning mod's normal game-action implementation. A handler returning true owns the operation completely. Returning false continues into AutoAnthony's legacy compatibility dispatcher.

Runtime context

ComponentRuntimeContext exposes:

  • Card, OperationIndex, Operation, and validated RuntimeSpec
  • resolved Amount, including supported X/dependency scaling
  • Target, CardPlay, ChoiceContext, IsTriggered, EventCard, and EventAmount
  • read-only named CardSlots
  • RecordDamageDealt, ReplaceDrawnCards, and SetCardSlot for sibling-operation state
  • RequestEndTurn() for the same deferred, play-phase-safe end-turn path used by built-in effects

Handlers must await all game actions they create. Do not open an interactive choice from an enemy-only timing unless the owning mechanic has a safe noninteractive path. Do not resolve semantics from localized card text.

Hover tips

ComponentPresentationApi.Register(
    "watcher_stance",
    "enter_calm",
    new CalmHoverTips());

sealed class CalmHoverTips : IComponentHoverTipProvider
{
    public IEnumerable<IHoverTip> BuildHoverTips(ComponentPresentationContext context)
    {
        return [WatcherHoverTips.Calm()];
    }
}

Presentation routes are optional. Exact opcode/variant routes override an opcode-wide registration using an empty variant. Providers receive the generated card, operation index, operation, runtime spec, and upgrade state.

Avoid adding a tip that merely repeats the generated card's own same-name Power. Respect AutoAnthony's Surprise Mode: the host suppresses registered tips when the card should remain hidden.

Clone this wiki locally