Table of Contents

Class Effect

Namespace
Anvil.API
Assembly
NWN.Anvil.dll

Represents an effect engine structure.

public sealed class Effect : EffectBase, IDisposable
Inheritance
Effect
Implements
Inherited Members
Extension Methods

Examples

/*
 * Examples for creating and applying effects to objects and locations.
 */

using System;
using System.Linq;
using System.Threading.Tasks;
using Anvil.API;
using Anvil.API.Events;
using Anvil.Services;

namespace NWN.Anvil.Samples.API.EngineStructures
{
  [ServiceBinding(typeof(EffectExamples))]
  public class EffectExamples
  {
    // Some effects can be declared as fields. This allows you to reuse effects, rather than creating them every time.
    private readonly Effect blindnessEffect = Effect.Blindness();
    private readonly Effect bloodVfx = Effect.VisualEffect(VfxType.ComBloodCrtRed);

    public EffectExamples()
    {
      // Make our blindness effect a supernatural effect.
      blindnessEffect.SubType = EffectSubType.Supernatural;

      // Register methods to listen for the player/client enter event.
      NwModule.Instance.OnClientEnter += eventData => _ = RatSummonExample(eventData);

      // When entering a specific area, remove all blindness effects:
      NwArea? area = NwObject.FindObjectsWithTag<NwArea>("clear_blind").FirstOrDefault();
      if (area != null)
      {
        area.OnEnter += RemoveBlindnessExample;
      }

      // Register methods to listen for the creature damage event.
      NwModule.Instance.OnCreatureDamage += BloodVfxExample;
      NwModule.Instance.OnCreatureDamage += BlindnessExample;
    }

    /// <summary>
    /// Spawns a rat creature summon at the module spawn location when a player connects.
    /// </summary>
    private async Task RatSummonExample(ModuleEvents.OnClientEnter eventData)
    {
      // Create the summon effect.
      // Some effects require a "caster" for the effect, and must be made within the caster's context.
      await eventData.Player.ControlledCreature!.WaitForObjectContext();
      Effect summon = Effect.SummonCreature("nw_rat001", VfxType.ImpUnsummon);

      // Spawn the summon at the module's starting location
      Location spawnLocation = NwModule.Instance.StartingLocation;
      spawnLocation.ApplyEffect(EffectDuration.Temporary, summon, TimeSpan.FromMinutes(5));
    }

    /// <summary>
    /// Applies a blood splatter effect to all creatures taking more than 50 damage.
    /// </summary>
    private void BloodVfxExample(OnCreatureDamage eventData)
    {
      // If the target is a creature, and the attack does more than 50 slashing damage...
      if (eventData.Target is NwCreature && eventData.DamageData.GetDamageByType(DamageType.Slashing) > 50)
      {
        // ...Apply our blood effect to the creature
        eventData.Target.ApplyEffect(EffectDuration.Instant, bloodVfx);
      }
    }

    /// <summary>
    /// Applies a 5 second blindness effect to all creatures taking more than 100 damage.
    /// </summary>
    private void BlindnessExample(OnCreatureDamage eventData)
    {
      // If the target is a creature, and the attack does more than 100 bludgeoning damage...
      if (eventData.Target is NwCreature && eventData.DamageData.GetDamageByType(DamageType.Bludgeoning) > 100)
      {
        // ...Apply our blindness effect for 5 seconds.
        eventData.Target.ApplyEffect(EffectDuration.Temporary, blindnessEffect, TimeSpan.FromSeconds(5));
      }
    }

    /// <summary>
    /// Removes any blindness effect still active once a creature enters the area.
    /// </summary>
    private void RemoveBlindnessExample(AreaEvents.OnEnter eventData)
    {
      // If the object entering is not a creature, early return.
      if (eventData.EnteringObject is not NwCreature creature)
      {
        return;
      }

      // Loop through all active effects on the creature, and remove any with the blindness type.
      foreach (Effect effect in creature.ActiveEffects)
      {
        if (effect.EffectType == EffectType.Blindness)
        {
          creature.RemoveEffect(effect);
        }
      }
    }
  }
}

