Inheritance: CLRScriptFramework.CLRScriptBase
        public static void Fire(CLRScriptBase s, ALFA.Shared.ActiveTrap trap, uint specialTarget)
        {
            List <uint> targets = new List <uint>();

            if (s.GetIsObjectValid(specialTarget) == TRUE)
            {
                targets.Add(specialTarget);
            }
            foreach (uint contents in s.GetObjectsInPersistentObject(s.GetObjectByTag(trap.Tag, 0), OBJECT_TYPE_CREATURE, 0))
            {
                if (FitsTrapTargetRestriction(s, trap, contents))
                {
                    targets.Add(contents);
                }
            }

            if (targets.Count == 0)
            {
                // Might be that they all left. In any case
                // we have nothing to shoot
                trap.IsFiring = false;
                return;
            }
            uint target;

            if (targets.Count == 1)
            {
                target = targets[0];
            }
            else
            {
                target = targets[s.Random(targets.Count)];
            }

            uint caster;

            if (s.GetIsObjectValid(trap.TrapOrigin) == FALSE)
            {
                caster = s.GetObjectByTag(trap.Tag, 0);
            }
            else
            {
                caster = trap.TrapOrigin;
            }

            if (trap.SpellTrap)
            {
                // It's a spell-- guess this is simple.
                s.AssignCommand(caster, delegate { s.ActionCastSpellAtObject(trap.SpellId, target, METAMAGIC_NONE, TRUE, 0, 0, 1); });
            }
            else
            {
                foreach (uint victim in s.GetObjectsInShape(trap.EffectArea, trap.EffectSize, s.GetLocation(target), false, OBJECT_TYPE_CREATURE, s.GetPosition(caster)))
                {
                    s.ApplyEffectToObject(DURATION_TYPE_INSTANT, GetTrapEffect(s, trap, victim), victim, 0.0f);
                    _doSoloVFX(s, trap, victim);
                }
                _doGroupVFX(s, trap, s.GetLocation(target));
            }

            if (trap.NumberOfShots > -1)
            {
                if (trap.NumberOfShots < 2)
                {
                    TrapDisable.RemoveTrap(s, trap);
                    return;
                }
                else
                {
                    trap.NumberOfShots--;
                }
            }

            trap.IsFiring = true;
            s.DelayCommand(6.0f, delegate { Fire(s, trap); });
        }
