Example #1
0
        public static void ChangeSecondaryBot(string botName)
        {
            BotBase bot =
                BotManager.Instance.Bots.Values.FirstOrDefault(
                    b => b.Name.IndexOf(botName, StringComparison.InvariantCultureIgnoreCase) >= 0);

            if (bot != null)
            {
                if (Instance.SecondaryBot != null && Instance.SecondaryBot.Name != bot.Name ||
                    Instance.SecondaryBot == null)
                {
                    Instance.IsRunning = false;
                    // execute from GUI thread since this thread will get aborted when switching bot
                    Application.Current.Dispatcher.Invoke(
                        new Action(() =>
                    {
                        _isChangingBot = true;
                        bool isRunning = TreeRoot.IsRunning;
                        if (isRunning)
                        {
                            TreeRoot.Stop();
                        }
                        Instance.SecondaryBot = bot;
                        if (!bot.Initialized)
                        {
                            bot.Initialize();
                        }
                        if (ProfessionBuddySettings.Instance.LastBotBase != bot.Name)
                        {
                            ProfessionBuddySettings.Instance.LastBotBase = bot.Name;
                            ProfessionBuddySettings.Instance.Save();
                        }
                        if (MainForm.IsValid)
                        {
                            MainForm.Instance.UpdateBotCombo();
                        }
                        if (isRunning)
                        {
                            TreeRoot.Start();
                        }
                        _isChangingBot = false;
                    }
                                   ));
                    Log("Changing SecondaryBot to {0}", botName);
                }
            }
            else
            {
                Err("Bot with name: {0} was not found", botName);
            }
        }
Example #2
0
        /// <summary>
        /// Switches to a different character on same account
        /// </summary>
        /// <param name="character"></param>
        /// <param name="server"></param>
        /// <param name="botName">Name of bot to use on that character</param>
        public static void SwitchCharacter(string character, string server, string botName)
        {
            if (_isSwitchingToons)
            {
                Professionbuddy.Log("Already switching characters");
                return;
            }
            string loginLua = string.Format(LoginLua, character, server);

            _isSwitchingToons = true;
            // reset all actions
            Professionbuddy.Instance.IsRunning = false;
            Professionbuddy.Instance.PbBehavior.Reset();

            Application.Current.Dispatcher.Invoke(
                new Action(() =>
            {
                TreeRoot.Stop();
                BotBase bot =
                    BotManager.Instance.Bots.FirstOrDefault(
                        b => b.Key.IndexOf(botName, StringComparison.OrdinalIgnoreCase) >= 0).Value;
                if (bot != null)
                {
                    if (Professionbuddy.Instance.SecondaryBot.Name != bot.Name)
                    {
                        Professionbuddy.Instance.SecondaryBot = bot;
                    }
                    if (!bot.Initialized)
                    {
                        bot.Initialize();
                    }
                    if (ProfessionBuddySettings.Instance.LastBotBase != bot.Name)
                    {
                        ProfessionBuddySettings.Instance.LastBotBase = bot.Name;
                        ProfessionBuddySettings.Instance.Save();
                    }
                }
                else
                {
                    Professionbuddy.Err("Could not find bot with name {0}", botName);
                }

                Lua.DoString("Logout()");

                new Thread(() =>
                {
                    while (ObjectManager.IsInGame)
                    {
                        Thread.Sleep(2000);
                    }
                    while (!ObjectManager.IsInGame)
                    {
                        Lua.DoString(loginLua);
                        Thread.Sleep(2000);
                    }
                    TreeRoot.Start();
                    Professionbuddy.Instance.OnTradeSkillsLoaded +=
                        Professionbuddy.Instance.Professionbuddy_OnTradeSkillsLoaded;
                    Professionbuddy.Instance.LoadTradeSkills();
                    _isSwitchingToons = false;
                    Professionbuddy.Instance.IsRunning = true;
                })
                {
                    IsBackground = true
                }.Start();
            }));
        }
Example #3
0
 public override void Initialize()
 {
     _botBase.Initialize();
 }