/MCQuai/Commands/Undone/CmdSpleef.cs

https://bitbucket.org/realquaisaq/mcrevive · C# · 128 lines · 126 code · 2 blank · 0 comment · 11 complexity · a89499df388315c78fa4ebf3320d6443 MD5 · raw file

  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using System.Threading;
  5. namespace MCRevive
  6. {
  7. public class CmdSpleef : Command
  8. {
  9. public override string name { get { return "spleef"; } }
  10. public override string shortcut { get { return ""; } }
  11. public override string type { get { return "game"; } }
  12. public override int defaultRank { get { return LevelPermission.Operator; } }
  13. public override void Use(Player p, string message)
  14. {
  15. try
  16. {
  17. if (message == "") { Help(p); return; }
  18. Spleef spl;
  19. switch (message.Split(' ')[0])
  20. {
  21. case "create":
  22. if (p.level.GetSpleef() != null)
  23. {
  24. p.SendMessage("There is already a spleef game arena on this map. Use &a/spleef delete&e.");
  25. }
  26. p.SendMessage("Click or place two blocks to determine the edges of your spleef arena.");
  27. p.ClearBlockchange();
  28. p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
  29. break;
  30. case "sp":
  31. case "startpoint":
  32. case "startingpoint":
  33. spl = p.level.GetSpleef();
  34. spl.StartingPoints.Add(new SpleefStartingPoint(p.pos[0], p.pos[1], p.pos[2], p.rot[0]));
  35. p.SendMessage("Spleef starting point was added.");
  36. break;
  37. case "start":
  38. spl = p.level.GetSpleef();
  39. if (spl.StartingPoints.Count < 2)
  40. p.SendMessage("Could not start spleef: Not enough starting points created.");
  41. else if (spl.Started)
  42. p.SendMessage("Spleef is already running on this map. Use &a/spleef stop&e to stop.");
  43. else
  44. spl.Start();
  45. break;
  46. case "stop":
  47. spl = p.level.GetSpleef();
  48. if (spl.Started)
  49. {
  50. foreach (SpleefStartingPoint ssp in spl.StartingPoints) { ssp.p.frozen = false; }
  51. spl.Restore();
  52. spl.Thread.Abort();
  53. spl.Started = false;
  54. }
  55. break;
  56. case "join":
  57. spl = p.level.GetSpleef();
  58. if (!spl.Started)
  59. {
  60. p.SendMessage("Spleef on this map hasn't been started yet.");
  61. return;
  62. }
  63. List<SpleefStartingPoint> TempSSP = spl.StartingPoints;
  64. int i = 0;
  65. foreach (SpleefStartingPoint ssp in TempSSP)
  66. {
  67. if (!ssp.Occupied)
  68. {
  69. SpleefStartingPoint ssp2 = spl.StartingPoints[i];
  70. ssp2.p = p;
  71. ssp2.Occupied = true;
  72. p.SendPos(ssp2.x, ssp2.y, ssp2.z, ssp2.rotX, 0);
  73. return;
  74. }
  75. i++;
  76. }
  77. p.SendMessage("Sorry, spleef is full. Try again later =]");
  78. break;
  79. }
  80. }
  81. catch (Exception e)
  82. {
  83. Server.s.Log(e.Message);
  84. }
  85. }
  86. public override void Help(Player p)
  87. {
  88. Player.SendMessage(p, "/spleef create - Define the spleef arena that you built");
  89. Player.SendMessage(p, "/spleef sp - Define a start point for the spleef game");
  90. Player.SendMessage(p, "/spleef start [seconds] - Start the spleef game in a certain time");
  91. Player.SendMessage(p, "/spleef join - Join the spleef game on the map you're in");
  92. Player.SendMessage(p, "/spleef stop - Stop the spleef game");
  93. }
  94. public override string[] Example(Player p)
  95. {
  96. return new string []
  97. {
  98. ""
  99. };
  100. }
  101. public void Blockchange1(Player p, ushort x, ushort y, ushort z, ushort type, byte action)
  102. {
  103. p.ClearBlockchange();
  104. ushort b = p.level.GetTile(x, y, z);
  105. p.SendBlockchange(x, y, z, b);
  106. CatchPos cpos = (CatchPos)p.blockchangeObject;
  107. cpos.x = x; cpos.y = y; cpos.z = z; p.blockchangeObject = cpos;
  108. p.Blockchange += new Player.BlockchangeEventHandler(Blockchange2);
  109. }
  110. public void Blockchange2(Player p, ushort x, ushort y, ushort z, ushort type, byte action)
  111. {
  112. p.ClearBlockchange();
  113. ushort b = p.level.GetTile(x, y, z);
  114. p.SendBlockchange(x, y, z, b);
  115. CatchPos cpos = (CatchPos)p.blockchangeObject;
  116. Spleef spl = new Spleef(p.level, x, y, z, cpos.x, cpos.y, cpos.z);
  117. Spleef.Spleefs.Add(spl);
  118. p.SendMessage("Spleef arena determined and saved.");
  119. p.SendMessage("Now create at least two spleef starting points with &a/spleef sp" + Server.DefaultColor + ".");
  120. }
  121. struct CatchPos
  122. {
  123. public ushort x, y, z;
  124. }
  125. }
  126. }