Skip to content

Commit

Permalink
save the ship: retreat if local is not clean.
Browse files Browse the repository at this point in the history
  • Loading branch information
Viir committed Jul 19, 2016
1 parent 4fbd6c7 commit 0e681c8
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 0 deletions.
Binary file modified lib/Sanderling.dll
Binary file not shown.
7 changes: 7 additions & 0 deletions src/Sanderling.ABot/Bot/Bot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,19 @@ IEnumerable<IBotTask> SequenceRootTask()
{
yield return new EnableInfoPanelCurrentSystem { MemoryMeasurement = MemoryMeasurementAtTime?.Value };

var saveShipTask = new SaveShipTask { Bot = this };

yield return saveShipTask;

yield return this.EnsureIsActive(MemoryMeasurementAccu?.ShipUiModule?.Where(module => module?.TooltipLast?.Value?.IsHardener ?? false));

var moduleUnknown = MemoryMeasurementAccu?.ShipUiModule?.FirstOrDefault(module => null == module?.TooltipLast?.Value);

yield return new BotTask { Motion = moduleUnknown?.MouseMove() };

if (!saveShipTask.AllowRoam)
yield break;

var combatTask = new CombatTask { bot = this };

yield return combatTask;
Expand Down
56 changes: 56 additions & 0 deletions src/Sanderling.ABot/Bot/Task/SaveShip.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System.Collections.Generic;
using System.Linq;
using Sanderling.Motor;
using BotEngine.Common;
using Sanderling.ABot.Parse;
using Sanderling.Interface.MemoryStruct;

namespace Sanderling.ABot.Bot.Task
{
public class SaveShipTask : IBotTask
{
public Bot Bot;

public bool AllowRoam;

static public bool ChatIsClean(WindowChatChannel chatWindow)
{
if (null == chatWindow)
return false;

if (chatWindow?.ParticipantView?.Scroll?.IsScrollable() ?? true)
return false;

var listParticipantNeutralOrEnemy =
chatWindow?.ParticipantView?.Entry?.Where(participant => participant.IsNeutralOrEnemy())?.ToArray();

// we expect own char to show up there as well so there has to be one participant with neutral or enemy flag.
return 1 == listParticipantNeutralOrEnemy?.Length;
}

public IEnumerable<IBotTask> Component
{
get
{
var memoryMeasurement = Bot?.MemoryMeasurementAtTime?.Value;

var charIsLocatedInHighsec = 500 < memoryMeasurement?.InfoPanelCurrentSystem?.SecurityLevelMilli;

var localChatWindow = memoryMeasurement?.WindowChatChannel?.FirstOrDefault(window => window?.Caption?.RegexMatchSuccessIgnoreCase(@"local\s*\[") ?? false);

if (charIsLocatedInHighsec || ChatIsClean(localChatWindow))
{
AllowRoam = true;
yield break;
}

yield return new RetreatTask
{
Bot = Bot,
};
}
}

public MotionParam Motion => null;
}
}
14 changes: 14 additions & 0 deletions src/Sanderling.ABot/Parse/ParseExtension.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using Bib3;
using Bib3.Geometrik;
using BotEngine.Common;
using MemoryStruct = Sanderling.Interface.MemoryStruct;
using Sanderling.Parse;
using System;
using System.Linq;

namespace Sanderling.ABot.Parse
Expand All @@ -22,5 +25,16 @@ static public bool ManeuverStartPossible(this IMemoryMeasurement memoryMeasureme
!(memoryMeasurement?.IsDocked ?? false) &&
!new[] { ShipManeuverTypeEnum.Warp, ShipManeuverTypeEnum.Jump, ShipManeuverTypeEnum.Docked }.Contains(
memoryMeasurement?.ShipUi?.Indication?.ManeuverType ?? ShipManeuverTypeEnum.None);

static public Int64 Width(this RectInt rect) => rect.Side0Length();
static public Int64 Height(this RectInt rect) => rect.Side1Length();

static public bool IsScrollable(this MemoryStruct.IScroll scroll) =>
scroll?.ScrollHandle?.Region.Height() < scroll?.ScrollHandleBound?.Region.Height() - 4;

static public bool IsNeutralOrEnemy(this MemoryStruct.IChatParticipantEntry participantEntry) =>
!(participantEntry?.FlagIcon?.Any(flagIcon =>
new[] { "good standing", "excellent standing", "Pilot is in your (fleet|corporation)", }
.Any(goodStandingText => flagIcon?.HintText?.RegexMatchSuccessIgnoreCase(goodStandingText) ?? false)) ?? false);
}
}
1 change: 1 addition & 0 deletions src/Sanderling.ABot/Sanderling.ABot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<Compile Include="Bot\Task\Menu.cs" />
<Compile Include="Bot\Task\Module.cs" />
<Compile Include="Bot\Task\Retreat.cs" />
<Compile Include="Bot\Task\SaveShip.cs" />
<Compile Include="Parse\ParseExtension.cs" />
<Compile Include="Parse\ParseStatic.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down

0 comments on commit 0e681c8

Please sign in to comment.