Skip to content

Commit

Permalink
Core: AddonBits: IsMoving.
Browse files Browse the repository at this point in the history
Core: StopMoving: Simplify StopForward

Core: LootGoal: SkinningGoal: Improve detecting movement stopped event
  • Loading branch information
Xian55 committed Oct 21, 2023
1 parent e198e27 commit cf88e21
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 44 deletions.
3 changes: 2 additions & 1 deletion Core/AddonComponent/AddonBits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions Core/Goals/LootGoal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions Core/Goals/SkinningGoal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
53 changes: 18 additions & 35 deletions Core/GoalsComponent/StopMoving.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Threading;
using System.Numerics;
using SharedLib.Extensions;
using Game;
using Core.GOAP;
using SharedLib;
Expand All @@ -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<GoapAgent> cts)
CancellationTokenSource<GoapAgent> cts,
AddonBits bits)
{
this.input = input;
this.playerReader = playerReader;
ct = cts.Token;
this.bits = bits;
}

public void Stop()
Expand All @@ -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()
Expand All @@ -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;
Expand Down

0 comments on commit cf88e21

Please sign in to comment.