Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------
- PROGRAM.CS
- ----------
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using PlayerIOClient;
- using System.IO;
- using System.Threading;
- using System.Diagnostics;
- using System.Timers;
- namespace TestingBot
- {
- public class Program
- {
- public static Connection conn;
- public static Client client;
- public static Dictionary<int, string> PlayersOn = new Dictionary<int, string>();
- public static bool gameOn = false;
- public static int gameID, i_;
- static void Main(string[] args)
- {
- string lginfo = @"..\..\..\logininfo.txt";
- string password = File.ReadAllText(lginfo, Encoding.UTF8);
- client = PlayerIO.QuickConnect.SimpleConnect("everybody-edits-su9rn58o40itdbnw69plyw", "soulrunner2@hotmail.com", password, null);
- conn = client.Multiplayer.JoinRoom("PWmgZxBQqkb0I", null);
- conn.OnMessage += OnMessage;
- conn.Send("init");
- Console.WriteLine("Press any key to exit...");
- Console.ReadKey();
- }
- static void chmsg(string msg)
- {
- conn.Send("say", "HIVE | " + msg + ".");
- }
- static void chmsg(int msg)
- {
- conn.Send("say", "HIVE | " + msg + ".");
- }
- static void OnMessage(object sender, Message m)
- {
- {
- switch(m.Type)
- {
- #region Joined
- case "init":
- conn.Send("init2");
- var roomData = new uint[2, m.GetInt(18), m.GetInt(19)];
- var chunks = InitParse.Parse(m);
- foreach (var chunk in chunks)
- foreach (var pos in chunk.Locations)
- roomData[chunk.Layer, pos.X, pos.Y] = chunk.Type;
- chmsg("Connected");
- conn.Send("m", 48 * 16 + 8, 36 * 16, 0, 0, 0, 0, 0, 0, 0, false, false, 0);
- blockPlace(0, 34, 36, 63, 36, 14);
- break;
- #endregion //Does stuff when Bot joins
- #region PlayerJoin
- case "add":
- PlayersOn.Add(m.GetInt(0), m.GetString(1));
- break;
- #endregion //Does stuff when playerjoins
- #region PlayerLeft
- case "left":
- if (PlayersOn.ContainsKey(m.GetInt(0)))
- PlayersOn.Remove(m.GetInt(0));
- break;
- #endregion//dDoes stuff when player leaves
- #region Say
- case "say":
- string[] args;
- string tempName;
- args = m.GetString(1).Split(' ');
- if (PlayersOn.TryGetValue(m.GetInt(0), out tempName))
- {
- if(tempName.ToLower() == "sirsoul")
- {
- switch (args[0])
- {
- #region testbp
- case ".testbp":
- if (args.Length <= 2)
- blockPlace(0, 34, 36, 63, 36, Int32.Parse(args[1]));
- Thread.Sleep(1);
- blockPlace(0, 34, 63, 63, 63, Int32.Parse(args[1]));
- break;
- #endregion
- #region start
- case ".start":
- {
- int bid_ = 182; //current blockID
- System.Timers.Timer roundT = new System.Timers.Timer();
- roundT.Interval = 1000;
- int CurrentSeconds = 29; //countdown start time + 1
- Random rnd1 = new Random();
- gameID = rnd1.Next(1);
- switch (gameID)
- {
- case 0:
- {
- chmsg("Gamemode: Survive");
- middleClear();
- Thread.Sleep(1);
- blockPlace(0, 36, 50, 61, 50, 19);
- Thread.Sleep(1);
- blockPlace(0, 36, 51, 61, 52, 16);
- }
- break;
- default:
- {
- chmsg(gameID);
- }
- break;
- }
- roundT.Elapsed += delegate(object sndr, ElapsedEventArgs eea)
- {
- #region Timer
- #region Countdown
- if (!(1 <= CurrentSeconds))
- {
- gameOn = false;
- roundT.Stop();
- }
- CurrentSeconds--;
- #endregion
- blockPlace(0, 62 - CurrentSeconds, 36, bid_);
- blockPlace(0, 35 + CurrentSeconds, 63, bid_);
- if(CurrentSeconds == 14)
- {
- blockPlace(0, 63 - 14, 36, 63, 36, 1018);
- blockPlace(0, 34, 63, 63 - 15, 63, 1018);
- }
- if(CurrentSeconds == 4)
- {
- blockPlace(0, 63 - 4, 36, 63, 36, 12);
- blockPlace(0, 34, 63, 63 - 25, 63, 12);
- }
- #endregion
- switch (gameID)
- {
- case 0:
- {
- int block_x = rnd1.Next(26);
- blockFall(36 + block_x);
- }
- break;
- }
- };
- gameOn = true;
- roundT.Start();
- }
- break;
- #endregion
- }
- }
- }
- break;
- #endregion
- case "b":
- {
- }
- break;
- }
- }
- }
- public static void blockPlace(int layer,int x, int y, int bid)
- {
- conn.Send("b", layer,x, y, bid);
- }
- static void blockPlace(int layer, int x1, int y1, int x2, int y2, int bid)
- {
- for (int x3 = x1; x3 < x2 + 1; x3++)
- for (int y3 = y1; y3 < y2 + 1; y3++)
- {
- Thread.Sleep(1);
- conn.Send("b", layer, x3, y3, bid);
- }
- }
- static void middleClear()
- {
- for (int x3 = 30; x3 < 67 + 1; x3++)
- for (int y3 = 38; y3 < 61 + 1; y3++)
- {
- Thread.Sleep(1);
- conn.Send("b", 0, x3, y3, 0);
- Thread.Sleep(1);
- conn.Send("b", 1, x3, y3, 610);
- }
- }
- static void blockFall(int x_)
- {
- for(i_ = 43; i_ < 53; i_++)
- {
- blockPlace(0, x_, i_, 368);
- Thread.Sleep(5);
- blockPlace(0, x_, i_ - 1, 0);
- Thread.Sleep(5);
- }
- blockPlace(0, x_, i_, 0);
- }
- }
- }
- ---------
- INITPARSE.CS
- ---------
- using System;
- using System.Collections.Generic;
- using PlayerIOClient;
- using System.Drawing;
- namespace TestingBot
- {
- public static class InitParse
- {
- public static DataChunk[] Parse(Message m)
- {
- if (m == null) throw new ArgumentNullException("m");
- if (m.Type != "init" && m.Type != "reset") throw new ArgumentException("Invalid message type.", "m");
- // Get world data
- var p = 0u;
- var data = new Stack<object>();
- while (m[p++] as string != "ws") { }
- while (m[p] as string != "we") { data.Push(m[p++]); }
- // Parse world data
- var chunks = new List<DataChunk>();
- while (data.Count > 0)
- {
- var args = new Stack<object>();
- while (!(data.Peek() is byte[]))
- args.Push(data.Pop());
- var ys = (byte[])data.Pop();
- var xs = (byte[])data.Pop();
- var layer = (int)data.Pop();
- var type = (uint)data.Pop();
- chunks.Add(new DataChunk(layer, type, xs, ys, args.ToArray()));
- }
- return chunks.ToArray();
- }
- }
- public class DataChunk
- {
- public int Layer { get; set; }
- public uint Type { get; set; }
- public Point[] Locations { get; set; }
- public object[] Args { get; set; }
- public DataChunk(int layer, uint type, byte[] xs, byte[] ys, object[] args)
- {
- this.Layer = layer;
- this.Type = type;
- this.Args = args;
- this.Locations = GetLocations(xs, ys);
- }
- private static Point[] GetLocations(byte[] xs, byte[] ys)
- {
- var points = new List<Point>();
- for (var i = 0; i < xs.Length; i += 2)
- points.Add(new Point(
- (xs[i] << 8) | xs[i + 1],
- (ys[i] << 8) | ys[i + 1]));
- return points.ToArray();
- }
- }
- public struct Point
- {
- public int X { get; set; }
- public int Y { get; set; }
- public Point(int x, int y) : this()
- {
- this.X = x;
- this.Y = y;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement