Skip to content

Commit

Permalink
Merge branch 'explorer_ai'
Browse files Browse the repository at this point in the history
  • Loading branch information
jackpoz committed Dec 28, 2015
2 parents c94f2cc + 75c7771 commit 37120f3
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 44 deletions.
2 changes: 1 addition & 1 deletion BotFarm UnitTests/Maps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void MMapsRaceConditions()
{
using (var detour = new DetourCLI.Detour())
{
List<DetourCLI.Point> resultPath;
List<MapCLI.Point> resultPath;
bool successful = detour.FindPath(-8896.072266f, -82.352325f, 86.421661f,
-8915.272461f, -111.634041f, 82.275642f,
0, out resultPath);
Expand Down
2 changes: 1 addition & 1 deletion BotFarm.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
VisualStudioVersion = 14.0.24720.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client", "Client\Client.csproj", "{7A45F050-E215-4388-B0BE-F11001537A25}"
EndProject
Expand Down
15 changes: 15 additions & 0 deletions BotFarm/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
<setting name="MAPsFolderPath" serializeAs="String">
<value>C:\</value>
</setting>
<setting name="DBCsFolderPath" serializeAs="String">
<value>C:\</value>
</setting>
<setting name="Behaviors" serializeAs="Xml">
<value>
<ArrayOfBotBehaviorSettings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
Expand All @@ -54,6 +57,7 @@
<AutoResurrect>true</AutoResurrect>
<Begger>false</Begger>
<FollowGroupLeader>true</FollowGroupLeader>
<Explorer>false</Explorer>
</BotBehaviorSettings>
<BotBehaviorSettings>
<Name>Begger</Name>
Expand All @@ -63,6 +67,17 @@
<AutoResurrect>true</AutoResurrect>
<Begger>true</Begger>
<FollowGroupLeader>false</FollowGroupLeader>
<Explorer>false</Explorer>
</BotBehaviorSettings>
<BotBehaviorSettings>
<Name>Explorer</Name>
<Probability>0</Probability>
<AutoAcceptGroupInvites>false</AutoAcceptGroupInvites>
<AutoAcceptResurrectRequests>false</AutoAcceptResurrectRequests>
<AutoResurrect>true</AutoResurrect>
<Begger>false</Begger>
<FollowGroupLeader>false</FollowGroupLeader>
<Explorer>true</Explorer>
</BotBehaviorSettings>
</ArrayOfBotBehaviorSettings>
</value>
Expand Down
1 change: 1 addition & 0 deletions BotFarm/BotBehaviorSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ public struct BotBehaviorSettings
public bool AutoResurrect;
public bool Begger;
public bool FollowGroupLeader;
public bool Explorer;
}
}
5 changes: 5 additions & 0 deletions BotFarm/BotFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ public BotFactory()
DetourCLI.Detour.Initialize(Settings.Default.MMAPsFolderPath);
VMapCLI.VMap.Initialize(Settings.Default.VMAPsFolderPath);
MapCLI.Map.Initialize(Settings.Default.MAPsFolderPath);
DBCStoresCLI.DBCStores.Initialize(Settings.Default.DBCsFolderPath);
DBCStoresCLI.DBCStores.LoadDBCs();

factoryGame = new AutomatedGame(Settings.Default.Hostname,
Settings.Default.Port,
Expand Down Expand Up @@ -216,6 +218,8 @@ public void SetupFactory(int botCount)
for (; ; )
{
string line = Console.ReadLine();
if (line == null)
return;
string[] lineSplit = line.Split(' ');
switch(lineSplit[0])
{
Expand Down Expand Up @@ -260,6 +264,7 @@ void DisplayStatistics(string botname)
void DisplayStatistics(BotGame bot)
{
Console.WriteLine("Bot username: " + bot.Username);
Console.WriteLine("\tBehavior: " + bot.Behavior.Name);
Console.WriteLine("\tRunning: " + bot.Running);
Console.WriteLine("\tConnected: " + bot.Connected);
Console.WriteLine("\tLogged In: " + bot.LoggedIn);
Expand Down
66 changes: 59 additions & 7 deletions BotFarm/BotGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
using Client.World.Definitions;
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 @@ -180,6 +182,56 @@ public override void Start()
}, DateTime.Now.AddSeconds(30), new TimeSpan(0, 0, 30));
}
#endregion

#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
}

public override void NoCharactersFound()
Expand Down Expand Up @@ -332,7 +384,7 @@ public void MoveTo(Position destination)
Path path = null;
using(var detour = new DetourCLI.Detour())
{
List<DetourCLI.Point> resultPath;
List<MapCLI.Point> resultPath;
bool successful = detour.FindPath(Player.X, Player.Y, Player.Z,
destination.X, destination.Y, destination.Z,
Player.MapID, out resultPath);
Expand Down Expand Up @@ -391,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 @@ -411,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 Expand Up @@ -479,7 +531,7 @@ public void Follow(WorldObject target)
{
using (var detour = new DetourCLI.Detour())
{
List<DetourCLI.Point> resultPath;
List<MapCLI.Point> resultPath;
bool successful = detour.FindPath(Player.X, Player.Y, Player.Z,
target.X, target.Y, target.Z,
Player.MapID, out resultPath);
Expand Down
1 change: 1 addition & 0 deletions BotFarm/Path.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text;
using System.Threading.Tasks;
using DetourCLI;
using MapCLI;

namespace BotFarm
{
Expand Down
60 changes: 38 additions & 22 deletions BotFarm/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 24 additions & 11 deletions BotFarm/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@
<Value Profile="(Default)">C:\</Value>
</Setting>
<Setting Name="Behaviors" Type="BotFarm.BotBehaviorSettings[]" Scope="User">
<Value Profile="(Default)">
&lt;ArrayOfBotBehaviorSettings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
<Value Profile="(Default)"> &lt;ArrayOfBotBehaviorSettings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
&lt;BotBehaviorSettings&gt;
&lt;Name&gt;Default&lt;/Name&gt;
&lt;Probability&gt;100&lt;/Probability&gt;
&lt;AutoAcceptGroupInvites&gt;true&lt;/AutoAcceptGroupInvites&gt;
&lt;AutoAcceptResurrectRequests&gt;true&lt;/AutoAcceptResurrectRequests&gt;
&lt;AutoResurrect&gt;true&lt;/AutoResurrect&gt;
&lt;Begger&gt;false&lt;/Begger&gt;
&lt;FollowGroupLeader&gt;true&lt;/FollowGroupLeader&gt;
&lt;Name&gt;Default&lt;/Name&gt;
&lt;Probability&gt;100&lt;/Probability&gt;
&lt;AutoAcceptGroupInvites&gt;true&lt;/AutoAcceptGroupInvites&gt;
&lt;AutoAcceptResurrectRequests&gt;true&lt;/AutoAcceptResurrectRequests&gt;
&lt;AutoResurrect&gt;true&lt;/AutoResurrect&gt;
&lt;Begger&gt;false&lt;/Begger&gt;
&lt;FollowGroupLeader&gt;true&lt;/FollowGroupLeader&gt;
&lt;Explorer&gt;false&lt;/Explorer&gt;
&lt;/BotBehaviorSettings&gt;
&lt;BotBehaviorSettings&gt;
&lt;Name&gt;Begger&lt;/Name&gt;
Expand All @@ -55,9 +55,22 @@
&lt;AutoResurrect&gt;true&lt;/AutoResurrect&gt;
&lt;Begger&gt;true&lt;/Begger&gt;
&lt;FollowGroupLeader&gt;false&lt;/FollowGroupLeader&gt;
&lt;Explorer&gt;false&lt;/Explorer&gt;
&lt;/BotBehaviorSettings&gt;
&lt;BotBehaviorSettings&gt;
&lt;Name&gt;Explorer&lt;/Name&gt;
&lt;Probability&gt;0&lt;/Probability&gt;
&lt;AutoAcceptGroupInvites&gt;false&lt;/AutoAcceptGroupInvites&gt;
&lt;AutoAcceptResurrectRequests&gt;false&lt;/AutoAcceptResurrectRequests&gt;
&lt;AutoResurrect&gt;true&lt;/AutoResurrect&gt;
&lt;Begger&gt;false&lt;/Begger&gt;
&lt;FollowGroupLeader&gt;false&lt;/FollowGroupLeader&gt;
&lt;Explorer&gt;true&lt;/Explorer&gt;
&lt;/BotBehaviorSettings&gt;
&lt;/ArrayOfBotBehaviorSettings&gt;
</Value>
&lt;/ArrayOfBotBehaviorSettings&gt;</Value>
</Setting>
<Setting Name="DBCsFolderPath" Type="System.String" Scope="User">
<Value Profile="(Default)">C:\</Value>
</Setting>
</Settings>
</SettingsFile>
Loading

0 comments on commit 37120f3

Please sign in to comment.