Guest User

Untitled

a guest
Feb 3rd, 2016
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.97 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 asteroid 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. using Parse = Sanderling.Parse;
  15.  
  16. // begin of configuration section ->
  17.  
  18. // The bot uses the bookmarks from the menu which is opened from the button in the 'System info' panel.
  19. // Bookmark to station where ore should be transfered to item hangar.
  20. string StationOrPosBookmark = "Hangar";
  21. // Bookmark to place with asteroids.
  22. string MiningSiteBookmark = "Mine";
  23.  
  24. //if Use a Station
  25. bool UseStation = false;
  26.  
  27. // Container name to push it on a pos or POSContainer = "Item hangar" in station
  28. string DestinationContainerName ="Without";
  29.  
  30. // The bot loads this preset to the active tab.
  31. string OverviewPreset = "mining";
  32.  
  33. var ActivateHardener = true;
  34.  
  35. // bot will start fighting (and stop mining) when hitpoints are lower.
  36. var DefenseEnterHitpointThresholdPercent = 85;
  37. var DefenseExitHitpointThresholdPercent = 90;
  38.  
  39. var EmergencyWarpOutHitpointPercent = 60;
  40.  
  41. var FightAllRats = true; // when this is set to true, the bot will attack rats independent of shield hp.
  42.  
  43. // <- end of configuration section
  44.  
  45. Func<object> BotStopActivity = () => new object();
  46.  
  47. Func<object> NextActivity = MainStep;
  48.  
  49. for(;;)
  50. {
  51. MemoryUpdate();
  52.  
  53. Host.Log(
  54. "ore hold fill: " + OreHoldFillPercent + "%" +
  55. ", mining range: " + MiningRange +
  56. ", mining modules (inactive): " + SetModuleMiner?.Length + "(" + SetModuleMinerInactive?.Length + ")" +
  57. ", shield.hp: " + ShieldHpPercent + "%" +
  58. ", EWO: " + EmergencyWarpOutEnabled.ToString() +
  59. ", JLA: " + JammedLastAge +
  60. ", overview.rats: " + ListRatOverviewEntry?.Length +
  61. ", overview.roids: " + ListAsteroidOverviewEntry?.Length +
  62. ", offload count: " + OffloadCount +
  63. ", nextAct: " + NextActivity?.Method?.Name);
  64.  
  65. CloseModalUIElement();
  66.  
  67. if(EmergencyWarpOutEnabled)
  68. if(!(Measurement?.IsDocked ?? false))
  69. {
  70. InitiateDockToOrWarpToBookmark(StationOrPosBookmark);
  71. continue;
  72. }
  73.  
  74. NextActivity = NextActivity?.Invoke() as Func<object>;
  75.  
  76. if(BotStopActivity == NextActivity)
  77. break;
  78.  
  79. if(null == NextActivity)
  80. NextActivity = MainStep;
  81.  
  82. Host.Delay(1111);
  83. }
  84.  
  85. // seconds since ship was jammed.
  86. long? JammedLastAge => Jammed ? 0 : (Host.GetTimeContinuousMilli() - JammedLastTime) / 1000;
  87.  
  88. int? ShieldHpPercent => ShipUi?.HitpointsAndEnergy?.Shield / 10;
  89.  
  90. bool DefenseExit =>
  91. (Measurement?.IsDocked ?? false) ||
  92. !(0 < ListRatOverviewEntry?.Length) ||
  93. (DefenseExitHitpointThresholdPercent < ShieldHpPercent && !(JammedLastAge < 40) &&
  94. !(FightAllRats && 0 < ListRatOverviewEntry?.Length));
  95.  
  96. bool DefenseEnter =>
  97. !DefenseExit ||
  98. !(DefenseEnterHitpointThresholdPercent < ShieldHpPercent) || JammedLastAge < 10;
  99.  
  100. bool OreHoldFilledForOffload => 97 < OreHoldFillPercent;
  101.  
  102. Int64? JammedLastTime = null;
  103. bool EmergencyWarpOutEnabled = false;
  104. int? LastCheckOreHoldFillPercent = null;
  105.  
  106. int OffloadCount = 0;
  107.  
  108.  
  109.  
  110. Func<object> MainStep()
  111. {
  112. var DestinationContainer =
  113. WindowInventory?.LeftTreeListEntry?.SelectMany(entry => new[]{entry}.Concat(entry.EnumerateChildNodeTransitive()))
  114. ?.FirstOrDefault(entry => string.Equals(entry?.Text, DestinationContainerName, StringComparison.InvariantCultureIgnoreCase));
  115. if(UseStation){
  116. if(Measurement?.IsDocked ?? false)
  117. {
  118. UnloadToHangar(DestinationContainerName);
  119.  
  120. if (EmergencyWarpOutEnabled)
  121. return BotStopActivity;
  122.  
  123. Undock();
  124. }
  125. }
  126. else{
  127. if(DestinationContainer != null)
  128. {
  129. UnloadToHangar(DestinationContainerName);
  130.  
  131. if (EmergencyWarpOutEnabled)
  132. return BotStopActivity;
  133. }
  134. }
  135.  
  136. if(DefenseEnter)
  137. {
  138. Host.Log("enter defense.");
  139. return DefenseStep;
  140. }
  141.  
  142. EnsureOverviewTypeSelectionLoaded();
  143.  
  144. EnsureWindowInventoryOpenOreHold();
  145.  
  146. if(ReadyForManeuver)
  147. {
  148. DroneEnsureInBay();
  149.  
  150. if(OreHoldFilledForOffload)
  151. {
  152. if(ReadyForManeuver)
  153. InitiateDockToOrWarpToBookmark(StationOrPosBookmark);
  154. return MainStep;
  155. }
  156.  
  157. if(!(0 < ListAsteroidOverviewEntry?.Length))
  158. InitiateDockToOrWarpToBookmark(MiningSiteBookmark);
  159. }
  160.  
  161. ModuleMeasureAllTooltip();
  162.  
  163. if(ActivateHardener)
  164. ActivateHardenerExecute();
  165.  
  166. return InBeltMineStep;
  167. }
  168.  
  169. void CloseModalUIElement()
  170. {
  171. var ButtonClose =
  172. ModalUIElement?.ButtonText?.FirstOrDefault(button => (button?.Text).RegexMatchSuccessIgnoreCase("close|no|ok"));
  173.  
  174. Sanderling.MouseClickLeft(ButtonClose);
  175. }
  176.  
  177. void DroneLaunch()
  178. {
  179. Host.Log("launch drones.");
  180. Sanderling.MouseClickRight(DronesInBayListEntry);
  181. Sanderling.MouseClickLeft(Menu?.FirstOrDefault()?.EntryFirstMatchingRegexPattern("launch", RegexOptions.IgnoreCase));
  182. }
  183.  
  184. void DroneEnsureInBay()
  185. {
  186. if(0 == DronesInSpaceCount)
  187. return;
  188.  
  189. DroneReturnToBay();
  190.  
  191. Host.Delay(4444);
  192. }
  193.  
  194. void DroneReturnToBay()
  195. {
  196. Host.Log("return drones to bay.");
  197. Sanderling.MouseClickRight(DronesInSpaceListEntry);
  198. Sanderling.MouseClickLeft(Menu?.FirstOrDefault()?.EntryFirstMatchingRegexPattern("return.*bay", RegexOptions.IgnoreCase));
  199. }
  200.  
  201. Func<object> DefenseStep()
  202. {
  203. if(DefenseExit)
  204. {
  205. Host.Log("exit defense.");
  206. return null;
  207. }
  208.  
  209. if (!(0 < DronesInSpaceCount))
  210. DroneLaunch();
  211.  
  212. EnsureOverviewTypeSelectionLoaded();
  213.  
  214. var SetRatName =
  215. ListRatOverviewEntry?.Select(entry => Regex.Split(entry?.Name ?? "", @"\s+")?.FirstOrDefault())
  216. ?.Distinct()
  217. ?.ToArray();
  218.  
  219. var SetRatTarget = Measurement?.Target?.Where(target =>
  220. SetRatName?.Any(ratName => target?.TextRow?.Any(row => row.RegexMatchSuccessIgnoreCase(ratName)) ?? false) ?? false);
  221.  
  222. var RatTargetNext = SetRatTarget?.OrderBy(target => target?.DistanceMax ?? int.MaxValue)?.FirstOrDefault();
  223.  
  224. if(null == RatTargetNext)
  225. {
  226. Host.Log("no rat targeted.");
  227. Sanderling.MouseClickRight(ListRatOverviewEntry?.FirstOrDefault());
  228. Sanderling.MouseClickLeft(MenuEntryLockTarget);
  229. }
  230. else
  231. {
  232. Host.Log("rat targeted. sending drones.");
  233. Sanderling.MouseClickLeft(RatTargetNext);
  234. Sanderling.MouseClickRight(DronesInSpaceListEntry);
  235. Sanderling.MouseClickLeft(Menu?.FirstOrDefault()?.EntryFirstMatchingRegexPattern("engage", RegexOptions.IgnoreCase));
  236. }
  237.  
  238. return DefenseStep;
  239. }
  240.  
  241. Func<object> InBeltMineStep()
  242. {
  243. if (DefenseEnter)
  244. {
  245. Host.Log("enter defense.");
  246. return DefenseStep;
  247. }
  248.  
  249. EnsureWindowInventoryOpenOreHold();
  250.  
  251. EnsureOverviewTypeSelectionLoaded();
  252.  
  253. if(OreHoldFilledForOffload)
  254. return null;
  255.  
  256. if(!(0 < SetModuleMinerInactive?.Length))
  257. {
  258. Host.Delay(7777);
  259. return InBeltMineStep;
  260. }
  261.  
  262. var SetTargetAsteroidInRange =
  263. SetTargetAsteroid?.Where(target => target?.DistanceMax <= MiningRange)?.ToArray();
  264.  
  265. Host.Log("targeted asteroids in range: " + SetTargetAsteroidInRange?.Length);
  266. if(0 < SetTargetAsteroidInRange?.Length)
  267. {
  268. var TargetAsteroidInputFocus =
  269. SetTargetAsteroidInRange?.FirstOrDefault(target => target?.IsSelected ?? false);
  270.  
  271. if(null == TargetAsteroidInputFocus)
  272. Sanderling.MouseClickLeft(SetTargetAsteroid?.FirstOrDefault());
  273.  
  274. foreach (var Module in SetModuleMinerInactive)
  275. ModuleToggle(Module);
  276. return InBeltMineStep;
  277. }
  278.  
  279. var AsteroidOverviewEntry = ListAsteroidOverviewEntry?.FirstOrDefault();
  280.  
  281. Host.Log("next asteroid: " + AsteroidOverviewEntry?.Name + " , Distance: " + AsteroidOverviewEntry?.DistanceMax);
  282.  
  283. if(null == AsteroidOverviewEntry)
  284. {
  285. Host.Log("no asteroid available");
  286. return null;
  287. }
  288.  
  289. if(!(AsteroidOverviewEntry.DistanceMax < MiningRange))
  290. {
  291. Host.Log("out of range, approaching");
  292. ClickMenuEntryOnMenuRoot(AsteroidOverviewEntry, "approach");
  293. }
  294. else
  295. {
  296. Host.Log("locking");
  297. ClickMenuEntryOnMenuRoot(AsteroidOverviewEntry, "^lock");
  298. }
  299.  
  300. return InBeltMineStep;
  301. }
  302.  
  303.  
  304. Sanderling.Parse.IMemoryMeasurement Measurement =>
  305. Sanderling?.MemoryMeasurementParsed?.Value;
  306.  
  307. IWindow ModalUIElement =>
  308. Measurement?.EnumerateReferencedUIElementTransitive()?.OfType<IWindow>()?.Where(window => window?.isModal ?? false)
  309. ?.OrderByDescending(window => window?.InTreeIndex ?? int.MinValue)
  310. ?.FirstOrDefault();
  311.  
  312. Sanderling.Interface.MemoryStruct.IMenu[] Menu => Measurement?.Menu;
  313.  
  314. IShipUi ShipUi => Measurement?.ShipUi;
  315.  
  316. bool Jammed => ShipUi?.EWarElement?.Any(EwarElement => (EwarElement?.EWarType).RegexMatchSuccess("electronic")) ?? false;
  317.  
  318. Sanderling.Interface.MemoryStruct.IMenuEntry MenuEntryLockTarget =>
  319. Menu?.FirstOrDefault()?.Entry?.FirstOrDefault(entry => entry.Text.RegexMatchSuccessIgnoreCase("^lock"));
  320.  
  321. Sanderling.Parse.IWindowOverview WindowOverview =>
  322. Measurement?.WindowOverview?.FirstOrDefault();
  323.  
  324. Sanderling.Parse.IWindowInventory WindowInventory =>
  325. Measurement?.WindowInventory?.FirstOrDefault();
  326.  
  327. IWindowDroneView WindowDrones =>
  328. Measurement?.WindowDroneView?.FirstOrDefault();
  329.  
  330. ITreeViewEntry InventoryActiveShipOreHold =>
  331. WindowInventory?.ActiveShipEntry?.TreeEntryFromCargoSpaceType(ShipCargoSpaceTypeEnum.OreHold);
  332.  
  333. IInventoryCapacityGauge OreHoldCapacityMilli =>
  334. (InventoryActiveShipOreHold?.IsSelected ?? false) ? WindowInventory?.SelectedRightInventoryCapacityMilli : null;
  335.  
  336. int? OreHoldFillPercent => (int?)((OreHoldCapacityMilli?.Used * 100) / OreHoldCapacityMilli?.Max);
  337.  
  338. Tab OverviewPresetTabActive =>
  339. WindowOverview?.PresetTab
  340. ?.OrderByDescending(tab => tab?.LabelColorOpacityMilli ?? 0)
  341. ?.FirstOrDefault();
  342.  
  343. string OverviewTypeSelectionName =>
  344. WindowOverview?.Caption?.RegexMatchIfSuccess(@"\(([^\)]*)\)")?.Groups?[1]?.Value;
  345.  
  346. Parse.IOverviewEntry[] ListRatOverviewEntry => WindowOverview?.ListView?.Entry?.Where(entry =>
  347. (entry?.MainIconIsRed ?? false) && (entry?.IsAttackingMe ?? false))
  348. ?.OrderBy(entry => entry?.DistanceMax ?? int.MaxValue)
  349. ?.ToArray();
  350.  
  351. Parse.IOverviewEntry[] ListAsteroidOverviewEntry =>
  352. WindowOverview?.ListView?.Entry
  353. ?.Where(entry => null != OreTypeFromAsteroidName(entry?.Name))
  354. ?.OrderBy(entry => entry.DistanceMax ?? int.MaxValue)
  355. ?.ToArray();
  356.  
  357.  
  358. DroneViewEntryGroup DronesInBayListEntry =>
  359. WindowDrones?.ListView?.Entry?.OfType<DroneViewEntryGroup>()?.FirstOrDefault(Entry => null != Entry?.Caption?.Text?.RegexMatchIfSuccess(@"Drones in bay", RegexOptions.IgnoreCase));
  360.  
  361. DroneViewEntryGroup DronesInSpaceListEntry =>
  362. WindowDrones?.ListView?.Entry?.OfType<DroneViewEntryGroup>()?.FirstOrDefault(Entry => null != Entry?.Caption?.Text?.RegexMatchIfSuccess(@"Drones in Local Space", RegexOptions.IgnoreCase));
  363.  
  364. int? DronesInSpaceCount => DronesInSpaceListEntry?.Caption?.Text?.AsDroneLabel()?.Status?.TryParseInt();
  365.  
  366. bool ReadyForManeuverNot =>
  367. Measurement?.ShipUi?.Indication?.Any(indication =>
  368. (indication?.Text).RegexMatchSuccessIgnoreCase("warp|docking")) ?? false;
  369.  
  370. bool ReadyForManeuver => !ReadyForManeuverNot && !(Measurement?.IsDocked ?? true);
  371.  
  372. Sanderling.Parse.IShipUiTarget[] SetTargetAsteroid =>
  373. Measurement?.Target?.Where(target =>
  374. target?.TextRow?.Any(textRow => textRow.RegexMatchSuccessIgnoreCase("asteroid")) ?? false)?.ToArray();
  375.  
  376. Sanderling.Interface.MemoryStruct.IListEntry WindowInventoryItem =>
  377. WindowInventory?.SelectedRightInventory?.ListView?.Entry?.FirstOrDefault();
  378.  
  379. Sanderling.Accumulation.IShipUiModule[] SetModuleMiner =>
  380. Sanderling.MemoryMeasurementAccu?.Value?.ShipUiModule?.Where(module => module?.TooltipLast?.Value?.IsMiner ?? false)?.ToArray();
  381.  
  382. Sanderling.Accumulation.IShipUiModule[] SetModuleMinerInactive =>
  383. SetModuleMiner?.Where(module => !(module?.RampActive ?? false))?.ToArray();
  384.  
  385. int? MiningRange => SetModuleMiner?.Select(module =>
  386. module?.TooltipLast?.Value?.RangeOptimal ?? module?.TooltipLast?.Value?.RangeMax ?? module?.TooltipLast?.Value?.RangeWithin ?? 0)?.DefaultIfEmpty(0)?.Min();;
  387.  
  388. // extract the ore type from the name as seen in overview. "Asteroid (Plagioclase)"
  389. string OreTypeFromAsteroidName(string AsteroidName) =>
  390. AsteroidName.ValueFromRegexMatchGroupAtIndex(@"Asteroid \(([^\)]+)", 0);
  391.  
  392. void ClickMenuEntryOnMenuRoot(IUIElement MenuRoot, string MenuEntryRegexPattern)
  393. {
  394. Sanderling.MouseClickRight(MenuRoot);
  395.  
  396. var Menu = Measurement?.Menu?.FirstOrDefault();
  397.  
  398. var MenuEntry = Menu?.EntryFirstMatchingRegexPattern(MenuEntryRegexPattern, RegexOptions.IgnoreCase);
  399.  
  400. Sanderling.MouseClickLeft(MenuEntry);
  401. }
  402.  
  403. void EnsureWindowInventoryOpen()
  404. {
  405. if (null != WindowInventory)
  406. return;
  407.  
  408. Host.Log("open Inventory.");
  409. Sanderling.MouseClickLeft(Measurement?.Neocom?.InventoryButton);
  410. }
  411.  
  412. void EnsureWindowInventoryOpenOreHold()
  413. {
  414. EnsureWindowInventoryOpen();
  415.  
  416. if(!(InventoryActiveShipOreHold?.IsSelected ?? false))
  417. Sanderling.MouseClickLeft(InventoryActiveShipOreHold);
  418. }
  419.  
  420. void UnloadToHangar(string DestinationContainerName)
  421. {
  422. Host.Log("unload to hangar.");
  423.  
  424. EnsureWindowInventoryOpenOreHold();
  425.  
  426. for ( ; ; )
  427. {
  428. var OreHoldItem = WindowInventory?.SelectedRightInventory?.ListView?.Entry?.FirstOrDefault();
  429. var DestinationContainer =
  430. WindowInventory?.LeftTreeListEntry?.SelectMany(entry => new[]{entry}.Concat(entry.EnumerateChildNodeTransitive()))
  431. ?.FirstOrDefault(entry => string.Equals(entry?.Text, DestinationContainerName, StringComparison.InvariantCultureIgnoreCase));
  432.  
  433. if (null == DestinationContainer)
  434. Host.Log("error: Inventory entry labeled '" + DestinationContainerName + "' not found");
  435.  
  436. if(null == OreHoldItem)
  437. break; // 0 items in OreHold
  438. Sanderling.MouseDragAndDrop(OreHoldItem, DestinationContainer);
  439. }
  440. }
  441.  
  442. bool InitiateDockToOrWarpToBookmark(string Bookmark)
  443. {
  444. Host.Log("dock to or warp to bookmark: '" + Bookmark + "'");
  445.  
  446. var ListSurroundingsButton = Measurement?.InfoPanelCurrentSystem?.ListSurroundingsButton;
  447.  
  448. Sanderling.MouseClickRight(ListSurroundingsButton);
  449.  
  450. var BookmarkMenuEntry = Measurement?.Menu?.FirstOrDefault()?.EntryFirstMatchingRegexPattern("^" + Bookmark + "$", RegexOptions.IgnoreCase);
  451.  
  452. if(null == BookmarkMenuEntry)
  453. {
  454. Host.Log("menu entry not found for bookmark: '" + Bookmark + "'");
  455. return true;
  456. }
  457.  
  458. Sanderling.MouseClickLeft(BookmarkMenuEntry);
  459.  
  460. var Menu = Measurement?.Menu?.ElementAtOrDefault(1);
  461. var DockMenuEntry = Menu?.EntryFirstMatchingRegexPattern("dock",RegexOptions.IgnoreCase);
  462. var WarpMenuEntry = Menu?.EntryFirstMatchingRegexPattern(@"warp.*within\s*0",RegexOptions.IgnoreCase);
  463. var ApproachEntry = Menu?.EntryFirstMatchingRegexPattern(@"approach",RegexOptions.IgnoreCase);
  464.  
  465. var MenuEntry = DockMenuEntry ?? WarpMenuEntry;
  466.  
  467. if(null == MenuEntry)
  468. {
  469. if(null != ApproachEntry)
  470. {
  471. Host.Log("found menu entry '" + ApproachEntry.Text + "'. Assuming we are already there.");
  472. return false;
  473. }
  474.  
  475. Host.Log("no suitable menu entry found");
  476. return true;
  477. }
  478.  
  479. Host.Log("initiating " + MenuEntry.Text);
  480. Sanderling.MouseClickLeft(MenuEntry);
  481.  
  482. return false;
  483. }
  484.  
  485. void Undock()
  486. {
  487. Sanderling.MouseClickLeft(Measurement?.WindowStation?.FirstOrDefault()?.UndockButton);
  488.  
  489. Host.Log("waiting for undocking to complete.");
  490. while(Measurement?.IsDocked ?? true) Host.Delay(1111);
  491.  
  492. Host.Delay(4444);
  493. Sanderling.InvalidateMeasurement();
  494. }
  495.  
  496. void ModuleMeasureAllTooltip()
  497. {
  498. Host.Log("measure tooltips of all modules.");
  499.  
  500. for (;;)
  501. {
  502. var NextModule = Sanderling.MemoryMeasurementAccu?.Value?.ShipUiModule?.FirstOrDefault(m => null == m?.TooltipLast);
  503.  
  504. if(null == NextModule)
  505. break;
  506.  
  507. Host.Log("measure module.");
  508. // take multiple measurements of module tooltip to reduce risk to keep bad read tooltip.
  509. Sanderling.MouseMove(NextModule);
  510. Sanderling.WaitForMeasurement();
  511. Sanderling.MouseMove(NextModule);
  512. }
  513. }
  514.  
  515. void ActivateHardenerExecute()
  516. {
  517. var SubsetModuleHardener =
  518. Sanderling.MemoryMeasurementAccu?.Value?.ShipUiModule
  519. ?.Where(module => module?.TooltipLast?.Value?.IsHardener ?? false);
  520.  
  521. var SubsetModuleToToggle =
  522. SubsetModuleHardener
  523. ?.Where(module => !(module?.RampActive ?? false));
  524.  
  525. foreach (var Module in SubsetModuleToToggle.EmptyIfNull())
  526. ModuleToggle(Module);
  527. }
  528.  
  529. void ModuleToggle(Sanderling.Accumulation.IShipUiModule Module)
  530. {
  531. var ToggleKey = Module?.TooltipLast?.Value?.ToggleKey;
  532.  
  533. Host.Log("toggle module using " + (null == ToggleKey ? "mouse" : Module?.TooltipLast?.Value?.ToggleKeyTextLabel?.Text));
  534.  
  535. if(null == ToggleKey)
  536. Sanderling.MouseClickLeft(Module);
  537. else
  538. Sanderling.KeyboardPressCombined(ToggleKey);
  539. }
  540.  
  541. void EnsureOverviewTypeSelectionLoaded()
  542. {
  543. if(null == OverviewPresetTabActive || null == WindowOverview || null == OverviewPreset)
  544. return;
  545.  
  546. if(string.Equals(OverviewTypeSelectionName, OverviewPreset, StringComparison.OrdinalIgnoreCase))
  547. return;
  548.  
  549. Host.Log("loading preset '" + OverviewPreset + "' to overview (current selection is '" + OverviewTypeSelectionName + "').");
  550. Sanderling.MouseClickRight(OverviewPresetTabActive);
  551. Sanderling.MouseClickLeft(Menu?.FirstOrDefault()?.EntryFirstMatchingRegexPattern("load.*preset", RegexOptions.IgnoreCase));
  552. var PresetMenuEntry = Menu?.ElementAtOrDefault(1)?.EntryFirstMatchingRegexPattern(@"^\s*" + Regex.Escape(OverviewPreset) + @"\s*$", RegexOptions.IgnoreCase);
  553.  
  554. if(null == PresetMenuEntry)
  555. {
  556. Host.Log("error: menu entry '" + OverviewPreset + "' not found");
  557. return;
  558. }
  559.  
  560. Sanderling.MouseClickLeft(PresetMenuEntry);
  561. }
  562.  
  563. void MemoryUpdate()
  564. {
  565. EmergencyWarpOutUpdate();
  566. JammedLastTimeUpdate();
  567. OffloadCountUpdate();
  568. }
  569.  
  570. void JammedLastTimeUpdate()
  571. {
  572. if(Jammed)
  573. JammedLastTime = Host.GetTimeContinuousMilli();
  574. }
  575.  
  576. bool MeasurementEmergencyWarpOutEnter =>
  577. !(Measurement?.IsDocked ?? false) && !(EmergencyWarpOutHitpointPercent < ShieldHpPercent);
  578.  
  579. void EmergencyWarpOutUpdate()
  580. {
  581. if (!MeasurementEmergencyWarpOutEnter)
  582. return;
  583.  
  584. // measure multiple times to avoid being scared off by noise from a single measurement.
  585. Sanderling.InvalidateMeasurement();
  586.  
  587. if (!MeasurementEmergencyWarpOutEnter)
  588. return;
  589.  
  590. EmergencyWarpOutEnabled = true;
  591. }
  592.  
  593. void OffloadCountUpdate()
  594. {
  595. var OreHoldFillPercentSynced = OreHoldFillPercent;
  596.  
  597. if(!OreHoldFillPercentSynced.HasValue)
  598. return;
  599.  
  600. if(0 == OreHoldFillPercentSynced && OreHoldFillPercentSynced < LastCheckOreHoldFillPercent)
  601. ++OffloadCount;
  602.  
  603. LastCheckOreHoldFillPercent = OreHoldFillPercentSynced;
  604. }
Advertisement
Add Comment
Please, Sign In to add comment