Skip to content

Runtime and Presentation

mewcodex edited this page Sep 3, 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.RegisterPackage(
    "my_watcher:autoanthony:presentation",
    [new ComponentPresentationRoute(
        "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.

Custom keywords

Register a stable ASCII ID in ComponentPackageRegistration.Keywords, put that ID on source recipes, and register its game projection with ComponentKeywordRuntimeApi.RegisterPackage. An IComponentKeywordRuntimeAdapter may provide native CardKeyword values, semantic card tags, hover tips, and an upgrade callback. The keyword's actual gameplay and balance still belong to a structured operation with runtime and valuation routes.

Runtime, presentation, and keyword package registration preflights the whole route set before committing it. Prefer the package APIs so one duplicate route cannot leave a partially registered integration.

Clone this wiki locally