private static NWEffect GetTrapEffect(CLRScriptBase s, ALFA.Shared.ActiveTrap trap, uint target)
        {
            int damage = 0;
            for (int count = 0; count < trap.DiceNumber; count++)
            {
                damage += s.Random(trap.DiceType) + 1;
            }
            if (trap.SaveDC > -1)
            {
                if (s.ReflexSave(target, trap.SaveDC, SAVING_THROW_TYPE_TRAP, s.GetObjectByTag(trap.Tag, 0)) != TRUE)
                {
                    if (s.GetHasFeat(FEAT_IMPROVED_EVASION, target, TRUE) == TRUE)
                        damage /= 2;
                }
                else
                {
                    if (s.GetHasFeat(FEAT_EVASION, target, TRUE) == TRUE)
                        damage = 0;
                    else damage /= 2;
                }
            }
            else
            {
                int roll = new Random().Next(20) + 1;
                int final = roll + trap.AttackBonus;
                string hitormiss = " *hit* ";
                if (final < s.GetAC(target, FALSE) && roll != 20)
                {
                    hitormiss = " *miss* ";
                    damage = 0;
                }
                s.SendMessageToPC(target, "<C=DarkViolet>Trap</C><C=DarkOrange> attacks " + s.GetName(target) + ":" + hitormiss + ": " + roll + " + " + trap.AttackBonus + " = " + final);
            }

            NWEffect eVis = s.EffectVisualEffect(VFX_COM_HIT_DIVINE, FALSE);

            List<int> damageTypes = new List<int>();
            if ((trap.DamageType & DAMAGE_TYPE_ACID) == DAMAGE_TYPE_ACID)
            {
                damageTypes.Add(DAMAGE_TYPE_ACID);
                eVis = s.EffectVisualEffect(VFX_COM_HIT_ACID, FALSE);
            }
            if ((trap.DamageType & DAMAGE_TYPE_BLUDGEONING) == DAMAGE_TYPE_BLUDGEONING)
            {
                damageTypes.Add(DAMAGE_TYPE_BLUDGEONING);
                eVis = s.EffectVisualEffect(VFX_COM_BLOOD_CRT_RED, FALSE);
            }
            if ((trap.DamageType & DAMAGE_TYPE_COLD) == DAMAGE_TYPE_COLD)
            {
                damageTypes.Add(DAMAGE_TYPE_COLD);
                eVis = s.EffectVisualEffect(VFX_COM_HIT_FROST, FALSE);
            }
            if ((trap.DamageType & DAMAGE_TYPE_DIVINE) == DAMAGE_TYPE_DIVINE)
            {
                damageTypes.Add(DAMAGE_TYPE_DIVINE);
                eVis = s.EffectVisualEffect(VFX_COM_HIT_DIVINE, FALSE);
            }
            if ((trap.DamageType & DAMAGE_TYPE_ELECTRICAL) == DAMAGE_TYPE_ELECTRICAL)
            {
                damageTypes.Add(DAMAGE_TYPE_ELECTRICAL);
                eVis = s.EffectVisualEffect(VFX_COM_HIT_ELECTRICAL, FALSE);
            }
            if ((trap.DamageType & DAMAGE_TYPE_FIRE) == DAMAGE_TYPE_FIRE)
            {
                damageTypes.Add(DAMAGE_TYPE_FIRE);
                eVis = s.EffectVisualEffect(VFX_COM_HIT_FIRE, FALSE);
            }
            if ((trap.DamageType & DAMAGE_TYPE_MAGICAL) == DAMAGE_TYPE_MAGICAL)
            {
                damageTypes.Add(DAMAGE_TYPE_MAGICAL);
                eVis = s.EffectVisualEffect(VFX_COM_HIT_DIVINE, FALSE);
            }
            if ((trap.DamageType & DAMAGE_TYPE_NEGATIVE) == DAMAGE_TYPE_NEGATIVE)
            {
                damageTypes.Add(DAMAGE_TYPE_NEGATIVE);
                eVis = s.EffectVisualEffect(VFX_COM_HIT_NEGATIVE, FALSE);
            }
            if ((trap.DamageType & DAMAGE_TYPE_PIERCING) == DAMAGE_TYPE_PIERCING)
            {
                damageTypes.Add(DAMAGE_TYPE_PIERCING);
                eVis = s.EffectVisualEffect(VFX_COM_BLOOD_CRT_RED, FALSE);
            }
            if ((trap.DamageType & DAMAGE_TYPE_POSITIVE) == DAMAGE_TYPE_POSITIVE)
            {
                damageTypes.Add(DAMAGE_TYPE_POSITIVE);
                eVis = s.EffectVisualEffect(VFX_COM_HIT_DIVINE, FALSE);
            }
            if ((trap.DamageType & DAMAGE_TYPE_SLASHING) == DAMAGE_TYPE_SLASHING)
            {
                damageTypes.Add(DAMAGE_TYPE_SLASHING);
                eVis = s.EffectVisualEffect(VFX_COM_BLOOD_CRT_RED, FALSE);
            }
            if ((trap.DamageType & DAMAGE_TYPE_SONIC) == DAMAGE_TYPE_SONIC)
            {
                damageTypes.Add(DAMAGE_TYPE_SONIC);
                eVis = s.EffectVisualEffect(VFX_COM_HIT_SONIC, FALSE);
            }

            if (damage == 0)
            {
                return eVis;
            }

            NWEffect eDam = eVis;
            damage /= damageTypes.Count;
            if (damage < 1) damage = 1;
            foreach (int dmgType in damageTypes)
            {
                eDam = s.EffectLinkEffects(eDam, s.EffectDamage(damage, dmgType, DAMAGE_POWER_NORMAL, FALSE));
            }

            return eDam;
        }
 private static void _doGroupVFX(CLRScriptBase s, ALFA.Shared.ActiveTrap trap, NWLocation target)
 {
     if (trap.EffectSize < 2.0f) { return; } // these are probably single-target, and a group VFX would be overkill.
     else
     {
         if((trap.DamageType & DAMAGE_TYPE_DIVINE) == DAMAGE_TYPE_DIVINE)
         {
             s.ApplyEffectAtLocation(DURATION_TYPE_INSTANT, s.EffectVisualEffect(VFX_FNF_LOS_HOLY_10, FALSE), target, 0.0f);
         }
         else if ((trap.DamageType & DAMAGE_TYPE_FIRE) == DAMAGE_TYPE_FIRE)
         {
             s.ApplyEffectAtLocation(DURATION_TYPE_INSTANT, s.EffectVisualEffect(VFX_FNF_FIREBALL, FALSE), target, 0.0f);
         }
         else if ((trap.DamageType & DAMAGE_TYPE_MAGICAL) == DAMAGE_TYPE_MAGICAL)
         {
             s.ApplyEffectAtLocation(DURATION_TYPE_INSTANT, s.EffectVisualEffect(VFX_FNF_LOS_NORMAL_10, FALSE), target, 0.0f);
         }
         else if((trap.DamageType & DAMAGE_TYPE_NEGATIVE) == DAMAGE_TYPE_NEGATIVE)
         {
             s.ApplyEffectAtLocation(DURATION_TYPE_INSTANT, s.EffectVisualEffect(VFX_FNF_SUMMON_UNDEAD, FALSE), target, 0.0f);
         }
         else if((trap.DamageType & DAMAGE_TYPE_POSITIVE) == DAMAGE_TYPE_POSITIVE)
         {
             s.ApplyEffectAtLocation(DURATION_TYPE_INSTANT, s.EffectVisualEffect(VFX_FNF_LOS_HOLY_10, FALSE), target, 0.0f);
         }
         else
         {
             s.ApplyEffectAtLocation(DURATION_TYPE_INSTANT, s.EffectVisualEffect(VFX_FNF_FIREBALL, FALSE), target, 0.0f);
         }
     }
 }
 private static void _doSoloVFX(CLRScriptBase s, ALFA.Shared.ActiveTrap trap, uint target)
 {
     if (trap.EffectSize < 2.0f)
     {
         if (s.GetArea(trap.TrapOrigin) == s.GetArea(s.GetObjectByTag(trap.Tag, 0)))
         {
             if ((trap.DamageType & DAMAGE_TYPE_ACID) == DAMAGE_TYPE_ACID)
             {
                 s.ApplyEffectToObject(DURATION_TYPE_TEMPORARY, s.EffectBeam(VFX_BEAM_ACID, trap.TrapOrigin, BODY_NODE_CHEST, FALSE), target, 1.0f);
             }
             if ((trap.DamageType & DAMAGE_TYPE_BLUDGEONING) == DAMAGE_TYPE_BLUDGEONING)
             {
                 s.SpawnItemProjectile(trap.TrapOrigin, target, s.GetLocation(trap.TrapOrigin), s.GetLocation(target), BASE_ITEM_SLING, PROJECTILE_PATH_TYPE_HOMING, OVERRIDE_ATTACK_RESULT_HIT_SUCCESSFUL, 0);
                 float fShotDelay = 0.1f;
                 int c = 1;
                 while (c < trap.DiceNumber)
                 {
                     s.DelayCommand(fShotDelay, delegate { s.SpawnItemProjectile(trap.TrapOrigin, target, s.GetLocation(trap.TrapOrigin), s.GetLocation(target), BASE_ITEM_SLING, PROJECTILE_PATH_TYPE_HOMING, OVERRIDE_ATTACK_RESULT_HIT_SUCCESSFUL, 0); });
                     fShotDelay += 0.1f;
                     c++;
                 }
             }
             if ((trap.DamageType & DAMAGE_TYPE_COLD) == DAMAGE_TYPE_COLD)
             {
                 s.ApplyEffectToObject(DURATION_TYPE_TEMPORARY, s.EffectBeam(VFX_BEAM_ICE, trap.TrapOrigin, BODY_NODE_CHEST, FALSE), target, 1.0f);
             }
             if ((trap.DamageType & DAMAGE_TYPE_DIVINE) == DAMAGE_TYPE_DIVINE)
             {
                 s.ApplyEffectToObject(DURATION_TYPE_TEMPORARY, s.EffectBeam(VFX_BEAM_HOLY, trap.TrapOrigin, BODY_NODE_CHEST, FALSE), target, 1.0f);
             }
             if ((trap.DamageType & DAMAGE_TYPE_ELECTRICAL) == DAMAGE_TYPE_ELECTRICAL)
             {
                 s.ApplyEffectToObject(DURATION_TYPE_TEMPORARY, s.EffectBeam(VFX_BEAM_LIGHTNING, trap.TrapOrigin, BODY_NODE_CHEST, FALSE), target, 1.0f);
             }
             if ((trap.DamageType & DAMAGE_TYPE_FIRE) == DAMAGE_TYPE_FIRE)
             {
                 s.ApplyEffectToObject(DURATION_TYPE_TEMPORARY, s.EffectBeam(VFX_BEAM_FIRE, trap.TrapOrigin, BODY_NODE_CHEST, FALSE), target, 1.0f);
             }
             if ((trap.DamageType & DAMAGE_TYPE_MAGICAL) == DAMAGE_TYPE_MAGICAL)
             {
                 s.ApplyEffectToObject(DURATION_TYPE_TEMPORARY, s.EffectBeam(VFX_BEAM_MAGIC, trap.TrapOrigin, BODY_NODE_CHEST, FALSE), target, 1.0f);
             }
             if ((trap.DamageType & DAMAGE_TYPE_NEGATIVE) == DAMAGE_TYPE_NEGATIVE)
             {
                 s.ApplyEffectToObject(DURATION_TYPE_TEMPORARY, s.EffectBeam(VFX_BEAM_EVIL, trap.TrapOrigin, BODY_NODE_CHEST, FALSE), target, 1.0f);
             }
             if ((trap.DamageType & DAMAGE_TYPE_PIERCING) == DAMAGE_TYPE_PIERCING)
             {
                 s.SpawnItemProjectile(trap.TrapOrigin, target, s.GetLocation(trap.TrapOrigin), s.GetLocation(target), BASE_ITEM_DART, PROJECTILE_PATH_TYPE_HOMING, OVERRIDE_ATTACK_RESULT_HIT_SUCCESSFUL, 0);
                 float fShotDelay = 0.1f;
                 int c = 1;
                 while (c < trap.DiceNumber)
                 {
                     s.SpawnItemProjectile(trap.TrapOrigin, target, s.GetLocation(trap.TrapOrigin), s.GetLocation(target), BASE_ITEM_DART, PROJECTILE_PATH_TYPE_HOMING, OVERRIDE_ATTACK_RESULT_HIT_SUCCESSFUL, 0);
                     fShotDelay += 0.1f;
                     c++;
                 }
             }
             if ((trap.DamageType & DAMAGE_TYPE_POSITIVE) == DAMAGE_TYPE_POSITIVE)
             {
                 s.ApplyEffectToObject(DURATION_TYPE_TEMPORARY, s.EffectBeam(VFX_BEAM_HOLY, trap.TrapOrigin, BODY_NODE_CHEST, FALSE), target, 1.0f);
             }
             if ((trap.DamageType & DAMAGE_TYPE_SLASHING) == DAMAGE_TYPE_SLASHING)
             {
                 s.SpawnItemProjectile(trap.TrapOrigin, target, s.GetLocation(trap.TrapOrigin), s.GetLocation(target), BASE_ITEM_THROWINGAXE, PROJECTILE_PATH_TYPE_HOMING, OVERRIDE_ATTACK_RESULT_HIT_SUCCESSFUL, 0);
                 float fShotDelay = 0.1f;
                 int c = 1;
                 while (c < trap.DiceNumber)
                 {
                     s.SpawnItemProjectile(trap.TrapOrigin, target, s.GetLocation(trap.TrapOrigin), s.GetLocation(target), BASE_ITEM_THROWINGAXE, PROJECTILE_PATH_TYPE_HOMING, OVERRIDE_ATTACK_RESULT_HIT_SUCCESSFUL, 0);
                     fShotDelay += 0.1f;
                     c++;
                 }
             }
             if ((trap.DamageType & DAMAGE_TYPE_SONIC) == DAMAGE_TYPE_SONIC)
             {
                 s.ApplyEffectToObject(DURATION_TYPE_TEMPORARY, s.EffectBeam(VFX_BEAM_SONIC, trap.TrapOrigin, BODY_NODE_CHEST, FALSE), target, 1.0f);
             }
         }
         else
         {
             // These are pretty much single-target effects.
             if ((trap.DamageType & DAMAGE_TYPE_ACID) == DAMAGE_TYPE_ACID)
             {
                 s.ApplyEffectToObject(DURATION_TYPE_INSTANT, s.EffectVisualEffect(VFX_IMP_ACID_S, FALSE), target, 0.0f);
             }
             if ((trap.DamageType & DAMAGE_TYPE_BLUDGEONING) == DAMAGE_TYPE_BLUDGEONING)
             {
                 s.ApplyEffectToObject(DURATION_TYPE_INSTANT, s.EffectVisualEffect(VFX_COM_BLOOD_CRT_RED, FALSE), target, 0.0f);
             }
             if ((trap.DamageType & DAMAGE_TYPE_COLD) == DAMAGE_TYPE_COLD)
             {
                 s.ApplyEffectToObject(DURATION_TYPE_INSTANT, s.EffectVisualEffect(VFX_IMP_FROST_L, FALSE), target, 0.0f);
             }
             if ((trap.DamageType & DAMAGE_TYPE_DIVINE) == DAMAGE_TYPE_DIVINE)
             {
                 s.ApplyEffectToObject(DURATION_TYPE_INSTANT, s.EffectVisualEffect(VFX_COM_HIT_DIVINE, FALSE), target, 0.0f);
             }
             if ((trap.DamageType & DAMAGE_TYPE_ELECTRICAL) == DAMAGE_TYPE_ELECTRICAL)
             {
                 s.ApplyEffectToObject(DURATION_TYPE_INSTANT, s.EffectVisualEffect(VFX_IMP_LIGHTNING_S, FALSE), target, 0.0f);
             }
             if ((trap.DamageType & DAMAGE_TYPE_FIRE) == DAMAGE_TYPE_FIRE)
             {
                 s.ApplyEffectToObject(DURATION_TYPE_INSTANT, s.EffectVisualEffect(VFX_IMP_FLAME_S, FALSE), target, 0.0f);
             }
             if ((trap.DamageType & DAMAGE_TYPE_MAGICAL) == DAMAGE_TYPE_MAGICAL)
             {
                 s.ApplyEffectToObject(DURATION_TYPE_INSTANT, s.EffectVisualEffect(VFX_IMP_MAGBLUE, FALSE), target, 0.0f);
             }
             if ((trap.DamageType & DAMAGE_TYPE_NEGATIVE) == DAMAGE_TYPE_NEGATIVE)
             {
                 s.ApplyEffectToObject(DURATION_TYPE_INSTANT, s.EffectVisualEffect(VFX_IMP_NEGATIVE_ENERGY, FALSE), target, 0.0f);
             }
             if ((trap.DamageType & DAMAGE_TYPE_PIERCING) == DAMAGE_TYPE_PIERCING)
             {
                 s.ApplyEffectToObject(DURATION_TYPE_INSTANT, s.EffectVisualEffect(VFX_IMP_SPIKE_TRAP, FALSE), target, 0.0f);
             }
             if ((trap.DamageType & DAMAGE_TYPE_POSITIVE) == DAMAGE_TYPE_POSITIVE)
             {
                 s.ApplyEffectToObject(DURATION_TYPE_INSTANT, s.EffectVisualEffect(VFX_IMP_SUNSTRIKE, FALSE), target, 0.0f);
             }
             if ((trap.DamageType & DAMAGE_TYPE_SLASHING) == DAMAGE_TYPE_SLASHING)
             {
                 s.ApplyEffectToObject(DURATION_TYPE_INSTANT, s.EffectVisualEffect(VFX_COM_BLOOD_CRT_RED, FALSE), target, 0.0f);
             }
             if ((trap.DamageType & DAMAGE_TYPE_SONIC) == DAMAGE_TYPE_SONIC)
             {
                 s.ApplyEffectToObject(DURATION_TYPE_INSTANT, s.EffectVisualEffect(VFX_IMP_SONIC, FALSE), target, 0.0f);
             }
         }
     }
     else { return; }
 }
        public static uint _SpawnObject(string sResRef, int nObjectType, uint oWP, NWLocation lLoc, int nFlags, int nAlternate, CLRScriptBase s)
        {
            // if the object is not being spawned at it's waypoint location, we need to make sure
            // the actual spawn-in location isn't violating the "in PC sight" guidelines.
            if ((nAlternate != CLRScriptBase.FALSE) && ((nFlags & _SPAWN_FLAGS_IN_PC_SIGHT) == 0))
            {
                uint oNeighbor = s.GetNearestCreatureToLocation(CLRScriptBase.CREATURE_TYPE_PLAYER_CHAR, CLRScriptBase.PLAYER_CHAR_IS_PC, lLoc, 1, -1, -1, -1, -1);
                if (s.GetIsObjectValid(oNeighbor) == CLRScriptBase.FALSE && (s.GetDistanceBetweenLocations(lLoc, s.GetLocation(oNeighbor)) <= PC_PERCEPTION_RANGE))
                { // ACR_GetPCVisualRange() )) {
                    return CLRScriptBase.OBJECT_INVALID;
                }
                if (GetPrespawnPrediction(s) == CLRScriptBase.FALSE)
                {
                    uint oTestWP = s.GetNearestObjectToLocation(CLRScriptBase.OBJECT_TYPE_WAYPOINT, lLoc, 1);
                    int nWP_Index = 1;
                    while ((oTestWP != CLRScriptBase.OBJECT_INVALID) && (s.GetDistanceBetweenLocations(lLoc, s.GetLocation(oTestWP)) <= PC_PERCEPTION_RANGE))
                    { // ACR_GetPC_VisualRange() )) {
                        if (s.GetTag(oTestWP) == "ACR_SA_WP")
                        {
                            return CLRScriptBase.OBJECT_INVALID;
                        }
                        else
                        {
                            nWP_Index = nWP_Index + 1;
                            oTestWP = s.GetNearestObjectToLocation(CLRScriptBase.OBJECT_TYPE_WAYPOINT, lLoc, nWP_Index);
                        }
                    }
                }
            }

            uint oSpawned = s.CreateObject(nObjectType, sResRef, lLoc, nFlags & _SPAWN_FLAGS_WITH_ANIMATION, "");

            // Check to make sure it spawned ok, print an error and exit if not.
            if (s.GetIsObjectValid(oSpawned) == CLRScriptBase.FALSE)
            {
                return CLRScriptBase.OBJECT_INVALID;
            }

            // If it should be in stealth mode, place it there.
            if ((nFlags & _SPAWN_IN_STEALTH) == _SPAWN_IN_STEALTH)
            {
                s.SetActionMode(oSpawned, CLRScriptBase.ACTION_MODE_STEALTH, 1);
            }

            // If it should be in detect mode, place it there.
            if ((nFlags & _SPAWN_IN_DETECT) == _SPAWN_IN_DETECT)
            {
                s.SetActionMode(oSpawned, CLRScriptBase.ACTION_MODE_DETECT, 1);
            }

            // If this creature should buff himself, do it.
            if ((nFlags & _SPAWN_BUFFED) == _SPAWN_BUFFED)
            {
                ActivateLongTermBuffs(oSpawned, s);
            }

            // Play the spawn animation.
            s.PlayAnimation(s.GetLocalInt(oWP, _WP_SPAWN_ANIMATION), 1.0f, 0.0f);

            // Play the spawn in VFX.
            s.ApplyEffectAtLocation(CLRScriptBase.DURATION_TYPE_INSTANT, s.EffectVisualEffect(s.GetLocalInt(oWP, _WP_SPAWN_IN_VFX), CLRScriptBase.FALSE), s.GetLocation(oSpawned), 0.0f);

            // Play the spawn in SFX.
            s.AssignCommand(oSpawned, delegate { s.PlaySound(s.GetLocalString(oWP, _WP_SPAWN_IN_SFX), CLRScriptBase.FALSE); });

            // Determine facing.
            if ((nFlags & _SPAWN_FLAGS_RANDOM_FACING) == _SPAWN_FLAGS_RANDOM_FACING)
            {
                // Spawn facing is random.
                s.AssignCommand(oSpawned, delegate { s.SetFacing(new Random().Next() * 360.0f, CLRScriptBase.FALSE); });
            }

            // Colorize name if needed.
            if (s.GetLocalString(oSpawned, ACR_COLOR_NAME) != "")
            {
                s.SetFirstName(oSpawned, "<C='" + s.GetLocalString(oSpawned, ACR_COLOR_NAME) + "'>" + s.GetName(oSpawned) + "</C>");
                s.SetLastName(oSpawned, "");
            }

            // Run the spawn-in scripts, if any.
            int i = 1;
            while (true)
            {
                string sScript = s.GetLocalString(oWP, _WP_SPAWN_IN_SCRIPT_ARRAY + s.IntToString(i));
                if (sScript == "")
                {
                    break;
                }
                s.ExecuteScript(sScript, oSpawned);
                i++;
            }

            _AddObjectToSpawnPoint(oWP, oSpawned, s);

            return oSpawned;
        }