/
BotExtension.cs
58 lines (49 loc) · 2.15 KB
/
BotExtension.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using Bib3;
using BotEngine.Common;
using Sanderling.ABot.Bot.Task;
using Sanderling.Interface.MemoryStruct;
using Sanderling.Parse;
using System.Collections.Generic;
using System.Linq;
namespace Sanderling.ABot.Bot
{
static public class BotExtension
{
static readonly EWarTypeEnum[][] listEWarPriorityGroup = new[]
{
new[] { EWarTypeEnum.ECM },
new[] { EWarTypeEnum.Web},
new[] { EWarTypeEnum.WarpDisrupt, EWarTypeEnum.WarpScramble },
};
static public int AttackPriorityIndexForOverviewEntryEWar(IEnumerable<EWarTypeEnum> setEWar)
{
var setEWarRendered = setEWar?.ToArray();
return
listEWarPriorityGroup.FirstIndexOrNull(priorityGroup => priorityGroup.ContainsAny(setEWarRendered)) ??
(listEWarPriorityGroup.Length + (0 < setEWarRendered?.Length ? 0 : 1));
}
static public int AttackPriorityIndex(
this Bot bot,
Sanderling.Parse.IOverviewEntry entry) =>
AttackPriorityIndexForOverviewEntryEWar(bot?.OverviewMemory?.SetEWarTypeFromOverviewEntry(entry));
static public bool ShouldBeIncludedInStepOutput(this IBotTask task) =>
null != task?.Motion || task is DiagnosticTask;
static public bool LastHasMotion(this IEnumerable<IBotTask> listTask) =>
null != listTask?.LastOrDefault()?.Motion;
static public IEnumerable<IBotTask[]> TakeSubsequenceWhileUnwantedInferenceRuledOut(this IEnumerable<IBotTask[]> listTaskPath) =>
listTaskPath
?.EnumerateSubsequencesStartingWithFirstElement()
?.OrderBy(subsequenceTaskPath => 1 == subsequenceTaskPath?.Count(BotExtension.LastHasMotion))
?.LastOrDefault();
static public IUIElementText TitleElementText(this IModuleButtonTooltip tooltip) =>
tooltip?.LabelText?.OrderByCenterVerticalDown()?.FirstOrDefault();
static public bool ShouldBeActivePermanent(this Accumulation.IShipUiModule module, Bot bot) =>
new[]
{
module?.TooltipLast?.Value?.IsHardener,
bot?.ConfigSerialAndStruct.Value?.ModuleActivePermanentSetTitlePattern
?.Any(activePermanentTitlePattern => module?.TooltipLast?.Value?.TitleElementText()?.Text?.RegexMatchSuccessIgnoreCase(activePermanentTitlePattern) ?? false),
}
.Any(sufficientCondition => sufficientCondition ?? false);
}
}