Advertisement
Guest User

mining script

a guest
Jun 23rd, 2018
1,022
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 36.35 KB | None | 0 0
  1. //  This script mines ore from asteroids.
  2. //  before running this script, make sure to prepare as follows:
  3. //  +enter bookmark for mining site and bookmark for station in the configuration section below.
  4. //  +in the Overview create a preset which includes asteroids and rats and enter the name of that preset in the configuration section below at 'OverviewPreset'. The bot will make sure this preset is loaded when it needs to use the overview.
  5. //  +set Overview to sort by distance with the nearest entry at the top.
  6. //  +in the Inventory select the 'List' view.
  7. //  +set the UI language to english.
  8. //  +use a ship with an ore hold.
  9. //  +put some light drones into your ships' drone bay. The bot will make use of them to attack rats when HP are too low (configurable) or it gets jammed.
  10. //  +enable the info panel 'System info'. The bot will use the button in there to access bookmarks and a    steroid belts.
  11. //  +arrange windows to not occlude modules or info panels.
  12. //  +in the ship UI, disable "Display Passive Modules" and disable "Display Empty Slots" and enable "Display Module Tooltips". The bot uses the module tooltips to automatically identify the properties of the modules.
  13. //
  14. //  for optional features (such as warp to safe on hostile in local) see the configuration section below.
  15.  
  16. //    activate shield booster taken from Terpla (TPMiningScript-2018-06-21v2)
  17. //    cycle in the course of asteroid berries from beginners-ore-asteroid
  18.  
  19. //    other (ugly) improvements are :
  20. //        using Micro Warp Drive
  21. //        using Mining Crystal (optional)
  22. //        adding option to exclude Ore Type (without change overview)
  23. //        send drone in bay immediately after fight
  24.  
  25.  
  26. using BotSharp.ToScript.Extension;
  27. using MemoryStruct = Sanderling.Interface.MemoryStruct;
  28. using Parse = Sanderling.Parse;
  29.  
  30. //  begin of configuration section ->
  31.  
  32. //  The bot uses the bookmarks from the menu which is opened from the button in the 'System info' panel.
  33.  
  34. //  Should the bot use bookmarks for mining site?
  35. bool ShouldUseMiningBookmarks = false;
  36.  
  37. //  Bookmarks of places to mine. Add additional bookmarks separated by comma.
  38. string[] SetMiningSiteBookmark = new[] {
  39.     "Site1",
  40.     };
  41.  
  42. string[] BaseOre = new[] {
  43.     "Mercoxit", "Bistot", "Arkonor",
  44.     "Crokite", "Spodumain", "Ochre",
  45.     "Gneiss", "Hedbergite", "Hemorphite",
  46.     "Jaspet", "Kernite", "Omber",
  47.     "Plagioclase", "Pyroxeres",
  48.     "Scordite", "Veldspar",
  49.     };
  50.  
  51. //   List of excluded base ore
  52. string[] ExcludedBaseOre = new[] {
  53.     "Ice",
  54.     };
  55.    
  56. string[] ModifierOrePreference = new[] {
  57.     "Concentrated Veldspar", "Dense Veldspar", "Stable Veldspar",
  58.     "Condensed Scordite", "Massive Scordite", "Glossy Scordite",
  59.     "Solid Pyroxeres", "Viscous Pyroxeres", "Opulent Pyroxeres",
  60.     "Azure Plagioclase", "Rich Plagioclase", "Sparkling Plagioclase",
  61.     "Silvery Omber", "Golden Omber", "Platinoid Omber",
  62.     "Luminous Kernite", "Fiery Kernite", "Resplendant Kernite",
  63.     "Pure Jaspet", "Pristine Jaspet", "Immaculate Jaspet",
  64.     "Vivid Hemorphite", "Radiant Hemorphite", "Scintillating Hemorphite",
  65.     "Vitric Hedbergite", "Glazed Hedbergite", "Lustrous Hedbergite",
  66.     "Iridescent Gneiss", "Prismatic Gneiss", "Brilliant Gneiss",
  67.     "Onyx Ochre", "Obsidian Ochre", "Jet Ochre",
  68.     "Bright Spodumain", "Gleaming Spodumain", "Dazzling Spodumain",
  69.     "Sharp Crokite", "Crystalline Crokite", "Pellucid Crokite",
  70.     "Crimson Arkonor", "Prime Arkonor", "Flawless Arkonor",
  71.     "Triclinic Bistot", "Monoclinic Bistot", "Cubic Bistot",
  72.     "Magma Mercoxit", "Vitreous Mercoxit",
  73.     };
  74.    
  75. //  Bookmark of location where ore should be unloaded.
  76. string UnloadBookmark = "Depot";
  77.  
  78. //  Name of the container to unload to as shown in inventory.
  79. string UnloadDestContainerName = "Item Hangar";
  80.  
  81. //  when this is set to true, the bot will try to unload when undocked.
  82. bool UnloadInSpace = false;
  83.  
  84. //   when this is set to true, the bot will try to use mining crystal
  85. bool UseMiningCrystal = true;
  86.  
  87. //  Bookmark of place to retreat to to prevent ship loss.
  88. string RetreatBookmark = UnloadBookmark;
  89.  
  90. //  The bot loads this preset to the active tab.
  91. string OverviewPreset = "asteros_rats";
  92.  
  93. var ActivateHardener = true; // activate shield hardener.
  94.  
  95. //  bot will start fighting (and stop mining) when hitpoints are lower.
  96. var DefenseEnterHitpointThresholdPercent = 85;
  97. var DefenseExitHitpointThresholdPercent = 90;
  98.  
  99. var EmergencyWarpOutHitpointPercent = 60;
  100.  
  101. var FightAllRats = true;    //  when this is set to true, the bot will attack rats independent of shield hp.
  102.  
  103. var EnterOffloadOreHoldFillPercent = 95;    //  percentage of ore hold fill level at which to enter the offload process.
  104.  
  105. var RetreatOnNeutralOrHostileInLocal = false;   // warp to RetreatBookmark when a neutral or hostile is visible in local.
  106.  
  107. bool returnDronesToBayOnRetreat = false; // when set to true, bot will attempt to dock back the drones before retreating
  108.  
  109. //  <- end of configuration section
  110.  
  111. Queue<string> visitedLocations = new Queue<string>();
  112.  
  113. Func<object> BotStopActivity = () => null;
  114.  
  115. Func<object> NextActivity = MainStep;
  116.  
  117. for(;;)
  118. {
  119.     MemoryUpdate();
  120.  
  121.     Host.Log(
  122.         "ore hold fill: " + OreHoldFillPercent + "%" +
  123.         ", mining range: " + MiningRange +
  124.         ", mining modules (inactive): " + SetModuleMiner?.Length + "(" + SetModuleMinerInactive?.Length + ")" +
  125.         ", shield.hp: " + ShieldHpPercent + "%" +
  126.         ", retreat: " + RetreatReason +
  127.         ", JLA: " + JammedLastAge +
  128.         ", overview.rats: " + ListRatOverviewEntry?.Length +
  129.         ", overview.roids: " + ListAsteroidOverviewEntry?.Length +
  130.         ", offload count: " + OffloadCount +
  131.         ", nextAct: " + NextActivity?.Method?.Name);
  132.  
  133.     CloseModalUIElement();
  134.  
  135.     if(0 < RetreatReason?.Length && !(Measurement?.IsDocked ?? false))
  136.     {
  137.         if (returnDronesToBayOnRetreat) {
  138.             DroneEnsureInBay();
  139.         }
  140.  
  141.         if (!returnDronesToBayOnRetreat || (returnDronesToBayOnRetreat && 0 == DronesInSpaceCount)) {
  142.             InitiateDockToOrWarpToBookmark(RetreatBookmark);
  143.         }
  144.         continue;
  145.     }
  146.  
  147.     NextActivity = NextActivity?.Invoke() as Func<object>;
  148.  
  149.     if(BotStopActivity == NextActivity)
  150.         break;
  151.    
  152.     if(null == NextActivity)
  153.         NextActivity = MainStep;
  154.    
  155.     Host.Delay(1111);
  156. }
  157.  
  158. //  seconds since ship was jammed.
  159. long? JammedLastAge => Jammed ? 0 : (Host.GetTimeContinuousMilli() - JammedLastTime) / 1000;
  160.  
  161. int?     ShieldHpPercent => ShipUi?.HitpointsAndEnergy?.Shield / 10;
  162. int? CapacitorPercent => ShipUi?.HitpointsAndEnergy?.Capacitor / 10;
  163.  
  164. bool    DefenseExit =>
  165.     (Measurement?.IsDocked ?? false) ||
  166.     !(0 < ListRatOverviewEntry?.Length) ||
  167.     (DefenseExitHitpointThresholdPercent < ShieldHpPercent && !(JammedLastAge < 40) &&
  168.     !(FightAllRats && 0 < ListRatOverviewEntry?.Length));
  169.  
  170. bool    DefenseEnter =>
  171.     !DefenseExit    ||
  172.     !(DefenseEnterHitpointThresholdPercent < ShieldHpPercent) || JammedLastAge < 10;
  173.  
  174. bool    OreHoldFilledForOffload => Math.Max(0, Math.Min(100, EnterOffloadOreHoldFillPercent)) <= OreHoldFillPercent;
  175.  
  176. Int64?  JammedLastTime = null;
  177. string RetreatReasonTemporary = null;
  178. string RetreatReasonPermanent = null;
  179. string RetreatReason => RetreatReasonPermanent ?? RetreatReasonTemporary;
  180. int? LastCheckOreHoldFillPercent = null;
  181.  
  182. int OffloadCount = 0;
  183.  
  184. Func<object>    MainStep()
  185. {
  186.     if(Measurement?.IsDocked ?? false)
  187.     {
  188.         InInventoryUnloadItems();
  189.  
  190.         if (0 < RetreatReasonPermanent?.Length)
  191.             return BotStopActivity;
  192.  
  193.         if (0 < RetreatReason?.Length)
  194.             return MainStep;
  195.  
  196.         Undock();
  197.     }
  198.    
  199.     ToggleShieldBooster(ShieldHpPercent <90);
  200.    
  201.     if(DefenseEnter)
  202.     {
  203.         Host.Log("enter defense.");
  204.         return DefenseStep;
  205.     }
  206.  
  207.     EnsureOverviewTypeSelectionLoaded();
  208.  
  209.     EnsureWindowInventoryOpenOreHold();
  210.  
  211.     if(ReadyForManeuver)
  212.     {
  213.         DroneEnsureInBay();
  214.  
  215.         if(OreHoldFilledForOffload && 0 == DronesInSpaceCount)
  216.         {
  217.             if(ReadyForManeuver)
  218.                 InitiateDockToOrWarpToBookmark(UnloadBookmark);
  219.  
  220.             if (UnloadInSpace)
  221.             {
  222.                 Host.Delay(4444);
  223.                 InInventoryUnloadItems();
  224.             }
  225.  
  226.             return MainStep;
  227.         }
  228.        
  229.         if(!(0 < ListAsteroidOverviewEntry?.Length))
  230.             if(ShouldUseMiningBookmarks)
  231.                 InitiateWarpToRandomMiningBookmark();
  232.             else
  233.                 InitiateWarpToMiningSite();
  234.  
  235.             //InitiateWarpToRandomMiningSite();
  236.     }
  237.  
  238.     ModuleMeasureAllTooltip();
  239.  
  240.     if(ActivateHardener)
  241.         ActivateHardenerExecute();
  242.  
  243.     return InBeltMineStep;
  244. }
  245.  
  246. int RandomInt() => new Random((int)Host.GetTimeContinuousMilli()).Next();
  247.  
  248. T RandomElement<T>(IEnumerable<T> sequence)
  249. {
  250.     var array = (sequence as T[]) ?? sequence?.ToArray();
  251.  
  252.     if (!(0 < array?.Length))
  253.         return default(T);
  254.  
  255.     return array[RandomInt() % array.Length];
  256. }
  257.  
  258. void CloseModalUIElement()
  259. {
  260.     var ButtonClose =
  261.         ModalUIElement?.ButtonText?.FirstOrDefault(button => (button?.Text).RegexMatchSuccessIgnoreCase("close|no|ok"));
  262.        
  263.     Sanderling.MouseClickLeft(ButtonClose);
  264. }
  265.  
  266. void DroneLaunch()
  267. {
  268.     Host.Log("launch drones.");
  269.     Sanderling.MouseClickRight(DronesInBayListEntry);
  270.     Sanderling.MouseClickLeft(Menu?.FirstOrDefault()?.EntryFirstMatchingRegexPattern("launch", RegexOptions.IgnoreCase));
  271. }
  272.  
  273. void DroneEnsureInBay()
  274. {
  275.     if(0 == DronesInSpaceCount)
  276.         return;
  277.  
  278.     DroneReturnToBay();
  279.    
  280.     Host.Delay(4444);
  281. }
  282.  
  283. void DroneReturnToBay()
  284. {
  285.     Host.Log("return drones to bay.");
  286.     Sanderling.MouseClickRight(DronesInSpaceListEntry);
  287.     Sanderling.MouseClickLeft(Menu?.FirstOrDefault()?.EntryFirstMatchingRegexPattern("return.*bay", RegexOptions.IgnoreCase));
  288. }
  289.  
  290. Func<object>    DefenseStep()
  291. {
  292.     if(DefenseExit)
  293.     {
  294.         Host.Log("exit defense.");
  295.         DroneEnsureInBay();
  296.         return null;
  297.     }
  298.  
  299.     if (!(0 < DronesInSpaceCount))
  300.         DroneLaunch();
  301.  
  302.     EnsureOverviewTypeSelectionLoaded();
  303.  
  304.     var SetRatName =
  305.         ListRatOverviewEntry?.Select(entry => Regex.Split(entry?.Name ?? "", @"\s+")?.FirstOrDefault())
  306.         ?.Distinct()
  307.         ?.ToArray();
  308.    
  309.     var SetRatTarget = Measurement?.Target?.Where(target =>
  310.         SetRatName?.Any(ratName => target?.TextRow?.Any(row => row.RegexMatchSuccessIgnoreCase(ratName)) ?? false) ?? false);
  311.    
  312.     var RatTargetNext = SetRatTarget?.OrderBy(target => target?.DistanceMax ?? int.MaxValue)?.FirstOrDefault();
  313.    
  314.     if(null == RatTargetNext)
  315.     {
  316.         Host.Log("no rat targeted.");
  317.         Sanderling.MouseClickRight(ListRatOverviewEntry?.FirstOrDefault());
  318.         Sanderling.MouseClickLeft(MenuEntryLockTarget);
  319.     }
  320.     else
  321.     {
  322.         Host.Log("rat targeted. sending drones.");
  323.         Sanderling.MouseClickLeft(RatTargetNext);
  324.         Sanderling.MouseClickRight(DronesInSpaceListEntry);
  325.         Sanderling.MouseClickLeft(Menu?.FirstOrDefault()?.EntryFirstMatchingRegexPattern("engage", RegexOptions.IgnoreCase));
  326.     }
  327.    
  328.     return DefenseStep;
  329. }
  330.  
  331. Func<object> InBeltMineStep()
  332. {
  333.     if (DefenseEnter)
  334.     {
  335.         Host.Log("enter defense.");
  336.         return DefenseStep;
  337.     }
  338.  
  339.     EnsureWindowInventoryOpenOreHold();
  340.  
  341.     EnsureOverviewTypeSelectionLoaded();
  342.  
  343.     if(OreHoldFilledForOffload)
  344.         return null;
  345.  
  346.     var moduleMinerInactive = SetModuleMinerInactive?.FirstOrDefault();
  347.  
  348.     if (null == moduleMinerInactive)
  349.     {
  350.         Host.Delay(7777);
  351.         return InBeltMineStep;
  352.     }
  353.    
  354.     var setTargetAsteroidInRange    =
  355.         SetTargetAsteroid?.Where(target => target?.DistanceMax <= MiningRange)?.ToArray();
  356.  
  357.     var setTargetAsteroidInRangeNotAssigned =
  358.         setTargetAsteroidInRange?.Where(target => !(0 < target?.Assigned?.Length))?.ToArray();
  359.  
  360.     Host.Log("targeted asteroids in range (without assignment): " + setTargetAsteroidInRange?.Length + " (" + setTargetAsteroidInRangeNotAssigned?.Length + ")");
  361.    
  362.     if(0 < setTargetAsteroidInRangeNotAssigned?.Length)
  363.     {
  364.         ToggleMicroWarpDrive(false);
  365.         var targetAsteroidInputFocus    =
  366.             setTargetAsteroidInRangeNotAssigned?.FirstOrDefault(target => target?.IsSelected ?? false);
  367.  
  368.         if(null == targetAsteroidInputFocus)
  369.             Sanderling.MouseClickLeft(setTargetAsteroidInRangeNotAssigned?.FirstOrDefault());
  370.  
  371.         foreach (var moduleMinerIna in SetModuleMinerInactive)
  372.         {
  373.             if (UseMiningCrystal) {
  374.                 LoadMiningCrystalForTarget(moduleMinerIna, setTargetAsteroidInRangeNotAssigned?.FirstOrDefault());
  375.                 /*
  376.                 string[] targetTextRow = setTargetAsteroidInRangeNotAssigned?.FirstOrDefault()?.TextRow;
  377.                 if (targetTextRow != null && targetTextRow.Length > 0) {
  378.                     string baseOre = BaseOreFromAsteroidName(String.Join(" ", targetTextRow));
  379.                     if (!String.IsNullOrEmpty(baseOre)) {
  380.                             LoadMiningCrystal(moduleMinerIna, baseOre);
  381.                             Sanderling.MouseClickLeft(setTargetAsteroidInRangeNotAssigned?.FirstOrDefault());
  382.                             Sanderling.MouseMove(moduleMinerIna);
  383.                             Sanderling.WaitForMeasurement();   
  384.                     }
  385.                 }
  386.                 */
  387.             }
  388.            
  389.             ModuleToggle(moduleMinerIna);
  390.         }
  391.         return InBeltMineStep;
  392.     }
  393.  
  394.     var asteroidOverviewEntryNext = ListAsteroidOverviewEntry?.FirstOrDefault();
  395.     var asteroidOverviewEntryNextNotTargeted = ListAsteroidOverviewEntry?.FirstOrDefault(entry => !((entry?.MeTargeted ?? false) || (entry?.MeTargeting ?? false)));
  396.  
  397.     Host.Log("next asteroid: (" + asteroidOverviewEntryNext?.Name + " , distance: " + asteroidOverviewEntryNext?.DistanceMax + ")" +
  398.         ", next asteroid not targeted: (" + asteroidOverviewEntryNext?.Name + " , distance: " + asteroidOverviewEntryNext?.DistanceMax + ")");
  399.  
  400.     if(null == asteroidOverviewEntryNext)
  401.     {
  402.         Host.Log("no asteroid available");
  403.         return null;
  404.     }
  405.  
  406.     if(null == asteroidOverviewEntryNextNotTargeted)
  407.     {
  408.         Host.Log("all asteroids targeted");
  409.         return null;
  410.     }
  411.  
  412.     if (!(asteroidOverviewEntryNextNotTargeted.DistanceMax < MiningRange))
  413.     {
  414.         if(!(1111 < asteroidOverviewEntryNext?.DistanceMin))
  415.         {
  416.             Host.Log("distance between asteroids too large");
  417.             return null;
  418.         }
  419.  
  420.         Host.Log("out of range, approaching");
  421.         Random rnd = new Random();
  422.         if (!ApproachSomething || RandomInt() % 8 == 1)
  423.             ClickMenuEntryOnMenuRoot(asteroidOverviewEntryNext, "approach");
  424.            
  425.         if (SetModuleMinerActive?.FirstOrDefault() == null && CapacitorPercent > 50)
  426.         {
  427.             ToggleMicroWarpDrive(true);
  428.         }
  429.     }
  430.     else
  431.     {
  432.         Host.Log("initiate lock asteroid");
  433.         ClickMenuEntryOnMenuRoot(asteroidOverviewEntryNextNotTargeted, "^lock");
  434.     }
  435.    
  436.     return InBeltMineStep;
  437. }
  438.  
  439.  
  440. Sanderling.Parse.IMemoryMeasurement Measurement =>
  441.     Sanderling?.MemoryMeasurementParsed?.Value;
  442.  
  443. IWindow ModalUIElement =>
  444.     Measurement?.EnumerateReferencedUIElementTransitive()?.OfType<IWindow>()?.Where(window => window?.isModal ?? false)
  445.     ?.OrderByDescending(window => window?.InTreeIndex ?? int.MinValue)
  446.     ?.FirstOrDefault();
  447.  
  448. IEnumerable<Parse.IMenu> Menu => Measurement?.Menu;
  449.  
  450. Parse.IShipUi ShipUi => Measurement?.ShipUi;
  451.  
  452. bool Jammed => ShipUi?.EWarElement?.Any(EwarElement => (EwarElement?.EWarType).RegexMatchSuccess("electronic")) ?? false;
  453.  
  454. Sanderling.Interface.MemoryStruct.IMenuEntry MenuEntryLockTarget =>
  455.     Menu?.FirstOrDefault()?.Entry?.FirstOrDefault(entry => entry.Text.RegexMatchSuccessIgnoreCase("^lock"));
  456.  
  457. Sanderling.Parse.IWindowOverview    WindowOverview  =>
  458.     Measurement?.WindowOverview?.FirstOrDefault();
  459.  
  460. Sanderling.Parse.IWindowInventory   WindowInventory =>
  461.     Measurement?.WindowInventory?.FirstOrDefault();
  462.  
  463. IWindowDroneView    WindowDrones    =>
  464.     Measurement?.WindowDroneView?.FirstOrDefault();
  465.  
  466. ITreeViewEntry InventoryActiveShipOreHold =>
  467.     WindowInventory?.ActiveShipEntry?.TreeEntryFromCargoSpaceType(ShipCargoSpaceTypeEnum.OreHold);
  468.  
  469. IInventoryCapacityGauge OreHoldCapacityMilli =>
  470.     (InventoryActiveShipOreHold?.IsSelected ?? false) ? WindowInventory?.SelectedRightInventoryCapacityMilli : null;
  471.  
  472. int? OreHoldFillPercent => (int?)((OreHoldCapacityMilli?.Used * 100) / OreHoldCapacityMilli?.Max);
  473.  
  474. Tab OverviewPresetTabActive =>
  475.     WindowOverview?.PresetTab
  476.     ?.OrderByDescending(tab => tab?.LabelColorOpacityMilli ?? 0)
  477.     ?.FirstOrDefault();
  478.  
  479. string OverviewTypeSelectionName =>
  480.     WindowOverview?.Caption?.RegexMatchIfSuccess(@"\(([^\)]*)\)")?.Groups?[1]?.Value;
  481.  
  482. Parse.IOverviewEntry[] ListRatOverviewEntry => WindowOverview?.ListView?.Entry?.Where(entry =>
  483.         (entry?.MainIconIsRed ?? false) && (entry?.IsAttackingMe ?? false))
  484.         ?.OrderBy(entry => entry?.DistanceMax ?? int.MaxValue)
  485.         ?.ToArray();
  486.  
  487. Parse.IOverviewEntry[] ListAsteroidOverviewEntry =>
  488.     WindowOverview?.ListView?.Entry
  489.     ?.Where(entry => null != OreTypeFromAsteroidName(entry?.Name) && !IsExcludedBaseOre(entry?.Name))
  490.     ?.OrderBy(entry => entry.DistanceMax ?? int.MaxValue)
  491.     ?.ToArray();
  492.    
  493.  
  494. DroneViewEntryGroup DronesInBayListEntry =>
  495.     WindowDrones?.ListView?.Entry?.OfType<DroneViewEntryGroup>()?.FirstOrDefault(Entry => null != Entry?.Caption?.Text?.RegexMatchIfSuccess(@"Drones in bay", RegexOptions.IgnoreCase));
  496.  
  497. DroneViewEntryGroup DronesInSpaceListEntry =>
  498.     WindowDrones?.ListView?.Entry?.OfType<DroneViewEntryGroup>()?.FirstOrDefault(Entry => null != Entry?.Caption?.Text?.RegexMatchIfSuccess(@"Drones in Local Space", RegexOptions.IgnoreCase));
  499.  
  500. int?    DronesInSpaceCount => DronesInSpaceListEntry?.Caption?.Text?.AsDroneLabel()?.Status?.TryParseInt();
  501.  
  502. bool ReadyForManeuverNot =>
  503.     Measurement?.ShipUi?.Indication?.LabelText?.Any(indicationLabel =>
  504.         (indicationLabel?.Text).RegexMatchSuccessIgnoreCase("warp|docking")) ?? false;
  505.  
  506. bool ApproachSomething =>
  507.     Measurement?.ShipUi?.Indication?.LabelText?.Any(indicationLabel =>
  508.         (indicationLabel?.Text).RegexMatchSuccessIgnoreCase("approaching")) ?? false;
  509.  
  510. bool ReadyForManeuver => !ReadyForManeuverNot && !(Measurement?.IsDocked ?? true);
  511.  
  512. Sanderling.Parse.IShipUiTarget[] SetTargetAsteroid =>
  513.     Measurement?.Target?.Where(target =>
  514.         target?.TextRow?.Any(textRow => textRow.RegexMatchSuccessIgnoreCase("asteroid")) ?? false)?.ToArray();
  515.  
  516. Sanderling.Interface.MemoryStruct.IListEntry    WindowInventoryItem =>
  517.     WindowInventory?.SelectedRightInventory?.ListView?.Entry?.FirstOrDefault();
  518.  
  519. Sanderling.Accumulation.IShipUiModule[] SetModuleMiner =>
  520.     Sanderling.MemoryMeasurementAccu?.Value?.ShipUiModule?.Where(module => module?.TooltipLast?.Value?.IsMiner ?? false)?.ToArray();
  521.  
  522. Sanderling.Accumulation.IShipUiModule[] SetModuleMinerInactive   =>
  523.     SetModuleMiner?.Where(module => !(module?.RampActive ?? false))?.ToArray();
  524.  
  525. Sanderling.Accumulation.IShipUiModule[] SetModuleMinerActive     =>
  526.     SetModuleMiner?.Where(module => (module?.RampActive ?? false))?.ToArray();
  527.  
  528. int?    MiningRange => SetModuleMiner?.Select(module =>
  529.     module?.TooltipLast?.Value?.RangeOptimal ?? module?.TooltipLast?.Value?.RangeMax ?? module?.TooltipLast?.Value?.RangeWithin ?? 0)?.DefaultIfEmpty(0)?.Min();;
  530.  
  531. WindowChatChannel chatLocal =>
  532.      Sanderling.MemoryMeasurementParsed?.Value?.WindowChatChannel
  533.      ?.FirstOrDefault(windowChat => windowChat?.Caption?.RegexMatchSuccessIgnoreCase("local") ?? false);
  534.  
  535. //    assuming that own character is always visible in local
  536. bool hostileOrNeutralsInLocal => 1 != chatLocal?.ParticipantView?.Entry?.Count(IsNeutralOrEnemy);
  537.  
  538. //  extract the ore type from the name as seen in overview. "Asteroid (Plagioclase)"
  539. string OreTypeFromAsteroidName(string AsteroidName) =>
  540.     AsteroidName.ValueFromRegexMatchGroupAtIndex(@"Asteroid \(([^\)]+)", 0);
  541.  
  542. string BaseOreFromAsteroidName(string asteroidName)
  543. {
  544.     return Array.Find<string>(BaseOre, (Predicate<string>)delegate (string s)
  545.     {
  546.         return asteroidName.IndexOf(s, StringComparison.OrdinalIgnoreCase) > -1;
  547.     });
  548. }
  549.  
  550. bool IsExcludedBaseOre(string asteroidName) {
  551.     return Array.Exists<string>(ExcludedBaseOre, (Predicate<string>)delegate (string s)
  552.     {
  553.         return asteroidName.IndexOf(s, StringComparison.OrdinalIgnoreCase) > -1;
  554.     });
  555. }
  556.  
  557. void ClickMenuEntryOnMenuRoot(IUIElement MenuRoot, string MenuEntryRegexPattern)
  558. {
  559.     Sanderling.MouseClickRight(MenuRoot);
  560.    
  561.     var Menu = Measurement?.Menu?.FirstOrDefault();
  562.    
  563.     var MenuEntry = Menu?.EntryFirstMatchingRegexPattern(MenuEntryRegexPattern, RegexOptions.IgnoreCase);
  564.    
  565.     Sanderling.MouseClickLeft(MenuEntry);
  566. }
  567.  
  568. void EnsureWindowInventoryOpen()
  569. {
  570.     if (null != WindowInventory)
  571.         return;
  572.  
  573.     Host.Log("open Inventory.");
  574.     Sanderling.MouseClickLeft(Measurement?.Neocom?.InventoryButton);
  575. }
  576.  
  577. void EnsureWindowInventoryOpenOreHold()
  578. {
  579.     EnsureWindowInventoryOpen();
  580.  
  581.     var inventoryActiveShip = WindowInventory?.ActiveShipEntry;
  582.  
  583.     if(InventoryActiveShipOreHold == null && !(inventoryActiveShip?.IsExpanded ?? false))
  584.         Sanderling.MouseClickLeft(inventoryActiveShip?.ExpandToggleButton);
  585.  
  586.     if(!(InventoryActiveShipOreHold?.IsSelected ?? false))
  587.         Sanderling.MouseClickLeft(InventoryActiveShipOreHold);
  588. }
  589.  
  590. //  sample label text: Intensive Reprocessing Array <color=#66FFFFFF>1,123 m</color>
  591. string InventoryContainerLabelRegexPatternFromContainerName(string containerName) =>
  592.     @"^\s*" + Regex.Escape(containerName) + @"\s*($|\<)";
  593.  
  594. void InInventoryUnloadItems() => InInventoryUnloadItemsTo(UnloadDestContainerName);
  595.  
  596. void InInventoryUnloadItemsTo(string DestinationContainerName)
  597. {
  598.     Host.Log("unload items to '" + DestinationContainerName + "'.");
  599.  
  600.     EnsureWindowInventoryOpenOreHold();
  601.  
  602.     for (;;)
  603.     {
  604.         var oreHoldListItem = WindowInventory?.SelectedRightInventory?.ListView?.Entry?.ToArray();
  605.  
  606.         var oreHoldItem = oreHoldListItem?.FirstOrDefault();
  607.  
  608.         if(null == oreHoldItem)
  609.             break;    //    0 items in OreHold
  610.  
  611.         if(1 < oreHoldListItem?.Length)
  612.             ClickMenuEntryOnMenuRoot(oreHoldItem, @"select\s*all");
  613.  
  614.         var DestinationContainerLabelRegexPattern =
  615.             InventoryContainerLabelRegexPatternFromContainerName(DestinationContainerName);
  616.  
  617.         var DestinationContainer =
  618.             WindowInventory?.LeftTreeListEntry?.SelectMany(entry => new[] { entry }.Concat(entry.EnumerateChildNodeTransitive()))
  619.             ?.FirstOrDefault(entry => entry?.Text?.RegexMatchSuccessIgnoreCase(DestinationContainerLabelRegexPattern) ?? false);
  620.  
  621.         if (null == DestinationContainer)
  622.             Host.Log("error: Inventory entry labeled '" + DestinationContainerName + "' not found");
  623.  
  624.         Sanderling.MouseDragAndDrop(oreHoldItem, DestinationContainer);
  625.     }
  626. }
  627.  
  628. bool InitiateWarpToRandomMiningSite()   =>
  629.     InitiateDockToOrWarpToBookmark(RandomElement(SetMiningSiteBookmark));
  630.  
  631. bool InitiateWarpToRandomMiningBookmark() =>
  632.     InitiateDockToOrWarpToLocationInSolarSystemMenu(RandomElement(SetMiningSiteBookmark));
  633.  
  634. bool InitiateWarpToMiningSite() =>
  635.     InitiateDockToOrWarpToLocationInSolarSystemMenu("asteroid belts", PickNextMiningSiteFromSystemMenu);
  636.  
  637. bool InitiateDockToOffload()    =>
  638.     InitiateDockToOrWarpToLocationInSolarSystemMenu(UnloadBookmark, PickPlaceToOffloadfFromSystemMenu);
  639.  
  640. bool InitiateWarpToRetreat()    =>
  641.     InitiateDockToOrWarpToLocationInSolarSystemMenu("stations");
  642.  
  643. MemoryStruct.IMenuEntry PickNextMiningSiteFromSystemMenu(IReadOnlyList<MemoryStruct.IMenuEntry> availableMenuEntries)
  644. {
  645.     Host.Log("I am seeing " + availableMenuEntries?.Count.ToString() + " mining sites to choose from.");
  646.  
  647.     var nextSite =
  648.         availableMenuEntries
  649.         ?.OrderBy(menuEntry => visitedLocations.ToList().IndexOf(menuEntry?.Text))
  650.         ?.FirstOrDefault();
  651.  
  652.     Host.Log("I pick '" + nextSite?.Text + "' as next mining site, based on the intent to rotate through the mining sites and recorded previous locations.");
  653.     return nextSite;
  654. }
  655.  
  656. MemoryStruct.IMenuEntry PickPlaceToOffloadfFromSystemMenu(IReadOnlyList<MemoryStruct.IMenuEntry> availableMenuEntries)
  657. {
  658.     Host.Log("I am seeing " + availableMenuEntries?.Count.ToString() + " stations to choose from for offloading ore.");
  659.  
  660.     var availableMenuEntriesTexts =
  661.         availableMenuEntries
  662.         ?.Select(menuEntry => menuEntry.Text)
  663.         ?.ToList();
  664.  
  665.     foreach(var visitedLocation in visitedLocations.Reverse())
  666.     {
  667.         var visitedLocationMenuEntry =
  668.             availableMenuEntries?.FirstOrDefault(menuEntry =>
  669.                 StationFromSystemInfoPanelEqualsStationFromSystemMenu(visitedLocation, menuEntry?.Text));
  670.  
  671.         if(visitedLocationMenuEntry == null)
  672.             continue;
  673.  
  674.         Host.Log("I pick '" + visitedLocationMenuEntry?.Text + "' as destination, because this is the last one visited.");
  675.         return visitedLocationMenuEntry;
  676.     }
  677.  
  678.     var dockMenuEntry = availableMenuEntries?.Where(x => x?.Text?.Contains("Dock") ?? false)?.FirstOrDefault();
  679.     var destination = dockMenuEntry ?? availableMenuEntries?.FirstOrDefault();
  680.  
  681.     Host.Log("I pick '" + destination?.Text + "' as destination, because I do not remember having visited any of the available stations.");
  682.     return destination;
  683. }
  684.  
  685. bool InitiateDockToOrWarpToLocationInSolarSystemMenu(
  686.     string submenuLabel,
  687.     Func<IReadOnlyList<MemoryStruct.IMenuEntry>, MemoryStruct.IMenuEntry> pickPreferredDestination = null)
  688. {  
  689.     Host.Log("Attempt to initiate dock to or warp to menu entry in submenu '" + submenuLabel + "'");
  690.    
  691.     var listSurroundingsButton = Measurement?.InfoPanelCurrentSystem?.ListSurroundingsButton;
  692.    
  693.     Sanderling.MouseClickRight(listSurroundingsButton);
  694.  
  695.     var submenuEntry = Measurement?.Menu?.FirstOrDefault()?.EntryFirstMatchingRegexPattern("^" + submenuLabel + "$", RegexOptions.IgnoreCase);
  696.  
  697.     if(null == submenuEntry)
  698.     {
  699.         Host.Log("Submenu '" + submenuLabel + "' not found in the solar system menu.");
  700.         return true;
  701.     }
  702.  
  703.     Sanderling.MouseClickLeft(submenuEntry);
  704.  
  705.     var submenu = Measurement?.Menu?.ElementAtOrDefault(1);
  706.  
  707.     var destinationMenuEntry = pickPreferredDestination?.Invoke(submenu?.Entry?.ToList()) ?? submenu?.Entry?.FirstOrDefault();
  708.  
  709.     if(destinationMenuEntry == null)
  710.     {
  711.         Host.Log("Failed to open submenu '" + submenuLabel + "' in the solar system menu.");
  712.         return true;
  713.     }
  714.  
  715.     Sanderling.MouseClickLeft(destinationMenuEntry);
  716.  
  717.     var actionsMenu = Measurement?.Menu?.ElementAtOrDefault(2);
  718.  
  719.     if(destinationMenuEntry == null)
  720.     {
  721.         Host.Log("Failed to open actions menu for '" + destinationMenuEntry.Text + "' in the solar system menu.");
  722.         return true;
  723.     }
  724.  
  725.     var dockMenuEntry = actionsMenu?.EntryFirstMatchingRegexPattern("dock", RegexOptions.IgnoreCase);
  726.     var warpMenuEntry = actionsMenu?.EntryFirstMatchingRegexPattern(@"warp.*within.*m", RegexOptions.IgnoreCase);
  727.     var approachEntry = actionsMenu?.EntryFirstMatchingRegexPattern(@"approach", RegexOptions.IgnoreCase);
  728.  
  729.     var maneuverMenuEntry = dockMenuEntry ?? warpMenuEntry;
  730.  
  731.     if (null != maneuverMenuEntry)
  732.     {
  733.         Host.Log("initiating '" + maneuverMenuEntry.Text + "' on '" + destinationMenuEntry?.Text + "'");
  734.         Sanderling.MouseClickLeft(maneuverMenuEntry);
  735.         return false;
  736.     }
  737.  
  738.     if (null != approachEntry)
  739.     {
  740.         Host.Log("found menu entry '" + approachEntry.Text + "'. Assuming we are already there.");
  741.         return false;
  742.     }
  743.  
  744.     Host.Log("no suitable menu entry found on '" + destinationMenuEntry?.Text + "'");
  745.     return true;
  746. }
  747.  
  748. bool InitiateDockToOrWarpToBookmark(string bookmarkOrFolder)
  749. {
  750.     Host.Log("dock to or warp to bookmark or random bookmark in folder: '" + bookmarkOrFolder + "'");
  751.    
  752.     var listSurroundingsButton = Measurement?.InfoPanelCurrentSystem?.ListSurroundingsButton;
  753.    
  754.     Sanderling.MouseClickRight(listSurroundingsButton);
  755.    
  756.     var bookmarkMenuEntry = Measurement?.Menu?.FirstOrDefault()?.EntryFirstMatchingRegexPattern("^" + bookmarkOrFolder + "$", RegexOptions.IgnoreCase);
  757.  
  758.     if(null == bookmarkMenuEntry)
  759.     {
  760.         Host.Log("menu entry not found for bookmark or folder: '" + bookmarkOrFolder + "'");
  761.         return true;
  762.     }
  763.  
  764.     var currentLevelMenuEntry = bookmarkMenuEntry;
  765.  
  766.     for (var menuLevel = 1; ; ++menuLevel)
  767.     {
  768.         Sanderling.MouseClickLeft(currentLevelMenuEntry);
  769.  
  770.         var menu = Measurement?.Menu?.ElementAtOrDefault(menuLevel);
  771.         var dockMenuEntry = menu?.EntryFirstMatchingRegexPattern("dock", RegexOptions.IgnoreCase);
  772.         var warpMenuEntry = menu?.EntryFirstMatchingRegexPattern(@"warp.*within\s*0", RegexOptions.IgnoreCase);
  773.         var approachEntry = menu?.EntryFirstMatchingRegexPattern(@"approach", RegexOptions.IgnoreCase);
  774.  
  775.         var maneuverMenuEntry = dockMenuEntry ?? warpMenuEntry;
  776.  
  777.         if (null != maneuverMenuEntry)
  778.         {
  779.             Host.Log("initiating '" + maneuverMenuEntry.Text + "' on entry '" + currentLevelMenuEntry?.Text + "'");
  780.             Sanderling.MouseClickLeft(maneuverMenuEntry);
  781.             return false;
  782.         }
  783.  
  784.         if (null != approachEntry)
  785.         {
  786.             Host.Log("found menu entry '" + approachEntry.Text + "'. Assuming we are already there.");
  787.             return false;
  788.         }
  789.  
  790.         var setBookmarkOrFolderMenuEntry =
  791.             menu?.Entry;    //  assume that each entry on the current menu level is a bookmark or a bookmark folder.
  792.  
  793.         var nextLevelMenuEntry = RandomElement(setBookmarkOrFolderMenuEntry);
  794.  
  795.         if(null == nextLevelMenuEntry)
  796.         {
  797.             Host.Log("no suitable menu entry found");
  798.             return true;
  799.         }
  800.  
  801.         currentLevelMenuEntry = nextLevelMenuEntry;
  802.     }
  803. }
  804.  
  805. void Undock()
  806. {
  807.     while(Measurement?.IsDocked ?? true)
  808.     {
  809.         Sanderling.MouseClickLeft(Measurement?.WindowStation?.FirstOrDefault()?.UndockButton);
  810.         Host.Log("waiting for undocking to complete.");
  811.         Host.Delay(8000);
  812.     }
  813.  
  814.     Host.Delay(4444);
  815.     Sanderling.InvalidateMeasurement();
  816. }
  817.  
  818. void ModuleMeasureAllTooltip()
  819. {
  820.     Host.Log("measure tooltips of all modules.");
  821.  
  822.     for (;;)
  823.     {
  824.         var NextModule = Sanderling.MemoryMeasurementAccu?.Value?.ShipUiModule?.FirstOrDefault(m => null == m?.TooltipLast);
  825.  
  826.         if(null == NextModule)
  827.             break;
  828.  
  829.         Host.Log("measure module.");
  830.         //  take multiple measurements of module tooltip to reduce risk to keep bad read tooltip.
  831.         Sanderling.MouseMove(NextModule);
  832.         Sanderling.WaitForMeasurement();
  833.         Sanderling.MouseMove(NextModule);
  834.     }
  835. }
  836.  
  837. void ActivateHardenerExecute()
  838. {
  839.     var SubsetModuleHardener =
  840.         Sanderling.MemoryMeasurementAccu?.Value?.ShipUiModule
  841.         ?.Where(module => module?.TooltipLast?.Value?.IsHardener ?? false);
  842.  
  843.     var SubsetModuleToToggle =
  844.         SubsetModuleHardener
  845.         ?.Where(module => !(module?.RampActive ?? false));
  846.  
  847.     foreach (var Module in SubsetModuleToToggle.EmptyIfNull())
  848.         ModuleToggle(Module);
  849. }
  850.  
  851. // get all shield boosters in one array
  852. Sanderling.Accumulation.IShipUiModule[] SetModuleShieldBoosters =>
  853.     Sanderling.MemoryMeasurementAccu?.Value?.ShipUiModule?.Where(module => module?.TooltipLast?.Value?.IsShieldBooster ?? false)?.ToArray();
  854.  
  855. // if true then we should turn on shield booster if false - turn off
  856. void ToggleShieldBooster(bool turnOn = true)
  857. {
  858.     var shieldBooster = SetModuleShieldBoosters?.FirstOrDefault();
  859.     if((shieldBooster?.RampActive ?? false) !=turnOn)
  860.     {      
  861.         Host.Log("toggle Shield Booster.");
  862.         ModuleToggle(shieldBooster);
  863.     }
  864. }
  865. // get all micro warp drive in one array
  866. Sanderling.Accumulation.IShipUiModule[] SetModuleMicroWarpDrive =>
  867.     Sanderling.MemoryMeasurementAccu?.Value?.ShipUiModule?.Where(module => module?.TooltipLast?.Value?.IsMicroWarpDrive ?? false)?.ToArray();
  868.  
  869. // if true then we should turn on shield booster if false - turn off
  870. void ToggleMicroWarpDrive(bool turnOn = true)
  871. {
  872.     var microWarp = SetModuleMicroWarpDrive?.FirstOrDefault();
  873.     if((microWarp?.RampActive ?? false) !=turnOn)
  874.     {      
  875.         Host.Log("toggle Micro Warp Drive.");
  876.         ModuleToggle(microWarp);
  877.     }
  878. }
  879.  
  880. void LoadMiningCrystal(Sanderling.Accumulation.IShipUiModule Module, string baseOre)
  881. {
  882.     Sanderling.MouseClickRight(Module);
  883.     var menuCrystal = Menu?.FirstOrDefault()?.EntryFirstMatchingRegexPattern(baseOre +".*mining.*crystal", RegexOptions.IgnoreCase);
  884.     if (menuCrystal != null)
  885.         Sanderling.MouseClickLeft(menuCrystal);
  886. }
  887.  
  888. void LoadMiningCrystalForTarget(Sanderling.Accumulation.IShipUiModule module, Sanderling.Parse.IShipUiTarget target)
  889. {
  890.     string[] targetTextRow = target?.TextRow;
  891.     if (targetTextRow != null && targetTextRow.Length > 0) {
  892.         string baseOre = BaseOreFromAsteroidName(String.Join(" ", targetTextRow));
  893.         if (!String.IsNullOrEmpty(baseOre)) {
  894.             Sanderling.MouseMove(module);
  895.             Sanderling.WaitForMeasurement();
  896.             var foundCrystal = module?.TooltipLast?.Value?.LabelText?.FirstOrDefault(entry => entry.Text.RegexMatchSuccessIgnoreCase("Mining Crystal"));
  897.             //IEnumerable<Sanderling.Interface.MemoryStruct.UIElementText> foundLabels = module?.TooltipLast?.Value?.LabelText?.Text.Where(lbl => lbl.Text.Contains("Mining Crystal"));
  898.            
  899.             if (foundCrystal != null && foundCrystal.Text.Contains(baseOre))
  900.                 return;
  901.            
  902.             Sanderling.MouseClickRight(module);
  903.             var menuCrystal = Menu?.FirstOrDefault()?.EntryFirstMatchingRegexPattern(baseOre +".*mining.*crystal", RegexOptions.IgnoreCase);
  904.            
  905.             if (menuCrystal != null)
  906.                 Sanderling.MouseClickLeft(menuCrystal);
  907.             else if (foundCrystal != null)
  908.                 Sanderling.MouseClickLeft( Menu?.FirstOrDefault()?.EntryFirstMatchingRegexPattern("unload to cargo", RegexOptions.IgnoreCase));
  909.             else
  910.                 Sanderling.MouseClickLeft(target);
  911.         }
  912.     }
  913. }
  914.  
  915. void ModuleToggle(Sanderling.Accumulation.IShipUiModule Module)
  916. {
  917.     var ToggleKey = Module?.TooltipLast?.Value?.ToggleKey;
  918.  
  919.     Host.Log("toggle module using " + (null == ToggleKey ? "mouse" : Module?.TooltipLast?.Value?.ToggleKeyTextLabel?.Text));
  920.  
  921.     if(null == ToggleKey)
  922.         Sanderling.MouseClickLeft(Module);
  923.     else
  924.         Sanderling.KeyboardPressCombined(ToggleKey);
  925. }
  926.  
  927. void EnsureOverviewTypeSelectionLoaded()
  928. {
  929.     if(null == OverviewPresetTabActive || null == WindowOverview || null == OverviewPreset)
  930.         return;
  931.  
  932.     if(string.Equals(OverviewTypeSelectionName, OverviewPreset, StringComparison.OrdinalIgnoreCase))
  933.         return;
  934.  
  935.     Host.Log("loading preset '" + OverviewPreset + "' to overview (current selection is '" + OverviewTypeSelectionName + "').");
  936.     Sanderling.MouseClickRight(OverviewPresetTabActive);
  937.     Sanderling.MouseClickLeft(Menu?.FirstOrDefault()?.EntryFirstMatchingRegexPattern("load.*preset", RegexOptions.IgnoreCase));
  938.     var PresetMenuEntry = Menu?.ElementAtOrDefault(1)?.EntryFirstMatchingRegexPattern(@"^\s*" + Regex.Escape(OverviewPreset) + @"\s*$", RegexOptions.IgnoreCase);
  939.  
  940.     if(null == PresetMenuEntry)
  941.     {
  942.         Host.Log("error: menu entry '" + OverviewPreset + "' not found");
  943.         return;
  944.     }
  945.  
  946.     Sanderling.MouseClickLeft(PresetMenuEntry);
  947. }
  948.  
  949. void MemoryUpdate()
  950. {
  951.     RetreatUpdate();
  952.     JammedLastTimeUpdate();
  953.     UpdateLocationRecord();
  954.     OffloadCountUpdate();
  955. }
  956.  
  957. /*
  958. 2018-03 Observation: Station name containing reference to moon appears different between system menu and system info panel.
  959. In the info panel 'Moon 17' was used while in the system menu it was 'M17'.
  960. */
  961. public bool StationFromSystemInfoPanelEqualsStationFromSystemMenu(
  962.     string stationNameInCurrentSystemInfoPanel,
  963.     string stationNameInSystemMenu)
  964. {
  965.     //  Copied from https://github.com/botengine-de/Optimat.EO/blob/6c19e8f36e30d5468e94d627eb16dcb78bb47d12/src/Optimat.EveOnline.Bot/Sonst/AgentUndMission.Aktualisiire.cs#L1888-L1893
  966.  
  967.     var representationPattern =
  968.         Regex.Replace(
  969.         stationNameInCurrentSystemInfoPanel,
  970.         "Moon\\s*",
  971.         "M([\\w]*\\s*)",
  972.         RegexOptions.IgnoreCase);
  973.  
  974.     return
  975.         stationNameInSystemMenu.RegexMatchSuccessIgnoreCase(representationPattern);
  976. }
  977.  
  978. void JammedLastTimeUpdate()
  979. {
  980.     if(Jammed)
  981.         JammedLastTime  = Host.GetTimeContinuousMilli();
  982. }
  983.  
  984. bool MeasurementEmergencyWarpOutEnter =>
  985.     !(Measurement?.IsDocked ?? false) && !(EmergencyWarpOutHitpointPercent < ShieldHpPercent);
  986.  
  987. void RetreatUpdate()
  988. {
  989.     RetreatReasonTemporary = (RetreatOnNeutralOrHostileInLocal && hostileOrNeutralsInLocal) ? "hostile or neutral in local" : null;
  990.  
  991.     if (!MeasurementEmergencyWarpOutEnter)
  992.         return;
  993.  
  994.     //  measure multiple times to avoid being scared off by noise from a single measurement.
  995.     Sanderling.InvalidateMeasurement();
  996.  
  997.     if (!MeasurementEmergencyWarpOutEnter)
  998.         return;
  999.  
  1000.     RetreatReasonPermanent = "shield hp";
  1001. }
  1002.  
  1003. void OffloadCountUpdate()
  1004. {
  1005.     var OreHoldFillPercentSynced    = OreHoldFillPercent;
  1006.  
  1007.     if(!OreHoldFillPercentSynced.HasValue)
  1008.         return;
  1009.  
  1010.     if(0 == OreHoldFillPercentSynced && OreHoldFillPercentSynced < LastCheckOreHoldFillPercent)
  1011.         ++OffloadCount;
  1012.  
  1013.     LastCheckOreHoldFillPercent = OreHoldFillPercentSynced;
  1014. }
  1015.  
  1016. void UpdateLocationRecord()
  1017. {
  1018.     //  I am not interested in locations which are only close during warp.
  1019.     if (Measurement?.ShipUi?.Indication?.ManeuverType == ShipManeuverTypeEnum.Warp)
  1020.         return;
  1021.  
  1022.     // Purpose of recording locations is to prioritize our next destination when warping to mining site or docking to station.
  1023.     // For this purpose, I will compare the recorded locations with the menu entries in the system menu.
  1024.     // Therefore I want the format of the recorded location to be the same as it appears in the menu entries in the system menu.
  1025.  
  1026.     var currentSystemLocationLabelText =
  1027.         Measurement?.InfoPanelCurrentSystem?.ExpandedContent?.LabelText
  1028.         ?.OrderByCenterVerticalDown()?.FirstOrDefault()?.Text;
  1029.  
  1030.     if (currentSystemLocationLabelText == null)
  1031.         return;
  1032.  
  1033.     // 2018-03 observed label text: <url=showinfo:15//40088644 alt='Nearest'>Amsen V - Asteroid Belt 1</url>
  1034.  
  1035.     var currentLocationName = RegexExtension.RemoveXmlTag(currentSystemLocationLabelText)?.Trim();
  1036.  
  1037.     var lastRecordedLocation = visitedLocations.LastOrDefault();
  1038.  
  1039.     if (lastRecordedLocation == currentLocationName)
  1040.         return;
  1041.  
  1042.     visitedLocations.Enqueue(currentLocationName);
  1043.     Host.Log("Recorded transition from location '" + lastRecordedLocation + "' to location '" + currentLocationName + "'");
  1044.  
  1045.     if (100 < visitedLocations.Count)
  1046.         visitedLocations.Dequeue();
  1047. }
  1048.  
  1049. bool IsNeutralOrEnemy(IChatParticipantEntry participantEntry) =>
  1050.    !(participantEntry?.FlagIcon?.Any(flagIcon =>
  1051.      new[] { "good standing", "excellent standing", "Pilot is in your (fleet|corporation)", }
  1052.      .Any(goodStandingText =>
  1053.         flagIcon?.HintText?.RegexMatchSuccessIgnoreCase(goodStandingText) ?? false)) ?? false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement