Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addon: [1.7.50] - Feature: Improved movement detection #546

Merged
merged 2 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Addons/DataToColor/DataToColor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ DataToColor.CastNum = 0
DataToColor.targetChanged = true

DataToColor.autoFollow = false
DataToColor.moving = false

DataToColor.playerGUID = UnitGUID(DataToColor.C.unitPlayer)
DataToColor.petGUID = UnitGUID(DataToColor.C.unitPet)
Expand Down
2 changes: 1 addition & 1 deletion Addons/DataToColor/DataToColor.toc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Title: DataToColor
## Author: FreeHongKongMMO
## Notes: Displays data as colors
## Version: 1.7.49
## Version: 1.7.50
## RequiredDeps:
## OptionalDeps: Ace3, LibRangeCheck, LibClassicCasterino
## SavedVariables:
Expand Down
11 changes: 11 additions & 0 deletions Addons/DataToColor/EventHandlers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ function DataToColor:RegisterEvents()
DataToColor:RegisterEvent('AUTOFOLLOW_BEGIN', 'AutoFollowBegin')
DataToColor:RegisterEvent('AUTOFOLLOW_END', 'AutoFollowEnd')

DataToColor:RegisterEvent('PLAYER_STARTED_MOVING', 'PlayerStartedMoving')
DataToColor:RegisterEvent('PLAYER_STOPPED_MOVING', 'PlayerStoppedMoving')

DataToColor:RegisterEvent('CHAT_MSG_WHISPER', 'OnMessageWhisper')
DataToColor:RegisterEvent('CHAT_MSG_SAY', 'OnMessageSay')
DataToColor:RegisterEvent('CHAT_MSG_YELL', 'OnMessageYell')
Expand Down Expand Up @@ -607,6 +610,14 @@ function DataToColor:AutoFollowEnd()
DataToColor.autoFollow = false
end

function DataToColor:PlayerStartedMoving()
DataToColor.moving = true
end

function DataToColor:PlayerStoppedMoving()
DataToColor.moving = false
end

function DataToColor:OnMessageWhisper(event, msg, author)
AddMessageToQueue(0, msg, author)
end
Expand Down
3 changes: 2 additions & 1 deletion Addons/DataToColor/Query.lua
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ function DataToColor:Bits2()
(UnitPlayerControlled(DataToColor.C.unitTarget) and 2 or 0) ^ 18 +
((DataToColor.autoFollow) and 2 or 0) ^ 19 +
((GameMenuFrame:IsShown() and 2 or 0)) ^ 20 +
((IsFlying() and 2 or 0)) ^ 21
((IsFlying() and 2 or 0)) ^ 21 +
((DataToColor.moving and 2 or 0)) ^ 22
end

function DataToColor:CustomTrigger(t)
Expand Down
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