InteractionTrigger

Abstract base class for interaction triggers. Determines how an interaction can be initiated by matching against an incoming trigger instance. The generic variant InteractionTrigger<T> provides a type-safe matching pattern.

Definition

Namespace: Paragon.Townskeep.InteractionSystem Assembly: Townskeep.dll

[Serializable]
public abstract class InteractionTrigger
[Serializable]
public abstract class InteractionTrigger<TInteractionTrigger> : InteractionTrigger
    where TInteractionTrigger : InteractionTrigger

Remarks

The trigger system uses a two-level pattern:

  1. InteractionTrigger (non-generic) — base class with Initialize() and the abstract Match() method.

  2. InteractionTrigger<T> (generic) — implements Match() with type checking, then delegates to IsMatch(T).

This means concrete triggers only need to implement IsMatch(T), and the type dispatching is handled automatically.

Triggers are stored as a list on InteractionContext and matched via InteractionContext.CanBeTriggeredWith().

Quick Lookup

Goal
How

Create a custom trigger

Subclass InteractionTrigger<YourTrigger>, override IsMatch()

Match against a trigger

trigger.Match(incomingTrigger)

Access parent context

this.context (protected field)

Methods

Initialize

Initializes the trigger with its owning context. Called by InteractionContext.Initialize().

Parameter
Type
Description

context

InteractionContext

The owning context

Match (abstract, non-generic)

Tests whether this trigger matches the given incoming trigger.

Parameter
Type
Description

trigger

InteractionTrigger

The incoming trigger to match against

Returns: true if the triggers match.

Match (generic override)

The generic variant implements Match() by first type-checking the incoming trigger, then delegating to IsMatch().

IsMatch (abstract, generic)

Performs the actual comparison logic between two triggers of the same type.

Parameter
Type
Description

trigger

TInteractionTrigger

The typed trigger to compare against

Returns: true if the triggers are considered a match.

Extension Points

Required Overrides (non-generic path)

Method
Purpose

Match(InteractionTrigger)

Full match logic including type checking

Method
Purpose

IsMatch(T)

Type-safe comparison logic

circle-info

Prefer the generic path. Subclass InteractionTrigger<YourTrigger> instead of the non-generic InteractionTrigger to get automatic type dispatching.

Implementation Requirements

When creating a custom trigger, you MUST:

  1. Subclass InteractionTrigger<YourTrigger> (recommended) or InteractionTrigger

  2. Mark the class with [Serializable]

  3. Implement IsMatch(YourTrigger) (generic) or Match(InteractionTrigger) (non-generic)

You SHOULD:

  • Define serializable fields for match criteria (e.g., key codes, zone IDs)

  • Keep matching logic fast — it is called during interaction queries

Properties / Fields

context (protected)

The InteractionContext this trigger belongs to. Set during Initialize().

Common Pitfalls

circle-exclamation
circle-exclamation

Examples

Simple Click Trigger

Keyed Trigger (matching by ID)

Using a Trigger at Runtime

See Also

Last updated