protected override void OnClosing(System.ComponentModel.CancelEventArgs e) { if (DialogResult == DialogResult.OK || DialogResult == DialogResult.Yes) { Logger.WriteDebug(Color.LightGreen, "Settings saved, rebuilding behaviors..."); // in case bot not running when config change occurs SingularRoutine.OnPlayerTargetChange(StyxWoW.Me.CurrentTarget); HotkeyDirector.Update(); MovementManager.Update(); SingularRoutine.DescribeContext(); SingularRoutine.Instance.RebuildBehaviors(); SingularSettings.Instance.LogSettings(); } base.OnClosing(e); }
public override void Initialize() { DateTime timeStart = DateTime.UtcNow; Logger.WriteFile("Initialize: started"); // cannot call method which references SingularSettings TalentManager.Init(); // initializes CurrentSpec which is referenced everywhere SingularSettings.Initialize(); // loads Singular global and spec-specific settings (must determine spec first) DetermineCurrentWoWContext(); Task.Run(() => WriteSupportInfo()); _lastLogLevel = GlobalSettings.Instance.LogLevel; // When we actually need to use it, we will. Spell.Init(); Spell.GcdInitialize(); EventHandlers.Init(); MountManager.Init(); HotkeyDirector.Init(); MovementManager.Init(); // SoulstoneManager.Init(); // switch to using Death behavior Dispelling.Init(); PartyBuff.Init(); Singular.Lists.BossList.Init(); Targeting.Instance.WeighTargetsFilter += PullMoreWeighTargetsFilter; //Logger.Write("Combat log event handler started."); // Do this now, so we ensure we update our context when needed. BotEvents.Player.OnMapChanged += e => { // Don't run this handler if we're not the current routine! if (!WeAreTheCurrentCombatRoutine) { return; } // Only ever update the context. All our internal handlers will use the context changed event // so we're not reliant on anything outside of ourselves for updates. UpdateContext(); }; TreeHooks.Instance.HooksCleared += () => { // Don't run this handler if we're not the current routine! if (!WeAreTheCurrentCombatRoutine) { return; } Logger.Write(LogColor.Hilite, "Hooks cleared, re-creating behaviors"); RebuildBehaviors(silent: true); Spell.GcdInitialize(); // probably not needed, but quick }; GlobalSettings.Instance.PropertyChanged += (sender, e) => { // Don't run this handler if we're not the current routine! if (!WeAreTheCurrentCombatRoutine) { return; } // only LogLevel change will impact our behav trees // .. as we conditionally include/omit some diagnostic nodes if debugging // also need to keep a cached copy of prior value as the event // .. fires on the settor, not when the value is different if (e.PropertyName == "LogLevel" && _lastLogLevel != GlobalSettings.Instance.LogLevel) { _lastLogLevel = GlobalSettings.Instance.LogLevel; Logger.Write(LogColor.Hilite, "HonorBuddy {0} setting changed to {1}, re-creating behaviors", e.PropertyName, _lastLogLevel.ToString()); RebuildBehaviors(); Spell.GcdInitialize(); // probably not needed, but quick } }; // install botevent handler so we can consolidate validation on whether // .. local botevent handlers should be called or not SingularBotEventInitialize(); Logger.Write("Determining talent spec."); try { TalentManager.Update(); } catch (Exception e) { StopBot(e.ToString()); } Logger.Write("Current spec is " + SpecName()); // write current settings to log file... only written at startup and when Save press in Settings UI Task.Run(() => SingularSettings.Instance.LogSettings()); // Update the current WoWContext, and fire an event for the change. UpdateContext(); // NOTE: Hook these events AFTER the context update. OnWoWContextChanged += (orig, ne) => { Logger.Write(LogColor.Hilite, "Context changed, re-creating behaviors"); SingularRoutine.DescribeContext(); RebuildBehaviors(); Spell.GcdInitialize(); Singular.Lists.BossList.Init(); }; RoutineManager.Reloaded += (s, e) => { Logger.Write(LogColor.Hilite, "Routines were reloaded, re-creating behaviors"); RebuildBehaviors(silent: true); Spell.GcdInitialize(); }; // create silently since Start button will create a context change (at least first Start) // .. which will build behaviors again if (!Instance.RebuildBehaviors()) { return; } // if (IsPluginEnabled("DrinkPotions")) { Logger.Write(LogColor.Hilite, "info: disabling DrinkPotions plugin, conflicts with Singular potion support"); SetPluginEnabled("DrinkPotions", false); } SpellImmunityManager.Add(16292, WoWSpellSchool.Frost); // http://www.wowhead.com/npc=16292/aquantion Logger.WriteDebug(Color.White, "Verified behaviors can be created!"); Logger.Write("Initialization complete!"); Logger.WriteDiagnostic(Color.White, "Initialize: completed taking {0:F2} seconds", (DateTime.UtcNow - timeStart).TotalSeconds); }
public override void Pulse() { #region Pulse - check for conditions that we should not Pulse during /* * if (!StyxWoW.IsInGame) * { * if (DateTime.UtcNow > _nextNotInGameMsgAllowed) * { * Logger.WriteDebug(Color.HotPink, "info: not in game"); * _nextNotInGameMsgAllowed = DateTime.UtcNow.AddSeconds(30); * } * return; * } * _nextNotInGameMsgAllowed = DateTime.MinValue; * * if (!StyxWoW.IsInWorld) * { * if (DateTime.UtcNow > _nextNotInWorldMsgAllowed) * { * Logger.WriteDebug(Color.HotPink, "info: not in world"); * _nextNotInWorldMsgAllowed = DateTime.UtcNow.AddSeconds(30); * } * return; * } * _nextNotInWorldMsgAllowed = DateTime.MinValue; */ #endregion _pulsePhase++; if (_pulsePhase == 1) { if (WaitForLatencyCheck.IsFinished) { Latency = StyxWoW.WoWClient.Latency; WaitForLatencyCheck.Reset(); } // output messages about pulldistance and behaviorflag changes here MonitorPullDistance(); MonitorBehaviorFlags(); /* * // now if combat disabled, bail out * bool combatDisabled = Bots.Grind.BehaviorFlags.Combat != (Bots.Grind.LevelBot.BehaviorFlags & Bots.Grind.BehaviorFlags.Combat); * if (combatDisabled != _lastCombatDisabledState) * { * _lastCombatDisabledState = combatDisabled; * Logger.Write(Color.HotPink, * combatDisabled * ? "info: botbase disabled BehaviorFlags.Combat" * : "info: botbase enabled BehaviorFlags.Combat" * ); * } */ // check time since last call and be sure user knows if Singular isn't being called if (SingularSettings.Debug) { TimeSpan since = CallWatch.TimeSpanSinceLastCall; if (since.TotalSeconds > (4 * CallWatch.SecondsBetweenWarnings)) { if (!Me.IsGhost && !Me.Mounted && !Me.IsFlying && DateTime.UtcNow > _nextNoCallMsgAllowed) { Logger.WriteDebug(Color.HotPink, "info: {0:F0} seconds since {1} BotBase last called Singular", since.TotalSeconds, GetBotName()); _nextNoCallMsgAllowed = DateTime.UtcNow.AddSeconds(4 * CallWatch.SecondsBetweenWarnings); } } } UpdateDiagnosticFPS(); } else if (_pulsePhase == 2) { // talentmanager.Pulse() intense if does work, so return if true if (TalentManager.Pulse()) { return; } // check and output casting state information UpdateDiagnosticCastingState(); UpdatePullMoreConditionals(); // Update the current context, check if we need to rebuild any behaviors. UpdateContext(); } else if (_pulsePhase == 3) { _pulsePhase = 0; // Pulse our StopAt manager StopMoving.Pulse(); PetManager.Pulse(); // Double cast maintenance Spell.MaintainDoubleCast(); HotkeyDirector.Pulse(); WatchAurasForProcs(); } if (Me.Class == WoWClass.Warlock) { ClassSpecific.Warlock.Common.CancelBurningRushIfNeeded(fromPulse: true); } // Output if Target changed CheckCurrentTarget(); // Output if Pet or Pet Target changed CheckCurrentPet(); // check Targeting pulses if (HealerManager.NeedHealTargeting) { BotBase bot = GetCurrentBotBase(); if (bot != null && (bot.PulseFlags & PulseFlags.Targeting) != PulseFlags.Targeting) { HealerManager.Instance.Pulse(); } } else if (TankManager.NeedTankTargeting && Group.MeIsTank) { BotBase bot = GetCurrentBotBase(); if (bot != null && (bot.PulseFlags & PulseFlags.Targeting) != PulseFlags.Targeting) { TankManager.Instance.Pulse(); } } }