Beispiel #2
0
        public Int32 ScriptMain([In] object[] ScriptParameters, [In] Int32 DefaultReturnCode)
        {
            int Value = (int)ScriptParameters[0]; // ScriptParameterTypes[0] is typeof(int)

            TrapEvent currentEvent = (TrapEvent)ScriptParameters[0];

            switch (currentEvent)
            {
            case TrapEvent.CreateGeneric:
            {
                NWLocation loc    = Location((uint)ScriptParameters[4], Vector((float)ScriptParameters[1], (float)ScriptParameters[2], (float)ScriptParameters[3]), 0.0f);
                string     resRef = (string)ScriptParameters[20];
                if (resRef == "")
                {
                    TriggerArea triggerArea      = (TriggerArea)ScriptParameters[5];
                    int         effectArea       = (int)ScriptParameters[6];
                    float       effectSize       = (float)ScriptParameters[7];
                    int         damageType       = (int)ScriptParameters[8];
                    int         diceNumber       = (int)ScriptParameters[9];
                    int         diceType         = (int)ScriptParameters[10];
                    int         saveDC           = (int)ScriptParameters[11];
                    int         attackBonus      = (int)ScriptParameters[12];
                    int         numberOfShots    = (int)ScriptParameters[13];
                    uint        trapOrigin       = (uint)ScriptParameters[14];
                    int         targetAlignment  = (int)ScriptParameters[15];
                    int         targetRace       = (int)ScriptParameters[16];
                    int         minimumToTrigger = (int)ScriptParameters[17];
                    int         detectDC         = (int)ScriptParameters[18];
                    int         disarmDC         = (int)ScriptParameters[19];
                    CreateTraps.GenericDamage(this, loc, triggerArea, effectArea, effectSize, damageType, diceNumber, diceType, saveDC, attackBonus, numberOfShots, trapOrigin, targetAlignment, targetRace, minimumToTrigger, detectDC, disarmDC, "");
                    break;
                }
                else
                {
                    ALFA.Shared.TrapResource trapToSpawn = ALFA.Shared.Modules.InfoStore.ModuleTraps[(string)ScriptParameters[20]];
                    if (trapToSpawn.SpellTrap)
                    {
                        CreateTraps.Spell(this, loc, (TriggerArea)trapToSpawn.TriggerArea, trapToSpawn.SpellId, trapToSpawn.NumberOfShots, trapToSpawn.TrapOrigin, trapToSpawn.TargetAlignment, trapToSpawn.TargetRace, trapToSpawn.MinimumToTrigger, trapToSpawn.DetectDC, trapToSpawn.DisarmDC, trapToSpawn.Description);
                    }
                    else
                    {
                        CreateTraps.GenericDamage(this, loc, (TriggerArea)trapToSpawn.TriggerArea, trapToSpawn.EffectArea, trapToSpawn.EffectSize, trapToSpawn.DamageType, trapToSpawn.DiceNumber, trapToSpawn.DiceType, trapToSpawn.SaveDC, trapToSpawn.AttackBonus, trapToSpawn.NumberOfShots, trapToSpawn.TrapOrigin, trapToSpawn.TargetAlignment, trapToSpawn.TargetRace, trapToSpawn.MinimumToTrigger, trapToSpawn.DetectDC, trapToSpawn.DisarmDC, trapToSpawn.Description);
                    }
                }
                break;
            }

            case TrapEvent.CreateSpell:
            {
                NWLocation  loc              = Location((uint)ScriptParameters[4], Vector((float)ScriptParameters[1], (float)ScriptParameters[2], (float)ScriptParameters[3]), 0.0f);
                TriggerArea triggerArea      = (TriggerArea)ScriptParameters[5];
                int         spellId          = (int)ScriptParameters[8];
                int         numberOfShots    = (int)ScriptParameters[13];
                uint        trapOrigin       = (uint)ScriptParameters[14];
                int         targetAlignment  = (int)ScriptParameters[15];
                int         targetRace       = (int)ScriptParameters[16];
                int         minimumToTrigger = (int)ScriptParameters[17];
                int         detectDC         = (int)ScriptParameters[18];
                int         disarmDC         = (int)ScriptParameters[19];
                CreateTraps.Spell(this, loc, triggerArea, spellId, numberOfShots, trapOrigin, targetAlignment, targetRace, minimumToTrigger, detectDC, disarmDC, "");
                break;
            }

            case TrapEvent.DetectEnter:
            {
                string trapTag = GetTag(OBJECT_SELF);
                if (ALFA.Shared.Modules.InfoStore.SpawnedTrapDetect.Keys.Contains(trapTag))
                {
                    TrapDetect.Enter(this, ALFA.Shared.Modules.InfoStore.SpawnedTrapDetect[trapTag]);
                }
                else
                {
                    uint enteringObject = GetEnteringObject();
                    SendMessageToPC(enteringObject, String.Format("Error: This appears to be a trap detection trigger, but I can not find any trap named {0}", trapTag));
                }
                break;
            }

            case TrapEvent.DetectExit:
            {
                string trapTag        = GetTag(OBJECT_SELF);
                uint   enteringObject = GetEnteringObject();
                if (ALFA.Shared.Modules.InfoStore.SpawnedTrapDetect.Keys.Contains(trapTag))
                {
                    TrapDetect.Exit(this, ALFA.Shared.Modules.InfoStore.SpawnedTrapDetect[trapTag]);
                }
                break;
            }

            case TrapEvent.TriggerEnter:
            {
                string trapTag = GetTag(OBJECT_SELF);
                if (ALFA.Shared.Modules.InfoStore.SpawnedTrapTriggers.Keys.Contains(trapTag))
                {
                    TrapTrigger.Enter(this, ALFA.Shared.Modules.InfoStore.SpawnedTrapTriggers[trapTag]);
                }
                else
                {
                    uint enteringObject = GetEnteringObject();
                    SendMessageToPC(enteringObject, String.Format("Error: This appears to be a trap firing trigger, but I can not find any trap named {0}", trapTag));
                }
                break;
            }

            case TrapEvent.TriggerExit:
            {
                string trapTag        = GetTag(OBJECT_SELF);
                uint   enteringObject = GetEnteringObject();
                if (ALFA.Shared.Modules.InfoStore.SpawnedTrapTriggers.Keys.Contains(trapTag))
                {
                    TrapTrigger.Exit(this, ALFA.Shared.Modules.InfoStore.SpawnedTrapTriggers[trapTag]);
                }
                break;
            }

            case TrapEvent.TrapDisarm:
            {
                string trapTag = GetTag(OBJECT_SELF);
                trapTag = trapTag.Substring(0, trapTag.Length - 1);
                uint disabler = GetLastUsedBy();
                if (ALFA.Shared.Modules.InfoStore.SpawnedTrapTriggers.Keys.Contains(trapTag))
                {
                    TrapDisable.Disable(this, ALFA.Shared.Modules.InfoStore.SpawnedTrapTriggers[trapTag], disabler);
                }
                break;
            }

            case TrapEvent.TrapDespawn:
            {
                string trapTag = GetTag(OBJECT_SELF);
                if (ALFA.Shared.Modules.InfoStore.SpawnedTrapTriggers.Keys.Contains(trapTag))
                {
                    TrapDisable.RemoveTrap(this, ALFA.Shared.Modules.InfoStore.SpawnedTrapTriggers[trapTag]);
                }
                if (ALFA.Shared.Modules.InfoStore.SpawnedTrapDetect.Keys.Contains(trapTag))
                {
                    TrapDisable.RemoveTrap(this, ALFA.Shared.Modules.InfoStore.SpawnedTrapDetect[trapTag]);
                }
                break;
            }
            }

            return(0);
        }