Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.97 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 Dagobah";
  27.  
  28.  
  29.                 //  //  //      No need to go further if you don't want to tcustomize the script        //  //  //
  30.  
  31.  
  32. bool Tethered => Sanderling?.MemoryMeasurementParsed?.Value?.ShipUi?.EWarElement?.Any(status => (status?.EWarType).RegexMatchSuccess("tethering")) ?? false;
  33. bool ReadyForManeuverNot => Sanderling?.MemoryMeasurementParsed?.Value?.ShipUi?.Indication?.LabelText?.Any(indicationLabel =>   (indicationLabel?.Text).RegexMatchSuccessIgnoreCase("warp|docking")) ?? false;
  34. bool ReadyForManeuver => !ReadyForManeuverNot && !(Sanderling?.MemoryMeasurementParsed?.Value?.IsDocked ?? true);
  35. bool WarpOut = false;
  36. bool EmergencyWarpOutEnabled = false;
  37.  
  38. WindowChatChannel ChanLocal => Sanderling.MemoryMeasurementParsed?.Value?.WindowChatChannel?.FirstOrDefault(windowChat => windowChat?.Caption?.RegexMatchSuccessIgnoreCase(ChanToScout) ?? false);
  39. WindowChatChannel ChanPersonnalIntel => Sanderling.MemoryMeasurementParsed?.Value?.WindowChatChannel?.FirstOrDefault(windowChat => windowChat?.Caption?.RegexMatchSuccessIgnoreCase(PersonnalIntel) ?? false);
  40.  
  41. 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;
  42. 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);
  43. bool hostileOrNeutralsInLocal => 1 != ChanLocal?.ParticipantView?.Entry?.Count(IsNeutralOrEnemy);
  44. bool MeasurementEmergencyWarpOutEnter =>    hostileOrNeutralsInLocal ;
  45.  
  46. Func<object> BotStopActivity = () => null;
  47. Func<object> NextActivity = MainStep;
  48. for(;;)
  49. {   if(null == NextActivity)
  50.         NextActivity = MainStep;
  51.     NextActivity = NextActivity?.Invoke() as Func<object>;
  52. }
  53.  
  54. Func<object> MainStep()
  55. {   EmergencyWarpOutUpdate();
  56.     if (EmergencyWarpOutEnabled)
  57.     {   Host.Log("neutrals or ennemies"); Host.Delay(variation());  }
  58.     else
  59.     {   Host.Delay(variation(909,1212));    }
  60.    
  61.     Sanderling.InvalidateMeasurement();
  62.     Sanderling.WaitForMeasurement();
  63.     if(ShipManeuverTypeEnum.Warp == Sanderling?.MemoryMeasurementParsed?.Value?.ShipUi?.Indication?.ManeuverType)
  64.         WarpOut = true;
  65.    
  66.     if (WarpOut == true)
  67.     {   Host.Log("warping out");
  68.         loop:
  69.         Host.Delay(variation(222,333));
  70.         Sanderling.InvalidateMeasurement();
  71.         Sanderling.WaitForMeasurement();
  72.         if(ShipManeuverTypeEnum.Warp == Sanderling?.MemoryMeasurementParsed?.Value?.ShipUi?.Indication?.ManeuverType)
  73.         {   goto loop;  }   //  do nothing while warping   
  74.         WarpOut = false;
  75.     }
  76.    
  77.     if (EmergencyWarpOutEnabled && !Tethered && !(Sanderling?.MemoryMeasurementParsed?.Value.IsDocked ?? true))
  78.         switch (Action)
  79.         {   case "WARN":
  80.                 Turn();
  81.                 break;
  82.             case "WATCH":
  83.                 Console.Beep(1500, 200); Host.Delay(150); Console.Beep(1500, 200); Host.Delay(variation(800,1200));
  84.                 break;
  85.             default:
  86.                 Turn();
  87.                 break;
  88.         }
  89.        
  90.     return MainStep;
  91. }
  92.  
  93. Random rand => new System.Random();
  94. int variation(int min=175, int max=350) {return rand.Next(min, max);}
  95.  
  96. T RandomElement<T>(IEnumerable<T> seq)
  97. {   var counted = seq?.ToArray();
  98.     if(!(0 < counted?.Length))
  99.         return default(T);
  100.     return counted[rand.Next(counted.Length)];
  101. }
  102.  
  103. bool Turn()
  104. {   Host.Log("Turning");
  105.     var ListSurroundingsButton = Sanderling.MemoryMeasurementParsed?.Value?.InfoPanelCurrentSystem?.ListSurroundingsButton;
  106.     Sanderling.MouseClickRight(ListSurroundingsButton);
  107.     Host.Delay(variation());
  108.     string SSFolderBookmark = RandomElement(SafeSpots);
  109.     var FolderMenuEntry = Sanderling.MemoryMeasurementParsed?.Value?.Menu?.ElementAtOrDefault(0)?.EntryFirstMatchingRegexPattern("^" + SSFolderBookmark + "$", RegexOptions.IgnoreCase);
  110.     Sanderling.MouseClickLeft(FolderMenuEntry);
  111.     Host.Delay(variation());
  112.     int NbSF = Sanderling.MemoryMeasurementParsed?.Value?.Menu?.ElementAtOrDefault(1)?.Entry?.Count()??0;
  113.     var BookmarkMenuEntry = Sanderling.MemoryMeasurementParsed?.Value?.Menu?.ElementAtOrDefault(1)?.Entry?.ElementAtOrDefault(variation(0,NbSF));
  114.     Sanderling.MouseClickLeft(BookmarkMenuEntry);
  115.     Host.Delay(variation());
  116.     var Menu = Sanderling?.MemoryMeasurementParsed?.Value?.Menu?.Last();
  117.     var WarpMenuEntry = Menu?.EntryFirstMatchingRegexPattern(@"warp.*within\s*0",RegexOptions.IgnoreCase);
  118.     if(null == WarpMenuEntry)
  119.     {   return false;       }
  120.     Host.Delay(variation());
  121.     Sanderling.MouseClickLeft(WarpMenuEntry);  
  122.  
  123.     WarpOut = true;
  124.     return true;
  125. }
  126.  
  127. void EmergencyWarpOutUpdate()
  128. {
  129.     if (!MeasurementEmergencyWarpOutEnter)
  130.     {   EmergencyWarpOutEnabled = false;
  131.         return;}
  132.     Sanderling.InvalidateMeasurement();
  133.     Sanderling.WaitForMeasurement();
  134.     if (!MeasurementEmergencyWarpOutEnter)
  135.     {   EmergencyWarpOutEnabled = false;
  136.         return;}
  137.        
  138.     var WarnZone = ChanPersonnalIntel?.MessageInput;
  139.     if (!EmergencyWarpOutEnabled)
  140.     {   if (Action == "WARN")
  141.         {   Console.Beep(1500, 2200);
  142.             Sanderling.MouseClickLeft(WarnZone);
  143.             Sanderling.TextEntry(WarningText);
  144.             Sanderling.KeyboardPress(VirtualKeyCode.RETURN);       
  145.         }
  146.     }
  147.            
  148.     EmergencyWarpOutEnabled = true;
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement