Show / Hide Table of Contents

Class EffectTrigger<TriggerArgs>

Represents an "event" that can automatically trigger and manage one or more Effect<TriggerArgs> instances, and acts as part of the implementation of duration in Effect.

Inheritance
System.Object
EffectTrigger<TriggerArgs>
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace: GoRogue
Assembly: GoRogue.dll
Syntax
public class EffectTrigger<TriggerArgs>

    where TriggerArgs : EffectArgs
Type Parameters
Name Description
TriggerArgs

The type of argument that must be accepted by the Trigger(TriggerArgs) function of any Effect added to this EffectTrigger.

Remarks

EffectTrigger's primary purpose is to represent an event that can trigger one or more effects, and automatically remove those effects from the list when their duration reaches 0. Each EffectTrigger instance can have one or more (non-instantaneous) effects added to it. All Effects must take the same type of argument to their Trigger(TriggerArgs) function, as specified by this class's type parameter.

Each time the TriggerEffects(TriggerArgs) function is called, every Effect has its Trigger function called (provided its duration is not 0). Each Effect may, via the TriggerArgs CancelTrigger member, stop the effect from being sent to subsequent effects in the EffectTrigger's list. Once either all effects in the list have had their Trigger function called, or some effect has cancelled the triggering, any effect whose duration has reached 0 is removed from the EffectTrigger automatically.

Typically, one instance of this class is created per "event" that can trigger effects, and then the instance's TriggerEffects function is called whenever that event happens. For example, in a typical roguelike, all damageable creatures might have an instance of this class called OnDamageTakenEffects. Any effect that should trigger when that creature takes damage would then be added to that creature's OnDamageTakenEffects EffectTrigger. The TakeDamage function of that creature would then need to call OnDamageTakenEffects.TriggerEffects(...). In this way, all effects added to the OnDamageTakenEffects EffectTrigger would be triggered automatically whenever the creature takes damage.

For some complex game mechanics, it may be desireable to control how effects stack, the order they appear in the effects list of EffectTriggers, etc. In these cases, subclassing EffectTrigger and overriding the add and remove functions can allow this functionality.

Constructors

| Improve this Doc View Source

EffectTrigger()

Constructor.

Declaration
public EffectTrigger()

Properties

| Improve this Doc View Source

Effects

List of all effects that are part of this EffectTrigger.

Declaration
public IReadOnlyList<Effect<TriggerArgs>> Effects { get; }
Property Value
Type Description
System.Collections.Generic.IReadOnlyList<Effect<TriggerArgs>>

Methods

| Improve this Doc View Source

Add(Effect<TriggerArgs>)

Adds the given effect to this EffectTrigger, provided the effect's duration is not 0. If the effect's duration is 0, an ArgumentException is thrown.

Declaration
public virtual void Add(Effect<TriggerArgs> effect)
Parameters
Type Name Description
Effect<TriggerArgs> effect

The effect to add to this trigger.

| Improve this Doc View Source

Remove(Effect<TriggerArgs>)

Removes the given effect from this EffectTrigger.

Declaration
public virtual void Remove(Effect<TriggerArgs> effect)
Parameters
Type Name Description
Effect<TriggerArgs> effect

The effect to remove

| Improve this Doc View Source

ToString()

Yields a string representation of each effect that has been added to the effect trigger.

Declaration
public override string ToString()
Returns
Type Description
System.String

A string representation of each effect that has been added to the effect trigger.

Overrides
System.Object.ToString()
| Improve this Doc View Source

TriggerEffects(TriggerArgs)

Calls the Trigger(TriggerArgs) function of each effect in the Effects list (as long as its duration is not 0), then removes any effect that has duration 0.

Declaration
public void TriggerEffects(TriggerArgs args)
Parameters
Type Name Description
TriggerArgs args

Argument to pass to the Trigger(TriggerArgs) function of each effect.

Remarks

The argument given is passed along to the Trigger(TriggerArgs) function of each effect that has Trigger called. If some effect sets the CancelTrigger flag in the argument to true, the loop will be broken and no subsequent effects in the list will have Trigger called. After either this occurs or all effects have had Trigger called, any effect in the list that has a duration of 0 is automatically removed from the list. It is valid to pass null as the argument to this function, if the effects need no actual parameters.

Extension Methods

Utility.Yield<T>(T)
  • Improve this Doc
  • View Source
Back to top Generated by DocFX