Skip to content

Commit

Permalink
Merge pull request #254 from Xian55/feature/nonblocking-navigation
Browse files Browse the repository at this point in the history
Feature: nonblocking navigation - small fixes
  • Loading branch information
Xian55 authored Feb 11, 2022
2 parents 769d7e9 + 33e7c10 commit bd37f18
Show file tree
Hide file tree
Showing 16 changed files with 215 additions and 134 deletions.
11 changes: 1 addition & 10 deletions BlazorServer/PathingApi/LocalPathingApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public class LocalPathingApi : IPPather

private bool Enabled = true;

private int targetMapId;

public LocalPathingApi(ILogger logger, PPatherService service)
{
this.logger = logger;
Expand Down Expand Up @@ -51,12 +49,10 @@ public ValueTask<List<Vector3>> FindRoute(int map, Vector3 fromPoint, Vector3 to
return new ValueTask<List<Vector3>>();
}

targetMapId = map;

var sw = new Stopwatch();
sw.Start();

service.SetLocations(service.GetWorldLocation(map, fromPoint.X, fromPoint.Y, fromPoint.Z), service.GetWorldLocation(targetMapId, toPoint.X, toPoint.Y));
service.SetLocations(service.GetWorldLocation(map, fromPoint.X, fromPoint.Y, fromPoint.Z), service.GetWorldLocation(map, toPoint.X, toPoint.Y));
var path = service.DoSearch(PatherPath.Graph.PathGraph.eSearchScoreSpot.A_Star_With_Model_Avoidance);

if (path == null)
Expand All @@ -75,11 +71,6 @@ public ValueTask<List<Vector3>> FindRoute(int map, Vector3 fromPoint, Vector3 to
return new ValueTask<List<Vector3>>(result);
}

public ValueTask<List<Vector3>> FindRouteTo(AddonReader addonReader, Vector3 destination)
{
return FindRoute(addonReader.UIMapId.Value, addonReader.PlayerReader.PlayerLocation, destination);
}

public bool SelfTest()
{
var mpqFiles = MPQTriangleSupplier.GetArchiveNames(DataConfig.Load(), s => logger.LogInformation(s));
Expand Down
6 changes: 6 additions & 0 deletions Core/Goals/AdhocGoal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ public override ValueTask OnEnter()

public override ValueTask PerformAction()
{
if (key.Charge >= 1)
{
castingHandler.CastIfReady(key, key.DelayBeforeCast);
}

wait.Update(1);
return ValueTask.CompletedTask;
}
}
Expand Down
31 changes: 14 additions & 17 deletions Core/Goals/AdhocNPCGoal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ private enum PathState
{
ApproachPathStart,
FollowPath,
MoveBackToPathStart,
Finished,
}

Expand Down Expand Up @@ -122,7 +121,7 @@ public override ValueTask OnEnter()
input.TapClearTarget();
stopMoving.Stop();

var path = key.Path;
var path = key.Path.ToList();
navigation.SetWayPoints(path);

pathState = PathState.ApproachPathStart;
Expand All @@ -145,35 +144,36 @@ public override ValueTask OnExit()
return base.OnExit();
}

public override async ValueTask PerformAction()
public override ValueTask PerformAction()
{
if (this.playerReader.Bits.PlayerInCombat && this.classConfig.Mode != Mode.AttendedGather) { return; }
if (this.playerReader.Bits.PlayerInCombat && this.classConfig.Mode != Mode.AttendedGather) { return ValueTask.CompletedTask; }

if (playerReader.Bits.IsDrowning)
{
input.TapJump("Drowning! Swim up");
}

if (pathState != PathState.Finished)
await navigation.Update();
navigation.Update();

MountIfRequired();

wait.Update(1);

return ValueTask.CompletedTask;
}


private void Navigation_OnWayPointReached(object? sender, EventArgs e)
{
if (pathState is PathState.ApproachPathStart)
{
LogDebug("Reached the start point of the path.");

LogDebug("1 Reached the start point of the path.");
navigation.SimplifyRouteToWaypoint = false;
}
}

private async void Navigation_OnDestinationReached(object? sender, EventArgs e)
private void Navigation_OnDestinationReached(object? sender, EventArgs e)
{
if (pathState == PathState.ApproachPathStart)
{
Expand Down Expand Up @@ -219,6 +219,7 @@ private async void Navigation_OnDestinationReached(object? sender, EventArgs e)
wait.Update(1);

var path = key.Path.ToList();
path.Reverse();
navigation.SetWayPoints(path);

pathState++;
Expand All @@ -231,22 +232,18 @@ private async void Navigation_OnDestinationReached(object? sender, EventArgs e)
// instead keep it trapped to follow the route back
while (navigation.HasWaypoint())
{
await navigation.Update();
navigation.Update();
wait.Update(1);
}

pathState++;
pathState = PathState.Finished;

LogDebug("Reached the start point of the path.");
LogDebug("2 Reached the start point of the path.");
stopMoving.Stop();

navigation.SimplifyRouteToWaypoint = true;
}
}
else if (pathState == PathState.MoveBackToPathStart)
{
navigation.SimplifyRouteToWaypoint = true;
pathState++;
stopMoving.Stop();
}
}


Expand Down
23 changes: 20 additions & 3 deletions Core/Goals/FollowRouteGoal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public FollowRouteGoal(ILogger logger, ConfigurableInput input, Wait wait, Addon
this.targetFinder = targetFinder;

this.navigation = navigation;
navigation.OnPathCalculated += Navigation_OnPathCalculated;
navigation.OnDestinationReached += Navigation_OnDestinationReached;
navigation.OnWayPointReached += Navigation_OnWayPointReached;

Expand All @@ -100,6 +101,15 @@ public override void OnActionEvent(object sender, ActionEventArgs e)
{
StartLookingForTarget();
navigation.ResetStuckParameters();

if (!navigation.HasWaypoint())
{
RefillWaypoints(true);
}
else
{
navigation.Resume();
}
}
}
}
Expand Down Expand Up @@ -141,7 +151,7 @@ public override ValueTask OnExit()
return base.OnExit();
}

public override async ValueTask PerformAction()
public override ValueTask PerformAction()
{
if (playerReader.HasTarget && playerReader.Bits.TargetIsDead)
{
Expand All @@ -159,13 +169,15 @@ public override async ValueTask PerformAction()
AlternateGatherTypes();
}

if (playerReader.Bits.PlayerInCombat && classConfig.Mode != Mode.AttendedGather) { return; }
if (playerReader.Bits.PlayerInCombat && classConfig.Mode != Mode.AttendedGather) { return ValueTask.CompletedTask; }

await navigation.Update();
navigation.Update();

RandomJump();

wait.Update(1);

return ValueTask.CompletedTask;
}

private void StartLookingForTarget()
Expand Down Expand Up @@ -245,6 +257,11 @@ private void MountIfRequired()

#region Refill rules

private void Navigation_OnPathCalculated(object? sender, EventArgs e)
{
MountIfRequired();
}

private void Navigation_OnDestinationReached(object? sender, EventArgs e)
{
LogDebug("Navigation_OnDestinationReached");
Expand Down
1 change: 1 addition & 0 deletions Core/Goals/GoalFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public HashSet<GoapGoal> CreateGoals(ClassConfiguration classConfig, IBlacklist
{
var nav = new Navigation(logger, playerDirection, input, addonReader, stopMoving, stuckDetector, pather, mountHandler);
availableActions.Add(new AdhocNPCGoal(logger, input, item, wait, addonReader, nav, stopMoving, npcNameTargeting, classConfig, blacklist, mountHandler, exec));
item.Path.Clear();
item.Path.AddRange(ReadPath(item.Name, item.PathFilename));
}

Expand Down
1 change: 0 additions & 1 deletion Core/Goals/GoalThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace Core.Goals
{
Expand Down
Loading

0 comments on commit bd37f18

Please sign in to comment.