Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Fleet Mining Script V0.3
- // by Rayitaly
- //
- // For Fleetminig
- // Role Minier
- // - Script auto Unload to Fleet Hanger
- // - Script "Keep at Range" automaticly
- // - Script Alert if no FleetHanger
- // -
- using BotSharp.ToScript.Extension;
- using MemoryStruct = Sanderling.Interface.MemoryStruct;
- using Parse = Sanderling.Parse;
- // begin of configuration section for variables ->
- //Unload Settings
- var EnterOffloadOreHoldFillPercent = 60;
- string UnloadDestContainerName = "Fleet Hangar";
- //Follow settings
- bool FollowShip = true;
- string FollowShipName = "Pheebe Pouch";
- //var FollowShipDistance = "1000m";
- // <- end of configuration section
- // ################################### Script START ##########################################
- Func<object> BotStopActivity = () => null;
- Func<object> NextActivity = Step1;
- //Loop
- for(;;)
- {
- Host.Log(
- "FollowActive: " + FollowActive + " " +
- ", FoundShip: " + ListFollowShipOverviewEntry?.Length +
- "; ore hold fill: " + OreHoldFillPercent + "% (" + EnterOffloadOreHoldFillPercent + "%) "+
- "; nextAct: " + NextActivity?.Method?.Name);
- NextActivity = NextActivity?.Invoke() as Func<object>;
- if(BotStopActivity == NextActivity)
- {
- Host.Log("BotStop, no Next Activity?");
- break;
- }
- if(null == NextActivity)
- NextActivity = Step1;
- }
- // Steps for Working
- Func<object> Step1()
- {
- //##### Check Connection #####
- //Load Sanderlin infos in Variable "Measurement"
- Sanderling.Parse.IMemoryMeasurement Measurement = Sanderling?.MemoryMeasurementParsed?.Value;
- // Search for Word in "Measurement"
- var ConnectionLost = Measurement?.WindowOther?.FirstOrDefault()?.LabelText?.FirstOrDefault(text => (text?.Text.RegexMatchSuccessIgnoreCase("Connection") ?? false));
- if (ConnectionLost != null) //When found than...
- {
- Host.Log(" *** Lost connection at : " + DateTime.Now.ToString(" HH:mm:ss")+ " *** " );
- Console.Beep(1000,200);Console.Beep(800,250);Console.Beep(600,350);
- return BotStopActivity;
- }
- else //if not than...
- {
- //Host.Log(" *** Bot Running at : " + DateTime.Now.ToString(" HH:mm:ss")+ " *** " );
- }//##### Check Connection #####
- EnsureWindowInventoryOpenOreHold();
- //Check ShipHanger is in InventoryIndex
- var DestinationContainer =
- WindowInventory?.LeftTreeListEntry?.SelectMany(entry => new[] { entry }.Concat(entry.EnumerateChildNodeTransitive()))
- ?.FirstOrDefault(entry => entry?.Text?.RegexMatchSuccessIgnoreCase(UnloadDestContainerName, RegexOptions.IgnoreCase ) ?? false);
- if (null == DestinationContainer ){
- Console.Beep(1000,200);Console.Beep(800,250);Console.Beep(600,350);
- Host.Log(" Connect FrendlyShipHanger ");
- }
- //Check ShipHanger is in InventoryIndex
- //##### Unload #####
- if (OreHoldFilledForOffload)
- {
- InInventoryUnloadItems();
- return Step1();
- }//##### Unload #####
- //##### Follow #####
- if(FollowShip){
- //check if not active
- if(!(FollowActive)){
- Console.Beep(1000,200);Console.Beep(800,250);Console.Beep(600,350);
- Sanderling.MouseClickRight(ListFollowShipOverviewEntry?.FirstOrDefault());
- var firstmenu = Sanderling.MemoryMeasurementParsed?.Value?.Menu?.FirstOrDefault()?.EntryFirstMatchingRegexPattern("^Keep at Range$", RegexOptions.IgnoreCase);
- Sanderling.MouseClickLeft(firstmenu);
- var secondmenu = Sanderling.MemoryMeasurementParsed?.Value?.Menu?.ElementAt(1)?.Entry?.ElementAt(1);
- Host.Log("Second: "+ secondmenu.Text);
- Sanderling.MouseClickLeft(secondmenu);
- }
- }//##### Follow #####
- //Wait a while
- Host.Log(" *** Waiting 3sec *** " );
- Host.Delay(3000);
- // Jump back to Start
- return NextActivity;
- }
- // ##### Variables #####
- //### Standard Measurment ####
- Sanderling.Parse.IMemoryMeasurement Measurement =>
- Sanderling?.MemoryMeasurementParsed?.Value;
- // Inventory Measurement
- Sanderling.Parse.IWindowInventory WindowInventory =>
- Measurement?.WindowInventory?.FirstOrDefault();
- // Overview Measurement
- Sanderling.Parse.IWindowOverview WindowOverview =>
- Measurement?.WindowOverview?.FirstOrDefault();
- IEnumerable<Parse.IMenu> Menu => Measurement?.Menu;
- ITreeViewEntry InventoryActiveShipOreHold =>
- WindowInventory?.ActiveShipEntry?.TreeEntryFromCargoSpaceType(ShipCargoSpaceTypeEnum.OreHold);
- IInventoryCapacityGauge OreHoldCapacityMilli =>
- (InventoryActiveShipOreHold?.IsSelected ?? false) ? WindowInventory?.SelectedRightInventoryCapacityMilli : null;
- //Find FollowShip in Overview
- Parse.IOverviewEntry[] ListFollowShipOverviewEntry => WindowOverview?.ListView?.Entry?.Where(entry =>
- entry?.Name?.RegexMatchSuccessIgnoreCase(FollowShipName, RegexOptions.IgnoreCase ) ?? false)
- ?.OrderBy(entry => entry?.DistanceMax ?? int.MaxValue)
- ?.ToArray();
- //Check Keep At Range
- bool FollowActive =>
- Measurement?.ShipUi?.Indication?.LabelText?.Any(indicationLabel =>
- (indicationLabel?.Text).RegexMatchSuccessIgnoreCase("keeping")) ?? false;
- int? OreHoldFillPercent =>
- (int?)((OreHoldCapacityMilli?.Used * 100) / OreHoldCapacityMilli?.Max);
- bool OreHoldFilledForOffload => Math.Max(0, Math.Min(100, EnterOffloadOreHoldFillPercent)) <= OreHoldFillPercent;
- // ##### Voids #####
- void InInventoryUnloadItems() => InInventoryUnloadItemsTo(UnloadDestContainerName);
- void InInventoryUnloadItemsTo(string DestinationContainerName)
- {
- Host.Log("start unload items to '" + DestinationContainerName + "'.");
- EnsureWindowInventoryOpenOreHold();
- for (;;)
- {
- var oreHoldListItem = WindowInventory?.SelectedRightInventory?.ListView?.Entry?.ToArray();
- var oreHoldItem = oreHoldListItem?.FirstOrDefault();
- if(null == oreHoldItem)
- {
- Host.Log("done unload items");
- break; // 0 items in OreHold
- }
- if(1 < oreHoldListItem?.Length)
- ClickMenuEntryOnMenuRoot(oreHoldItem, @"select\s*all");
- var DestinationContainer =
- WindowInventory?.LeftTreeListEntry?.SelectMany(entry => new[] { entry }.Concat(entry.EnumerateChildNodeTransitive()))
- ?.FirstOrDefault(entry => entry?.Text?.RegexMatchSuccessIgnoreCase(DestinationContainerName, RegexOptions.IgnoreCase ) ?? false);
- if (null == DestinationContainer)
- Host.Log("error: Inventory entry labeled '" + DestinationContainerName + "' not found");
- Sanderling.MouseDragAndDrop(oreHoldItem, DestinationContainer);
- }
- }
- void EnsureWindowInventoryOpenOreHold()
- {
- EnsureWindowInventoryOpen();
- var inventoryActiveShip = WindowInventory?.ActiveShipEntry;
- if(InventoryActiveShipOreHold == null && !(inventoryActiveShip?.IsExpanded ?? false))
- Sanderling.MouseClickLeft(inventoryActiveShip?.ExpandToggleButton);
- if(!(InventoryActiveShipOreHold?.IsSelected ?? false))
- Sanderling.MouseClickLeft(InventoryActiveShipOreHold);
- }
- void ClickMenuEntryOnMenuRoot(IUIElement MenuRoot, string MenuEntryRegexPattern)
- {
- Sanderling.MouseClickRight(MenuRoot);
- var Menu = Measurement?.Menu?.FirstOrDefault();
- var MenuEntry = Menu?.EntryFirstMatchingRegexPattern(MenuEntryRegexPattern, RegexOptions.IgnoreCase);
- Sanderling.MouseClickLeft(MenuEntry);
- }
- void EnsureWindowInventoryOpen()
- {
- if (null != WindowInventory)
- return;
- Host.Log("open Inventory.");
- Sanderling.MouseClickLeft(Measurement?.Neocom?.InventoryButton);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement