Skip to content

Triggers

Michael Speth edited this page Oct 18, 2017 · 1 revision

(For version 0.1.2)

Triggers are used to work with order of abilities.

How triggers are resolved

First, events are fired. For example, "OnTokenIsAssigned" (to get triggers from upgrades that subscribed to this ship), then "OnTokenIsAssignedGlobal"(to get trigger from rules or upgrades that has effect for all ships).

Then, "Triggers.ResolveTriggers" is called. If there are only one trigger, it is automativally resolved. If there are few triggers for same player - window "Select order of triggers" is shown. When all triggers are resolved, callBack of "Triggers.ResolveTriggers" is called.

How to register a trigger

Call "Triggers.RegisterTrigger" to register a new instance of trigger. Trigger must have following parameters:

  • Name - will be shown if there are few triggers for one player
  • TriggerOwner - who owns this trigger and makes decision about order of his triggers
  • TriggerType - what type of triggers is resolved
  • EventHandler - method that will be executed Trigger can have additional parameters:
  • Sender - who sent this trigger
  • EventArgs - details about trigger. For example, source of damage for OnDamageIsDealt trigger
  • Skippable - if all triggers are skippable then window "Select order of triggers" is not shown. For example, when ship assigned 3 regular damage, 3 skippable triggers are created, because there is no differnce what of these damages to resolve first

How to finish a trigger

Call "Triggers.FinishTrigger"

When I must use triggers and when only events are enough

If interaction is required (decision must be taken by player, ship must be selected) - triggers must be used. If change can cause resolution of another triggers (for example, "assign token" can resolve ability "when token is assigned") - triggers must be used. If ability only subscrives to event or changes info in UI - this can be left as only event.