Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using BattleCore;
- using BattleCore.Events;
- using BattleCorePsyOps;
- using System.Timers;
- namespace BZOps
- {
- // Add the attribute and the base class
- [Behavior("Main", "false", "0.01", "PsyOps", "Main module to control Battle Zone.")]
- public class Main:BotEventListener
- {
- public Main()
- {
- RegisterTimedEvent("MainTimer", 10, updateMainTimer);
- RegisterCommand("!sc", doSC);
- RegisterCommand("!list", doList);
- // debug mode set to true
- msg.DebugMode = true;
- // make sure spam control is on for module
- msg.SpamControl = true;
- // Log bot into chan
- msg.SCPubCommand("?chat=battledev,battle");
- }
- public void doList(ChatEvent c)
- {
- Game(msg.pm(c.PlayerName, "-------------------------------<[ Player List ]>-------------------------------"));
- Game(msg.pm(c.PlayerName, " Name | Status | Freq | Custom Ship 1"));
- Game(msg.pm(c.PlayerName, "----------------+--------+--------+--------------------------------------------"));
- for (int i = 0; i < PlayerList.Count; i += 1)
- {
- Game(msg.pm(c.PlayerName, PlayerList[i].PlayerName.PadRight(16) + "| "
- + PlayerList[i].Status.ToString().PadRight(7) + "| "
- + PlayerList[i].OnFreq.ToString().PadRight(7) + "| "
- + PlayerList[i].CustomShip1.ToString().PadRight(13)));
- }
- }
- // ---------------------------------------------------------- CHAT COMMANDS //
- // ------------------------------------------------------------------------//
- // Sets shiptype for each slot
- public void doSC(ChatEvent c)
- {
- Player p = GetPlayer(c.PlayerName);
- if (p == null || c.Message.Length <= 3 || !c.Message.Contains(" ")) return;
- string[] info = c.Message.Split(' ');
- int num = 0;
- bool isNum = int.TryParse(info[1], out num);
- if (!int.TryParse(info[1], out num)) return;
- switch (num)
- {
- case 1:
- p.CustomShip1 = CustomShip.SVS_Warbird;
- Game(msg.pm(c.PlayerName, "Your ship 1 has been set to [ Ship: " + p.CustomShip1 + " ]"));
- break;
- case 2:
- p.CustomShip1 = CustomShip.SVS_Javelin;
- Game(msg.pm(c.PlayerName, "Your ship 1 has been set to [ Ship: " + p.CustomShip1 + " ]"));
- break;
- case 3:
- p.CustomShip1 = CustomShip.SVS_Spider;
- Game(msg.pm(c.PlayerName, "Your ship 1 has been set to [ Ship: " + p.CustomShip1 + " ]"));
- break;
- case 4:
- p.CustomShip1 = CustomShip.SVS_Leviathan;
- Game(msg.pm(c.PlayerName, "Your ship 1 has been set to [ Ship: " + p.CustomShip1 + " ]"));
- break;
- }
- }
- // ------------------------------------------- VARIABLES AND NEEDED METHODS //
- // ------------------------------------------------------------------------//
- // Custom module to help with chatevents mainly
- ShortChat msg = new ShortChat();
- // Stores botname and arena
- string BotName, Arena = "";
- // Master list for players in arena
- List<Player> PlayerList = new List<Player>();
- // Game ON/OFF
- bool GameOn = false;
- // -------------------------------------------------------- SS GAME EVENTS //
- // ------------------------------------------------------------------------//
- // Monitor all incoming chat events
- public void MonitorChatEvents(object sender, ChatEvent c)
- {
- // Core sends each bot a pm with its own info 500ms after startup
- // I use it to initialize bot
- if (c.ChatType == ChatTypes.Private && c.Message.StartsWith("@BotInfo@"))
- // Initialize everything needed to get bot started
- InitializeBot(c.Message.Split(':')[1], c.Message.Split(':')[2]);
- else if (c.ChatType == ChatTypes.Arena && c.Message.StartsWith("This arena is Continuum-only. Please get Continuum client"))
- {
- DateTime time = DateTime.Now;
- if (!GameOn)
- Game(msg.arena("Login Detected! - " + time.ToString(" H:mm:ss ")));
- else
- {
- Game(msg.arena("Bot recovered from a crash! -" + time.ToString(" H:mm:ss ")));
- Game(msg.pub("?chat=battledev,battle,"));
- }
- }
- }
- public void MonitorPlayerPositionEvent(object sender, PlayerPositionEvent pe)
- {
- // Map is split into 2 sections - this is to avoid a double packet
- // area where both bots can see
- if (pe.MapPositionX >= (511 * 16) + 1 || pe.IsCoreEvent)
- {
- Player p = GetPlayer(pe.PlayerName);
- if (p == null) return;
- //if (pe.ShipState.IsSafe)
- // Game(msg.arena("InSafe"));
- if (InRegion(pe, new int[] { 520 * 16, 510 * 16, 524 * 16, 514 * 16 }))
- {
- if (pe.Bounty <= 0 && p.InShip == ShipTypes.Warbird)
- {
- if (p.CustomShip1 == CustomShip.SVS_Warbird)
- SpamCommands(Ship1(pe.PlayerName));
- else if (p.CustomShip1 == CustomShip.SVS_Javelin)
- SpamCommands(Ship2(pe.PlayerName));
- else if (p.CustomShip1 == CustomShip.SVS_Spider)
- SpamCommands(Ship3(pe.PlayerName));
- else if (p.CustomShip1 == CustomShip.SVS_Leviathan)
- SpamCommands(Ship4(pe.PlayerName));
- }
- // 0,328 1023,767
- Random ran = new Random();
- Game(msg.pm(pe.PlayerName,"*warpto " + ran.Next(0,1023) +" " + ran.Next(328,767)));
- }
- // Portal left side
- else if (InRegion(pe, new int[] { 17 * 16, 686 * 16, 33 * 16, 702 * 16 }))
- Game(msg.warp(pe.PlayerName, 934, 508));
- // Portal right side
- else if (InRegion(pe, new int[] { 940 * 16, 500 * 16, 956 * 16, 516 * 16 }))
- Game(msg.warp(pe.PlayerName, 25, 708));
- // Flag region
- else if (InRegion(pe, new int[] { 12336, 13328, 12496, 13488 }))
- Game(msg.arena("Flag area."));
- }
- }
- public void MonitorPlayerEnterEvent(object sender, PlayerEnteredEvent pe)
- { AddPlayer(pe); }
- public void MonitorFreqChangeEvent(object sender, TeamChangeEvent t)
- { UpdatePlayer(t.PlayerName,t); }
- public void MonitorShipChangeEvent(object sender, ShipChangeEvent s)
- { UpdatePlayer(s.PlayerName, s); }
- public void MonitorDeathEvents(object sender, PlayerDeathEvent pde)
- {
- if (pde.Bounty >= 15 && pde.Bounty < 200)
- Game(msg.arena("Arg1"));
- else
- Game(msg.arena("Arg2"));
- Game(msg.arena("NoArg"));
- }
- // ------------------------------------------------------- PLAYER FUNCTIONS //
- // ------------------------------------------------------------------------//
- public void AddPlayer(PlayerEnteredEvent pe)
- {
- // Call for player and see if he is on list - shouldn't be
- Player p = GetPlayer(pe.PlayerName);
- // If he is on list wtf?!?!
- if (p != null)
- {
- msg.DebugMessage("Player[ "+pe.PlayerName+" ] was already on list on PlayerEnterEvent.");
- return;
- }
- // Create player and add to master list
- p = new Player();
- p.PlayerName = pe.PlayerName;
- p.InShip = pe.ShipType;
- p.OnFreq = pe.Frequency;
- p.Status = PlayerStatus.Spec;
- PlayerList.Add(p);
- msg.DebugMessage("Player[ " + pe.PlayerName + " ] added to Master player list.");
- }
- public void UpdatePlayer(string PlayerName, EventArgs e)
- {
- Player p = GetPlayer(PlayerName);
- if (p == null)
- {
- msg.DebugMessage("Player["+PlayerName+"] was not found on the playerlist.");
- return;
- }
- if (e is TeamChangeEvent)
- {
- p.OnFreq = (e as TeamChangeEvent).Frequency;
- return;
- }
- if (e is ShipChangeEvent)
- {
- ShipChangeEvent sc = e as ShipChangeEvent;
- p.InShip = sc.ShipType;
- p.OldShip = sc.PreviousShipType;
- return;
- }
- if (e is PlayerDeathEvent)
- {
- PlayerDeathEvent pd = e as PlayerDeathEvent;
- Player Died = GetPlayer(pd.KilledName);
- }
- }
- // get player from master list using name - returns null if player is not found
- public Player GetPlayer(string PlayerName)
- {
- for (int i = 0; i < PlayerList.Count; i += 1)
- {
- if (PlayerName == PlayerList[i].PlayerName)
- return PlayerList[i];
- }
- return null;
- }
- // -------------------------------------------------------- TIMER FUNCTIONS //
- // ------------------------------------------------------------------------//
- //public void updateMainTimer(object sender, ElapsedEventArgs e)
- public void updateMainTimer()
- {
- UpdateBotPositions();
- // Check to see if we have any commands in our command chat q
- if (msg.NeedUpdate && GameOn) Game(msg.sendNextBCommand());
- }
- // Updates each bots position - we stagger so we dont flood
- DateTime ts_UpdatePosition = DateTime.Now;
- double delay_UpdatePosition = 25;
- bool PositionLeft = false;
- public void UpdateBotPositions()
- {
- if ((DateTime.Now - ts_UpdatePosition).TotalMilliseconds < delay_UpdatePosition) return;
- // Update timestamp
- ts_UpdatePosition = DateTime.Now;
- // Toggle which to refresh
- PositionLeft = !PositionLeft;
- if (PositionLeft) SendCoreEvent(msg.arena("##REFRESH##L"));
- else SendCoreEvent(msg.arena("##REFRESH##R"));
- }
- // Initialize bot for first time
- public void InitializeBot(string BotName, string Arena)
- {
- this.BotName = BotName;
- this.Arena = Arena;
- Game(msg.pm("PsyBot", "!right8675309"));
- Game(msg.pm("Evil Bot", "!left8675309"));
- // Turn game on
- GameOn = true;
- // update chat with bot initialized msg
- msg.SCChanMessage(1, BotName + " initialized.");
- Game(msg.pub("*objon 1427"));
- }
- // --------------------------------------------------------- MISC FUNCTIONS //
- // ------------------------------------------------------------------------//
- // Spams commands to a player
- public void SpamCommands( Queue<EventArgs> Commands)
- {
- // Ignores is no commands
- if (Commands == null || Commands.Count <= 0) return;
- // Remove and send each command
- while (Commands.Count > 0)
- Game(Commands.Dequeue());
- }
- // Collision check
- // Check player position against the 4int array region
- public bool InRegion(PlayerPositionEvent Position, int[] Region)
- {
- if (Position.MapPositionX < Region[2] &&
- Position.MapPositionX > Region[0] &&
- Position.MapPositionY < Region[3] &&
- Position.MapPositionY > Region[1]) return true;
- return false;
- }
- // ---------------------------------------------- Ship Settings
- public Queue<EventArgs> Ship1(string PlayerName)
- {
- Queue<EventArgs> q = new Queue<EventArgs>();
- q.Enqueue(msg.pm(PlayerName, "*shipreset"));
- q.Enqueue(msg.pm(PlayerName, "*prize #3"));
- q.Enqueue(msg.pm(PlayerName, "*prize #11"));
- q.Enqueue(msg.pm(PlayerName, "*prize #8"));
- q.Enqueue(msg.pm(PlayerName, "*prize #8"));
- q.Enqueue(msg.pm(PlayerName, "*prize #8"));
- q.Enqueue(msg.pm(PlayerName, "*prize #9"));
- q.Enqueue(msg.pm(PlayerName, "*prize #9"));
- return q;
- }
- public Queue<EventArgs> Ship2(string PlayerName)
- {
- Queue<EventArgs> q = new Queue<EventArgs>();
- q.Enqueue(msg.pm(PlayerName, "*shipreset"));
- q.Enqueue(msg.pm(PlayerName, "*prize #12"));
- q.Enqueue(msg.pm(PlayerName, "*prize #8"));
- q.Enqueue(msg.pm(PlayerName, "*prize #8"));
- q.Enqueue(msg.pm(PlayerName, "*prize #8"));
- q.Enqueue(msg.pm(PlayerName, "*prize #9"));
- q.Enqueue(msg.pm(PlayerName, "*prize #9"));
- return q;
- }
- public Queue<EventArgs> Ship3(string PlayerName)
- {
- Queue<EventArgs> q = new Queue<EventArgs>();
- q.Enqueue(msg.pm(PlayerName, "*shipreset"));
- q.Enqueue(msg.pm(PlayerName, "*prize #5"));
- q.Enqueue(msg.pm(PlayerName, "*prize #8"));
- q.Enqueue(msg.pm(PlayerName, "*prize #8"));
- q.Enqueue(msg.pm(PlayerName, "*prize #8"));
- q.Enqueue(msg.pm(PlayerName, "*prize #9"));
- q.Enqueue(msg.pm(PlayerName, "*prize #9"));
- return q;
- }
- public Queue<EventArgs> Ship4(string PlayerName)
- {
- Queue<EventArgs> q = new Queue<EventArgs>();
- q.Enqueue(msg.pm(PlayerName, "*shipreset"));
- q.Enqueue(msg.pm(PlayerName, "*prize #8"));
- q.Enqueue(msg.pm(PlayerName, "*prize #8"));
- q.Enqueue(msg.pm(PlayerName, "*prize #8"));
- q.Enqueue(msg.pm(PlayerName, "*prize #9"));
- q.Enqueue(msg.pm(PlayerName, "*prize #9"));
- q.Enqueue(msg.pm(PlayerName, "*prize #9"));
- return q;
- }
- public override void Dispose()
- {
- throw new NotImplementedException();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement