diff --git a/Core/AddonComponent/AddonBits.cs b/Core/AddonComponent/AddonBits.cs index c011b246..edaf94df 100644 --- a/Core/AddonComponent/AddonBits.cs +++ b/Core/AddonComponent/AddonBits.cs @@ -72,7 +72,8 @@ public void Update(IAddonDataProvider reader) public bool AutoFollow() => v2[Mask._19]; public bool GameMenuWindowShown() => v2[Mask._20]; public bool Flying() => v2[Mask._21]; - + public bool Moving() => v2[Mask._22]; + public bool NotMoving() => !Moving(); // Combined diff --git a/Core/Goals/LootGoal.cs b/Core/Goals/LootGoal.cs index 60d0ec0e..63497399 100644 --- a/Core/Goals/LootGoal.cs +++ b/Core/Goals/LootGoal.cs @@ -194,9 +194,9 @@ private bool FoundByCursor() if (!playerReader.MinRangeZero()) { - elapsedMs = - wait.AfterEquals(MAX_TIME_TO_REACH_MELEE, 2, playerReader._MapPosNoZ, - input.PressApproachOnCooldown); + elapsedMs = wait.Until(MAX_TIME_TO_REACH_MELEE, + bits.NotMoving, input.PressApproachOnCooldown); + LogReachedCorpse(logger, elapsedMs); return playerReader.MinRangeZero(); @@ -313,9 +313,9 @@ private bool LootKeyboard() if (!playerReader.MinRangeZero()) { - float elapsedMs = - wait.AfterEquals(MAX_TIME_TO_REACH_MELEE, 2, playerReader._MapPosNoZ, - input.PressApproachOnCooldown); + float elapsedMs = wait.Until(MAX_TIME_TO_REACH_MELEE, + bits.NotMoving, input.PressApproachOnCooldown); + LogReachedCorpse(logger, elapsedMs); return playerReader.MinRangeZero(); diff --git a/Core/Goals/SkinningGoal.cs b/Core/Goals/SkinningGoal.cs index e68243c9..192b3c09 100644 --- a/Core/Goals/SkinningGoal.cs +++ b/Core/Goals/SkinningGoal.cs @@ -166,8 +166,8 @@ public override void OnEnter() if (!playerReader.MinRangeZero()) { - e = wait.AfterEquals(MAX_TIME_TO_REACH_MELEE, 2, playerReader._MapPosNoZ, - input.PressApproachOnCooldown); + e = wait.Until(MAX_TIME_TO_REACH_MELEE, + bits.NotMoving, input.PressApproachOnCooldown); LogReachedCorpse(logger, e); interact = !playerReader.MinRangeZero(); diff --git a/Core/GoalsComponent/StopMoving.cs b/Core/GoalsComponent/StopMoving.cs index 8bf04d05..e4c5949d 100644 --- a/Core/GoalsComponent/StopMoving.cs +++ b/Core/GoalsComponent/StopMoving.cs @@ -1,7 +1,5 @@ using System; using System.Threading; -using System.Numerics; -using SharedLib.Extensions; using Game; using Core.GOAP; using SharedLib; @@ -12,20 +10,20 @@ public sealed class StopMoving { private readonly WowProcessInput input; private readonly PlayerReader playerReader; + private readonly AddonBits bits; private readonly CancellationToken ct; - private const float MinDist = 0.001f; - - private Vector3 mapPos; private float direction; public StopMoving(WowProcessInput input, PlayerReader playerReader, - CancellationTokenSource cts) + CancellationTokenSource cts, + AddonBits bits) { this.input = input; this.playerReader = playerReader; ct = cts.Token; + this.bits = bits; } public void Stop() @@ -36,35 +34,21 @@ public void Stop() public void StopForward() { - if (mapPos != playerReader.MapPos) - { - bool pressedAny = false; - - if (!input.IsKeyDown(input.BackwardKey) && - !input.IsKeyDown(input.ForwardKey) && - mapPos.MapDistanceXYTo(playerReader.MapPos) >= MinDist) - { - input.PressFixed(input.ForwardKey, Random.Shared.Next(2, 5), ct); - pressedAny = true; - } - - if (input.IsKeyDown(input.ForwardKey)) - { - input.SetKeyState(input.ForwardKey, false, true); - pressedAny = true; - } + if (!bits.Moving()) + return; - if (input.IsKeyDown(input.BackwardKey)) - { - input.SetKeyState(input.BackwardKey, false, true); - pressedAny = true; - } - - if (pressedAny) - ct.WaitHandle.WaitOne(Random.Shared.Next(25, 30)); + if (input.IsKeyDown(input.ForwardKey)) + { + input.SetKeyState(input.ForwardKey, false, true); + } + else if (input.IsKeyDown(input.BackwardKey)) + { + input.SetKeyState(input.BackwardKey, false, true); + } + else // moving by interact key + { + input.PressFixed(input.ForwardKey, Random.Shared.Next(2, 5), ct); } - - mapPos = playerReader.MapPos; } public void StopTurn() @@ -78,8 +62,7 @@ public void StopTurn() input.SetKeyState(input.TurnLeftKey, false, true); pressedAny = true; } - - if (input.IsKeyDown(input.TurnRightKey)) + else if (input.IsKeyDown(input.TurnRightKey)) { input.SetKeyState(input.TurnRightKey, false, true); pressedAny = true;