Inheritance: CLRScriptFramework.CLRScriptBase
Ejemplo n.º 1
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);
        }
        public static void StallForTime(CLRScriptBase s, ALFA.Shared.ActiveTrap trap, uint disabler, float delay, NWLocation loc)
        {
            delay -= 2.0f;
            if (delay <= 0.5f)
            {
                DisableResult result = IsDisableSuccessful(s, trap, trap.DisarmDC, disabler);
                if (result == DisableResult.Success)
                {
                    RemoveTrap(s, trap);
                    s.SendMessageToPC(disabler, "<c=#98FFFF>This trap is now gone, and needs no more work from you.</c>");
                    return;
                }
                else if (result == DisableResult.CriticalFailure)
                {
                    trap.Disabler  = 0;
                    trap.Helpers   = new List <uint>();
                    trap.TotalHelp = 0;
                    TrapTrigger.Fire(s, trap, disabler);
                    s.SendMessageToPC(disabler, "<c=#98FFFF>Your disable attempt has backfired, causing you to cease work.</c>");
                    return;
                }
                else
                {
                    trap.Disabler  = 0;
                    trap.Helpers   = new List <uint>();
                    trap.TotalHelp = 0;
                    s.SendMessageToPC(disabler, "<c=#98FFFF>Your disable attempt has failed. You may retry if you like.</c>");
                    return;
                }
            }
            else
            {
                Vector3    oldPos = s.GetPositionFromLocation(loc);
                NWLocation newLoc = s.GetLocation(disabler);
                Vector3    newPos = s.GetPosition(disabler);
                if (Math.Abs(oldPos.x - newPos.x) > DisarmMovementThreshhold ||
                    Math.Abs(oldPos.y - newPos.y) > DisarmMovementThreshhold)
                {
                    // The disabler has moved. Interpret as canceling.
                    trap.Disabler  = 0;
                    trap.Helpers   = new List <uint>();
                    trap.TotalHelp = 0;
                    s.SendMessageToPC(disabler, "<c=#98FFFF>You stop working on the trap, due to having moved from your workspace.</c>");
                    return;
                }

                int action = s.GetCurrentAction(disabler);
                if (action == ACTION_ANIMALEMPATHY ||
                    action == ACTION_ATTACKOBJECT ||
                    action == ACTION_CASTSPELL ||
                    action == ACTION_CLOSEDOOR ||
                    action == ACTION_COUNTERSPELL ||
                    action == ACTION_DIALOGOBJECT ||
                    action == ACTION_DROPITEM ||
                    action == ACTION_EXAMINETRAP ||
                    action == ACTION_FLAGTRAP ||
                    action == ACTION_FOLLOW ||
                    action == ACTION_HEAL ||
                    action == ACTION_ITEMCASTSPELL ||
                    action == ACTION_KIDAMAGE ||
                    action == ACTION_LOCK ||
                    action == ACTION_MOVETOPOINT ||
                    action == ACTION_OPENDOOR ||
                    action == ACTION_OPENLOCK ||
                    action == ACTION_PICKPOCKET ||
                    action == ACTION_PICKUPITEM ||
                    action == ACTION_RANDOMWALK ||
                    action == ACTION_RECOVERTRAP ||
                    action == ACTION_REST ||
                    action == ACTION_SETTRAP ||
                    action == ACTION_SIT ||
                    action == ACTION_SMITEGOOD ||
                    action == ACTION_TAUNT ||
                    action == ACTION_USEOBJECT)
                {
                    // Disabler isn't working on the trap any more. Abort.
                    trap.Disabler  = 0;
                    trap.Helpers   = new List <uint>();
                    trap.TotalHelp = 0;
                    s.SendMessageToPC(disabler, "<c=#98FFFF>You stop working on the trap, due to having begun another task.</c>");
                    return;
                }

                s.SendMessageToPC(disabler, "<c=#98FFFF>You continue work on the trap...</c>");
                s.PlayAnimation(ANIMATION_FIREFORGET_KNEELFIDGET, 1.0f, 2.0f);
                s.DelayCommand(2.0f, delegate { StallForTime(s, trap, disabler, delay, newLoc); });
            }
        }