public static void ChangeSecondaryBot(BotBase bot) { if (bot == null) { return; } if (Instance.SecondaryBot != null && Instance.SecondaryBot.Name == bot.Name) { return; } Util.ExecuteActionWhileBotIsStopped( () => { Instance.SecondaryBot = bot; if (!bot.Initialized) { bot.DoInitialize(); } if (ProfessionBuddySettings.Instance.LastBotBase != bot.Name) { ProfessionBuddySettings.Instance.LastBotBase = bot.Name; ProfessionBuddySettings.Instance.Save(); } if (MainForm.IsValid) { MainForm.Instance.UpdateBotCombo(); } }, "Changing SecondaryBot"); }
/// <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. The bot class type name will also work.</param> public static void SwitchCharacter(string character, string server, string botName) { if (_isSwitchingToons) { PBLog.Log("Already switching characters"); return; } string loginLua = string.Format(LoginLua, character, server); _isSwitchingToons = true; // reset all actions ProfessionbuddyBot.Instance.IsRunning = false; ProfessionbuddyBot.Instance.Reset(); Application.Current.Dispatcher.BeginInvoke( new Action( () => { Lua.DoString("Logout()"); new Thread( () => { while (StyxWoW.IsInGame) { Thread.Sleep(2000); } while (!StyxWoW.IsInGame) { Lua.DoString(loginLua); Thread.Sleep(2000); } BotBase bot = Util.GetBotByName(botName); if (bot != null) { if (ProfessionbuddyBot.Instance.SecondaryBot.Name != bot.Name) { ProfessionbuddyBot.Instance.SecondaryBot = bot; } if (!bot.Initialized) { bot.DoInitialize(); } if (ProfessionBuddySettings.Instance.LastBotBase != bot.Name) { ProfessionBuddySettings.Instance.LastBotBase = bot.Name; ProfessionBuddySettings.Instance.Save(); } } else { PBLog.Warn("Could not find bot with name {0}", botName); } TreeRoot.Start(); ProfessionbuddyBot.Instance.OnTradeSkillsLoaded += ProfessionbuddyBot.Instance.Professionbuddy_OnTradeSkillsLoaded; ProfessionbuddyBot.Instance.LoadTradeSkills(); _isSwitchingToons = false; ProfessionbuddyBot.Instance.IsRunning = true; }) { IsBackground = true }.Start(); })); TreeRoot.Stop(); }
public override void Initialize() { try { if (!_init) { PBLog.Debug("Initializing ..."); Util.ScanForOffsets(); if (!Directory.Exists(BotPath)) { Directory.CreateDirectory(BotPath); } DynamicCodeCompiler.WipeTempFolder(); // force Tripper.Tools.dll to load........ new Vector3(0, 0, 0); MySettings = new ProfessionBuddySettings( Path.Combine( Utilities.AssemblyDirectory, string.Format(@"Settings\{0}\{0}[{1}-{2}].xml", Name, Me.Name, Lua.GetReturnVal <string>("return GetRealmName()", 0)))); IsTradeSkillsLoaded = false; LoadTradeSkills(); DataStore = new DataStore(); DataStore.ImportDataStore(); LoadTradeskillTools(); // load localized strings LoadStrings(); // load the previous BotBase bot = BotManager.Instance.Bots.Values.FirstOrDefault( b => b.Name.IndexOf(MySettings.LastBotBase, StringComparison.InvariantCultureIgnoreCase) >= 0); if (bot == null) { // look for combat bot, otherwise select first bot if combat bot is not found bot = BotManager.Instance.Bots.Values.FirstOrDefault(b => b.GetType().ToString() == "CombatBot") ?? BotManager.Instance.Bots.Values.FirstOrDefault(); MySettings.LastBotBase = bot.Name; MySettings.Save(); } SecondaryBot = bot; bot.DoInitialize(); try { if (!string.IsNullOrEmpty(_profileToLoad)) { LoadPBProfile(_profileToLoad); } else if (!string.IsNullOrEmpty(MySettings.LastProfile)) { LoadPBProfile(MySettings.LastProfile); } } catch (Exception ex) { PBLog.Warn(ex.ToString()); } _init = true; } } catch (Exception ex) { Logging.Write(Colors.Red, ex.ToString()); } }