Start cleaning up countdown classes, probably breaks countdown.

This commit is contained in:
UnknownShadow200 2017-06-29 14:48:57 +10:00
parent 05f49b60c7
commit 8eeb0e5614
4 changed files with 264 additions and 277 deletions

View File

@ -49,30 +49,31 @@ namespace MCGalaxy.Commands.Fun {
if (args.Length > 1) arg1 = args[1]; if (args.Length > 1) arg1 = args[1];
if (args.Length > 2) arg2 = args[2]; if (args.Length > 2) arg2 = args[2];
if (args.Length > 3) arg3 = args[3]; if (args.Length > 3) arg3 = args[3];
CountdownGame game = Server.Countdown;
switch (cmd) { switch (cmd) {
case "join": case "join":
HandleJoin(p); return; HandleJoin(p, game); return;
case "leave": case "leave":
HandleLeave(p); return; HandleLeave(p, game); return;
case "players": case "players":
HandlePlayers(p); return; HandlePlayers(p, game); return;
case "rules": case "rules":
HandleRules(p, arg1); return; HandleRules(p, arg1); return;
case "download": case "download":
case "generate": case "generate":
HandleGenerate(p, arg1, arg2, arg3); return; HandleGenerate(p, game, arg1, arg2, arg3); return;
case "enable": case "enable":
HandleEnable(p); return; HandleEnable(p, game); return;
case "disable": case "disable":
HandleDisable(p); return; HandleDisable(p, game); return;
case "cancel": case "cancel":
HandleCancel(p); return; HandleCancel(p, game); return;
case "start": case "start":
case "play": case "play":
HandleStart(p, arg1, arg2); return; HandleStart(p, game, arg1, arg2); return;
case "reset": case "reset":
HandleReset(p, arg1); return; HandleReset(p, game, arg1); return;
case "tutorial": case "tutorial":
HandleTutorial(p); return; HandleTutorial(p); return;
default: default:
@ -80,13 +81,13 @@ namespace MCGalaxy.Commands.Fun {
} }
} }
void HandleJoin(Player p) { void HandleJoin(Player p, CountdownGame game) {
switch (Server.Countdown.Status) { switch (game.Status) {
case CountdownGameStatus.Disabled: case CountdownGameStatus.Disabled:
Player.Message(p, "Cannot join as countdown is not running."); Player.Message(p, "Cannot join as countdown is not running.");
return; return;
case CountdownGameStatus.Enabled: case CountdownGameStatus.Enabled:
Server.Countdown.PlayerJoinedGame(p); game.PlayerJoinedGame(p);
return; return;
case CountdownGameStatus.RoundCountdown: case CountdownGameStatus.RoundCountdown:
Player.Message(p, "Cannot join when a round is about to start. Wait until next round."); 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) { void HandleLeave(Player p, CountdownGame game) {
if (Server.Countdown.Players.Contains(p)) { if (!game.Players.Contains(p)) {
switch (Server.Countdown.Status) { Player.Message(p, "Cannot leave as you did not join countdown to begin with.");
return;
}
switch (game.Status) {
case CountdownGameStatus.Disabled: case CountdownGameStatus.Disabled:
Player.Message(p, "Cannot leave as countdown is not running."); Player.Message(p, "Cannot leave as countdown is not running.");
return; return;
case CountdownGameStatus.Enabled: case CountdownGameStatus.Enabled:
case CountdownGameStatus.RoundFinished:
Player.Message(p, "You've left countdown."); Player.Message(p, "You've left countdown.");
Server.Countdown.PlayerLeftGame(p); game.PlayerLeftGame(p);
break; return;
case CountdownGameStatus.RoundCountdown: case CountdownGameStatus.RoundCountdown:
Player.Message(p, "Cannot leave when a round is about to start."); 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; return;
case CountdownGameStatus.RoundFinished: case CountdownGameStatus.RoundInProgress:
Server.Countdown.Players.Remove(p); if (game.PlayersRemaining.Contains(p)) {
Server.Countdown.PlayersRemaining.Remove(p); Player.Message(p, "Cannot leave when a round in progress - please wait until the round ends or you die.");
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 { } else {
Player.Message(p, "Cannot leave as you did not join countdown to begin with."); game.Players.Remove(p);
Player.Message(p, "You've left countdown.");
}
return;
} }
} }
void HandlePlayers(Player p) { void HandlePlayers(Player p, CountdownGame game) {
switch (Server.Countdown.Status) { switch (game.Status) {
case CountdownGameStatus.Disabled: case CountdownGameStatus.Disabled:
Player.Message(p, "Countdown is not running."); Player.Message(p, "Countdown is not running.");
break; break;
case CountdownGameStatus.RoundInProgress: case CountdownGameStatus.RoundInProgress:
Player.Message(p, "Players in countdown:"); Player.Message(p, "Players in countdown:");
Player.Message(p, Server.Countdown.Players.Join(FormatPlayer)); Player.Message(p, game.Players.Join(pl => FormatPlayer(pl, game)));
break; break;
default: default:
Player.Message(p, "Players in countdown: "); 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; break;
} }
} }
static string FormatPlayer(Player pl) { static string FormatPlayer(Player pl, CountdownGame game) {
if (Server.Countdown.PlayersRemaining.Contains(pl)) { if (game.PlayersRemaining.Contains(pl)) {
return pl.ColoredName + " &a[IN]"; return pl.ColoredName + " &a[IN]";
} else { } else {
return pl.ColoredName + " &c[OUT]"; return pl.ColoredName + " &c[OUT]";
@ -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; } if (!CheckExtraPerm(p, 2)) { MessageNeedExtra(p, 2); return; }
int width, height, length; 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; width = 32; height = 32; length = 32;
} }
if (width < 32 || !MapGen.OkayAxis(width)) width = 32; if (width < 32 || !MapGen.OkayAxis(width)) width = 32;
@ -197,8 +196,8 @@ namespace MCGalaxy.Commands.Fun {
else LevelInfo.Loaded.Add(lvl); else LevelInfo.Loaded.Add(lvl);
lvl.Save(); lvl.Save();
if (Server.Countdown.Status != CountdownGameStatus.Disabled) if (game.Status != CountdownGameStatus.Disabled)
Server.Countdown.mapon = lvl; game.Map = lvl;
const string format = "Generated map ({0}x{1}x{2}), sending you to it.."; const string format = "Generated map ({0}x{1}x{2}), sending you to it..";
Player.Message(p, format, width, height, length); Player.Message(p, format, width, height, length);
@ -208,113 +207,118 @@ namespace MCGalaxy.Commands.Fun {
p.SendPos(Entities.SelfID, pos, p.Rot); 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 (!CheckExtraPerm(p, 2)) { MessageNeedExtra(p, 2); return; }
if (Server.Countdown.Status == CountdownGameStatus.Disabled) { if (game.Status == CountdownGameStatus.Disabled) {
CmdLoad.LoadLevel(null, "countdown"); CmdLoad.LoadLevel(null, "countdown");
Server.Countdown.mapon = LevelInfo.FindExact("countdown"); game.Map = LevelInfo.FindExact("countdown");
if (Server.Countdown.mapon == null) { if (game.Map == null) {
Player.Message(p, "countdown level not found, generating.."); Player.Message(p, "Countdown level not found, generating..");
HandleGenerate(p, "", "", ""); HandleGenerate(p, game, "", "", "");
Server.Countdown.mapon = LevelInfo.FindExact("countdown"); game.Map = LevelInfo.FindExact("countdown");
} }
Server.Countdown.mapon.Config.Deletable = false; game.Map.Config.Deletable = false;
Server.Countdown.mapon.Config.Buildable = false; game.Map.Config.Buildable = false;
Server.Countdown.mapon.BuildAccess.Min = LevelPermission.Nobody; game.Map.BuildAccess.Min = LevelPermission.Nobody;
Server.Countdown.mapon.Config.MOTD = "Welcome to the Countdown map! -hax"; game.Map.Config.MOTD = "Welcome to the Countdown map! -hax";
Server.Countdown.Status = CountdownGameStatus.Enabled; game.Status = CountdownGameStatus.Enabled;
Chat.MessageGlobal("Countdown has been enabled!!"); Chat.MessageGlobal("Countdown has been enabled!");
} else { } 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 (!CheckExtraPerm(p, 2)) { MessageNeedExtra(p, 2); return; }
if (Server.Countdown.Status == CountdownGameStatus.RoundCountdown || Server.Countdown.Status == CountdownGameStatus.RoundInProgress) { if (game.Status == CountdownGameStatus.RoundCountdown || game.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; 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 (Server.Countdown.Status == CountdownGameStatus.Disabled) { } else if (game.Status == CountdownGameStatus.Disabled) {
Player.Message(p, "Already disabled!!"); return; Player.Message(p, "Countdown is not running."); return;
} else { } else {
foreach (Player pl in Server.Countdown.Players) foreach (Player pl in game.Players)
Player.Message(pl, "The countdown game was disabled."); Player.Message(pl, "The countdown game was disabled.");
Server.Countdown.Reset(p, true); game.Reset(p, true);
Server.Countdown.Status = CountdownGameStatus.Disabled; game.Status = CountdownGameStatus.Disabled;
Player.Message(p, "Countdown 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 (!CheckExtraPerm(p, 2)) { MessageNeedExtra(p, 2); return; }
if (Server.Countdown.Status == CountdownGameStatus.RoundCountdown || Server.Countdown.Status == CountdownGameStatus.RoundInProgress) { if (game.Status == CountdownGameStatus.RoundCountdown || game.Status == CountdownGameStatus.RoundInProgress) {
Server.Countdown.cancel = true; game.cancel = true;
Thread.Sleep(1500); Thread.Sleep(1500);
Player.Message(p, "Countdown has been canceled"); Player.Message(p, "Countdown has been canceled");
Server.Countdown.Status = CountdownGameStatus.Enabled; game.Status = CountdownGameStatus.Enabled;
} else if (Server.Countdown.Status == CountdownGameStatus.Disabled) { } else if (game.Status == CountdownGameStatus.Disabled) {
Player.Message(p, "The game is disabled!!"); Player.Message(p, "Countdown is not running.");
} else { } else {
foreach (Player pl in Server.Countdown.Players) foreach (Player pl in game.Players)
Player.Message(pl, "The countdown game was canceled"); 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 (!CheckExtraPerm(p, 2)) { MessageNeedExtra(p, 2); return; }
if (Server.Countdown.Status != CountdownGameStatus.Enabled) { switch (game.Status) {
Player.Message(p, "Either a game is already in progress or it hasn't been enabled"); return; 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;
} }
if (Server.Countdown.Players.Count < 2) { game.Status = CountdownGameStatus.RoundCountdown; break;
Player.Message(p, "Sorry, there aren't enough players to play."); return;
} }
Server.Countdown.PlayersRemaining = Server.Countdown.Players; switch (speed) {
CountdownGame game = Server.Countdown;
switch (par1) {
case "slow": case "slow":
game.speed = 800; game.speedtype = "slow"; break; game.Speed = 800; game.SpeedType = "slow"; break;
case "normal": case "normal":
game.speed = 650; game.speedtype = "normal"; break; game.Speed = 650; game.SpeedType = "normal"; break;
case "fast": case "fast":
game.speed = 500; game.speedtype = "fast"; break; game.Speed = 500; game.SpeedType = "fast"; break;
case "extreme": case "extreme":
game.speed = 300; game.speedtype = "extreme"; break; game.Speed = 300; game.SpeedType = "extreme"; break;
case "ultimate": case "ultimate":
game.speed = 150; game.speedtype = "ultimate"; break; game.Speed = 150; game.SpeedType = "ultimate"; break;
default: default:
Player.Message(p, "You didn't specify a speed, resorting to 'normal'"); Player.Message(p, "No speed specified, playing at 'normal' speed.");
game.speed = 650; game.speedtype = "normal"; break; game.Speed = 650; game.SpeedType = "normal"; break;
}
Server.Countdown.freezemode = (par2 == "freeze" || par2 == "frozen");
Server.Countdown.GameStart(p);
} }
void HandleReset(Player p, string par1) { game.FreezeMode = (mode == "freeze" || mode == "frozen");
game.BeginRound(p);
}
void HandleReset(Player p, CountdownGame game, string type) {
if (!CheckExtraPerm(p, 2)) { MessageNeedExtra(p, 2); return; } if (!CheckExtraPerm(p, 2)) { MessageNeedExtra(p, 2); return; }
switch (Server.Countdown.Status) { switch (game.Status) {
case CountdownGameStatus.Disabled: case CountdownGameStatus.Disabled:
Player.Message(p, "Please enable countdown first."); break; Player.Message(p, "Please enable countdown first."); break;
case CountdownGameStatus.RoundCountdown: 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: 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: default:
Player.Message(p, "Reseting"); Player.Message(p, "Reseting");
if (par1 == "map") if (type == "map") game.Reset(p, false);
Server.Countdown.Reset(p, false); else if (type == "all") game.Reset(p, true);
else if (par1 == "all") else Player.Message(p, "Can only reset 'map' or 'all'");
Server.Countdown.Reset(p, true);
else
Player.Message(p, "Please specify whether it is 'map' or 'all'");
break; break;
} }
} }

View File

@ -22,107 +22,105 @@ using System.Threading;
namespace MCGalaxy.Games { namespace MCGalaxy.Games {
public sealed class CountdownGame : IGame { public sealed class CountdownGame : IGame {
/// <summary> All players who are playing this countdown game. </summary>
public List<Player> Players = new List<Player>(); public List<Player> Players = new List<Player>();
/// <summary> Players who are still alive in the current round. </summary>
public List<Player> PlayersRemaining = new List<Player>(); public List<Player> PlayersRemaining = new List<Player>();
public List<SquarePos> squaresLeft = new List<SquarePos>();
public Level mapon;
public int speed; /// <summary> Map countdown is running on. </summary>
public bool freezemode = false; public Level Map;
public bool cancel = false;
public string speedtype;
/// <summary> Current status of the countdown game. </summary>
public CountdownGameStatus Status = CountdownGameStatus.Disabled; public CountdownGameStatus Status = CountdownGameStatus.Disabled;
CountdownPlugin plugin;
public void GameStart(Player p) { public int Speed;
public bool FreezeMode = false;
public bool cancel = false;
public string SpeedType;
CountdownPlugin plugin;
List<SquarePos> squaresLeft = new List<SquarePos>();
public void BeginRound(Player p) {
if (plugin == null) { if (plugin == null) {
plugin = new CountdownPlugin(); plugin = new CountdownPlugin();
plugin.Game = this; plugin.Game = this;
plugin.Load(false); 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); SetGlassTube(Block.glass, Block.glass);
mapon.ChatLevel("Countdown is about to start!!"); Map.ChatLevel("Countdown is about to start!");
mapon.BuildAccess.Min = LevelPermission.Nobody; Map.BuildAccess.Min = LevelPermission.Nobody;
int midX = mapon.Width / 2, midY = mapon.Height / 2, midZ = mapon.Length / 2; int midX = Map.Width / 2, midY = Map.Height / 2, midZ = Map.Length / 2;
int xSpawn = (midX * 32 + 16); int xSpawn = (midX * 32 + 16);
int ySpawn = ((mapon.Height - 2) * 32); int ySpawn = ((Map.Height - 2) * 32);
int zSpawn = (midZ * 32 + 16); int zSpawn = (midZ * 32 + 16);
squaresLeft.Clear(); squaresLeft.Clear();
for(int zz = 6; zz < mapon.Length - 6; zz += 3) for(int zz = 6; zz < Map.Length - 6; zz += 3)
for (int xx = 6; xx < mapon.Width - 6; xx += 3) for (int xx = 6; xx < Map.Width - 6; xx += 3)
squaresLeft.Add(new SquarePos(xx, zz)); squaresLeft.Add(new SquarePos(xx, zz));
if (freezemode) if (FreezeMode)
mapon.ChatLevel("Countdown starting with difficulty " + speedtype + " and mode freeze in:"); Map.ChatLevel("Countdown starting with difficulty " + SpeedType + " and mode freeze in:");
else 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); Thread.Sleep(2000);
SpawnPlayers(xSpawn, ySpawn, zSpawn); 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); Thread.Sleep(1000);
mapon.ChatLevel("-----&b4%S-----"); Thread.Sleep(1000); Map.ChatLevel("-----&b4%S-----"); Thread.Sleep(1000);
mapon.ChatLevel("-----&b3%S-----"); Thread.Sleep(1000); Map.ChatLevel("-----&b3%S-----"); Thread.Sleep(1000);
Cuboid(midX, mapon.Height - 5, midZ, midX + 1, mapon.Height - 5, midZ + 1, Block.air, mapon); Cuboid(midX, Map.Height - 5, midZ, midX + 1, Map.Height - 5, midZ + 1, Block.air, Map);
mapon.ChatLevel("-----&b2%S-----"); Thread.Sleep(1000); Map.ChatLevel("-----&b2%S-----"); Thread.Sleep(1000);
mapon.ChatLevel("-----&b1%S-----"); Thread.Sleep(1000); Map.ChatLevel("-----&b1%S-----"); Thread.Sleep(1000);
mapon.ChatLevel("GO!!!!!!!"); Map.ChatLevel("GO!!!!!!!");
PlayersRemaining = Players; PlayersRemaining = new List<Player>(Players);
foreach (Player pl in Players) foreach (Player pl in Players) {
pl.InCountdown = true; pl.InCountdown = true;
AfterStart();
Play();
} }
public void Play() { DoRound();
if (!freezemode) {
RemoveRandomSquares();
} else {
SendFreezeMessages();
MessageAll("&bPlayers Frozen");
Status = CountdownGameStatus.RoundInProgress;
foreach (Player pl in Players)
pl.CountdownSetFreezePos = true;
Thread.Sleep(500);
RemoveGlassBlocks();
RemoveRandomSquares();
}
} }
void SpawnPlayers(int x, int y, int z) { void SpawnPlayers(int x, int y, int z) {
Position pos = new Position(x, y, z); Position pos = new Position(x, y, z);
foreach (Player pl in Players) { foreach (Player pl in Players) {
if (pl.level != mapon) { if (pl.level != Map) {
pl.SendMessage("Sending you to the correct 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); 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); Thread.Sleep(500);
MessageAll("Welcome to Freeze Mode of countdown"); MessageAll("Welcome to Freeze Mode of countdown");
MessageAll("You have 15 seconds to stand on a square"); MessageAll("You have 15 seconds to stand on a square");
@ -154,128 +152,122 @@ namespace MCGalaxy.Games {
MessageAll("-----&b1%S-----"); Thread.Sleep(1000); MessageAll("-----&b1%S-----"); Thread.Sleep(1000);
} }
void RemoveGlassBlocks() { void CloseOffBoard() {
int maxX = mapon.Width - 1, maxZ = mapon.Length - 1; SetGlassTube(Block.air, Block.glass);
for (int xx = 6; xx < maxX - 6; xx += 3) int maxX = Map.Width - 1, maxZ = Map.Length - 1;
Cuboid(xx - 1, 4, 4, xx - 1, 4, maxZ - 4, Block.air, mapon);
for(int zz = 6; zz < maxZ - 6; zz += 3) // Cuboid the borders around game board with air
Cuboid(4, 4, zz - 1, maxX - 4, 4, zz - 2, Block.air, mapon); 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 RemoveRandomSquares() {
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, Map);
for(int zz = 6; zz < maxZ - 6; zz += 3)
Cuboid(4, 4, zz - 1, maxX - 4, 4, zz - 2, Block.air, Map);
}
void RemoveSquares() {
Random rng = new Random();
while (squaresLeft.Count > 0 && PlayersRemaining.Count != 0 while (squaresLeft.Count > 0 && PlayersRemaining.Count != 0
&& (Status == CountdownGameStatus.RoundInProgress || Status == CountdownGameStatus.RoundFinished)) && (Status == CountdownGameStatus.RoundInProgress || Status == CountdownGameStatus.RoundFinished))
{ {
Random number = new Random(); int index = rng.Next(squaresLeft.Count);
int index = number.Next(squaresLeft.Count); SquarePos nextSquare = squaresLeft[index];
SquarePos nextsquare = squaresLeft[index];
squaresLeft.RemoveAt(index); squaresLeft.RemoveAt(index);
RemoveSquare(nextsquare); RemoveSquare(nextSquare);
if (squaresLeft.Count % 10 == 0 && Status != CountdownGameStatus.RoundFinished) 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) if (cancel)
End(null); End(null);
} }
} }
void RemoveSquare(SquarePos pos) { void RemoveSquare(SquarePos pos) {
ushort x1 = pos.X, x2 = (ushort)(pos.X + 1), y = 4, z1 = pos.Z, z2 = (ushort)(pos.Z + 1); ushort minX = pos.X, maxX = (ushort)(pos.X + 1), y = 4, minZ = pos.Z, maxZ = (ushort)(pos.Z + 1);
Cuboid(x1, y, z1, x2, y, z2, Block.yellow, mapon); Cuboid(minX, y, minZ, maxX, y, maxZ, Block.yellow, Map);
Thread.Sleep(speed); Thread.Sleep(Speed);
Cuboid(x1, y, z1, x2, y, z2, Block.orange, mapon); Cuboid(minX, y, minZ, maxX, y, maxZ, Block.orange, Map);
Thread.Sleep(speed); Thread.Sleep(Speed);
Cuboid(x1, y, z1, x2, y, z2, Block.red, mapon); Cuboid(minX, y, minZ, maxX, y, maxZ, Block.red, Map);
Thread.Sleep(speed); Thread.Sleep(Speed);
Cuboid(x1, y, z1, x2, y, z2, Block.air, mapon); 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 airMaxX = false, airMinZ = false, airMaxZ = false, airMinX = false;
bool up = false, left = false, right = false, down = false; if (Map.IsAirAt(minX, y, maxZ + 2)) {
//directly next to Map.Blockchange(minX, y, (ushort)(maxZ + 1), ExtBlock.Air);
if (mapon.IsAirAt(x1, y, z2 + 2)) //right Map.Blockchange(maxX, y, (ushort)(maxZ + 1), ExtBlock.Air);
{ airMaxZ = true;
mapon.Blockchange(x1, y, (ushort)(z2 + 1), ExtBlock.Air);
mapon.Blockchange(x2, y, (ushort)(z2 + 1), ExtBlock.Air);
right = true;
} }
if (mapon.IsAirAt(x1, y, z1 - 2)) //left if (Map.IsAirAt(minX, y, minZ - 2)) {
{ Map.Blockchange(minX, y, (ushort)(minZ - 1), ExtBlock.Air);
mapon.Blockchange(x1, y, (ushort)(z1 - 1), ExtBlock.Air); Map.Blockchange(maxX, y, (ushort)(minZ - 1), ExtBlock.Air);
mapon.Blockchange(x2, y, (ushort)(z1 - 1), ExtBlock.Air); airMinZ = true;
left = true;
} }
if (mapon.IsAirAt(x2 + 2, y, z1)) //up if (Map.IsAirAt(maxX + 2, y, minZ)) {
{ Map.Blockchange((ushort)(maxX + 1), y, minZ, ExtBlock.Air);
mapon.Blockchange((ushort)(x2 + 1), y, z1, ExtBlock.Air); Map.Blockchange((ushort)(maxX + 1), y, maxZ, ExtBlock.Air);
mapon.Blockchange((ushort)(x2 + 1), y, z2, ExtBlock.Air); airMaxX = true;
up = true;
} }
if (mapon.IsAirAt(x1 - 2, y, z1)) //down if (Map.IsAirAt(minX - 2, y, minZ)) {
{ Map.Blockchange((ushort)(minX - 1), y, minZ, ExtBlock.Air);
mapon.Blockchange((ushort)(x1 - 1), y, z1, ExtBlock.Air); Map.Blockchange((ushort)(minX - 1), y, maxZ, ExtBlock.Air);
mapon.Blockchange((ushort)(x1 - 1), y, z2, ExtBlock.Air); airMinX = true;
down = true;
} }
//diagonal >:( // Remove glass borders for diagonals too.
if (mapon.IsAirAt(x1 - 2, y, z1 - 2) && left && down) //bottom left if (Map.IsAirAt(minX - 2, y, minZ - 2) && airMinZ && airMinX) {
{ Map.Blockchange((ushort)(minX - 1), y, (ushort)(minZ - 1), ExtBlock.Air);
mapon.Blockchange((ushort)(x1 - 1), y, (ushort)(z1 - 1), ExtBlock.Air);
} }
if (mapon.IsAirAt(x1 - 2, y, z2 + 2) && right && down) //bottom right if (Map.IsAirAt(minX - 2, y, maxZ + 2) && airMaxZ && airMinX) {
{ Map.Blockchange((ushort)(minX - 1), y, (ushort)(maxZ + 1), ExtBlock.Air);
mapon.Blockchange((ushort)(x1 - 1), y, (ushort)(z2 + 1), ExtBlock.Air);
} }
if (mapon.IsAirAt(x2 + 2, y, z1 - 2) && left && up) //top left if (Map.IsAirAt(maxX + 2, y, minZ - 2) && airMinZ && airMaxX) {
{ Map.Blockchange((ushort)(maxX + 1), y, (ushort)(minZ - 1), ExtBlock.Air);
mapon.Blockchange((ushort)(x2 + 1), y, (ushort)(z1 - 1), ExtBlock.Air);
} }
if (mapon.IsAirAt(x2 + 2, y, z2 + 2) && right && up) //top right if (Map.IsAirAt(maxX + 2, y, maxZ + 2) && airMaxZ && airMaxX) {
{ Map.Blockchange((ushort)(maxX + 1), y, (ushort)(maxZ + 1), ExtBlock.Air);
mapon.Blockchange((ushort)(x2 + 1), y, (ushort)(z2 + 1), ExtBlock.Air);
} }
} }
void AfterStart() { #endregion
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;
}
}
public void Death(Player p) { public void Death(Player p) {
mapon.ChatLevel(p.ColoredName + " %Sis out of countdown!!"); Map.ChatLevel(p.ColoredName + " %Sis out of countdown!!");
p.InCountdown = false; p.InCountdown = false;
PlayersRemaining.Remove(p); PlayersRemaining.Remove(p);
MessagePlayersLeft(); UpdatePlayersLeft();
} }
public void MessagePlayersLeft() { public void UpdatePlayersLeft() {
if (Status != CountdownGameStatus.RoundInProgress) return;
switch (PlayersRemaining.Count) { switch (PlayersRemaining.Count) {
case 1: case 1:
mapon.ChatLevel(PlayersRemaining[0].ColoredName + " %Sis the winner!!"); Map.ChatLevel(PlayersRemaining[0].ColoredName + " %Sis the winner!!");
End(PlayersRemaining[0]); End(PlayersRemaining[0]);
break; break;
case 2: case 2:
mapon.ChatLevel("Only 2 Players left:"); Map.ChatLevel("Only 2 Players left:");
mapon.ChatLevel(PlayersRemaining[0].ColoredName + " %Sand " + PlayersRemaining[1].ColoredName); Map.ChatLevel(PlayersRemaining[0].ColoredName + " %Sand " + PlayersRemaining[1].ColoredName);
break; break;
case 5: case 5:
mapon.ChatLevel("Only 5 Players left:"); Map.ChatLevel("Only 5 Players left:");
foreach (Player pl in PlayersRemaining) { foreach (Player pl in PlayersRemaining) {
mapon.ChatLevel(pl.ColoredName); Map.ChatLevel(pl.ColoredName);
Thread.Sleep(500); Thread.Sleep(500);
} }
break; break;
default: default:
mapon.ChatLevel("Now there are " + PlayersRemaining.Count + " players left!!"); Map.ChatLevel("Now there are " + PlayersRemaining.Count + " players left!!");
break; break;
} }
} }
@ -315,11 +307,11 @@ namespace MCGalaxy.Games {
} }
SetGlassTube(Block.air, Block.air); SetGlassTube(Block.air, Block.air);
int maxX = mapon.Width - 1, maxZ = mapon.Length - 1; int maxX = Map.Width - 1, maxZ = Map.Length - 1;
Cuboid(4, 4, 4, maxX - 4, 4, maxZ - 4, Block.glass, mapon); Cuboid(4, 4, 4, maxX - 4, 4, maxZ - 4, Block.glass, Map);
for(int zz = 6; zz < maxZ - 6; zz += 3) for(int zz = 6; zz < maxZ - 6; zz += 3)
for (int xx = 6; xx < maxX - 6; xx += 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) { if (!all) {
Player.Message(p, "The Countdown map has been reset"); Player.Message(p, "The Countdown map has been reset");
@ -330,7 +322,7 @@ namespace MCGalaxy.Games {
Player[] online = PlayerInfo.Online.Items; Player[] online = PlayerInfo.Online.Items;
foreach (Player pl in online) { foreach (Player pl in online) {
if (!pl.playerofcountdown) continue; if (!pl.playerofcountdown) continue;
if (pl.level == mapon) { if (pl.level == Map) {
Command.all.Find("countdown").Use(pl, "join"); Command.all.Find("countdown").Use(pl, "join");
Player.Message(pl, "You've rejoined countdown!!"); Player.Message(pl, "You've rejoined countdown!!");
} else { } else {
@ -348,7 +340,7 @@ namespace MCGalaxy.Games {
Players.Clear(); Players.Clear();
squaresLeft.Clear(); squaresLeft.Clear();
speed = 750; Speed = 750;
Player[] online = PlayerInfo.Online.Items; Player[] online = PlayerInfo.Online.Items;
foreach (Player pl in online) { foreach (Player pl in online) {
pl.playerofcountdown = false; pl.playerofcountdown = false;
@ -358,12 +350,12 @@ namespace MCGalaxy.Games {
} }
void SetGlassTube(byte block, byte floorBlock) { void SetGlassTube(byte block, byte floorBlock) {
int midX = mapon.Width / 2, midY = mapon.Height / 2, midZ = mapon.Length / 2; 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, mapon); 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, mapon); 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, mapon); 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, mapon); Cuboid(midX + 1, midY + 1, midZ - 1, midX + 1, midY + 2, midZ, block, Map);
Cuboid(midX - 1, midY, midZ - 1, midX, midY, midZ, floorBlock, mapon); Cuboid(midX - 1, midY, midZ - 1, midX, midY, midZ, floorBlock, Map);
} }
public void MessageAll(string message) { public void MessageAll(string message) {
@ -384,7 +376,7 @@ namespace MCGalaxy.Games {
} }
} }
public struct SquarePos { struct SquarePos {
public ushort X, Z; public ushort X, Z;
public SquarePos(int x, int z) { public SquarePos(int x, int z) {
@ -398,7 +390,7 @@ namespace MCGalaxy.Games {
Server.Countdown.Players.Add(p); Server.Countdown.Players.Add(p);
Player.Message(p, "You've joined the Countdown game!!"); Player.Message(p, "You've joined the Countdown game!!");
Chat.MessageGlobal("{0} has joined Countdown!!", p.name); Chat.MessageGlobal("{0} has joined Countdown!!", p.name);
if (p.level != Server.Countdown.mapon) if (p.level != Server.Countdown.Map)
PlayerActions.ChangeMap(p, "countdown"); PlayerActions.ChangeMap(p, "countdown");
p.playerofcountdown = true; p.playerofcountdown = true;
} else { } else {
@ -411,7 +403,7 @@ namespace MCGalaxy.Games {
p.playerofcountdown = false; p.playerofcountdown = false;
Players.Remove(p); Players.Remove(p);
PlayersRemaining.Remove(p); PlayersRemaining.Remove(p);
MessagePlayersLeft(); UpdatePlayersLeft();
} }
} }

View File

@ -38,17 +38,9 @@ namespace MCGalaxy.Games {
void HandlePlayerMove(Player p, Position next, byte yaw, byte pitch) { 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; 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) { if (next.X != p.CountdownFreezeX || next.Z != p.CountdownFreezeZ) {
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)); p.SendPos(Entities.SelfID, next, new Orientation(yaw, pitch));
@ -63,7 +55,7 @@ namespace MCGalaxy.Games {
if (!Game.Players.Contains(p)) return; if (!Game.Players.Contains(p)) return;
if (Game.PlayersRemaining.Contains(p)) { 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.PlayerLeftGame(p);
} }
Game.Players.Remove(p); Game.Players.Remove(p);

View File

@ -173,7 +173,6 @@ namespace MCGalaxy {
public bool InCountdown = false; public bool InCountdown = false;
public int CountdownFreezeX; public int CountdownFreezeX;
public int CountdownFreezeZ; public int CountdownFreezeZ;
public bool CountdownSetFreezePos = false;
//Tnt Wars //Tnt Wars
public bool PlayingTntWars = false; public bool PlayingTntWars = false;