Skip to content

Commit

Permalink
Implement Explorer behavior.
Browse files Browse the repository at this point in the history
Fix issue in MoveTo() that teleported the bot if the path had a little detour moving far away from destination.
  • Loading branch information
jackpoz committed Dec 28, 2015
1 parent ff072c7 commit 75c7771
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
54 changes: 49 additions & 5 deletions BotFarm/BotGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
using Client.World.Entities;
using DetourCLI;
using MapCLI;
using DBCStoresCLI;

namespace BotFarm
{
class BotGame : AutomatedGame
{
const float MovementEpsilon = 1.0f;
const float MovementEpsilon = 0.5f;
const float FollowMovementEpsilon = 5f;
const float FollowTargetRecalculatePathEpsilon = 5f;

Expand Down Expand Up @@ -185,7 +186,50 @@ public override void Start()
#region Explorer
if (Behavior.Explorer)
{
AchievementExploreLocation targetLocation = null;
List<AchievementExploreLocation> missingLocations = null;
Position currentPosition = new Position();

ScheduleAction(() =>
{
if (!Player.IsAlive)
return;
if (targetLocation != null)
{
if (!HasExploreCriteria(targetLocation.CriteriaID) && (currentPosition - Player).Length > MovementEpsilon)
{
currentPosition = Player.GetPosition();
return;
}
targetLocation = null;
}
CancelActionsByFlag(ActionFlag.Movement);
currentPosition = Player.GetPosition();
if (missingLocations == null)
missingLocations = DBCStores.GetAchievementExploreLocations(Player.X, Player.Y, Player.Z, Player.MapID);
missingLocations = missingLocations.Where(loc => !HasExploreCriteria(loc.CriteriaID)).ToList();
if (missingLocations.Count == 0)
return;
float closestDistance = float.MaxValue;
var playerPosition = new Point(Player.X, Player.Y, Player.Z);
foreach (var missingLoc in missingLocations)
{
float distance = (missingLoc.Location - playerPosition).Length;
if (distance < closestDistance)
{
closestDistance = distance;
targetLocation = missingLoc;
}
}
MoveTo(new Position(targetLocation.Location.X, targetLocation.Location.Y, targetLocation.Location.Z, 0f, Player.MapID));
}, DateTime.Now.AddSeconds(30), new TimeSpan(0, 0, 5));
}
#endregion
}
Expand Down Expand Up @@ -399,7 +443,7 @@ public void MoveTo(Position destination)
previousMovingTime = DateTime.Now;
remaining = destination - Player.GetPosition();
if (remaining.Length > MovementEpsilon && oldRemaining.Length >= remaining.Length)
if (remaining.Length > MovementEpsilon)
{
oldRemaining = remaining;
Expand All @@ -419,9 +463,9 @@ public void MoveTo(Position destination)
var stopMoving = new MovementPacket(WorldCommand.MSG_MOVE_STOP)
{
GUID = Player.GUID,
X = destination.X,
Y = destination.Y,
Z = destination.Z,
X = Player.X,
Y = Player.Y,
Z = Player.Z,
O = path.CurrentOrientation
};
SendPacket(stopMoving);
Expand Down
2 changes: 1 addition & 1 deletion Client/AutomatedGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ protected Dictionary<uint, ulong> AchievementCriterias
get;
private set;
}
bool HasExploreCriteria(uint criteriaId)
protected bool HasExploreCriteria(uint criteriaId)
{
ulong counter;
if (AchievementCriterias.TryGetValue(criteriaId, out counter))
Expand Down

0 comments on commit 75c7771

Please sign in to comment.