public void Execute()
        {
            if (WowInterface.XMemory.Process == null || WowInterface.XMemory.Process.HasExited)
            {
                AmeisenLogger.Instance.Log("StateMachine", "WoW crashed...", LogLevel.Verbose);
                WowInterface.MovementEngine.Reset();
                WowInterface.ObjectManager.WowObjects.Clear();
                SetState(BotState.None);
            }

            if (WowInterface.ObjectManager != null && CurrentState.Key != BotState.LoadingScreen)
            {
                if (!WowInterface.ObjectManager.IsWorldLoaded)
                {
                    AmeisenLogger.Instance.Log("StateMachine", "World is not loaded...", LogLevel.Verbose);
                    SetState(BotState.LoadingScreen, true);
                    WowInterface.MovementEngine.Reset();
                }
                else
                {
                    HandleObjectUpdates();
                    HandleEventPull();

                    if (WowInterface.ObjectManager.Player != null)
                    {
                        HandlePlayerDeadOrGhostState();

                        if (CurrentState.Key != BotState.Dead && CurrentState.Key != BotState.Ghost)
                        {
                            if (Config.AutoDodgeAoeSpells &&
                                BotUtils.IsPositionInsideAoeSpell(WowInterface.ObjectManager.Player.Position, WowInterface.ObjectManager.WowObjects.OfType <WowDynobject>().ToList()))
                            {
                                SetState(BotState.InsideAoeDamage, true);
                            }

                            if (WowInterface.ObjectManager.Player.IsInCombat || IsAnyPartymemberInCombat())
                            {
                                SetState(BotState.Attacking, true);
                            }
                        }
                    }
                }
            }

            // execute the State
            CurrentState.Value.Execute();

            // anti AFK
            WowInterface.CharacterManager.AntiAfk();

            // used for ui updates
            OnStateMachineTick?.Invoke();
        }
Esempio n. 2
0
        public void Execute()
        {
            if (XMemory.Process == null || XMemory.Process.HasExited)
            {
                AmeisenLogger.Instance.Log("WoW crashed...", LogLevel.Verbose);
                SetState(AmeisenBotState.None);
            }

            if (ObjectManager != null)
            {
                if (!ObjectManager.IsWorldLoaded)
                {
                    SetState(AmeisenBotState.LoadingScreen);
                }

                HandleEventPull();

                if (ObjectManager.Player != null)
                {
                    HandlePlayerDeadOrGhostState();

                    if (CurrentState.Key != AmeisenBotState.Dead && CurrentState.Key != AmeisenBotState.Ghost)
                    {
                        if (Config.AutoDodgeAoeSpells &&
                            BotUtils.IsPositionInsideAoeSpell(ObjectManager.Player.Position, ObjectManager.WowObjects.OfType <WowDynobject>().ToList()))
                        {
                            SetState(AmeisenBotState.InsideAoeDamage);
                        }

                        if (ObjectManager.Player.IsInCombat || IsAnyPartymemberInCombat())
                        {
                            SetState(AmeisenBotState.Attacking);
                        }
                    }
                }
            }

            HandleObjectUpdates();
            CharacterManager.AntiAfk();

            // used for ui updates
            OnStateMachineTick?.Invoke();
            CurrentState.Value.Execute();
        }
