/************************************************************************************/
        protected static void PressAndHoldKey(string strKey)
        {
            string strIndexedKey = strKey.ToLower().Trim();

            if (!s_PressedKeys.Contains(strIndexedKey))
            {
                Program.Log("Pressing and holding keyboard key: {0}", strKey);
                s_PressedKeys.Add(strIndexedKey);
            }

            /// Reapply the key even if it was applied before.
            /// Sometimes with window focus changes, the press gets lost.
            LavishScriptAPI.LavishScript.ExecuteCommand("press -hold " + strKey);
            return;
        }
        /************************************************************************************/
        protected Actor GetNestedCombatAssistTarget(string strPlayerName)
        {
            Actor AssistedPlayerActor = GetPlayerActor(strPlayerName);

            if (AssistedPlayerActor == null)
            {
                Program.Log("No player actor was found with the name {0}.", strPlayerName);
                return(null);
            }

            string strAssistDescription = string.Empty;
            Actor  FinalTargetActor     = null;

            SetCollection <int> TraversedActorIDSet = new SetCollection <int>();

            /// Nested assist targetting. Go through assist targets until either a recursive loop or a killable NPC is found.
            /// This is more advanced than even the normal UI allows.
            for (Actor ThisActor = AssistedPlayerActor; ThisActor.IsValid; ThisActor = ThisActor.Target())
            {
                if (TraversedActorIDSet.Count > 0)
                {
                    strAssistDescription += " --> ";
                }
                strAssistDescription += string.Format("{0} ({1})", ThisActor.Name, ThisActor.ID);

                if (ThisActor.Type == "NPC" || ThisActor.Type == STR_NAMED_NPC)
                {
                    FinalTargetActor = ThisActor;
                    break;
                }

                /// Infinite recursion = FAIL
                if (TraversedActorIDSet.Contains(ThisActor.ID))
                {
                    Program.Log("Circular player assist chain detected! No enemy was found.");
                    break;
                }

                TraversedActorIDSet.Add(ThisActor.ID);
            }

            Program.Log("Assist chain: {0}", strAssistDescription);
            return(FinalTargetActor);
        }
        /************************************************************************************/
        /// <summary>
        /// </summary>
        /// <param name="fBlockageSeconds">The number of seconds to wait before allowing any other copy of the same command to run. If 0, then there will be no throttling.</param>
        /// <param name="strCommand"></param>
        protected static bool RunCommand(double fBlockageSeconds, string strCommandLineFormat, params object[] aobjParams)
        {
            if (string.IsNullOrEmpty(strCommandLineFormat))
            {
                return(false);
            }

            try
            {
                string strFinalCommandLine = string.Empty;

                if (aobjParams.Length == 0)
                {
                    strFinalCommandLine += string.Format("{0}", strCommandLineFormat);
                }
                else
                {
                    strFinalCommandLine += string.Format(strCommandLineFormat, aobjParams);
                }

                /// Throttle it only if the parameter says so.
                /// The only time a command gets removed from the cache is during zoning.
                if (fBlockageSeconds > 0.0)
                {
                    DateTime ExpirationTime = DateTime.FromBinary(0);
                    if (s_RecentThrottledCommandCache.TryGetValue(strFinalCommandLine, out ExpirationTime))
                    {
                        /// Overwrite an old entry.
                        if (CurrentCycleTimestamp > ExpirationTime)
                        {
                            s_RecentThrottledCommandCache[strFinalCommandLine] = CurrentCycleTimestamp + TimeSpan.FromSeconds(fBlockageSeconds);
                        }
                        else
                        {
                            Program.Log("Throttled command blocked: {0}", strFinalCommandLine);
                            return(false);
                        }
                    }
                    else
                    {
                        s_RecentThrottledCommandCache.Add(strFinalCommandLine, CurrentCycleTimestamp + TimeSpan.FromSeconds(fBlockageSeconds));
                    }
                }

                using (new FrameLock(true))
                {
                    Program.Log("Executing: {0}", strFinalCommandLine);

                    /// Break the command up as if it were a custom one.
                    List <string> astrParameters = new List <string>(strFinalCommandLine.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries));
                    string        strCommand     = astrParameters[0];
                    if (strCommand[0] == '/')
                    {
                        strCommand = strCommand.Substring(1);
                    }
                    astrParameters.RemoveAt(0);

                    /// We have to manually process custom commands, EQ2Execute does not handle them.
                    if (s_RegisteredCustomSlashCommands.Contains(strCommand))
                    {
                        if (s_Controller != null && UpdateStaticGlobals())
                        {
                            return(s_Controller.OnCustomSlashCommand(strCommand, astrParameters.ToArray()));
                        }
                    }
                    else
                    {
                        s_Extension.EQ2Execute(strFinalCommandLine);
                        return(true);
                    }
                }
            }
            catch
            {
            }

            return(true);
        }
Exemplo n.º 4
0
 private void removeBtnClick(object sender, RoutedEventArgs e)
 {
     SubsetCollection.RemoveAll(x => SetCollection.Contains(x));
 }