Properties

DurationRemaining

Gets the remaining duration of this effect in seconds. Returns 0 if the duration type is not Temporary.

DurationType

Gets or sets the duration type (Temporary, Instant, Permanent) of this effect.

EffectType

Gets the type of this effect.

IgnoreImmunity

Gets or sets if this effect should ignore immunities.

LinkId

Gets the link id of this effect, if it is a linked effect. There is no guarantees about this identifier other than it is unique and the same for all effects linked to it.

StructureId
SubType

Gets or sets the subtype of this effect.

Tag

Gets or sets the tag for this effect.

TotalDuration

Gets the total duration of this effect in seconds. Returns 0 if the duration type is not Temporary.

Methods

ACDecrease(int, ACBonus)

Creates an effect that decreases the AC of an object.

ACIncrease(int, ACBonus)

Creates an effect that increases the AC of an object.

AbilityDecrease(Ability, int)

Creates an effect that decreases a certain ability score.

AbilityIncrease(Ability, int)

Creates an effect that increases a certain ability score.

Appear()

Creates a special effect to make an object "fly in".

AreaOfEffect(PersistentVfxTableEntry, ScriptCallbackHandle?, ScriptCallbackHandle?, ScriptCallbackHandle?)

Creates an area of effect (AOE) effect.

AttackDecrease(int, AttackBonus)

Creates an effect that applies a penalty to an attack roll.

AttackIncrease(int, AttackBonus)

Creates an effect that applies a bonus to an attack roll.

Beam(VfxType, NwGameObject, BodyNode, bool)

Creates a visual beam effect.

Blindness()

Creates an effect that blinds a creature.

BonusFeat(NwFeat)

Creates an effect that grants a bonus feat, similar to BonusFeat(IPFeat).

Charmed()

Creates an effect that increases the personal reputation to the target by 50 points.

Clone()

Creates a new copy of this effect.

Concealment(int, MissChanceType)

Creates an effect that conceals an object.

Confused()

Creates a confuse effect.

Curse(int, int, int, int, int, int)

Creates a curse effect.

CutsceneDominated()

Creates an effect that is guaranteed to dominate a creature, bypassing immunities and cannot be resisted.

CutsceneGhost()

Creates an effect that allows creatures to pathfind through other creatures without bumping.

CutsceneImmobilize()

Creates an effect that will prevent the target from moving, but can otherwise act unpenalized. The cutscene version bypasses immunities and cannot be resisted.

CutsceneParalyze()

Creates an effect that is guaranteed to paralyze a creature, but can not be resisted.

Damage(int, DamageType, DamagePower)

Creates an effect that immediately applies damage to a target.

DamageDecrease(int, DamageType)

Creates an effect that applies a penalty to a specified damage type.

DamageImmunityDecrease(DamageType, int)

Creates an effect that decreases immunity to a certain damage type.
If a creature does not have an immunity to the specified type, the creature will instead become more vulnerable to the damage, to a max of 100% (double damage).

DamageImmunityIncrease(DamageType, int)

Creates an effect that increases immunity to a certain damage type, to a max of 100% (complete immunity).

DamageIncrease(DamageBonus, DamageType)

Creates an effect that applies a bonus to a specified damage type.

DamageIncrease(int, DamageType)

Creates an effect that applies a bonus to a specified damage type.

DamageReduction(int, DamagePower, int, bool)

Creates an effect that resists a constant amount of damage from a physical attack with a certain magical power.

DamageResistance(DamageType, int, int, bool)

Creates an effect that resists a constant amount of damage from a specific damage type.

DamageShield(int, DamageBonus, DamageType)

Creates an effect that reflects damage to melee attackers from successful hits.

Darkness()

Creates an effect that shrouds an area in darkness, applying a miss chance to all those standing within.
Creatures with an Ultravision effect will bypass this miss chance.

Dazed()

Creates an effect that dazes a creature, preventing all actions but walking movement.

Deaf()

Creates an effect that deafens a creature, applying a 20% spell failure chance for spells with (V)erbal components.

Death(bool, bool)

Creates an effect that kills, or destroys an object.

Disappear()

Creates an effect that causes the object to "fly away", before destroying itself.
This effect should not be applied to PCs.

DisappearAppear(Location, int)

Creates an effect that causes the object to "fly away", before appearing in another location.

Disease(DiseaseType)

Creates an effect that applies a disease to a creature.

DispelMagicAll(int)

Creates an effect that attempts to strip all (Sp)ell effects on a target, up to a specified caster level.
(Su)pernatural and (Ex)traordinary effects can never be dispelled.

DispelMagicBest(int)

Creates an effect that will attempt to strip the highest level spell effect on a target, up to a specified caster level.

Dominated()

Creates a dominate effect.
A dominated creature is added to the effect creators party. This means they will become instantly friendly and not attack each other, and they are treated as a normal friend as a henchman would be.

EnemyAttackBonus(int)

Creates an effect that gives a creature with melee/ranged/touched attacks a bonus to hit.

Entangle()

Creates an effect that prevents all movement, and applies a -2 to all attacks and a -4 to AC.

Ethereal()

Creates an effect that causes the creature to become invisible and un-perceivable, and taking on an ethereal appearance.
The effect is cancelled when the creature performs a hostile action.

ForceWalk()

Creates an effect that forces creatures to always walk.

Frightened()

Creates a frightened effect for use in making creatures shaken or flee.

Haste()

Creates a haste effect.
Haste effects add +4 dodge AC, +1 action/round and 50% movement speed increase.

Heal(int)

Creates a heal effect that will heal the object it is applied to by the specified damage amount.

HitPointChangeWhenDying(float)

Creates a special effect for healing/damaging dying players.

Icon(EffectIconTableEntry)

Creates an icon effect. Icons appear in the top right and in the character sheet and examine panels.

Immunity(ImmunityType)

Creates an immunity effect. This provides immunity to a specific effect type.

Invisibility(InvisibilityType)

Creates an invisiblity effect. Behaviour is defined from the specified invisibility type.

Knockdown()

Creates a knockdown effect. This effect knocks creatures off their feet, they will sit until the effect is removed.

LinkEffects(Effect, params Effect[])

Creates a new linked effect from the specified effects.
If you remove/dispel one of the effects from a target which is linked to others, the other linked effects will be removed/dispelled too.

LinkEffects(Effect, IEnumerable<Effect>)

Creates a new linked effect from the specified effects.
If you remove/dispel one of the effects from a target which is linked to others, the other linked effects will be removed/dispelled too.

MissChance(int, MissChanceType)

Creates a new effect used to hinder the attacks of the creature it is applied to.

ModifyAttacks(int)

Creates an effect that modifies the amount of attacks a creature can perform.

MovementSpeedDecrease(int)

Creates an effect that reduces the movement speed of a creature.

MovementSpeedIncrease(int)

Creates an effect that increases the movement speed of a creature.

NegativeLevel(int)

Creates an effect that will "decrease" the level of the target.

Pacified()

Creates an effect that pacifies a creature, making them unable to do attacks.

Paralyze()

Creates a paralyze effect.

Petrify()

Creates an effect that will petrify a creature. It is similar to Paralyze(), but also applies the DurPetrify visual effect.

Poison(PoisonType)

Creates a poison effect that sets the poisoned status effect, with varying penalties based on the type chosen.

Polymorph(PolymorphTableEntry, bool, VfxType?, int, int)

Creates a polymorph effect that changes the target into a different kind of creature.

Regenerate(int, TimeSpan)

Creates a regeneration effect that will cause the target to heal the specified amount at each interval.

Resurrection()

Creates an effect that raises a creature who is dead to 1 hit point.

RunAction(ScriptCallbackHandle?, ScriptCallbackHandle?, ScriptCallbackHandle?, TimeSpan, string)

Creates a custom scripted effect.