Esempio n. 3
0
        public void Execute()
        {
            // Override states
            // --------------->
            if (CurrentState.Key != BotState.None &&
                CurrentState.Key != BotState.StartWow)
            {
                // Handle Wow crash
                // ---------------- >
                if ((WowInterface.XMemory.Process == null || WowInterface.XMemory.Process.HasExited) &&
                    SetState(BotState.None))
                {
                    AmeisenLogger.I.Log("StateMachine", "WoW crashed", LogLevel.Verbose);

                    WowCrashed = true;
                    GetState <StateIdle>().FirstStart = true;

                    WowInterface.MovementEngine.Reset();
                    WowInterface.EventHookManager.Stop();

                    return;
                }

                AntiAfkEvent.Run();

                if (CurrentState.Key != BotState.Login &&
                    WowInterface.ObjectManager != null)
                {
                    if (!WowInterface.ObjectManager.RefreshIsWorldLoaded())
                    {
                        if (SetState(BotState.LoadingScreen, true))
                        {
                            OnStateOverride?.Invoke(CurrentState.Key);
                            AmeisenLogger.I.Log("StateMachine", "World is not loaded", LogLevel.Verbose);
                            return;
                        }
                    }
                    else
                    {
                        WowInterface.ObjectManager.UpdateWowObjects();
                        EventPullEvent.Run();

                        if (WowInterface.ObjectManager.Player != null)
                        {
                            if (!WowInterface.ObjectManager.Player.IsCasting)
                            {
                                WowInterface.MovementEngine.Execute();
                            }

                            if (WowInterface.ObjectManager.Player.IsDead)
                            {
                                // we are dead, state needs to release the spirit
                                if (SetState(BotState.Dead, true))
                                {
                                    OnStateOverride?.Invoke(CurrentState.Key);
                                    return;
                                }
                            }
                            else if (GhostCheckEvent.Run(out bool isGhost) &&
                                     isGhost &&
                                     SetState(BotState.Ghost, true))
                            {
                                OnStateOverride?.Invoke(CurrentState.Key);
                                return;
                            }

                            // we cant fight when we are dead or a ghost
                            if (CurrentState.Key != BotState.Dead &&
                                CurrentState.Key != BotState.Ghost &&
                                !WowInterface.Globals.IgnoreCombat &&
                                !(Config.IgnoreCombatWhileMounted && WowInterface.ObjectManager.Player.IsMounted) &&
                                (WowInterface.Globals.ForceCombat || WowInterface.ObjectManager.Player.IsInCombat || IsAnyPartymemberInCombat() ||
                                 WowInterface.ObjectManager.GetEnemiesInCombatWithUs <WowUnit>(WowInterface.ObjectManager.Player.Position, 100.0).Any()))
                            {
                                if (SetState(BotState.Attacking, true))
                                {
                                    OnStateOverride?.Invoke(CurrentState.Key);
                                    return;
                                }
                            }
                        }
                    }

                    // auto disable rendering when not in focus
                    if (Config.AutoDisableRender && RenderSwitchEvent.Run())
                    {
                        IntPtr foregroundWindow = XMemory.GetForegroundWindow();
                        WowInterface.HookManager.WowSetRenderState(foregroundWindow == WowInterface.XMemory.Process.MainWindowHandle);
                    }
                }
            }

            // execute the State and Movement
            CurrentState.Value.Execute();
            OnStateMachineTick?.Invoke();
        }
        public override void Execute()
        {
            // we cant do anything if wow has crashed
            if ((WowInterface.XMemory.Process == null || WowInterface.XMemory.Process.HasExited) &&
                SetState(BotState.None))
            {
                AmeisenLogger.Instance.Log("StateMachine", "WoW crashed...", LogLevel.Verbose);

                WowCrashed = true;
                ((StateIdle)States[BotState.Idle]).FirstStart = true;

                WowInterface.MovementEngine.Reset();
                WowInterface.ObjectManager.WowObjects.Clear();
                WowInterface.EventHookManager.Stop();

                return;
            }

            // ingame override states
            if (CurrentState.Key != BotState.None &&
                CurrentState.Key != BotState.StartWow &&
                CurrentState.Key != BotState.Login &&
                WowInterface.ObjectManager != null)
            {
                WowInterface.ObjectManager.RefreshIsWorldLoaded();

                if (!WowInterface.ObjectManager.IsWorldLoaded)
                {
                    if (SetState(BotState.LoadingScreen, true))
                    {
                        OnStateOverride?.Invoke(CurrentState.Key);
                        AmeisenLogger.Instance.Log("StateMachine", "World is not loaded...", LogLevel.Verbose);
                        return;
                    }
                }
                else
                {
                    ObjectUpdateEvent.Run();
                    EventPullEvent.Run();

                    if (WowInterface.ObjectManager.Player != null)
                    {
                        if (WowInterface.ObjectManager.Player.IsDead &&
                            SetState(BotState.Dead, true))
                        {
                            // we are dead, state needs to release the spirit
                            OnStateOverride?.Invoke(CurrentState.Key);
                            return;
                        }
                        else if (GhostCheckEvent.Run(out bool isGhost) &&
                                 isGhost &&
                                 SetState(BotState.Ghost, true))
                        {
                            // we cant be a ghost if we are still dead
                            OnStateOverride?.Invoke(CurrentState.Key);
                            return;
                        }

                        // we cant fight nor do we receive damage when we are dead or a ghost
                        // so ignore these overrides
                        if (CurrentState.Key != BotState.Dead &&
                            CurrentState.Key != BotState.Ghost)
                        {
                            // if (Config.AutoDodgeAoeSpells
                            //     && BotUtils.IsPositionInsideAoeSpell(WowInterface.ObjectManager.Player.Position, WowInterface.ObjectManager.GetNearAoeSpells())
                            //     && SetState(BotState.InsideAoeDamage, true))
                            // {
                            //     OnStateOverride(CurrentState.Key);
                            //     return;
                            // }

                            // TODO: handle combat bug, sometimes when combat ends, the player stays in combot for no reason
                            if ((WowInterface.ObjectManager.Player.IsInCombat || IsAnyPartymemberInCombat()) && SetState(BotState.Attacking, true))
                            {
                                OnStateOverride?.Invoke(CurrentState.Key);
                                return;
                            }
                        }
                    }
                }
            }

            // execute the State
            CurrentState.Value.Execute();
            OnStateMachineTick?.Invoke();
            AntiAfkEvent.Run();
        }