Advertisement
Guest User

Fleet Mining Script V0.3

a guest
Mar 17th, 2019
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.19 KB | None | 0 0
  1.  
  2. //    Fleet Mining Script V0.3
  3. // by Rayitaly
  4. //
  5. // For Fleetminig
  6. // Role Minier
  7. // - Script auto Unload to Fleet Hanger
  8. // - Script "Keep at Range" automaticly
  9. // - Script Alert if no FleetHanger
  10. // -
  11.  
  12. using BotSharp.ToScript.Extension;
  13. using MemoryStruct = Sanderling.Interface.MemoryStruct;
  14. using Parse = Sanderling.Parse;
  15.  
  16. //  begin of configuration section for variables ->
  17.  
  18. //Unload Settings
  19. var EnterOffloadOreHoldFillPercent = 60;
  20.  
  21. string UnloadDestContainerName = "Fleet Hangar";
  22.  
  23. //Follow settings
  24. bool FollowShip = true;
  25.  
  26. string FollowShipName = "Pheebe Pouch";
  27.  
  28. //var FollowShipDistance = "1000m";
  29.  
  30. //  <- end of configuration section
  31.  
  32. // ################################### Script  START ##########################################
  33.  
  34. Func<object> BotStopActivity = () => null;
  35.  
  36. Func<object> NextActivity = Step1;
  37.  
  38. //Loop
  39. for(;;)
  40. {  
  41.    
  42.    
  43.    
  44.     Host.Log(
  45.         "FollowActive: " + FollowActive + " " +
  46.         ", FoundShip: " + ListFollowShipOverviewEntry?.Length +
  47.         "; ore hold fill: " + OreHoldFillPercent + "% (" + EnterOffloadOreHoldFillPercent + "%) "+
  48.         "; nextAct: " + NextActivity?.Method?.Name);
  49.        
  50.     NextActivity = NextActivity?.Invoke() as Func<object>;
  51.    
  52.     if(BotStopActivity == NextActivity)
  53.     {
  54.         Host.Log("BotStop, no Next Activity?");
  55.         break;
  56.     }
  57.  
  58.     if(null == NextActivity)
  59.         NextActivity = Step1;
  60. }
  61.  
  62. // Steps for Working
  63. Func<object>    Step1()
  64. {  
  65.     //##### Check Connection #####
  66.     //Load Sanderlin infos in Variable "Measurement"
  67.     Sanderling.Parse.IMemoryMeasurement Measurement =   Sanderling?.MemoryMeasurementParsed?.Value;
  68.    
  69.     // Search for Word in "Measurement"
  70.     var ConnectionLost = Measurement?.WindowOther?.FirstOrDefault()?.LabelText?.FirstOrDefault(text => (text?.Text.RegexMatchSuccessIgnoreCase("Connection") ?? false));
  71.    
  72.     if (ConnectionLost != null) //When found than...
  73.     {
  74.         Host.Log(" ***              Lost connection at : " + DateTime.Now.ToString(" HH:mm:ss")+ " ***   " );
  75.         Console.Beep(1000,200);Console.Beep(800,250);Console.Beep(600,350);
  76.         return BotStopActivity;
  77.     }
  78.     else //if not than...
  79.     {
  80.         //Host.Log(" ***              Bot Running at : " + DateTime.Now.ToString(" HH:mm:ss")+ " ***   " );
  81.     }//##### Check Connection #####
  82.    
  83.     EnsureWindowInventoryOpenOreHold();
  84.    
  85.     //Check ShipHanger is in InventoryIndex
  86.     var DestinationContainer =
  87.         WindowInventory?.LeftTreeListEntry?.SelectMany(entry => new[] { entry }.Concat(entry.EnumerateChildNodeTransitive()))
  88.         ?.FirstOrDefault(entry => entry?.Text?.RegexMatchSuccessIgnoreCase(UnloadDestContainerName, RegexOptions.IgnoreCase ) ?? false);
  89.     if (null == DestinationContainer ){
  90.         Console.Beep(1000,200);Console.Beep(800,250);Console.Beep(600,350);
  91.         Host.Log(" Connect FrendlyShipHanger ");
  92.     }
  93.     //Check ShipHanger is in InventoryIndex
  94.    
  95.     //##### Unload #####
  96.     if (OreHoldFilledForOffload)
  97.     {
  98.         InInventoryUnloadItems();
  99.         return Step1();
  100.     }//##### Unload #####
  101.    
  102.     //##### Follow #####
  103.     if(FollowShip){
  104.         //check if not active
  105.         if(!(FollowActive)){
  106.             Console.Beep(1000,200);Console.Beep(800,250);Console.Beep(600,350);
  107.             Sanderling.MouseClickRight(ListFollowShipOverviewEntry?.FirstOrDefault());
  108.             var firstmenu = Sanderling.MemoryMeasurementParsed?.Value?.Menu?.FirstOrDefault()?.EntryFirstMatchingRegexPattern("^Keep at Range$", RegexOptions.IgnoreCase);
  109.             Sanderling.MouseClickLeft(firstmenu);
  110.             var secondmenu = Sanderling.MemoryMeasurementParsed?.Value?.Menu?.ElementAt(1)?.Entry?.ElementAt(1);
  111.             Host.Log("Second: "+ secondmenu.Text);
  112.             Sanderling.MouseClickLeft(secondmenu);
  113.         }
  114.     }//##### Follow #####
  115.    
  116.     //Wait a while
  117.     Host.Log(" ***  Waiting 3sec ***   " );
  118.     Host.Delay(3000);
  119.    
  120.     // Jump back to Start
  121.     return NextActivity;
  122. }
  123.  
  124. // ##### Variables #####
  125.  
  126. //### Standard Measurment ####
  127. Sanderling.Parse.IMemoryMeasurement Measurement =>
  128.     Sanderling?.MemoryMeasurementParsed?.Value;
  129. // Inventory Measurement
  130. Sanderling.Parse.IWindowInventory   WindowInventory =>
  131.     Measurement?.WindowInventory?.FirstOrDefault();
  132. // Overview Measurement
  133. Sanderling.Parse.IWindowOverview    WindowOverview  =>
  134.     Measurement?.WindowOverview?.FirstOrDefault();
  135.    
  136. IEnumerable<Parse.IMenu> Menu => Measurement?.Menu;
  137.    
  138. ITreeViewEntry InventoryActiveShipOreHold =>
  139.     WindowInventory?.ActiveShipEntry?.TreeEntryFromCargoSpaceType(ShipCargoSpaceTypeEnum.OreHold);
  140.    
  141. IInventoryCapacityGauge OreHoldCapacityMilli    =>
  142.     (InventoryActiveShipOreHold?.IsSelected ?? false) ? WindowInventory?.SelectedRightInventoryCapacityMilli : null;   
  143.  
  144. //Find FollowShip in Overview          
  145. Parse.IOverviewEntry[] ListFollowShipOverviewEntry => WindowOverview?.ListView?.Entry?.Where(entry =>
  146.     entry?.Name?.RegexMatchSuccessIgnoreCase(FollowShipName, RegexOptions.IgnoreCase ) ?? false)
  147.     ?.OrderBy(entry => entry?.DistanceMax ?? int.MaxValue)
  148.     ?.ToArray();
  149.  
  150. //Check Keep At Range
  151. bool FollowActive =>
  152.     Measurement?.ShipUi?.Indication?.LabelText?.Any(indicationLabel =>
  153.         (indicationLabel?.Text).RegexMatchSuccessIgnoreCase("keeping")) ?? false;
  154.  
  155. int? OreHoldFillPercent =>
  156.     (int?)((OreHoldCapacityMilli?.Used * 100) / OreHoldCapacityMilli?.Max);
  157.    
  158. bool OreHoldFilledForOffload => Math.Max(0, Math.Min(100, EnterOffloadOreHoldFillPercent)) <= OreHoldFillPercent;
  159.  
  160. // ##### Voids #####
  161.  
  162. void InInventoryUnloadItems() => InInventoryUnloadItemsTo(UnloadDestContainerName);
  163.  
  164. void InInventoryUnloadItemsTo(string DestinationContainerName)
  165. {
  166.     Host.Log("start unload items to '" + DestinationContainerName + "'.");
  167.  
  168.     EnsureWindowInventoryOpenOreHold();
  169.  
  170.     for (;;)
  171.     {
  172.         var oreHoldListItem = WindowInventory?.SelectedRightInventory?.ListView?.Entry?.ToArray();
  173.  
  174.         var oreHoldItem = oreHoldListItem?.FirstOrDefault();
  175.  
  176.         if(null == oreHoldItem)
  177.         {  
  178.             Host.Log("done unload items");
  179.             break;    //    0 items in OreHold
  180.         }
  181.        
  182.         if(1 < oreHoldListItem?.Length)
  183.             ClickMenuEntryOnMenuRoot(oreHoldItem, @"select\s*all");
  184.  
  185.         var DestinationContainer =
  186.             WindowInventory?.LeftTreeListEntry?.SelectMany(entry => new[] { entry }.Concat(entry.EnumerateChildNodeTransitive()))
  187.             ?.FirstOrDefault(entry => entry?.Text?.RegexMatchSuccessIgnoreCase(DestinationContainerName, RegexOptions.IgnoreCase ) ?? false);
  188.  
  189.         if (null == DestinationContainer)
  190.             Host.Log("error: Inventory entry labeled '" + DestinationContainerName + "' not found");
  191.  
  192.         Sanderling.MouseDragAndDrop(oreHoldItem, DestinationContainer);
  193.     }
  194. }
  195.  
  196. void EnsureWindowInventoryOpenOreHold()
  197. {
  198.     EnsureWindowInventoryOpen();
  199.  
  200.     var inventoryActiveShip = WindowInventory?.ActiveShipEntry;
  201.  
  202.     if(InventoryActiveShipOreHold == null && !(inventoryActiveShip?.IsExpanded ?? false))
  203.         Sanderling.MouseClickLeft(inventoryActiveShip?.ExpandToggleButton);
  204.  
  205.     if(!(InventoryActiveShipOreHold?.IsSelected ?? false))
  206.         Sanderling.MouseClickLeft(InventoryActiveShipOreHold);
  207. }
  208.  
  209. void ClickMenuEntryOnMenuRoot(IUIElement MenuRoot, string MenuEntryRegexPattern)
  210. {
  211.     Sanderling.MouseClickRight(MenuRoot);
  212.    
  213.     var Menu = Measurement?.Menu?.FirstOrDefault();
  214.    
  215.     var MenuEntry = Menu?.EntryFirstMatchingRegexPattern(MenuEntryRegexPattern, RegexOptions.IgnoreCase);
  216.    
  217.     Sanderling.MouseClickLeft(MenuEntry);
  218. }
  219.  
  220. void EnsureWindowInventoryOpen()
  221. {
  222.     if (null != WindowInventory)
  223.         return;
  224.  
  225.     Host.Log("open Inventory.");
  226.     Sanderling.MouseClickLeft(Measurement?.Neocom?.InventoryButton);
  227. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement