Advertisement
Guest User

Untitled

a guest
Apr 18th, 2017
594
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.90 KB | None | 0 0
  1. ----------
  2. PROGRAM.CS
  3. ----------
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using PlayerIOClient;
  10. using System.IO;
  11. using System.Threading;
  12. using System.Diagnostics;
  13. using System.Timers;
  14. namespace TestingBot
  15. {
  16. public class Program
  17. {
  18. public static Connection conn;
  19. public static Client client;
  20. public static Dictionary<int, string> PlayersOn = new Dictionary<int, string>();
  21. public static bool gameOn = false;
  22. public static int gameID, i_;
  23. static void Main(string[] args)
  24. {
  25. string lginfo = @"..\..\..\logininfo.txt";
  26. string password = File.ReadAllText(lginfo, Encoding.UTF8);
  27.  
  28. client = PlayerIO.QuickConnect.SimpleConnect("everybody-edits-su9rn58o40itdbnw69plyw", "soulrunner2@hotmail.com", password, null);
  29. conn = client.Multiplayer.JoinRoom("PWmgZxBQqkb0I", null);
  30. conn.OnMessage += OnMessage;
  31. conn.Send("init");
  32. Console.WriteLine("Press any key to exit...");
  33. Console.ReadKey();
  34. }
  35. static void chmsg(string msg)
  36. {
  37. conn.Send("say", "HIVE | " + msg + ".");
  38. }
  39. static void chmsg(int msg)
  40. {
  41. conn.Send("say", "HIVE | " + msg + ".");
  42. }
  43. static void OnMessage(object sender, Message m)
  44. {
  45. {
  46. switch(m.Type)
  47. {
  48. #region Joined
  49. case "init":
  50. conn.Send("init2");
  51. var roomData = new uint[2, m.GetInt(18), m.GetInt(19)];
  52. var chunks = InitParse.Parse(m);
  53. foreach (var chunk in chunks)
  54. foreach (var pos in chunk.Locations)
  55. roomData[chunk.Layer, pos.X, pos.Y] = chunk.Type;
  56. chmsg("Connected");
  57. conn.Send("m", 48 * 16 + 8, 36 * 16, 0, 0, 0, 0, 0, 0, 0, false, false, 0);
  58. blockPlace(0, 34, 36, 63, 36, 14);
  59. break;
  60. #endregion //Does stuff when Bot joins
  61. #region PlayerJoin
  62. case "add":
  63. PlayersOn.Add(m.GetInt(0), m.GetString(1));
  64. break;
  65. #endregion //Does stuff when playerjoins
  66. #region PlayerLeft
  67. case "left":
  68. if (PlayersOn.ContainsKey(m.GetInt(0)))
  69. PlayersOn.Remove(m.GetInt(0));
  70. break;
  71. #endregion//dDoes stuff when player leaves
  72. #region Say
  73. case "say":
  74. string[] args;
  75. string tempName;
  76. args = m.GetString(1).Split(' ');
  77. if (PlayersOn.TryGetValue(m.GetInt(0), out tempName))
  78. {
  79. if(tempName.ToLower() == "sirsoul")
  80. {
  81. switch (args[0])
  82. {
  83. #region testbp
  84. case ".testbp":
  85. if (args.Length <= 2)
  86. blockPlace(0, 34, 36, 63, 36, Int32.Parse(args[1]));
  87. Thread.Sleep(1);
  88. blockPlace(0, 34, 63, 63, 63, Int32.Parse(args[1]));
  89. break;
  90. #endregion
  91. #region start
  92. case ".start":
  93. {
  94. int bid_ = 182; //current blockID
  95. System.Timers.Timer roundT = new System.Timers.Timer();
  96. roundT.Interval = 1000;
  97. int CurrentSeconds = 29; //countdown start time + 1
  98. Random rnd1 = new Random();
  99. gameID = rnd1.Next(1);
  100. switch (gameID)
  101. {
  102. case 0:
  103. {
  104. chmsg("Gamemode: Survive");
  105. middleClear();
  106. Thread.Sleep(1);
  107. blockPlace(0, 36, 50, 61, 50, 19);
  108. Thread.Sleep(1);
  109. blockPlace(0, 36, 51, 61, 52, 16);
  110.  
  111. }
  112. break;
  113. default:
  114. {
  115. chmsg(gameID);
  116. }
  117. break;
  118. }
  119. roundT.Elapsed += delegate(object sndr, ElapsedEventArgs eea)
  120. {
  121. #region Timer
  122. #region Countdown
  123. if (!(1 <= CurrentSeconds))
  124. {
  125. gameOn = false;
  126. roundT.Stop();
  127. }
  128. CurrentSeconds--;
  129. #endregion
  130. blockPlace(0, 62 - CurrentSeconds, 36, bid_);
  131. blockPlace(0, 35 + CurrentSeconds, 63, bid_);
  132. if(CurrentSeconds == 14)
  133. {
  134. blockPlace(0, 63 - 14, 36, 63, 36, 1018);
  135. blockPlace(0, 34, 63, 63 - 15, 63, 1018);
  136. }
  137. if(CurrentSeconds == 4)
  138. {
  139. blockPlace(0, 63 - 4, 36, 63, 36, 12);
  140. blockPlace(0, 34, 63, 63 - 25, 63, 12);
  141. }
  142. #endregion
  143. switch (gameID)
  144. {
  145. case 0:
  146. {
  147. int block_x = rnd1.Next(26);
  148. blockFall(36 + block_x);
  149. }
  150. break;
  151. }
  152.  
  153. };
  154. gameOn = true;
  155. roundT.Start();
  156. }
  157. break;
  158. #endregion
  159. }
  160. }
  161. }
  162. break;
  163. #endregion
  164. case "b":
  165. {
  166.  
  167. }
  168. break;
  169.  
  170. }
  171. }
  172. }
  173.  
  174. public static void blockPlace(int layer,int x, int y, int bid)
  175. {
  176. conn.Send("b", layer,x, y, bid);
  177. }
  178. static void blockPlace(int layer, int x1, int y1, int x2, int y2, int bid)
  179. {
  180. for (int x3 = x1; x3 < x2 + 1; x3++)
  181. for (int y3 = y1; y3 < y2 + 1; y3++)
  182. {
  183. Thread.Sleep(1);
  184. conn.Send("b", layer, x3, y3, bid);
  185. }
  186. }
  187. static void middleClear()
  188. {
  189. for (int x3 = 30; x3 < 67 + 1; x3++)
  190. for (int y3 = 38; y3 < 61 + 1; y3++)
  191. {
  192. Thread.Sleep(1);
  193. conn.Send("b", 0, x3, y3, 0);
  194. Thread.Sleep(1);
  195. conn.Send("b", 1, x3, y3, 610);
  196. }
  197. }
  198. static void blockFall(int x_)
  199. {
  200. for(i_ = 43; i_ < 53; i_++)
  201. {
  202. blockPlace(0, x_, i_, 368);
  203. Thread.Sleep(5);
  204. blockPlace(0, x_, i_ - 1, 0);
  205. Thread.Sleep(5);
  206. }
  207. blockPlace(0, x_, i_, 0);
  208. }
  209. }
  210. }
  211. ---------
  212. INITPARSE.CS
  213. ---------
  214. using System;
  215. using System.Collections.Generic;
  216. using PlayerIOClient;
  217. using System.Drawing;
  218.  
  219. namespace TestingBot
  220. {
  221. public static class InitParse
  222. {
  223. public static DataChunk[] Parse(Message m)
  224. {
  225. if (m == null) throw new ArgumentNullException("m");
  226. if (m.Type != "init" && m.Type != "reset") throw new ArgumentException("Invalid message type.", "m");
  227.  
  228. // Get world data
  229. var p = 0u;
  230. var data = new Stack<object>();
  231. while (m[p++] as string != "ws") { }
  232. while (m[p] as string != "we") { data.Push(m[p++]); }
  233.  
  234. // Parse world data
  235. var chunks = new List<DataChunk>();
  236. while (data.Count > 0)
  237. {
  238. var args = new Stack<object>();
  239. while (!(data.Peek() is byte[]))
  240. args.Push(data.Pop());
  241.  
  242. var ys = (byte[])data.Pop();
  243. var xs = (byte[])data.Pop();
  244. var layer = (int)data.Pop();
  245. var type = (uint)data.Pop();
  246.  
  247. chunks.Add(new DataChunk(layer, type, xs, ys, args.ToArray()));
  248. }
  249.  
  250. return chunks.ToArray();
  251. }
  252. }
  253.  
  254. public class DataChunk
  255. {
  256. public int Layer { get; set; }
  257. public uint Type { get; set; }
  258. public Point[] Locations { get; set; }
  259. public object[] Args { get; set; }
  260.  
  261. public DataChunk(int layer, uint type, byte[] xs, byte[] ys, object[] args)
  262. {
  263. this.Layer = layer;
  264. this.Type = type;
  265. this.Args = args;
  266. this.Locations = GetLocations(xs, ys);
  267. }
  268.  
  269. private static Point[] GetLocations(byte[] xs, byte[] ys)
  270. {
  271. var points = new List<Point>();
  272. for (var i = 0; i < xs.Length; i += 2)
  273. points.Add(new Point(
  274. (xs[i] << 8) | xs[i + 1],
  275. (ys[i] << 8) | ys[i + 1]));
  276. return points.ToArray();
  277. }
  278. }
  279.  
  280. public struct Point
  281. {
  282. public int X { get; set; }
  283. public int Y { get; set; }
  284.  
  285. public Point(int x, int y) : this()
  286. {
  287. this.X = x;
  288. this.Y = y;
  289. }
  290. }
  291. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement