public static void Enter(CLRScriptBase s, ALFA.Shared.ActiveTrap trap)
        {
            uint enterer = s.GetEnteringObject();

            if (trap.IsFiring)
            {
                // Trap's already firing. It'll reset when it runs out of targets.
                return;
            }

            // If one is enough, we don't need to check the trigger's contents.
            if (trap.MinimumToTrigger == 1)
            {
                if (FitsTrapTargetRestriction(s, trap, enterer))
                {
                    Fire(s, trap);
                }
            }
            else
            {
                int validTargets = 0;
                foreach (uint contents in s.GetObjectsInPersistentObject(s.GetObjectByTag(trap.Tag, 0), OBJECT_TYPE_CREATURE, 0))
                {
                    if (FitsTrapTargetRestriction(s, trap, contents))
                    {
                        validTargets++;
                    }
                }
                if (validTargets >= trap.MinimumToTrigger)
                {
                    Fire(s, trap);
                }
            }
        }
 public static DisableResult IsDisableSuccessful(CLRScriptBase s, ALFA.Shared.ActiveTrap trap, int DC, uint disabler)
 {
     if (s.GetSkillRank(SKILL_DISABLE_TRAP, disabler, TRUE) == 0)
     {
         s.SendMessageToPC(disabler, "<c=#98FFFF>Disable Device: * Success will never be possible *</c>");
         return DisableResult.Failure;
     }
     
     int roll = s.d20(1);
     int skill = s.GetSkillRank(SKILL_DISABLE_TRAP, disabler, FALSE) + trap.TotalHelp;
     int final = roll + skill;
     string resultString = "Failure!";
     DisableResult value = DisableResult.Failure;
     if (final >= DC)
     {
         value = DisableResult.Success;
         resultString = "Success!";
     }
     if (DC > final + 4)
     {
         value = DisableResult.CriticalFailure;
         resultString = "CRITICAL FAILURE!";
     }
     string message = String.Format("<c=#98FFFF>Disable Device : {0} + {1} = {2} vs. DC {3}. * {4} *</c>", roll, skill, final, DC, resultString);
     s.SendMessageToPC(disabler, message);
     
     return value;
 }
        /// <summary>
        /// Dispatch the event (in a script context).
        /// </summary>
        /// <param name="Script">Supplies the script object.</param>
        /// <param name="Database">Supplies the database connection.</param>
        public void DispatchEvent(ACR_ServerCommunicator Script, ALFA.Database Database)
        {
            foreach (uint PlayerObject in Script.GetPlayers(true))
            {
                string FormattedMessage = String.Format(
                    "</c><c=#FFFF00>{0}</c>",
                    Message);

                NWScript.Vector3 v;
                v.x = v.y = v.z = 0.0f;

                Script.SendChatMessage(
                    CLRScriptBase.OBJECT_INVALID,
                    PlayerObject,
                    CLRScriptBase.CHAT_MODE_SERVER,
                    FormattedMessage,
                    CLRScriptBase.FALSE);

                Script.FloatingTextStringOnCreature(FormattedMessage,
                    PlayerObject,
                    CLRScriptBase.FALSE,
                    5.0f,
                    CLRScriptBase.COLOR_WHITE,
                    CLRScriptBase.COLOR_WHITE,
                    0.0f,
                    v);
            }

            Database.ACR_IncrementStatistic("BROADCAST_MESSAGE");
            Script.WriteTimestampedLogEntry("Received broadcast notification: " + Message);
        }
 private static void DetectHeartBeat(CLRScriptBase s, ALFA.Shared.ActiveTrap trap, uint detector)
 {
     if (IsTrapDetectedBy(s, trap, detector))
     {
         HandleTrapDetected(s, trap, detector);
     }
 }
        private static bool IsTrapDetectedBy(CLRScriptBase s, ALFA.Shared.ActiveTrap trap, uint detector)
        {
            if (trap.Detected)
            {
                return false;
            }
            if(!IsInArea(s, trap, detector))
            {
                return false;
            }

            if (s.GetDetectMode(detector) == FALSE)
            {
                s.DelayCommand(6.0f, delegate { DetectHeartBeat(s, trap, detector); });
                return false;
            }

            if (trap.DetectDC > 20 &&
                s.GetLevelByClass(CLASS_TYPE_ROGUE, detector) == FALSE &&
                s.GetHasSpellEffect(SPELL_FIND_TRAPS, detector) == FALSE)
            {
                s.DelayCommand(6.0f, delegate { DetectHeartBeat(s, trap, detector); }); 
                return false;
            }

            int searchBonus = s.GetSkillRank(SKILL_SEARCH, detector, FALSE);
            int roll = s.d20(1);
            int finalDice = roll + searchBonus;
            if (trap.DetectDC <= finalDice)
            {
                return true;
            }
            s.DelayCommand(6.0f, delegate { DetectHeartBeat(s, trap, detector); });
            return false;
        }
        public static void Enter(CLRScriptBase s, ALFA.Shared.ActiveTrap trap)
        {
            uint enteringObject = s.GetEnteringObject();

            if (IsTrapDetectedBy(s, trap, enteringObject))
            {
                HandleTrapDetected(s, trap, enteringObject);
            }
        }
        /// <summary>
        /// Dispatch the event (in a script context).
        /// </summary>
        /// <param name="Script">Supplies the script object.</param>
        /// <param name="Database">Supplies the database connection.</param>
        public void DispatchEvent(ACR_ServerCommunicator Script, ALFA.Database Database)
        {
            string FormattedMessage = String.Format(
                "ACR_ServerCommunicator: Received unsupported IPC event {0}: {1}.{2}.{3}.{4}.  Record ID was {5}.",
                EventType,
                P0,
                P1,
                P2,
                P3,
                RecordId);

            Script.WriteTimestampedLogEntry(FormattedMessage);
        }
        /// <summary>
        /// Run the event queue down.  All events in the queue are given a
        /// chance to run.
        /// </summary>
        /// <param name="Script">Supplies the script object.</param>
        /// <param name="Database">Supplies the database connection.</param>
        public void RunQueue(ACR_ServerCommunicator Script, ALFA.Database Database)
        {
#if DEBUG_MODE
            Script.WriteTimestampedLogEntry(String.Format("ACR_ServerCommunicator: Running queue of {0} entries", EventQueue.Count));
#endif

            while (!Empty())
            {
                IGameEventQueueEvent Event = EventQueue.Dequeue();

                Event.DispatchEvent(Script, Database);
            }
        }
Beispiel #9
0
    static void Main(string[] args)
    {
        var s   = ReadLine();
        var set = new HashSet <char>();

        for (var i = 0; i < s.Length; i++)
        {
            set.Add(s[i]);
        }
        if (set.Count != ALFA.Length)
        {
            for (var i = 0; i < ALFA.Length; i++)
            {
                if (!set.Contains(ALFA[i]))
                {
                    s += ALFA[i];
                    break;
                }
            }
            WriteLine(s);
        }
        else
        {
            var r = -1;
            for (var i = 0; i < s.Length - 1; i++)
            {
                if (s[i] < s[i + 1])
                {
                    r = i;
                }
            }
            if (r == -1)
            {
                WriteLine(-1); return;
            }
            for (var i = r + 1; i < s.Length; i++)
            {
                set.Remove(s[i]);
            }
            var ad = ' ';
            for (var i = ALFA.IndexOf(s[r]) + 1; i < ALFA.Length; i++)
            {
                if (!set.Contains(ALFA[i]))
                {
                    ad = ALFA[i]; break;
                }
            }
            s = s.Substring(0, r) + ad;
            WriteLine(s);
        }
    }
        /// <summary>
        /// Dispatch the event (in a script context).
        /// </summary>
        /// <param name="Script">Supplies the script object.</param>
        /// <param name="Database">Supplies the database connection.</param>
        public void DispatchEvent(ACR_ServerCommunicator Script, ALFA.Database Database)
        {
            int SourceServerId = (SourceServer != null) ? SourceServer.ServerId : 0;

            Script.WriteTimestampedLogEntry(String.Format("RunScriptEvent.DispatchEvent: Executing script {0} ({1}) on request from {2}.",
                ScriptName,
                ScriptArgument,
                SourceServerId));
            Script.AddScriptParameterInt(SourceServerId);
            Script.AddScriptParameterString(ScriptArgument);
            Script.ExecuteScriptEnhanced(ScriptName, Script.GetModule(), CLRScriptBase.TRUE);

            Database.ACR_IncrementStatistic("RUN_REMOTE_SCRIPT");
        }
        /// <summary>
        /// Dispatch the event (in a script context).
        /// </summary>
        /// <param name="Script">Supplies the script object.</param>
        /// <param name="Database">Supplies the database connection.</param>
        public void DispatchEvent(ACR_ServerCommunicator Script, ALFA.Database Database)
        {
            foreach (uint PlayerObject in Script.GetPlayers(true))
            {
                if (Database.ACR_GetPlayerID(PlayerObject) != Player.PlayerId)
                    continue;

                Database.ACR_IncrementStatistic("DISCONNECT_PLAYER");
                Script.WriteTimestampedLogEntry("DisconnectPlayerEvent.DispatchEvent: Disconnecting player " + Script.GetPCPlayerName(PlayerObject) + " due to IPC request.");
                Script.BootPC(PlayerObject);
                return;
            }

            Script.WriteTimestampedLogEntry("DisconnectPlayerEvent.DispatchEvent: No player '" + Player.PlayerName + "' found locally connected to disconnect.");
        }
 public static void Disable(CLRScriptBase s, ALFA.Shared.ActiveTrap trap, uint disabler)
 {
     if (trap.Disabler == 0)
     {
         // no one is currently working on this trap.
         s.SendMessageToPC(disabler, "<c=#98FFFF>You begin to disable the trap...</c>");
         trap.Disabler = disabler;
         trap.Helpers = new List<uint>();
     }
     else
     {
         if (trap.Disabler == disabler)
         {
             s.SendMessageToPC(disabler, "<c=#98FFFF>Error: You are already disabling this device.</c>");
         }
         else if (trap.Helpers.Contains(disabler))
         {
             s.SendMessageToPC(disabler, "<c=#98FFFF>Disable Device: * Failure * You have already given aid to this attempt.</c>");
             return;
         }
         else
         {
             trap.Helpers.Add(disabler);
             if (IsDisableSuccessful(s, trap, 10, disabler) == DisableResult.Success)
             {
                 s.SendMessageToPC(disabler, String.Format("<c=#98FFFF>Disable Device: You grant {0} useful assistance with the trap.</c>", s.GetName(trap.Disabler)));
                 trap.TotalHelp += 2;
                 return;
             }
             else
             {
                 s.SendMessageToPC(disabler, String.Format("<c=#98FFFF>Disable Device: You are unable to grant {0} useful assistance with the trap.</c>", s.GetName(trap.Disabler)));
                 return;
             }
         }
     }
     if (s.GetIsDM(disabler) == TRUE && s.GetIsDMPossessed(disabler) == FALSE)
     {
         RemoveTrap(s, trap);
         s.SendMessageToPC(disabler, String.Format("<c=#98FFFF>Removing trap {0}</c>", trap.Tag));
         return;
     }
     float neededTime = s.d4(2) * 6.0f;
     NWLocation oldLoc = s.GetLocation(disabler);
     s.DelayCommand(2.0f, delegate { StallForTime(s, trap, disabler, neededTime, oldLoc); });
 }
        /// <summary>
        /// Dispatch the event (in a script context).
        /// </summary>
        /// <param name="Script">Supplies the script object.</param>
        /// <param name="Database">Supplies the database connection.</param>
        public void DispatchEvent(ACR_ServerCommunicator Script, ALFA.Database Database)
        {
            //
            // If the event was for the local server, then don't re-broadcast
            // it.
            //

            if (Database.ACR_GetServerID() == Server.ServerId)
                return;

            string Message = String.Format(
                "<c=#FFFF00>Server {0} is now offline.</c>",
                Server.Name);
            string ChatMessage = "</c>" + Message;

            foreach (uint PlayerObject in Script.GetPlayers(true))
            {
                PlayerState Player = Script.TryGetPlayerState(PlayerObject);

                if (Player == null)
                    continue;

                if (!Script.IsCrossServerNotificationEnabled(PlayerObject))
                    continue;

                if ((Player.Flags & PlayerStateFlags.SendCrossServerNotificationsToCombatLog) != 0)
                {
                    Script.SendMessageToPC(PlayerObject, Message);
                }
                else
                {
                    Script.SendChatMessage(
                        CLRScriptBase.OBJECT_INVALID,
                        PlayerObject,
                        CLRScriptBase.CHAT_MODE_SERVER,
                        ChatMessage,
                        CLRScriptBase.FALSE);
                }
            }

#if DEBUG_MODE
            Script.WriteTimestampedLogEntry(Message);
#endif
        }
        /// <summary>
        /// Dispatch the event (in a script context).
        /// </summary>
        /// <param name="Script">Supplies the script object.</param>
        /// <param name="Database">Supplies the database connection.</param>
        public void DispatchEvent(ACR_ServerCommunicator Script, ALFA.Database Database)
        {
            string VaultPath = SystemInfo.GetServerVaultPathForAccount(Player.Name);

            if (VaultPath == null)
            {
                Script.WriteTimestampedLogEntry(String.Format(
                    "PurgeCachedCharacterEvent.DispatchEvent: Could not resolve vault path for player '{0}'.",
                    Player.PlayerName));
                return;
            }

            VaultPath += CharacterFileName;

            if (!File.Exists(VaultPath))
            {
                Script.WriteTimestampedLogEntry(String.Format(
                    "PurgeCachedCharacterEvent.DispatchEvent: Character file '{0}' for player '{1}' was not locally cached.",
                    CharacterFileName,
                    Player.PlayerName));
                return;
            }

            try
            {
                File.Delete(VaultPath);
            }
            catch (Exception e)
            {
                Script.WriteTimestampedLogEntry(String.Format(
                    "PurgeCachedCharacterEvent.DispatchEvent: Exception '{0}' removing cached character '{1}' for player '{2}'.",
                    e,
                    CharacterFileName,
                    Player.PlayerName));
                return;
            }

            Script.WriteTimestampedLogEntry(String.Format(
                "PurgeCachedCharacterEvent.DispatchEvent: Removed cached character '{0}' from player '{1}' vault cache.",
                CharacterFileName,
                Player.PlayerName));
        }
        /// <summary>
        /// Dispatch the event (in a script context).
        /// </summary>
        /// <param name="Script">Supplies the script object.</param>
        /// <param name="Database">Supplies the database connection.</param>
        public void DispatchEvent(ACR_ServerCommunicator Script, ALFA.Database Database)
        {
            foreach (uint PlayerObject in Script.GetPlayers(true))
            {
                string FormattedMessage = String.Format(
                    "</c><c=#FFFF00>Server shutting down: {0}</c>",
                    Message);

                NWScript.Vector3 v;
                v.x = v.y = v.z = 0.0f;

                Script.SendChatMessage(
                    CLRScriptBase.OBJECT_INVALID,
                    PlayerObject,
                    CLRScriptBase.CHAT_MODE_SERVER,
                    FormattedMessage,
                    CLRScriptBase.FALSE);

                Script.FloatingTextStringOnCreature(FormattedMessage,
                    PlayerObject,
                    CLRScriptBase.FALSE,
                    5.0f,
                    CLRScriptBase.COLOR_WHITE,
                    CLRScriptBase.COLOR_WHITE,
                    0.0f,
                    v);
            }

            Script.WriteTimestampedLogEntry("Received shutdown request: " + Message);

            Database.ACR_IncrementStatistic("SERVER_SHUTDOWN");
            Script.SendInfrastructureIrcMessage(String.Format(
                "Server '{0}' shutting down or restarting: {1}",
                Script.GetName(Script.GetModule()),
                Message));

            Script.DelayCommand(5.0f, delegate()
            {
                Database.ACR_FlushAllQueryQueues();
                SystemInfo.ShutdownGameServer(Script);
            });
        }
        /// <summary>
        /// Dispatch the event (in a script context).
        /// </summary>
        /// <param name="Script">Supplies the script object.</param>
        /// <param name="Database">Supplies the database connection.</param>
        public void DispatchEvent(ACR_ServerCommunicator Script, ALFA.Database Database)
        {
            PlayerState State = Script.TryGetPlayerState(PlayerObject);
            string RequestURL;

            //
            // If the player is logged off, then there's nothing to do.
            //

            if (State == null || State.IsDM)
                return;

            if (String.IsNullOrEmpty(AccountAssociationSecret))
                return;

            RequestURL = AccountAssociator.GenerateAssociationURL(Script.GetPCPlayerName(PlayerObject), AccountAssociationSecret, AccountAssociationURL);

            Script.DisplayGuiScreen(PlayerObject, "acr_account_association", CLRScriptBase.FALSE, "acr_account_association.XML", CLRScriptBase.FALSE);
            Script.SetLocalGUIVariable(PlayerObject, "acr_account_association", 0, RequestURL);
        }
        /// <summary>
        /// Dispatch the event (in a script context).
        /// </summary>
        /// <param name="Script">Supplies the script object.</param>
        /// <param name="Database">Supplies the database connection.</param>
        public void DispatchEvent(ACR_ServerCommunicator Script, ALFA.Database Database)
        {
            foreach (uint PlayerObject in Script.GetPlayers(true))
            {
                if (Database.ACR_GetPlayerID(PlayerObject) != Recipient.PlayerId)
                    continue;

                string FormattedMessage = String.Format(
                    "</c><c=#FFCC99>{0}: </c><c=#30DDCC>[Page] {1}</c>",
                    Sender.PlayerName,
                    Message);

                Script.SendChatMessage(
                    CLRScriptBase.OBJECT_INVALID,
                    PlayerObject,
                    CLRScriptBase.CHAT_MODE_SERVER,
                    FormattedMessage,
                    CLRScriptBase.FALSE);
                break;
            }
        }
        /// <summary>
        /// Dispatch the event (in a script context).
        /// </summary>
        /// <param name="Script">Supplies the script object.</param>
        /// <param name="Database">Supplies the database connection.</param>
        public void DispatchEvent(ACR_ServerCommunicator Script, ALFA.Database Database)
        {
            foreach (uint PlayerObject in Script.GetPlayers(true))
            {
                if (Database.ACR_GetPlayerID(PlayerObject) != Recipient.PlayerId)
                    continue;

                string FormattedMessage = String.Format(
                    "</c><c=#FFCC99>{0}: </c><c=#30DDCC>[ServerTell] {1}</c>",
                    Sender.CharacterName,
                    Message);

                Script.SetLastTellFromPlayerId(PlayerObject, Sender.Player.PlayerId);
                Script.SendChatMessage(
                    CLRScriptBase.OBJECT_INVALID,
                    PlayerObject,
                    CLRScriptBase.CHAT_MODE_SERVER,
                    FormattedMessage,
                    CLRScriptBase.FALSE);

                //
                // If this is the first time that we have delivered a
                // cross-server tell to this player (since login), remind them
                // of how to respond.
                //

                if ((Database.ACR_GetPCLocalFlags(PlayerObject) & ALFA.Database.ACR_PC_LOCAL_FLAG_SERVER_TELL_HELP) == 0)
                {
                    Script.SendMessageToPC(
                        PlayerObject,
                        "To respond to a [ServerTell] from a player on a different server, type: #re [message], or #t \"character name\" [message], or #tp \"player name\" [message].  Quotes are optional unless the name has spaces.  The #rt [message] command will send a tell to the last player that you had sent a tell to.");
                    Database.ACR_SetPCLocalFlags(
                        PlayerObject,
                        Database.ACR_GetPCLocalFlags(PlayerObject) | ALFA.Database.ACR_PC_LOCAL_FLAG_SERVER_TELL_HELP);
                }
                break;
            }
        }
        private static void HandleTrapDetected(CLRScriptBase s, ALFA.Shared.ActiveTrap trap, uint detector)
        {
            trap.Detected = true;
           
            NWEffect vfx = s.SupernaturalEffect(s.EffectNWN2SpecialEffectFile(trap.TrapTriggerVFX, OBJECT_INVALID, s.Vector(0.0f, 0.0f, 0.0f)));
            s.ApplyEffectToObject(DURATION_TYPE_PERMANENT, vfx, s.GetObjectByTag(trap.Tag, 0), 0.0f);

            uint detectWidget = s.CreateObject(OBJECT_TYPE_PLACEABLE, "acr_trap_disarm", s.GetLocation(detector), TRUE, trap.Tag + "_");
            if (!String.IsNullOrEmpty(trap.Description))
            {
                s.SetDescription(detectWidget, trap.Description);
            }
            s.SetFirstName(detectWidget, String.Format("Disarm the {0} trap", trap.SpellTrap ? "Spell" : "Mechanical"));
            
            // If they clicked to walk, let's stop them from walking into the hazard they just found.
            if (s.GetCurrentAction(detector) == ACTION_MOVETOPOINT)
            {
                s.AssignCommand(detector, delegate { s.ClearAllActions(0); });
            }
            s.PlaySound("alert", FALSE);
            s.ApplyEffectToObject(DURATION_TYPE_TEMPORARY, s.SupernaturalEffect(s.EffectNWN2SpecialEffectFile("fx_bang", detector, s.Vector(0.0f,0.0f,0.0f))), detector, 6.0f);
            s.SendMessageToPC(detector, "You spot a trap!");
        }
        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); });
            }
        }
        /// <summary>
        /// Dispatch the event (in a script context).
        /// </summary>
        /// <param name="Script">Supplies the script object.</param>
        /// <param name="Database">Supplies the database connection.</param>
        public void DispatchEvent(ACR_ServerCommunicator Script, ALFA.Database Database)
        {
            //
            // If the event was for a player logging off of the local server,
            // then don't re-broadcast it.
            //

            foreach (uint PlayerObject in Script.GetPlayers(true))
            {
                PlayerState Player = Script.TryGetPlayerState(PlayerObject);

                if (Player == null)
                    continue;

                if (Player.CharacterIdsShown.Contains(Character.CharacterId))
                {
                    string sPlayerListBox = "";

                    if (Server.ServerId == Script.GetDatabase().ACR_GetServerID() || Script.GetLocalInt(PlayerObject, "chatselect_expanded") == 0)
                    {
                        if (IsDM == true)
                        {
                            sPlayerListBox = "LocalDMList";
                            Player.ChatSelectLocalDMsShown -= 1;
                        }
                        else
                        {
                            sPlayerListBox = "LocalPlayerList";
                            Player.ChatSelectLocalPlayersShown -= 1;
                        }
                    }
                    else
                    {
                        if (IsDM == true)
                        {
                            sPlayerListBox = "RemoteDMList";
                            Player.ChatSelectRemoteDMsShown -= 1;
                        }
                        else
                        {
                            sPlayerListBox = "RemotePlayerList";
                            Player.ChatSelectRemotePlayersShown -= 1;
                        }
                    }

                    Script.RemoveListBoxRow(Player.ObjectId, "ChatSelect", sPlayerListBox, Character.CharacterName);
                    Player.CharacterIdsShown.Remove(Character.CharacterId);
                    Player.UpdateChatSelectGUIHeaders();
                }
            }

            if (Database.ACR_GetServerID() == Server.ServerId)
                return;

            string Message = String.Format(
                "{0}<c=#FFDAB9>{1} ({2}) left {3}.</c>", // <c=Peachpuff...>
                IsDM ? "<c=#99CCFF>[DM] </c>" : "",
                Character.Name,
                Character.Player.Name,
                Server.Name);
            string ChatMessage = "</c>" + Message;

            foreach (uint PlayerObject in Script.GetPlayers(true))
            {
                PlayerState Player = Script.TryGetPlayerState(PlayerObject);

                if (Player == null)
                    continue;

                if (!Script.IsCrossServerNotificationEnabled(PlayerObject))
                    continue;

                if ((Player.Flags & PlayerStateFlags.SendCrossServerNotificationsToCombatLog) != 0)
                {
                    Script.SendMessageToPC(PlayerObject, Message);
                }
                else
                {
                    Script.SendChatMessage(
                        CLRScriptBase.OBJECT_INVALID,
                        PlayerObject,
                        CLRScriptBase.CHAT_MODE_SERVER,
                        ChatMessage,
                        CLRScriptBase.FALSE);
                }
            }

#if DEBUG_MODE
            Script.WriteTimestampedLogEntry(Message);
#endif
        }
 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; }
 }
        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;
        }
 public static void Exit(CLRScriptBase s, ALFA.Shared.ActiveTrap trap)
 {
     s.SendMessageToPC(s.GetEnteringObject(), String.Format("This event has no functionality in it. If it has fired, you should write up a ticket about how. Trap ID: {0}", trap.Tag));
 }
 private static bool IsInArea(CLRScriptBase s, ALFA.Shared.ActiveTrap trap, uint creature)
 {
     uint nwTrap = s.GetObjectByTag(trap.DetectTag, 0);
     foreach (uint item in s.GetObjectsInPersistentObject(nwTrap, OBJECT_TYPE_CREATURE, PERSISTENT_ZONE_ACTIVE))
     {
         if (item == creature)
         {
             return true;
         }
     }
     return false;
 }
 public static bool FitsTrapTargetRestriction(CLRScriptBase s, ALFA.Shared.ActiveTrap trap, uint target)
 {
     if (s.GetIsDead(target, FALSE) == TRUE)
     {
         return false;
     }
     if (trap.TargetAlignment != ALIGNMENT_ALL)
     {
         if ((trap.TargetAlignment == ALIGNMENT_CHAOTIC ||
             trap.TargetAlignment == ALIGNMENT_LAWFUL ||
             trap.TargetAlignment == ALIGNMENT_NEUTRAL) &&
             s.GetAlignmentLawChaos(target) != trap.TargetAlignment)
         {
             return false;
         }
         if ((trap.TargetAlignment == ALIGNMENT_GOOD ||
             trap.TargetAlignment == ALIGNMENT_EVIL ||
             trap.TargetAlignment == ALIGNMENT_NEUTRAL) &&
             s.GetAlignmentGoodEvil(target) != trap.TargetAlignment)
         {
             return false;
         }
     }
     if (trap.TargetRace != RACIAL_TYPE_ALL)
     {
         if (trap.TargetRace != s.GetRacialType(target))
         {
             return false;
         }
     }
     return true;
 }
 /// <summary>
 /// Dispatch the event (in a script context).
 /// </summary>
 /// <param name="Script">Supplies the script object.</param>
 /// <param name="Database">Supplies the database connection.</param>
 public void DispatchEvent(ACR_ServerCommunicator Script, ALFA.Database Database)
 {
     Script.SendMessageToPC(PlayerObject, Message);
 }
 public static void Fire(CLRScriptBase s, ALFA.Shared.ActiveTrap trap)
 {
     Fire(s, trap, OBJECT_INVALID);
 }
        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); });
        }
 /// <summary>
 /// Run the event queue down.  All events in the queue are given a
 /// chance to run.
 /// </summary>
 /// <param name="Script">Supplies the script object.</param>
 /// <param name="Database">Supplies the database connection.</param>
 public void RunQueue(ACR_ServerCommunicator Script, ALFA.Database Database)
 {
     EventQueue.RunQueue(Script, Database);
     EventsQueued = false;
 }
        public static void RemoveTrap(CLRScriptBase s, ALFA.Shared.ActiveTrap trap)
        {
            uint triggerAOE = s.GetObjectByTag(trap.Tag, 0);
            uint detectAOE = s.GetObjectByTag(trap.DetectTag, 0);
            uint disarmPlaceable = s.GetObjectByTag(trap.Tag + "_", 0);

            s.DestroyObject(triggerAOE, 0.0f, FALSE);
            s.DestroyObject(detectAOE, 0.0f, FALSE);
            s.DestroyObject(disarmPlaceable, 0.0f, FALSE);
        }