diff --git a/MCGalaxy/Commands/Fun/CmdCountdown.cs b/MCGalaxy/Commands/Fun/CmdCountdown.cs
index 7e7887744..6b13fdae0 100644
--- a/MCGalaxy/Commands/Fun/CmdCountdown.cs
+++ b/MCGalaxy/Commands/Fun/CmdCountdown.cs
@@ -49,30 +49,31 @@ namespace MCGalaxy.Commands.Fun {
if (args.Length > 1) arg1 = args[1];
if (args.Length > 2) arg2 = args[2];
if (args.Length > 3) arg3 = args[3];
+ CountdownGame game = Server.Countdown;
switch (cmd) {
case "join":
- HandleJoin(p); return;
+ HandleJoin(p, game); return;
case "leave":
- HandleLeave(p); return;
+ HandleLeave(p, game); return;
case "players":
- HandlePlayers(p); return;
+ HandlePlayers(p, game); return;
case "rules":
HandleRules(p, arg1); return;
case "download":
case "generate":
- HandleGenerate(p, arg1, arg2, arg3); return;
+ HandleGenerate(p, game, arg1, arg2, arg3); return;
case "enable":
- HandleEnable(p); return;
+ HandleEnable(p, game); return;
case "disable":
- HandleDisable(p); return;
+ HandleDisable(p, game); return;
case "cancel":
- HandleCancel(p); return;
+ HandleCancel(p, game); return;
case "start":
case "play":
- HandleStart(p, arg1, arg2); return;
+ HandleStart(p, game, arg1, arg2); return;
case "reset":
- HandleReset(p, arg1); return;
+ HandleReset(p, game, arg1); return;
case "tutorial":
HandleTutorial(p); return;
default:
@@ -80,13 +81,13 @@ namespace MCGalaxy.Commands.Fun {
}
}
- void HandleJoin(Player p) {
- switch (Server.Countdown.Status) {
+ void HandleJoin(Player p, CountdownGame game) {
+ switch (game.Status) {
case CountdownGameStatus.Disabled:
Player.Message(p, "Cannot join as countdown is not running.");
return;
case CountdownGameStatus.Enabled:
- Server.Countdown.PlayerJoinedGame(p);
+ game.PlayerJoinedGame(p);
return;
case CountdownGameStatus.RoundCountdown:
Player.Message(p, "Cannot join when a round is about to start. Wait until next round.");
@@ -100,57 +101,55 @@ namespace MCGalaxy.Commands.Fun {
}
}
- void HandleLeave(Player p) {
- if (Server.Countdown.Players.Contains(p)) {
- switch (Server.Countdown.Status) {
- case CountdownGameStatus.Disabled:
- Player.Message(p, "Cannot leave as countdown is not running.");
- return;
- case CountdownGameStatus.Enabled:
- Player.Message(p, "You've left countdown.");
- Server.Countdown.PlayerLeftGame(p);
- break;
- case CountdownGameStatus.RoundCountdown:
- Player.Message(p, "Cannot leave when a round is about to start.");
- return; ;
- case CountdownGameStatus.RoundInProgress:
- Player.Message(p, "Cannot leave when a round in progress - please wait until the round ends or you die.");
- return;
- case CountdownGameStatus.RoundFinished:
- Server.Countdown.Players.Remove(p);
- Server.Countdown.PlayersRemaining.Remove(p);
- p.playerofcountdown = false;
- Player.Message(p, "You've left the game.");
- break;
- }
- } else if (!(Server.Countdown.PlayersRemaining.Contains(p)) && Server.Countdown.Players.Contains(p)) {
- Server.Countdown.Players.Remove(p);
- Player.Message(p, "You've left the game.");
- } else {
+ void HandleLeave(Player p, CountdownGame game) {
+ if (!game.Players.Contains(p)) {
Player.Message(p, "Cannot leave as you did not join countdown to begin with.");
+ return;
+ }
+
+ switch (game.Status) {
+ case CountdownGameStatus.Disabled:
+ Player.Message(p, "Cannot leave as countdown is not running.");
+ return;
+ case CountdownGameStatus.Enabled:
+ case CountdownGameStatus.RoundFinished:
+ Player.Message(p, "You've left countdown.");
+ game.PlayerLeftGame(p);
+ return;
+ case CountdownGameStatus.RoundCountdown:
+ Player.Message(p, "Cannot leave when a round is about to start.");
+ return;
+ case CountdownGameStatus.RoundInProgress:
+ if (game.PlayersRemaining.Contains(p)) {
+ Player.Message(p, "Cannot leave when a round in progress - please wait until the round ends or you die.");
+ } else {
+ game.Players.Remove(p);
+ Player.Message(p, "You've left countdown.");
+ }
+ return;
}
}
- void HandlePlayers(Player p) {
- switch (Server.Countdown.Status) {
+ void HandlePlayers(Player p, CountdownGame game) {
+ switch (game.Status) {
case CountdownGameStatus.Disabled:
Player.Message(p, "Countdown is not running.");
break;
case CountdownGameStatus.RoundInProgress:
Player.Message(p, "Players in countdown:");
- Player.Message(p, Server.Countdown.Players.Join(FormatPlayer));
- break;
+ Player.Message(p, game.Players.Join(pl => FormatPlayer(pl, game)));
+ break;
default:
Player.Message(p, "Players in countdown: ");
- Player.Message(p, Server.Countdown.Players.Join(pl => pl.ColoredName));
+ Player.Message(p, game.Players.Join(pl => pl.ColoredName));
break;
}
}
- static string FormatPlayer(Player pl) {
- if (Server.Countdown.PlayersRemaining.Contains(pl)) {
+ static string FormatPlayer(Player pl, CountdownGame game) {
+ if (game.PlayersRemaining.Contains(pl)) {
return pl.ColoredName + " &a[IN]";
} else {
return pl.ColoredName + " &c[OUT]";
@@ -166,7 +165,7 @@ namespace MCGalaxy.Commands.Fun {
if (p.Rank < who.Rank) {
MessageTooHighRank(p, "send countdown rules", true); return;
}
- }
+ }
Player.Message(who, "The aim of the game is to stay alive the longest.");
Player.Message(who, "Don't fall in the lava!");
@@ -179,11 +178,11 @@ namespace MCGalaxy.Commands.Fun {
}
}
- void HandleGenerate(Player p, string arg1, string arg2, string arg3) {
+ void HandleGenerate(Player p, CountdownGame game, string x, string y, string z) {
if (!CheckExtraPerm(p, 2)) { MessageNeedExtra(p, 2); return; }
int width, height, length;
- if(!int.TryParse(arg1, out width) || !int.TryParse(arg2, out height) || !int.TryParse(arg3, out length)) {
+ if(!int.TryParse(x, out width) || !int.TryParse(y, out height) || !int.TryParse(z, out length)) {
width = 32; height = 32; length = 32;
}
if (width < 32 || !MapGen.OkayAxis(width)) width = 32;
@@ -197,8 +196,8 @@ namespace MCGalaxy.Commands.Fun {
else LevelInfo.Loaded.Add(lvl);
lvl.Save();
- if (Server.Countdown.Status != CountdownGameStatus.Disabled)
- Server.Countdown.mapon = lvl;
+ if (game.Status != CountdownGameStatus.Disabled)
+ game.Map = lvl;
const string format = "Generated map ({0}x{1}x{2}), sending you to it..";
Player.Message(p, format, width, height, length);
@@ -208,113 +207,118 @@ namespace MCGalaxy.Commands.Fun {
p.SendPos(Entities.SelfID, pos, p.Rot);
}
- void HandleEnable(Player p) {
+ void HandleEnable(Player p, CountdownGame game) {
if (!CheckExtraPerm(p, 2)) { MessageNeedExtra(p, 2); return; }
- if (Server.Countdown.Status == CountdownGameStatus.Disabled) {
+ if (game.Status == CountdownGameStatus.Disabled) {
CmdLoad.LoadLevel(null, "countdown");
- Server.Countdown.mapon = LevelInfo.FindExact("countdown");
+ game.Map = LevelInfo.FindExact("countdown");
- if (Server.Countdown.mapon == null) {
- Player.Message(p, "countdown level not found, generating..");
- HandleGenerate(p, "", "", "");
- Server.Countdown.mapon = LevelInfo.FindExact("countdown");
+ if (game.Map == null) {
+ Player.Message(p, "Countdown level not found, generating..");
+ HandleGenerate(p, game, "", "", "");
+ game.Map = LevelInfo.FindExact("countdown");
}
- Server.Countdown.mapon.Config.Deletable = false;
- Server.Countdown.mapon.Config.Buildable = false;
- Server.Countdown.mapon.BuildAccess.Min = LevelPermission.Nobody;
- Server.Countdown.mapon.Config.MOTD = "Welcome to the Countdown map! -hax";
+ game.Map.Config.Deletable = false;
+ game.Map.Config.Buildable = false;
+ game.Map.BuildAccess.Min = LevelPermission.Nobody;
+ game.Map.Config.MOTD = "Welcome to the Countdown map! -hax";
- Server.Countdown.Status = CountdownGameStatus.Enabled;
- Chat.MessageGlobal("Countdown has been enabled!!");
+ game.Status = CountdownGameStatus.Enabled;
+ Chat.MessageGlobal("Countdown has been enabled!");
} else {
- Player.Message(p, "A Game is either already enabled or is already progress");
+ Player.Message(p, "Countdown has already been enabled.");
}
}
- void HandleDisable(Player p) {
+ void HandleDisable(Player p, CountdownGame game) {
if (!CheckExtraPerm(p, 2)) { MessageNeedExtra(p, 2); return; }
- if (Server.Countdown.Status == CountdownGameStatus.RoundCountdown || Server.Countdown.Status == CountdownGameStatus.RoundInProgress) {
- Player.Message(p, "A game is currently in progress - please wait until it is finished, or use '/cd cancel' to cancel the game"); return;
- } else if (Server.Countdown.Status == CountdownGameStatus.Disabled) {
- Player.Message(p, "Already disabled!!"); return;
+ if (game.Status == CountdownGameStatus.RoundCountdown || game.Status == CountdownGameStatus.RoundInProgress) {
+ Player.Message(p, "A round is currently in progress - please wait until it is finished, or use '/cd cancel' to cancel the game"); return;
+ } else if (game.Status == CountdownGameStatus.Disabled) {
+ Player.Message(p, "Countdown is not running."); return;
} else {
- foreach (Player pl in Server.Countdown.Players)
+ foreach (Player pl in game.Players)
Player.Message(pl, "The countdown game was disabled.");
- Server.Countdown.Reset(p, true);
- Server.Countdown.Status = CountdownGameStatus.Disabled;
+ game.Reset(p, true);
+ game.Status = CountdownGameStatus.Disabled;
Player.Message(p, "Countdown Disabled");
}
}
- void HandleCancel(Player p) {
+ void HandleCancel(Player p, CountdownGame game) {
if (!CheckExtraPerm(p, 2)) { MessageNeedExtra(p, 2); return; }
- if (Server.Countdown.Status == CountdownGameStatus.RoundCountdown || Server.Countdown.Status == CountdownGameStatus.RoundInProgress) {
- Server.Countdown.cancel = true;
+ if (game.Status == CountdownGameStatus.RoundCountdown || game.Status == CountdownGameStatus.RoundInProgress) {
+ game.cancel = true;
Thread.Sleep(1500);
Player.Message(p, "Countdown has been canceled");
- Server.Countdown.Status = CountdownGameStatus.Enabled;
- } else if (Server.Countdown.Status == CountdownGameStatus.Disabled) {
- Player.Message(p, "The game is disabled!!");
+ game.Status = CountdownGameStatus.Enabled;
+ } else if (game.Status == CountdownGameStatus.Disabled) {
+ Player.Message(p, "Countdown is not running.");
} else {
- foreach (Player pl in Server.Countdown.Players)
+ foreach (Player pl in game.Players)
Player.Message(pl, "The countdown game was canceled");
- Server.Countdown.Reset(null, true);
+ game.Reset(null, true);
}
}
- void HandleStart(Player p, string par1, string par2) {
+ void HandleStart(Player p, CountdownGame game, string speed, string mode) {
if (!CheckExtraPerm(p, 2)) { MessageNeedExtra(p, 2); return; }
- if (Server.Countdown.Status != CountdownGameStatus.Enabled) {
- Player.Message(p, "Either a game is already in progress or it hasn't been enabled"); return;
+ switch (game.Status) {
+ case CountdownGameStatus.Disabled:
+ Player.Message(p, "Countdown is not yet enabled."); return;
+ case CountdownGameStatus.RoundCountdown:
+ Player.Message(p, "A round is already about to begin."); return;
+ case CountdownGameStatus.RoundInProgress:
+ Player.Message(p, "A round is already in progress."); return;
+ case CountdownGameStatus.RoundFinished:
+ Player.Message(p, "Game has finished"); return;
+ case CountdownGameStatus.Enabled:
+ if (game.Players.Count < 2) {
+ Player.Message(p, "At least two players must join countdown before a round can begin."); return;
+ }
+ game.Status = CountdownGameStatus.RoundCountdown; break;
}
- if (Server.Countdown.Players.Count < 2) {
- Player.Message(p, "Sorry, there aren't enough players to play."); return;
- }
-
- Server.Countdown.PlayersRemaining = Server.Countdown.Players;
- CountdownGame game = Server.Countdown;
- switch (par1) {
+
+ switch (speed) {
case "slow":
- game.speed = 800; game.speedtype = "slow"; break;
+ game.Speed = 800; game.SpeedType = "slow"; break;
case "normal":
- game.speed = 650; game.speedtype = "normal"; break;
+ game.Speed = 650; game.SpeedType = "normal"; break;
case "fast":
- game.speed = 500; game.speedtype = "fast"; break;
+ game.Speed = 500; game.SpeedType = "fast"; break;
case "extreme":
- game.speed = 300; game.speedtype = "extreme"; break;
+ game.Speed = 300; game.SpeedType = "extreme"; break;
case "ultimate":
- game.speed = 150; game.speedtype = "ultimate"; break;
+ game.Speed = 150; game.SpeedType = "ultimate"; break;
default:
- Player.Message(p, "You didn't specify a speed, resorting to 'normal'");
- game.speed = 650; game.speedtype = "normal"; break;
+ Player.Message(p, "No speed specified, playing at 'normal' speed.");
+ game.Speed = 650; game.SpeedType = "normal"; break;
}
- Server.Countdown.freezemode = (par2 == "freeze" || par2 == "frozen");
- Server.Countdown.GameStart(p);
+
+ game.FreezeMode = (mode == "freeze" || mode == "frozen");
+ game.BeginRound(p);
}
- void HandleReset(Player p, string par1) {
+ void HandleReset(Player p, CountdownGame game, string type) {
if (!CheckExtraPerm(p, 2)) { MessageNeedExtra(p, 2); return; }
- switch (Server.Countdown.Status) {
+ switch (game.Status) {
case CountdownGameStatus.Disabled:
Player.Message(p, "Please enable countdown first."); break;
case CountdownGameStatus.RoundCountdown:
- Player.Message(p, "Sorry - The game is about to start"); break;
+ Player.Message(p, "Cannot reset as a round is about to begin."); break;
case CountdownGameStatus.RoundInProgress:
- Player.Message(p, "Sorry - The game is already in progress."); break;
+ Player.Message(p, "Cannot reset as a round is already in progress."); break;
default:
Player.Message(p, "Reseting");
- if (par1 == "map")
- Server.Countdown.Reset(p, false);
- else if (par1 == "all")
- Server.Countdown.Reset(p, true);
- else
- Player.Message(p, "Please specify whether it is 'map' or 'all'");
+ if (type == "map") game.Reset(p, false);
+ else if (type == "all") game.Reset(p, true);
+ else Player.Message(p, "Can only reset 'map' or 'all'");
break;
}
}
@@ -332,10 +336,10 @@ namespace MCGalaxy.Commands.Fun {
public override void Help(Player p) {
Player.Message(p, "%T/cd joins/leave %H- joins/leaves the game");
Player.Message(p, "%T/cd players %H- lists players currently playing");
- Player.Message(p, "%T/cd rules %H- view the rules of countdown");
+ Player.Message(p, "%T/cd rules %H- view the rules of countdown");
if (CheckExtraPerm(p, 1)) {
Player.Message(p, "%T/cd rules [player] %H- sends rules of countdown to that player.");
- }
+ }
if (!CheckExtraPerm(p, 2)) return;
Player.Message(p, "%T/cd generate [width] [height] [length] %H- generates the countdown map (default is 32x32x32)");
diff --git a/MCGalaxy/Games/Countdown/CountdownGame.cs b/MCGalaxy/Games/Countdown/CountdownGame.cs
index a608373d9..e73a84ba6 100644
--- a/MCGalaxy/Games/Countdown/CountdownGame.cs
+++ b/MCGalaxy/Games/Countdown/CountdownGame.cs
@@ -22,107 +22,105 @@ using System.Threading;
namespace MCGalaxy.Games {
public sealed class CountdownGame : IGame {
+ /// All players who are playing this countdown game.
public List Players = new List();
+
+ /// Players who are still alive in the current round.
public List PlayersRemaining = new List();
- public List squaresLeft = new List();
- public Level mapon;
+
+ /// Map countdown is running on.
+ public Level Map;
+
+ /// Current status of the countdown game.
+ public CountdownGameStatus Status = CountdownGameStatus.Disabled;
- public int speed;
- public bool freezemode = false;
+ public int Speed;
+ public bool FreezeMode = false;
public bool cancel = false;
-
- public string speedtype;
-
- public CountdownGameStatus Status = CountdownGameStatus.Disabled;
+ public string SpeedType;
+
CountdownPlugin plugin;
+ List squaresLeft = new List();
- public void GameStart(Player p) {
+ public void BeginRound(Player p) {
if (plugin == null) {
plugin = new CountdownPlugin();
plugin.Game = this;
plugin.Load(false);
}
- switch (Status) {
- case CountdownGameStatus.Disabled:
- Player.Message(p, "Please enable Countdown first!!"); return;
- case CountdownGameStatus.RoundCountdown:
- Player.Message(p, "Game is about to start"); return;
- case CountdownGameStatus.RoundInProgress:
- Player.Message(p, "Game is already in progress"); return;
- case CountdownGameStatus.RoundFinished:
- Player.Message(p, "Game has finished"); return;
- case CountdownGameStatus.Enabled:
- Status = CountdownGameStatus.RoundCountdown;
- Thread.Sleep(2000); break;
- }
-
SetGlassTube(Block.glass, Block.glass);
- mapon.ChatLevel("Countdown is about to start!!");
- mapon.BuildAccess.Min = LevelPermission.Nobody;
- int midX = mapon.Width / 2, midY = mapon.Height / 2, midZ = mapon.Length / 2;
+ Map.ChatLevel("Countdown is about to start!");
+ Map.BuildAccess.Min = LevelPermission.Nobody;
+ int midX = Map.Width / 2, midY = Map.Height / 2, midZ = Map.Length / 2;
int xSpawn = (midX * 32 + 16);
- int ySpawn = ((mapon.Height - 2) * 32);
+ int ySpawn = ((Map.Height - 2) * 32);
int zSpawn = (midZ * 32 + 16);
squaresLeft.Clear();
- for(int zz = 6; zz < mapon.Length - 6; zz += 3)
- for (int xx = 6; xx < mapon.Width - 6; xx += 3)
+ for(int zz = 6; zz < Map.Length - 6; zz += 3)
+ for (int xx = 6; xx < Map.Width - 6; xx += 3)
squaresLeft.Add(new SquarePos(xx, zz));
- if (freezemode)
- mapon.ChatLevel("Countdown starting with difficulty " + speedtype + " and mode freeze in:");
+ if (FreezeMode)
+ Map.ChatLevel("Countdown starting with difficulty " + SpeedType + " and mode freeze in:");
else
- mapon.ChatLevel("Countdown starting with difficulty " + speedtype + " and mode normal in:");
+ Map.ChatLevel("Countdown starting with difficulty " + SpeedType + " and mode normal in:");
Thread.Sleep(2000);
SpawnPlayers(xSpawn, ySpawn, zSpawn);
- mapon.ChatLevel("-----&b5%S-----");
+ Map.ChatLevel("-----&b5%S-----");
- Cuboid(midX - 1, midY, midZ - 1, midX, midY, midZ, Block.air, mapon);
+ Cuboid(midX - 1, midY, midZ - 1, midX, midY, midZ, Block.air, Map);
Thread.Sleep(1000);
- mapon.ChatLevel("-----&b4%S-----"); Thread.Sleep(1000);
- mapon.ChatLevel("-----&b3%S-----"); Thread.Sleep(1000);
- Cuboid(midX, mapon.Height - 5, midZ, midX + 1, mapon.Height - 5, midZ + 1, Block.air, mapon);
- mapon.ChatLevel("-----&b2%S-----"); Thread.Sleep(1000);
- mapon.ChatLevel("-----&b1%S-----"); Thread.Sleep(1000);
- mapon.ChatLevel("GO!!!!!!!");
+ Map.ChatLevel("-----&b4%S-----"); Thread.Sleep(1000);
+ Map.ChatLevel("-----&b3%S-----"); Thread.Sleep(1000);
+ Cuboid(midX, Map.Height - 5, midZ, midX + 1, Map.Height - 5, midZ + 1, Block.air, Map);
+ Map.ChatLevel("-----&b2%S-----"); Thread.Sleep(1000);
+ Map.ChatLevel("-----&b1%S-----"); Thread.Sleep(1000);
+ Map.ChatLevel("GO!!!!!!!");
- PlayersRemaining = Players;
- foreach (Player pl in Players)
+ PlayersRemaining = new List(Players);
+ foreach (Player pl in Players) {
pl.InCountdown = true;
- AfterStart();
- Play();
- }
-
- public void Play() {
- if (!freezemode) {
- RemoveRandomSquares();
- } else {
- SendFreezeMessages();
- MessageAll("&bPlayers Frozen");
- Status = CountdownGameStatus.RoundInProgress;
- foreach (Player pl in Players)
- pl.CountdownSetFreezePos = true;
- Thread.Sleep(500);
-
- RemoveGlassBlocks();
- RemoveRandomSquares();
}
+
+ DoRound();
}
void SpawnPlayers(int x, int y, int z) {
Position pos = new Position(x, y, z);
foreach (Player pl in Players) {
- if (pl.level != mapon) {
+ if (pl.level != Map) {
pl.SendMessage("Sending you to the correct map.");
- PlayerActions.ChangeMap(pl, mapon.name);
+ PlayerActions.ChangeMap(pl, Map.name);
}
Entities.Spawn(pl, pl, pos, pl.Rot);
}
}
- void SendFreezeMessages() {
+
+ #region Do a round
+
+ void DoRound() {
+ if (FreezeMode) {
+ MessageFreezeCountdown();
+ MessageAll("&bPlayers Frozen");
+
+ foreach (Player pl in Players) {
+ Position pos = pl.Pos;
+ pl.CountdownFreezeX = pos.X;
+ pl.CountdownFreezeZ = pos.Z;
+ }
+ RemoveAllSquareBorders();
+ }
+
+ CloseOffBoard();
+ Status = CountdownGameStatus.RoundInProgress;
+ RemoveSquares();
+ }
+
+ void MessageFreezeCountdown() {
Thread.Sleep(500);
MessageAll("Welcome to Freeze Mode of countdown");
MessageAll("You have 15 seconds to stand on a square");
@@ -153,129 +151,123 @@ namespace MCGalaxy.Games {
MessageAll("-----&b2%S-----"); Thread.Sleep(1000);
MessageAll("-----&b1%S-----"); Thread.Sleep(1000);
}
+
+ void CloseOffBoard() {
+ SetGlassTube(Block.air, Block.glass);
+ int maxX = Map.Width - 1, maxZ = Map.Length - 1;
+
+ // Cuboid the borders around game board with air
+ Cuboid(4, 4, 4, maxX - 4, 4, 4, Block.air, Map);
+ Cuboid(4, 4, maxZ - 4, maxX - 4, 4, maxZ - 4, Block.air, Map);
+ Cuboid(4, 4, 4, 4, 4, maxZ - 4, Block.air, Map);
+ Cuboid(maxX - 4, 4, 4, maxX - 4, 4, maxZ - 4, Block.air, Map);
+ }
- void RemoveGlassBlocks() {
- int maxX = mapon.Width - 1, maxZ = mapon.Length - 1;
+
+ void RemoveAllSquareBorders() {
+ int maxX = Map.Width - 1, maxZ = Map.Length - 1;
for (int xx = 6; xx < maxX - 6; xx += 3)
- Cuboid(xx - 1, 4, 4, xx - 1, 4, maxZ - 4, Block.air, mapon);
+ Cuboid(xx - 1, 4, 4, xx - 1, 4, maxZ - 4, Block.air, Map);
for(int zz = 6; zz < maxZ - 6; zz += 3)
- Cuboid(4, 4, zz - 1, maxX - 4, 4, zz - 2, Block.air, mapon);
+ Cuboid(4, 4, zz - 1, maxX - 4, 4, zz - 2, Block.air, Map);
}
- void RemoveRandomSquares() {
+ void RemoveSquares() {
+ Random rng = new Random();
while (squaresLeft.Count > 0 && PlayersRemaining.Count != 0
&& (Status == CountdownGameStatus.RoundInProgress || Status == CountdownGameStatus.RoundFinished))
- {
- Random number = new Random();
- int index = number.Next(squaresLeft.Count);
- SquarePos nextsquare = squaresLeft[index];
+ {
+ int index = rng.Next(squaresLeft.Count);
+ SquarePos nextSquare = squaresLeft[index];
squaresLeft.RemoveAt(index);
- RemoveSquare(nextsquare);
+ RemoveSquare(nextSquare);
if (squaresLeft.Count % 10 == 0 && Status != CountdownGameStatus.RoundFinished)
- mapon.ChatLevel(squaresLeft.Count + " Squares Left and " + PlayersRemaining.Count + " Players left!!");
+ Map.ChatLevel(squaresLeft.Count + " squares left and " + PlayersRemaining.Count + " players remaining!");
if (cancel)
End(null);
}
}
void RemoveSquare(SquarePos pos) {
- ushort x1 = pos.X, x2 = (ushort)(pos.X + 1), y = 4, z1 = pos.Z, z2 = (ushort)(pos.Z + 1);
- Cuboid(x1, y, z1, x2, y, z2, Block.yellow, mapon);
- Thread.Sleep(speed);
- Cuboid(x1, y, z1, x2, y, z2, Block.orange, mapon);
- Thread.Sleep(speed);
- Cuboid(x1, y, z1, x2, y, z2, Block.red, mapon);
- Thread.Sleep(speed);
- Cuboid(x1, y, z1, x2, y, z2, Block.air, mapon);
+ ushort minX = pos.X, maxX = (ushort)(pos.X + 1), y = 4, minZ = pos.Z, maxZ = (ushort)(pos.Z + 1);
+ Cuboid(minX, y, minZ, maxX, y, maxZ, Block.yellow, Map);
+ Thread.Sleep(Speed);
+ Cuboid(minX, y, minZ, maxX, y, maxZ, Block.orange, Map);
+ Thread.Sleep(Speed);
+ Cuboid(minX, y, minZ, maxX, y, maxZ, Block.red, Map);
+ Thread.Sleep(Speed);
+ Cuboid(minX, y, minZ, maxX, y, maxZ, Block.air, Map);
+ // Remove glass borders if neighbouring squared were previously removed.
- //beneath this is checking the glass next to the square
- bool up = false, left = false, right = false, down = false;
- //directly next to
- if (mapon.IsAirAt(x1, y, z2 + 2)) //right
- {
- mapon.Blockchange(x1, y, (ushort)(z2 + 1), ExtBlock.Air);
- mapon.Blockchange(x2, y, (ushort)(z2 + 1), ExtBlock.Air);
- right = true;
+ bool airMaxX = false, airMinZ = false, airMaxZ = false, airMinX = false;
+ if (Map.IsAirAt(minX, y, maxZ + 2)) {
+ Map.Blockchange(minX, y, (ushort)(maxZ + 1), ExtBlock.Air);
+ Map.Blockchange(maxX, y, (ushort)(maxZ + 1), ExtBlock.Air);
+ airMaxZ = true;
}
- if (mapon.IsAirAt(x1, y, z1 - 2)) //left
- {
- mapon.Blockchange(x1, y, (ushort)(z1 - 1), ExtBlock.Air);
- mapon.Blockchange(x2, y, (ushort)(z1 - 1), ExtBlock.Air);
- left = true;
+ if (Map.IsAirAt(minX, y, minZ - 2)) {
+ Map.Blockchange(minX, y, (ushort)(minZ - 1), ExtBlock.Air);
+ Map.Blockchange(maxX, y, (ushort)(minZ - 1), ExtBlock.Air);
+ airMinZ = true;
}
- if (mapon.IsAirAt(x2 + 2, y, z1)) //up
- {
- mapon.Blockchange((ushort)(x2 + 1), y, z1, ExtBlock.Air);
- mapon.Blockchange((ushort)(x2 + 1), y, z2, ExtBlock.Air);
- up = true;
+ if (Map.IsAirAt(maxX + 2, y, minZ)) {
+ Map.Blockchange((ushort)(maxX + 1), y, minZ, ExtBlock.Air);
+ Map.Blockchange((ushort)(maxX + 1), y, maxZ, ExtBlock.Air);
+ airMaxX = true;
}
- if (mapon.IsAirAt(x1 - 2, y, z1)) //down
- {
- mapon.Blockchange((ushort)(x1 - 1), y, z1, ExtBlock.Air);
- mapon.Blockchange((ushort)(x1 - 1), y, z2, ExtBlock.Air);
- down = true;
+ if (Map.IsAirAt(minX - 2, y, minZ)) {
+ Map.Blockchange((ushort)(minX - 1), y, minZ, ExtBlock.Air);
+ Map.Blockchange((ushort)(minX - 1), y, maxZ, ExtBlock.Air);
+ airMinX = true;
}
- //diagonal >:(
- if (mapon.IsAirAt(x1 - 2, y, z1 - 2) && left && down) //bottom left
- {
- mapon.Blockchange((ushort)(x1 - 1), y, (ushort)(z1 - 1), ExtBlock.Air);
+ // Remove glass borders for diagonals too.
+ if (Map.IsAirAt(minX - 2, y, minZ - 2) && airMinZ && airMinX) {
+ Map.Blockchange((ushort)(minX - 1), y, (ushort)(minZ - 1), ExtBlock.Air);
}
- if (mapon.IsAirAt(x1 - 2, y, z2 + 2) && right && down) //bottom right
- {
- mapon.Blockchange((ushort)(x1 - 1), y, (ushort)(z2 + 1), ExtBlock.Air);
+ if (Map.IsAirAt(minX - 2, y, maxZ + 2) && airMaxZ && airMinX) {
+ Map.Blockchange((ushort)(minX - 1), y, (ushort)(maxZ + 1), ExtBlock.Air);
}
- if (mapon.IsAirAt(x2 + 2, y, z1 - 2) && left && up) //top left
- {
- mapon.Blockchange((ushort)(x2 + 1), y, (ushort)(z1 - 1), ExtBlock.Air);
+ if (Map.IsAirAt(maxX + 2, y, minZ - 2) && airMinZ && airMaxX) {
+ Map.Blockchange((ushort)(maxX + 1), y, (ushort)(minZ - 1), ExtBlock.Air);
}
- if (mapon.IsAirAt(x2 + 2, y, z2 + 2) && right && up) //top right
- {
- mapon.Blockchange((ushort)(x2 + 1), y, (ushort)(z2 + 1), ExtBlock.Air);
+ if (Map.IsAirAt(maxX + 2, y, maxZ + 2) && airMaxZ && airMaxX) {
+ Map.Blockchange((ushort)(maxX + 1), y, (ushort)(maxZ + 1), ExtBlock.Air);
}
}
- void AfterStart() {
- SetGlassTube(Block.air, Block.glass);
-
- int maxX = mapon.Width - 1, maxZ = mapon.Length - 1;
- Cuboid(4, 4, 4, maxX - 4, 4, 4, Block.air, mapon);
- Cuboid(4, 4, maxZ - 4, maxX - 4, 4, maxZ - 4, Block.air, mapon);
- Cuboid(4, 4, 4, 4, 4, maxZ - 4, Block.air, mapon);
- Cuboid(maxX - 4, 4, 4, maxX - 4, 4, maxZ - 4, Block.air, mapon);
-
- if (!freezemode) {
- Status = CountdownGameStatus.RoundInProgress;
- }
- }
+ #endregion
+
public void Death(Player p) {
- mapon.ChatLevel(p.ColoredName + " %Sis out of countdown!!");
+ Map.ChatLevel(p.ColoredName + " %Sis out of countdown!!");
p.InCountdown = false;
PlayersRemaining.Remove(p);
- MessagePlayersLeft();
+ UpdatePlayersLeft();
}
- public void MessagePlayersLeft() {
+ public void UpdatePlayersLeft() {
+ if (Status != CountdownGameStatus.RoundInProgress) return;
+
switch (PlayersRemaining.Count) {
case 1:
- mapon.ChatLevel(PlayersRemaining[0].ColoredName + " %Sis the winner!!");
+ Map.ChatLevel(PlayersRemaining[0].ColoredName + " %Sis the winner!!");
End(PlayersRemaining[0]);
break;
case 2:
- mapon.ChatLevel("Only 2 Players left:");
- mapon.ChatLevel(PlayersRemaining[0].ColoredName + " %Sand " + PlayersRemaining[1].ColoredName);
+ Map.ChatLevel("Only 2 Players left:");
+ Map.ChatLevel(PlayersRemaining[0].ColoredName + " %Sand " + PlayersRemaining[1].ColoredName);
break;
case 5:
- mapon.ChatLevel("Only 5 Players left:");
+ Map.ChatLevel("Only 5 Players left:");
foreach (Player pl in PlayersRemaining) {
- mapon.ChatLevel(pl.ColoredName);
+ Map.ChatLevel(pl.ColoredName);
Thread.Sleep(500);
}
break;
default:
- mapon.ChatLevel("Now there are " + PlayersRemaining.Count + " players left!!");
+ Map.ChatLevel("Now there are " + PlayersRemaining.Count + " players left!!");
break;
}
}
@@ -315,11 +307,11 @@ namespace MCGalaxy.Games {
}
SetGlassTube(Block.air, Block.air);
- int maxX = mapon.Width - 1, maxZ = mapon.Length - 1;
- Cuboid(4, 4, 4, maxX - 4, 4, maxZ - 4, Block.glass, mapon);
+ int maxX = Map.Width - 1, maxZ = Map.Length - 1;
+ Cuboid(4, 4, 4, maxX - 4, 4, maxZ - 4, Block.glass, Map);
for(int zz = 6; zz < maxZ - 6; zz += 3)
for (int xx = 6; xx < maxX - 6; xx += 3)
- Cuboid(xx, 4, zz, xx + 1, 4, zz + 1, Block.green, mapon);
+ Cuboid(xx, 4, zz, xx + 1, 4, zz + 1, Block.green, Map);
if (!all) {
Player.Message(p, "The Countdown map has been reset");
@@ -330,7 +322,7 @@ namespace MCGalaxy.Games {
Player[] online = PlayerInfo.Online.Items;
foreach (Player pl in online) {
if (!pl.playerofcountdown) continue;
- if (pl.level == mapon) {
+ if (pl.level == Map) {
Command.all.Find("countdown").Use(pl, "join");
Player.Message(pl, "You've rejoined countdown!!");
} else {
@@ -348,7 +340,7 @@ namespace MCGalaxy.Games {
Players.Clear();
squaresLeft.Clear();
- speed = 750;
+ Speed = 750;
Player[] online = PlayerInfo.Online.Items;
foreach (Player pl in online) {
pl.playerofcountdown = false;
@@ -358,12 +350,12 @@ namespace MCGalaxy.Games {
}
void SetGlassTube(byte block, byte floorBlock) {
- int midX = mapon.Width / 2, midY = mapon.Height / 2, midZ = mapon.Length / 2;
- Cuboid(midX - 1, midY + 1, midZ - 2, midX, midY + 2, midZ - 2, block, mapon);
- Cuboid(midX - 1, midY + 1, midZ + 1, midX, midY + 2, midZ + 1, block, mapon);
- Cuboid(midX - 2, midY + 1, midZ - 1, midX - 2, midY + 2, midZ, block, mapon);
- Cuboid(midX + 1, midY + 1, midZ - 1, midX + 1, midY + 2, midZ, block, mapon);
- Cuboid(midX - 1, midY, midZ - 1, midX, midY, midZ, floorBlock, mapon);
+ int midX = Map.Width / 2, midY = Map.Height / 2, midZ = Map.Length / 2;
+ Cuboid(midX - 1, midY + 1, midZ - 2, midX, midY + 2, midZ - 2, block, Map);
+ Cuboid(midX - 1, midY + 1, midZ + 1, midX, midY + 2, midZ + 1, block, Map);
+ Cuboid(midX - 2, midY + 1, midZ - 1, midX - 2, midY + 2, midZ, block, Map);
+ Cuboid(midX + 1, midY + 1, midZ - 1, midX + 1, midY + 2, midZ, block, Map);
+ Cuboid(midX - 1, midY, midZ - 1, midX, midY, midZ, floorBlock, Map);
}
public void MessageAll(string message) {
@@ -384,7 +376,7 @@ namespace MCGalaxy.Games {
}
}
- public struct SquarePos {
+ struct SquarePos {
public ushort X, Z;
public SquarePos(int x, int z) {
@@ -398,7 +390,7 @@ namespace MCGalaxy.Games {
Server.Countdown.Players.Add(p);
Player.Message(p, "You've joined the Countdown game!!");
Chat.MessageGlobal("{0} has joined Countdown!!", p.name);
- if (p.level != Server.Countdown.mapon)
+ if (p.level != Server.Countdown.Map)
PlayerActions.ChangeMap(p, "countdown");
p.playerofcountdown = true;
} else {
@@ -411,12 +403,12 @@ namespace MCGalaxy.Games {
p.playerofcountdown = false;
Players.Remove(p);
PlayersRemaining.Remove(p);
- MessagePlayersLeft();
+ UpdatePlayersLeft();
}
}
public enum CountdownGameStatus {
- /// Countdown is not running.
+ /// Countdown is not running.
Disabled,
/// Countdown is running, but no round has been started at all yet.
diff --git a/MCGalaxy/Games/Countdown/CountdownPlugin.cs b/MCGalaxy/Games/Countdown/CountdownPlugin.cs
index 1347d22ee..3c9355c46 100644
--- a/MCGalaxy/Games/Countdown/CountdownPlugin.cs
+++ b/MCGalaxy/Games/Countdown/CountdownPlugin.cs
@@ -38,17 +38,9 @@ namespace MCGalaxy.Games {
void HandlePlayerMove(Player p, Position next, byte yaw, byte pitch) {
- if (!p.InCountdown || Game.Status != CountdownGameStatus.RoundInProgress || !Game.freezemode)
+ if (!p.InCountdown || Game.Status != CountdownGameStatus.RoundInProgress || !Game.FreezeMode)
return;
- if (p.CountdownSetFreezePos) {
- p.CountdownFreezeX = next.X;
- Thread.Sleep(100);
- p.CountdownFreezeZ = next.Z;
- Thread.Sleep(100);
- p.CountdownSetFreezePos = false;
- }
-
if (next.X != p.CountdownFreezeX || next.Z != p.CountdownFreezeZ) {
next.X = p.CountdownFreezeX; next.Z = p.CountdownFreezeZ;
p.SendPos(Entities.SelfID, next, new Orientation(yaw, pitch));
@@ -63,7 +55,7 @@ namespace MCGalaxy.Games {
if (!Game.Players.Contains(p)) return;
if (Game.PlayersRemaining.Contains(p)) {
- Game.mapon.ChatLevel(p.ColoredName + " %Slogged out, and so is out of countdown");
+ Game.Map.ChatLevel(p.ColoredName + " %Slogged out, and so is out of countdown");
Game.PlayerLeftGame(p);
}
Game.Players.Remove(p);
diff --git a/MCGalaxy/Player/Player.Fields.cs b/MCGalaxy/Player/Player.Fields.cs
index 1a617bfaa..bb74e42b5 100644
--- a/MCGalaxy/Player/Player.Fields.cs
+++ b/MCGalaxy/Player/Player.Fields.cs
@@ -173,7 +173,6 @@ namespace MCGalaxy {
public bool InCountdown = false;
public int CountdownFreezeX;
public int CountdownFreezeZ;
- public bool CountdownSetFreezePos = false;
//Tnt Wars
public bool PlayingTntWars = false;