Sanctuary(int)

Creates a sanctuary effect. Sanctuary effects work similar to invisibility effects, but also cause creatures to be unable to hear the target creature, if they fail the DC.

SavingThrowDecrease(SavingThrow, int, SavingThrowType)

Creates an effect to decrease one saving throw type.

SavingThrowIncrease(SavingThrow, int, SavingThrowType)

Creates an effect to increase one saving throw type.

SeeInvisible()

Creates an effect that allows a creature to see through magical invisibility.

Silence()

Creates an effect that silences a creature. Silent creatures may not cast spell with verbal components.

SkillDecrease(NwSkill, int)

Creates an effect that decreases a specific skill score.

SkillDecreaseAll(int)

Creates an effect that decreases all skill scores.

SkillIncrease(NwSkill, int)

Creates an effect that increases a specific skill score.

SkillIncreaseAll(int)

Creates an effect that increases all skill scores.

Sleep()

Creates a sleep effect. Sleeping creatures may not act, and are subject to coup de grace (4 or less HD)

Slow()

Creates a slow effect. Slowed creatures have no benefits from any haste applied to them, or if they have no haste, have 1 attack per round, -2 AC, -2 attack, -2 Reflex Saving Throw, and -50% movement speed.

SpellFailure(int, SpellSchool, SpellFailureType)

Creates an effect that inhibits spells.

SpellImmunity(Spell)

Creates an effect that provides immunity to a specific spell

SpellLevelAbsorption(int, int, SpellSchool)

Creates an effect that absorbs a certain amount of spells.

SpellResistanceDecrease(int)

Creates an effect that decreases the spell resistance of a creature.

SpellResistanceIncrease(int)

Creates an effect that increases the spell resistance of a creature.

Stunned()

Creates a stun effect. This is a mind-effecting effect, and so immunity to mind effects prevents this from working.
Stunned creatures are flat-footed (no AC dex bonus), and cannot move.

SummonCreature(NwCreature, VisualEffectTableEntry, VisualEffectTableEntry?)

Creates an effect that uses summon behaviours on an existing creature.

SummonCreature(string, VisualEffectTableEntry, TimeSpan, int, VisualEffectTableEntry?)

Creates an effect to summon a creature from a resref.
THIS IS OBJECT CONTEXT SENSITIVE! Use WaitForObjectContext() to correctly assign the right owner of the master.

Swarm(bool, string, string, string, string)

Creates a swarm effect. This is exactly the same as SummonCreature(string, VisualEffectTableEntry, TimeSpan, int, VisualEffectTableEntry?), except, after one dies, another takes its place.

TemporaryHitpoints(int)

Creates an effect that will give temporary hitpoints to a target.

TimeStop()

Creates a time stop effect.
Time stop applies a special module-wide pause which only the object it is applied to (and DM's) can move and cast spells without penalties or hindrance.
This is not recommended for multiplayer games as it will cause everyone in the module to pause.
You can query the current timestop state with IsTimestopPaused.

TimeStopImmunity()

Creates a time stop immunity effect.
Immunity allows objects to continue taking actions during an active time stop effect.

TrueSeeing()

Creates a true seeing effect. Creatures with true sight can see through stealth, invisibility, sanctuary and darkness.

TurnResistanceDecrease(int)

Creates an effect that decreases a creature's turn resistance, making them more susceptible to turning.

TurnResistanceIncrease(int)

Creates an effect that increases a creature's turn resistance, making them more resistant to turning.

Turned()

Creates a turned effect. Turning bypass all fear immunity effects, but should only be used in the turn undead script.

Ultravision()

Creates an Ultravision effect. Ultravision lets the target see through Darkness() and Invisibility(InvisibilityType) effects with Darkness.

VisualEffect(VfxType, bool, float, Vector3, Vector3)

Creates an effect that plays a visual effect when applied.

VisualEffect(VisualEffectTableEntry, bool, float, Vector3, Vector3)

Creates an effect that plays a visual effect when applied.

Operators

implicit operator Effect?(nint)