Advertisement
Guest User

Untitled

a guest
Feb 25th, 2019
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.61 KB | None | 0 0
  1. using BotSharp.ToScript.Extension;
  2. using Parse = Sanderling.Parse;
  3. using System.Timers;
  4. using BotEngine.Interface;
  5.     // If the action is to WARN you: This script will warn you on a defined (by you) chan if neutrals or
  6. //ennemies are in the scout current system and (if not docked or tethered) start warping between safe spots randomly
  7. //during the neutral presence. (random planet or asteroid by default). It warns you by both anoing console beep AND
  8. //write a predefined text in your peronnal intel chan, to make it blink so it visualy warns you on your main.
  9.     // If the action is to WATCH: While not docked, in warp or tethered, the script will play a sound to warn you if a
  10. //neutral or ennemy has entered your system.
  11.  
  12. // Be sure to have the local chan solo and visible. Be sure your intel chan is visible both on your scout AND your main... ("blink on" strongly recommended )
  13. // If you have a safe spot folder, replace the "Ateroid Belts","Planets" folder by its name.
  14. // Create your private chan, join it with your scout(s) and your main and define it as your PersonnalIntel.
  15. // Start and fly safe.
  16.  
  17.                                                         //      What do you want the script to do for you?      //
  18. //WARN your main account with a scout placed in an other system or WATCH at your Local and beep when an ennemy enters yous system.
  19. string Action = "WATCH"; // Here enter WARN or WATCH
  20.                                                     //      Where do you want the script to pick your warping spots?        //
  21. string[] SafeSpots = {"Asteroid Belts","Planets"};
  22.                                                         //      Where do the script watch and where it warns        //
  23. string PersonnalIntel = "PersonnalIntel";
  24. string ChanToScout = "Local";
  25.                                                         //      What do you want the script to write to warn you        //
  26. string WarningText = "Neutral Or Ennemy in System XXX-xxx";
  27. string ClearText = "System XXX-xxx Clear";
  28.  
  29.  
  30.  
  31.                                             //  //  //      No need to go further if you don't want to tcustomize the script        //  //  //
  32.  
  33.  
  34. bool Tethered => Sanderling?.MemoryMeasurementParsed?.Value?.ShipUi?.EWarElement?.Any(status => (status?.EWarType).RegexMatchSuccess("tethering")) ?? false;
  35. bool ReadyForManeuverNot => Sanderling?.MemoryMeasurementParsed?.Value?.ShipUi?.Indication?.LabelText?.Any(indicationLabel =>   (indicationLabel?.Text).RegexMatchSuccessIgnoreCase("warp|docking")) ?? false;
  36. bool ReadyForManeuver => !ReadyForManeuverNot && !(Sanderling?.MemoryMeasurementParsed?.Value?.IsDocked ?? true);
  37. bool WarpOut = false;
  38. bool EmergencyWarpOutEnabled = false;
  39.  
  40. WindowChatChannel ChanLocal => Sanderling.MemoryMeasurementParsed?.Value?.WindowChatChannel?.FirstOrDefault(windowChat => windowChat?.Caption?.RegexMatchSuccessIgnoreCase(ChanToScout) ?? false);
  41. WindowChatChannel ChanPersonnalIntel => Sanderling.MemoryMeasurementParsed?.Value?.WindowChatChannel?.FirstOrDefault(windowChat => windowChat?.Caption?.RegexMatchSuccessIgnoreCase(PersonnalIntel) ?? false);
  42.  
  43. Sanderling.Interface.MemoryStruct.IChatParticipantEntry[] Ennemies => ChanLocal?.Participant ?.Where(entry => !entry?.FlagIcon?.Any(flagIcon => new[] { "good standing", "excellent standing", "Pilot is in your (alliance|fleet|corporation)", } .Any(goodStandingText => flagIcon?.HintText?.RegexMatchSuccessIgnoreCase(goodStandingText) ?? false)) ?? false)?.ToArray() ?? null;
  44. bool IsNeutralOrEnemy(IChatParticipantEntry participantEntry) =>   !(participantEntry?.FlagIcon?.Any(flagIcon => new[] { "good standing", "excellent standing", "Pilot is in your (alliance|fleet|corporation)", } .Any(goodStandingText => flagIcon?.HintText?.RegexMatchSuccessIgnoreCase(goodStandingText) ?? false)) ?? false);
  45. bool hostileOrNeutralsInLocal => 1 != ChanLocal?.ParticipantView?.Entry?.Count(IsNeutralOrEnemy);
  46. bool MeasurementEmergencyWarpOutEnter =>    hostileOrNeutralsInLocal ;
  47.  
  48.  
  49. Host.Delay(8000);
  50. Func<object> BotStopActivity = () => null;
  51. Func<object> NextActivity = MainStep;
  52. for(;;)
  53. {   if(null == NextActivity)
  54.         NextActivity = MainStep;
  55.     NextActivity = NextActivity?.Invoke() as Func<object>;
  56. }
  57.  
  58. Func<object> MainStep()
  59. {   Host.Log("Mainstep");
  60.  
  61.     EmergencyWarpOutUpdate();
  62.     if (EmergencyWarpOutEnabled)
  63.     {   Host.Log("neutrals or ennemies"); Host.Delay(variation());  }
  64.     else
  65.     {   Host.Delay(variation(909,1212));    }
  66.    
  67.     Sanderling.InvalidateMeasurement();
  68.     Sanderling.WaitForMeasurement();
  69.     if(ShipManeuverTypeEnum.Warp == Sanderling?.MemoryMeasurementParsed?.Value?.ShipUi?.Indication?.ManeuverType)
  70.         WarpOut = true;
  71.    
  72.     if (WarpOut == true)
  73.     {   Host.Log("warping out");
  74.         Host.Delay(variation());
  75.         Sanderling.InvalidateMeasurement();
  76.         Sanderling.WaitForMeasurement();
  77.         goto loop11;
  78.         loop:
  79.         Host.Delay(variation());
  80.         Sanderling.InvalidateMeasurement();
  81.         Sanderling.WaitForMeasurement();
  82.         loop11:
  83.         if(ShipManeuverTypeEnum.Warp == Sanderling?.MemoryMeasurementParsed?.Value?.ShipUi?.Indication?.ManeuverType)
  84.         {   goto loop;  }   //  do nothing while warping   
  85.         WarpOut = false;
  86.     }
  87.    
  88.     if (EmergencyWarpOutEnabled && !Tethered && !(Sanderling?.MemoryMeasurementParsed?.Value.IsDocked ?? true))
  89.         switch (Action)
  90.         {   case "WARN":
  91.                 Turn();
  92.                 break;
  93.             case "WATCH":
  94.                 Console.Beep(1500, 200); Host.Delay(150); Console.Beep(1500, 200); Host.Delay(variation(800,1200));
  95.                 break;
  96.             default:
  97.                 Turn();
  98.                 break;
  99.         }
  100.        
  101.     return MainStep;
  102. }
  103.  
  104. Random rand => new System.Random();
  105. int variation(int min=175, int max=350) {return rand.Next(min, max);}
  106.  
  107. T RandomElement<T>(IEnumerable<T> seq)
  108. {   var counted = seq?.ToArray();
  109.     if(!(0 < counted?.Length))
  110.         return default(T);
  111.     return counted[rand.Next(counted.Length)];
  112. }
  113.  
  114. bool Turn()
  115. {   Host.Log("Turning");
  116.     var ListSurroundingsButton = Sanderling.MemoryMeasurementParsed?.Value?.InfoPanelCurrentSystem?.ListSurroundingsButton;
  117.     Sanderling.MouseClickRight(ListSurroundingsButton);
  118.     Host.Delay(variation());
  119.     string SSFolderBookmark = RandomElement(SafeSpots);
  120.     var FolderMenuEntry = Sanderling.MemoryMeasurementParsed?.Value?.Menu?.ElementAtOrDefault(0)?.EntryFirstMatchingRegexPattern("^" + SSFolderBookmark + "$", RegexOptions.IgnoreCase);
  121.     Sanderling.MouseClickLeft(FolderMenuEntry);
  122.     Host.Delay(variation());
  123.     int NbSF = Sanderling.MemoryMeasurementParsed?.Value?.Menu?.ElementAtOrDefault(1)?.Entry?.Count()??0;
  124.     var BookmarkMenuEntry = Sanderling.MemoryMeasurementParsed?.Value?.Menu?.ElementAtOrDefault(1)?.Entry?.ElementAtOrDefault(variation(0,NbSF));
  125.     Sanderling.MouseClickLeft(BookmarkMenuEntry);
  126.     Host.Delay(variation());
  127.     var Menu = Sanderling?.MemoryMeasurementParsed?.Value?.Menu?.Last();
  128.     var WarpMenuEntry = Menu?.EntryFirstMatchingRegexPattern(@"warp.*within\s*0",RegexOptions.IgnoreCase);
  129.     if(null == WarpMenuEntry)
  130.     {   return false;       }
  131.     Host.Delay(variation());
  132.     Sanderling.MouseClickLeft(WarpMenuEntry);  
  133.  
  134.     WarpOut = true;
  135.     return true;
  136. }
  137.  
  138. void EmergencyWarpOutUpdate()
  139. {   var WarnZone = ChanPersonnalIntel?.MessageInput;
  140.     if (!MeasurementEmergencyWarpOutEnter)
  141.     {   if (EmergencyWarpOutEnabled)
  142.         {   if (Action == "WARN")
  143.             {   Sanderling.MouseClickLeft(WarnZone);
  144.                 Sanderling.TextEntry(ClearText);
  145.                 Sanderling.KeyboardPress(VirtualKeyCode.RETURN);    }
  146.         }
  147.         EmergencyWarpOutEnabled = false;
  148.         return;
  149.     }
  150.     Sanderling.InvalidateMeasurement();
  151.     Sanderling.WaitForMeasurement();
  152.     if (!MeasurementEmergencyWarpOutEnter)
  153.     {   if (EmergencyWarpOutEnabled)
  154.         {   if (Action == "WARN")
  155.             {   Sanderling.MouseClickLeft(WarnZone);
  156.                 Sanderling.TextEntry(ClearText);
  157.                 Sanderling.KeyboardPress(VirtualKeyCode.RETURN);    }
  158.         }
  159.         EmergencyWarpOutEnabled = false;
  160.         return;
  161.     }
  162.        
  163.     if (!EmergencyWarpOutEnabled)
  164.     {   if (Action == "WARN")
  165.         {   Console.Beep(1500, 2200);
  166.             Sanderling.MouseClickLeft(WarnZone);
  167.             Sanderling.TextEntry(WarningText);
  168.             Sanderling.KeyboardPress(VirtualKeyCode.RETURN);       
  169.         }
  170.     }
  171.            
  172.     EmergencyWarpOutEnabled = true;
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement