Advertisement
PsyOps

KillStuff

May 6th, 2014
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 14.80 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. using BattleCore;
  7. using BattleCore.Events;
  8. using BattleCorePsyOps;
  9. using System.Timers;
  10.  
  11. namespace BZOps
  12. {
  13.     // Add the attribute and the base class
  14.     [Behavior("Main", "false", "0.01", "PsyOps", "Main module to control Battle Zone.")]
  15.     public class Main:BotEventListener
  16.     {
  17.         public Main()
  18.         {
  19.             RegisterTimedEvent("MainTimer", 10, updateMainTimer);
  20.             RegisterCommand("!sc", doSC);
  21.             RegisterCommand("!list", doList);
  22.  
  23.             // debug mode set to true
  24.             msg.DebugMode = true;
  25.             // make sure spam control is on for module
  26.             msg.SpamControl = true;
  27.             // Log bot into chan
  28.             msg.SCPubCommand("?chat=battledev,battle");
  29.         }
  30.  
  31.         public void doList(ChatEvent c)
  32.         {
  33.             Game(msg.pm(c.PlayerName, "-------------------------------<[ Player List ]>-------------------------------"));
  34.             Game(msg.pm(c.PlayerName, "   Name         | Status | Freq   | Custom Ship 1"));
  35.             Game(msg.pm(c.PlayerName, "----------------+--------+--------+--------------------------------------------"));
  36.             for (int i = 0; i < PlayerList.Count; i += 1)
  37.             {
  38.                 Game(msg.pm(c.PlayerName, PlayerList[i].PlayerName.PadRight(16) + "| "
  39.                     + PlayerList[i].Status.ToString().PadRight(7) + "| "
  40.                     + PlayerList[i].OnFreq.ToString().PadRight(7) + "| "
  41.                     + PlayerList[i].CustomShip1.ToString().PadRight(13)));
  42.             }
  43.         }
  44.  
  45.         // ---------------------------------------------------------- CHAT COMMANDS //
  46.         // ------------------------------------------------------------------------//
  47.         // Sets shiptype for each slot
  48.         public void doSC(ChatEvent c)
  49.         {
  50.             Player p = GetPlayer(c.PlayerName);
  51.  
  52.             if (p == null || c.Message.Length <= 3 || !c.Message.Contains(" ")) return;
  53.  
  54.             string[] info = c.Message.Split(' ');
  55.             int num = 0;
  56.             bool isNum = int.TryParse(info[1], out num);
  57.             if (!int.TryParse(info[1], out num)) return;
  58.             switch (num)
  59.             {
  60.                 case 1:
  61.                     p.CustomShip1 = CustomShip.SVS_Warbird;
  62.                     Game(msg.pm(c.PlayerName, "Your ship 1 has been set to [ Ship: " + p.CustomShip1 + " ]"));
  63.                     break;
  64.                 case 2:
  65.                     p.CustomShip1 = CustomShip.SVS_Javelin;
  66.                     Game(msg.pm(c.PlayerName, "Your ship 1 has been set to [ Ship: " + p.CustomShip1 + " ]"));
  67.                     break;
  68.                 case 3:
  69.                     p.CustomShip1 = CustomShip.SVS_Spider;
  70.                     Game(msg.pm(c.PlayerName, "Your ship 1 has been set to [ Ship: " + p.CustomShip1 + " ]"));
  71.                     break;
  72.                 case 4:
  73.                     p.CustomShip1 = CustomShip.SVS_Leviathan;
  74.                     Game(msg.pm(c.PlayerName, "Your ship 1 has been set to [ Ship: " + p.CustomShip1 + " ]"));
  75.                     break;
  76.             }
  77.         }
  78.         // ------------------------------------------- VARIABLES AND NEEDED METHODS //
  79.         // ------------------------------------------------------------------------//
  80.  
  81.         // Custom module to help with chatevents mainly
  82.         ShortChat msg = new ShortChat();
  83.         // Stores botname and arena
  84.         string BotName, Arena = "";
  85.         // Master list for players in arena
  86.         List<Player> PlayerList = new List<Player>();
  87.  
  88.         // Game ON/OFF
  89.         bool GameOn = false;
  90.         // --------------------------------------------------------  SS GAME EVENTS //
  91.         // ------------------------------------------------------------------------//
  92.         // Monitor all incoming chat events
  93.         public void MonitorChatEvents(object sender, ChatEvent c)
  94.         {
  95.             // Core sends each bot a pm with its own info 500ms after startup
  96.             // I use it to initialize bot
  97.             if (c.ChatType == ChatTypes.Private && c.Message.StartsWith("@BotInfo@"))
  98.                 // Initialize everything needed to get bot started
  99.                 InitializeBot(c.Message.Split(':')[1], c.Message.Split(':')[2]);
  100.             else if (c.ChatType == ChatTypes.Arena && c.Message.StartsWith("This arena is Continuum-only. Please get Continuum client"))
  101.             {
  102.                 DateTime time = DateTime.Now;
  103.  
  104.                 if (!GameOn)
  105.                     Game(msg.arena("Login Detected! - " + time.ToString(" H:mm:ss ")));
  106.                 else
  107.                 {
  108.                     Game(msg.arena("Bot recovered from a crash! -" + time.ToString(" H:mm:ss ")));
  109.                     Game(msg.pub("?chat=battledev,battle,"));
  110.                 }
  111.             }
  112.         }
  113.  
  114.         public void MonitorPlayerPositionEvent(object sender, PlayerPositionEvent pe)
  115.         {
  116.             // Map is split into 2 sections - this is to avoid a double packet
  117.             // area where both bots can see
  118.             if (pe.MapPositionX >= (511 * 16) + 1 || pe.IsCoreEvent)
  119.             {
  120.                 Player p = GetPlayer(pe.PlayerName);
  121.  
  122.                 if (p == null) return;
  123.                 //if (pe.ShipState.IsSafe)
  124.                 //  Game(msg.arena("InSafe"));
  125.  
  126.                 if (InRegion(pe, new int[] { 520 * 16, 510 * 16, 524 * 16, 514 * 16 }))
  127.                 {
  128.                     if (pe.Bounty <= 0 && p.InShip == ShipTypes.Warbird)
  129.                     {
  130.                         if (p.CustomShip1 == CustomShip.SVS_Warbird)
  131.                             SpamCommands(Ship1(pe.PlayerName));
  132.                         else if (p.CustomShip1 == CustomShip.SVS_Javelin)
  133.                             SpamCommands(Ship2(pe.PlayerName));
  134.                         else if (p.CustomShip1 == CustomShip.SVS_Spider)
  135.                             SpamCommands(Ship3(pe.PlayerName));
  136.                         else if (p.CustomShip1 == CustomShip.SVS_Leviathan)
  137.                             SpamCommands(Ship4(pe.PlayerName));
  138.                     }
  139.                     // 0,328 1023,767
  140.                     Random ran = new Random();
  141.                     Game(msg.pm(pe.PlayerName,"*warpto " + ran.Next(0,1023)  +" " + ran.Next(328,767)));
  142.                 }
  143.                 // Portal left side
  144.                 else if (InRegion(pe, new int[] { 17 * 16, 686 * 16, 33 * 16, 702 * 16 }))
  145.                     Game(msg.warp(pe.PlayerName, 934, 508));
  146.                 // Portal right side
  147.                 else if (InRegion(pe, new int[] { 940 * 16, 500 * 16, 956 * 16, 516 * 16 }))
  148.                     Game(msg.warp(pe.PlayerName, 25, 708));
  149.                 // Flag region
  150.                 else if (InRegion(pe, new int[] { 12336, 13328, 12496, 13488 }))
  151.                     Game(msg.arena("Flag area."));
  152.             }
  153.         }
  154.  
  155.         public void MonitorPlayerEnterEvent(object sender, PlayerEnteredEvent pe)
  156.         {   AddPlayer(pe);  }
  157.         public void MonitorFreqChangeEvent(object sender, TeamChangeEvent t)
  158.         {   UpdatePlayer(t.PlayerName,t); }
  159.         public void MonitorShipChangeEvent(object sender, ShipChangeEvent s)
  160.         {   UpdatePlayer(s.PlayerName, s); }
  161.         public void MonitorDeathEvents(object sender, PlayerDeathEvent pde)
  162.         {
  163.             if (pde.Bounty >= 15 && pde.Bounty < 200)
  164.                 Game(msg.arena("Arg1"));
  165.             else
  166.                 Game(msg.arena("Arg2"));
  167.             Game(msg.arena("NoArg"));
  168.         }
  169.  
  170.         // ------------------------------------------------------- PLAYER FUNCTIONS //
  171.         // ------------------------------------------------------------------------//
  172.         public void AddPlayer(PlayerEnteredEvent pe)
  173.         {
  174.             // Call for player and see if he is on list - shouldn't be
  175.             Player p = GetPlayer(pe.PlayerName);
  176.  
  177.             // If he is on list wtf?!?!
  178.             if (p != null)
  179.             {
  180.                 msg.DebugMessage("Player[ "+pe.PlayerName+" ] was already on list on PlayerEnterEvent.");
  181.                 return;
  182.             }
  183.  
  184.             // Create player and add to master list
  185.             p = new Player();
  186.             p.PlayerName = pe.PlayerName;
  187.             p.InShip = pe.ShipType;
  188.             p.OnFreq = pe.Frequency;
  189.             p.Status = PlayerStatus.Spec;
  190.             PlayerList.Add(p);
  191.             msg.DebugMessage("Player[ " + pe.PlayerName + " ] added to Master player list.");
  192.         }
  193.  
  194.         public void UpdatePlayer(string PlayerName, EventArgs e)
  195.         {
  196.             Player p = GetPlayer(PlayerName);
  197.  
  198.             if (p == null)
  199.             {
  200.                 msg.DebugMessage("Player["+PlayerName+"] was not found on the playerlist.");
  201.                 return;
  202.             }
  203.  
  204.             if (e is TeamChangeEvent)
  205.             {
  206.                 p.OnFreq = (e as TeamChangeEvent).Frequency;
  207.                 return;
  208.             }
  209.  
  210.             if (e is ShipChangeEvent)
  211.             {
  212.                 ShipChangeEvent sc = e as ShipChangeEvent;
  213.  
  214.                 p.InShip = sc.ShipType;
  215.                 p.OldShip = sc.PreviousShipType;
  216.                 return;
  217.             }
  218.  
  219.             if (e is PlayerDeathEvent)
  220.             {
  221.                 PlayerDeathEvent pd = e as PlayerDeathEvent;
  222.                 Player Died = GetPlayer(pd.KilledName);
  223.             }
  224.         }
  225.  
  226.         // get player from master list using name - returns null if player is not found
  227.         public Player GetPlayer(string PlayerName)
  228.         {
  229.             for (int i = 0; i < PlayerList.Count; i += 1)
  230.             {
  231.                 if (PlayerName == PlayerList[i].PlayerName)
  232.                     return PlayerList[i];
  233.             }
  234.             return null;
  235.         }
  236.  
  237.         // -------------------------------------------------------- TIMER FUNCTIONS //
  238.         // ------------------------------------------------------------------------//
  239.         //public void updateMainTimer(object sender, ElapsedEventArgs e)
  240.         public void updateMainTimer()
  241.         {
  242.             UpdateBotPositions();
  243.             // Check to see if we have any commands in our command chat q
  244.             if (msg.NeedUpdate && GameOn) Game(msg.sendNextBCommand());
  245.         }
  246.  
  247.         // Updates each bots position - we stagger so we dont flood
  248.         DateTime ts_UpdatePosition = DateTime.Now;
  249.         double delay_UpdatePosition = 25;
  250.         bool PositionLeft = false;
  251.         public void UpdateBotPositions()
  252.         {
  253.             if ((DateTime.Now - ts_UpdatePosition).TotalMilliseconds < delay_UpdatePosition) return;
  254.  
  255.             // Update timestamp
  256.             ts_UpdatePosition = DateTime.Now;
  257.             // Toggle which to refresh
  258.             PositionLeft = !PositionLeft;
  259.  
  260.             if (PositionLeft) SendCoreEvent(msg.arena("##REFRESH##L"));
  261.             else SendCoreEvent(msg.arena("##REFRESH##R"));
  262.         }
  263.  
  264.         // Initialize bot for first time
  265.         public void InitializeBot(string BotName, string Arena)
  266.         {
  267.             this.BotName = BotName;
  268.             this.Arena = Arena;
  269.  
  270.             Game(msg.pm("PsyBot", "!right8675309"));
  271.             Game(msg.pm("Evil Bot", "!left8675309"));
  272.  
  273.             // Turn game on
  274.             GameOn = true;
  275.  
  276.             // update chat with bot initialized msg
  277.             msg.SCChanMessage(1, BotName + " initialized.");
  278.  
  279.             Game(msg.pub("*objon 1427"));
  280.         }
  281.         // --------------------------------------------------------- MISC FUNCTIONS //
  282.         // ------------------------------------------------------------------------//
  283.  
  284.         // Spams commands to a player
  285.         public void SpamCommands( Queue<EventArgs> Commands)
  286.         {
  287.             // Ignores is no commands
  288.             if (Commands == null || Commands.Count <= 0) return;
  289.             // Remove and send each command
  290.             while (Commands.Count > 0)
  291.                 Game(Commands.Dequeue());
  292.         }
  293.  
  294.         // Collision check
  295.         // Check player position against the 4int array region
  296.         public bool InRegion(PlayerPositionEvent Position, int[] Region)
  297.         {
  298.             if (Position.MapPositionX < Region[2] &&
  299.                 Position.MapPositionX > Region[0] &&
  300.                 Position.MapPositionY < Region[3] &&
  301.                 Position.MapPositionY > Region[1]) return true;
  302.             return false;
  303.         }
  304.  
  305.         // ----------------------------------------------  Ship Settings
  306.         public Queue<EventArgs> Ship1(string PlayerName)
  307.         {
  308.             Queue<EventArgs> q = new Queue<EventArgs>();
  309.             q.Enqueue(msg.pm(PlayerName, "*shipreset"));
  310.             q.Enqueue(msg.pm(PlayerName, "*prize #3"));
  311.             q.Enqueue(msg.pm(PlayerName, "*prize #11"));
  312.             q.Enqueue(msg.pm(PlayerName, "*prize #8"));
  313.             q.Enqueue(msg.pm(PlayerName, "*prize #8"));
  314.             q.Enqueue(msg.pm(PlayerName, "*prize #8"));
  315.             q.Enqueue(msg.pm(PlayerName, "*prize #9"));
  316.             q.Enqueue(msg.pm(PlayerName, "*prize #9"));
  317.             return q;
  318.         }
  319.         public Queue<EventArgs> Ship2(string PlayerName)
  320.         {
  321.             Queue<EventArgs> q = new Queue<EventArgs>();
  322.             q.Enqueue(msg.pm(PlayerName, "*shipreset"));
  323.             q.Enqueue(msg.pm(PlayerName, "*prize #12"));
  324.             q.Enqueue(msg.pm(PlayerName, "*prize #8"));
  325.             q.Enqueue(msg.pm(PlayerName, "*prize #8"));
  326.             q.Enqueue(msg.pm(PlayerName, "*prize #8"));
  327.             q.Enqueue(msg.pm(PlayerName, "*prize #9"));
  328.             q.Enqueue(msg.pm(PlayerName, "*prize #9"));
  329.             return q;
  330.         }
  331.         public Queue<EventArgs> Ship3(string PlayerName)
  332.         {
  333.             Queue<EventArgs> q = new Queue<EventArgs>();
  334.             q.Enqueue(msg.pm(PlayerName, "*shipreset"));
  335.             q.Enqueue(msg.pm(PlayerName, "*prize #5"));
  336.             q.Enqueue(msg.pm(PlayerName, "*prize #8"));
  337.             q.Enqueue(msg.pm(PlayerName, "*prize #8"));
  338.             q.Enqueue(msg.pm(PlayerName, "*prize #8"));
  339.             q.Enqueue(msg.pm(PlayerName, "*prize #9"));
  340.             q.Enqueue(msg.pm(PlayerName, "*prize #9"));
  341.             return q;
  342.         }
  343.         public Queue<EventArgs> Ship4(string PlayerName)
  344.         {
  345.             Queue<EventArgs> q = new Queue<EventArgs>();
  346.             q.Enqueue(msg.pm(PlayerName, "*shipreset"));
  347.             q.Enqueue(msg.pm(PlayerName, "*prize #8"));
  348.             q.Enqueue(msg.pm(PlayerName, "*prize #8"));
  349.             q.Enqueue(msg.pm(PlayerName, "*prize #8"));
  350.             q.Enqueue(msg.pm(PlayerName, "*prize #9"));
  351.             q.Enqueue(msg.pm(PlayerName, "*prize #9"));
  352.             q.Enqueue(msg.pm(PlayerName, "*prize #9"));
  353.  
  354.             return q;
  355.         }
  356.  
  357.         public override void Dispose()
  358.         {
  359.             throw new NotImplementedException();
  360.         }
  361.     }
  362. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement