From ab6c4288bc4f5b7cebba6bcf3f4eaf6152b5f2ed Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 13 Mar 2016 12:31:59 +1100 Subject: [PATCH] More code cleanup for zombie survival. --- Commands/Fun/CmdAlive.cs | 4 +- Commands/Fun/CmdDisinfect.cs | 2 +- Commands/{Moderation => Fun}/CmdEndRound.cs | 79 +++++----- Commands/Fun/CmdInfect.cs | 2 +- Commands/{Moderation => Fun}/CmdReferee.cs | 160 ++++++++++---------- Commands/Fun/CmdZombieGame.cs | 60 ++++---- Commands/World/CmdGoto.cs | 2 +- Commands/other/CmdSpawn.cs | 2 +- Games/ZombieSurvival/ZombieGame.Core.cs | 59 +++++--- Games/ZombieSurvival/ZombieGame.Game.cs | 2 +- Games/ZombieSurvival/ZombieGame.cs | 94 +++++------- MCGalaxy_.csproj | 4 +- Server/Server.Tasks.cs | 2 +- 13 files changed, 231 insertions(+), 241 deletions(-) rename Commands/{Moderation => Fun}/CmdEndRound.cs (83%) rename Commands/{Moderation => Fun}/CmdReferee.cs (84%) diff --git a/Commands/Fun/CmdAlive.cs b/Commands/Fun/CmdAlive.cs index 6da434ebc..e30c5ab40 100644 --- a/Commands/Fun/CmdAlive.cs +++ b/Commands/Fun/CmdAlive.cs @@ -21,10 +21,12 @@ namespace MCGalaxy.Commands { public override string name { get { return "alive"; } } public override string shortcut { get { return "alive"; } } - public override string type { get { return CommandTypes.Games; } } + public override string type { get { return CommandTypes.Games; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Banned; } } + public override bool Enabled { get { return Server.ZombieModeOn; } } public CmdAlive() { } + public override void Use(Player p, string message) { if (ZombieGame.alive.Count == 0) diff --git a/Commands/Fun/CmdDisinfect.cs b/Commands/Fun/CmdDisinfect.cs index 5683c92a2..a1740ea75 100644 --- a/Commands/Fun/CmdDisinfect.cs +++ b/Commands/Fun/CmdDisinfect.cs @@ -31,7 +31,7 @@ namespace MCGalaxy.Commands { Player who = message == "" ? p : PlayerInfo.FindOrShowMatches(p, message); if (who == null) return; - if (!who.infected || !Server.zombie.GameInProgess()) { + if (!who.infected || !Server.zombie.RoundInProgress) { Player.SendMessage(p, "Cannot disinfect player"); } else if (!who.referee) { Server.zombie.DisinfectPlayer(who); diff --git a/Commands/Moderation/CmdEndRound.cs b/Commands/Fun/CmdEndRound.cs similarity index 83% rename from Commands/Moderation/CmdEndRound.cs rename to Commands/Fun/CmdEndRound.cs index 1391ce89a..31fb5c0aa 100644 --- a/Commands/Moderation/CmdEndRound.cs +++ b/Commands/Fun/CmdEndRound.cs @@ -1,40 +1,39 @@ -/* - Copyright 2011 MCForge - - Dual-licensed under the Educational Community License, Version 2.0 and - the GNU General Public License, Version 3 (the "Licenses"); you may - not use this file except in compliance with the Licenses. You may - obtain a copy of the Licenses at - - http://www.opensource.org/licenses/ecl2.php - http://www.gnu.org/licenses/gpl-3.0.html - - Unless required by applicable law or agreed to in writing, - software distributed under the Licenses are distributed on an "AS IS" - BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - or implied. See the Licenses for the specific language governing - permissions and limitations under the Licenses. -*/ -namespace MCGalaxy.Commands -{ - public sealed class CmdEndRound : Command - { - public override string name { get { return "endround"; } } - public override string shortcut { get { return "er"; } } - public override string type { get { return CommandTypes.Moderation; } } - public override bool museumUsable { get { return true; } } - public override LevelPermission defaultRank { get { return LevelPermission.Banned; } } - public CmdEndRound() { } - public override void Use(Player p, string message) - { - if (Server.zombie.GameInProgess()) - { - Server.zombie.HandOutRewards(); - } - } - public override void Help(Player p) - { - Player.SendMessage(p, "/endround - ends the round"); - } - } -} +/* + Copyright 2011 MCForge + + Dual-licensed under the Educational Community License, Version 2.0 and + the GNU General Public License, Version 3 (the "Licenses"); you may + not use this file except in compliance with the Licenses. You may + obtain a copy of the Licenses at + + http://www.opensource.org/licenses/ecl2.php + http://www.gnu.org/licenses/gpl-3.0.html + + Unless required by applicable law or agreed to in writing, + software distributed under the Licenses are distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the Licenses for the specific language governing + permissions and limitations under the Licenses. +*/ +namespace MCGalaxy.Commands +{ + public sealed class CmdEndRound : Command + { + public override string name { get { return "endround"; } } + public override string shortcut { get { return "er"; } } + public override string type { get { return CommandTypes.Moderation; } } + public override bool museumUsable { get { return true; } } + public override LevelPermission defaultRank { get { return LevelPermission.Banned; } } + public override bool Enabled { get { return Server.ZombieModeOn; } } + public CmdEndRound() { } + + public override void Use(Player p, string message) { + if (Server.zombie.RoundInProgress) + Server.zombie.HandOutRewards(); + } + + public override void Help(Player p) { + Player.SendMessage(p, "/endround - ends the round"); + } + } +} diff --git a/Commands/Fun/CmdInfect.cs b/Commands/Fun/CmdInfect.cs index 59b7de302..b695463c1 100644 --- a/Commands/Fun/CmdInfect.cs +++ b/Commands/Fun/CmdInfect.cs @@ -31,7 +31,7 @@ namespace MCGalaxy.Commands { Player who = message == "" ? p : PlayerInfo.FindOrShowMatches(p, message); if (who == null) return; - if (who.infected || !Server.zombie.GameInProgess()) { + if (who.infected || !Server.zombie.RoundInProgress) { Player.SendMessage(p, "Cannot infect player"); } else if (!who.referee) { Server.zombie.InfectPlayer(who); diff --git a/Commands/Moderation/CmdReferee.cs b/Commands/Fun/CmdReferee.cs similarity index 84% rename from Commands/Moderation/CmdReferee.cs rename to Commands/Fun/CmdReferee.cs index 5c6e1e49f..140c9ba3c 100644 --- a/Commands/Moderation/CmdReferee.cs +++ b/Commands/Fun/CmdReferee.cs @@ -1,79 +1,81 @@ -/* - Copyright 2011 MCForge - - Dual-licensed under the Educational Community License, Version 2.0 and - the GNU General Public License, Version 3 (the "Licenses"); you may - not use this file except in compliance with the Licenses. You may - obtain a copy of the Licenses at - - http://www.opensource.org/licenses/ecl2.php - http://www.gnu.org/licenses/gpl-3.0.html - - Unless required by applicable law or agreed to in writing, - software distributed under the Licenses are distributed on an "AS IS" - BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - or implied. See the Licenses for the specific language governing - permissions and limitations under the Licenses. -*/ -namespace MCGalaxy.Commands -{ - public sealed class CmdReferee : Command - { - public override string name { get { return "ref"; } } - public override string shortcut { get { return ""; } } - public override string type { get { return CommandTypes.Moderation; } } - public override bool museumUsable { get { return true; } } - public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } - public CmdReferee() { } - public override void Use(Player p, string message) - { - if (p == null) { MessageInGameOnly(p); return; } - if (p.referee) - { - p.referee = false; - LevelPermission perm = Group.findPlayerGroup(name).Permission; - Player.GlobalDespawn(p, false); - Player.SendChatFrom(p, p.color + p.name + Server.DefaultColor + " is no longer a referee", false); - if (Server.zombie.GameInProgess()) - { - Server.zombie.InfectPlayer(p); - } - else - { - Player.GlobalDespawn(p, false); - Player.GlobalSpawn(p, p.pos[0], p.pos[1], p.pos[2], p.rot[0], p.rot[1], false); - ZombieGame.infectd.Remove(p); - ZombieGame.alive.Add(p); - p.color = p.group.color; - } - } - else - { - p.referee = true; - Player.SendChatFrom(p, p.color + p.name + Server.DefaultColor + " is now a referee", false); - Player.GlobalDespawn(p, false); - if (Server.zombie.GameInProgess()) - { - p.color = p.group.color; - try - { - ZombieGame.infectd.Remove(p); - ZombieGame.alive.Remove(p); - } - catch { } - Server.zombie.InfectedPlayerDC(); - } - else - { - ZombieGame.infectd.Remove(p); - ZombieGame.alive.Remove(p); - p.color = p.group.color; - } - } - } - public override void Help(Player p) - { - Player.SendMessage(p, "/referee - Turns referee mode on/off."); - } - } -} +/* + Copyright 2011 MCForge + + Dual-licensed under the Educational Community License, Version 2.0 and + the GNU General Public License, Version 3 (the "Licenses"); you may + not use this file except in compliance with the Licenses. You may + obtain a copy of the Licenses at + + http://www.opensource.org/licenses/ecl2.php + http://www.gnu.org/licenses/gpl-3.0.html + + Unless required by applicable law or agreed to in writing, + software distributed under the Licenses are distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the Licenses for the specific language governing + permissions and limitations under the Licenses. +*/ +namespace MCGalaxy.Commands +{ + public sealed class CmdReferee : Command + { + public override string name { get { return "ref"; } } + public override string shortcut { get { return ""; } } + public override string type { get { return CommandTypes.Moderation; } } + public override bool museumUsable { get { return true; } } + public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } + public override bool Enabled { get { return Server.ZombieModeOn; } } + public CmdReferee() { } + + public override void Use(Player p, string message) + { + if (p == null) { MessageInGameOnly(p); return; } + if (p.referee) + { + p.referee = false; + LevelPermission perm = Group.findPlayerGroup(name).Permission; + Player.GlobalDespawn(p, false); + Player.SendChatFrom(p, p.FullName + " %Sis no longer a referee", false); + if (Server.zombie.RoundInProgress) + { + Server.zombie.InfectPlayer(p); + } + else + { + Player.GlobalDespawn(p, false); + Player.GlobalSpawn(p, p.pos[0], p.pos[1], p.pos[2], p.rot[0], p.rot[1], false); + ZombieGame.infectd.Remove(p); + ZombieGame.alive.Add(p); + p.color = p.group.color; + } + } + else + { + p.referee = true; + Player.SendChatFrom(p, p.FullName + " %Sis now a referee", false); + Player.GlobalDespawn(p, false); + if (Server.zombie.RoundInProgress) + { + p.color = p.group.color; + try + { + ZombieGame.infectd.Remove(p); + ZombieGame.alive.Remove(p); + } + catch { } + Server.zombie.InfectedPlayerDC(); + } + else + { + ZombieGame.infectd.Remove(p); + ZombieGame.alive.Remove(p); + p.color = p.group.color; + } + } + } + public override void Help(Player p) + { + Player.SendMessage(p, "/referee - Turns referee mode on/off."); + } + } +} diff --git a/Commands/Fun/CmdZombieGame.cs b/Commands/Fun/CmdZombieGame.cs index 952ab1b2e..fa658569e 100644 --- a/Commands/Fun/CmdZombieGame.cs +++ b/Commands/Fun/CmdZombieGame.cs @@ -33,52 +33,50 @@ namespace MCGalaxy.Commands string[] s = message.ToLower().Split(' '); if (s[0] == "status") { - switch (Server.zombie.ZombieStatus()) - { - case 0: - Player.GlobalMessage("There is no Zombie Survival game currently in progress."); - return; - case 1: - Player.SendMessage(p, "There is a Zombie Survival game currently in progress with infinite rounds."); - return; - case 2: - Player.SendMessage(p, "There is a one-time Zombie Survival game currently in progress."); - return; - case 3: - Player.SendMessage(p, "There is a Zombie Survival game currently in progress with a " + Server.zombie.MaxRounds + " amount of rounds."); - return; - case 4: - Player.SendMessage(p, "There is a Zombie Survival game currently in progress, scheduled to stop after this round."); - return; - default: - Player.SendMessage(p, "An unknown error occurred."); - return; + switch (Server.zombie.Status) { + case ZombieGameStatus.NotStarted: + Player.SendMessage(p, "Zombie Survival is not ccurrently running."); return; + case ZombieGameStatus.InfiniteRounds: + Player.SendMessage(p, "Zombie Survival is currently in progress with infinite rounds."); return; + case ZombieGameStatus.SingleRound: + Player.SendMessage(p, "Zombie Survival game currently in progress."); return; + case ZombieGameStatus.VariableRounds: + Player.SendMessage(p, "Zombie Survival game currently in progress with " + Server.zombie.MaxRounds + " rounds."); return; + case ZombieGameStatus.LastRound: + Player.SendMessage(p, "Zombie Survival game currently in progress, with this round being the final round."); return; } + return; } else if (s[0] == "start") { - if (Server.zombie.ZombieStatus() != 0) { Player.SendMessage(p, "There is already a Zombie Survival game currently in progress."); return; } + if (Server.zombie.Status != ZombieGameStatus.NotStarted) { + Player.SendMessage(p, "There is already a Zombie Survival game currently in progress."); return; + } if (s.Length == 2) { int rounds = 1; - bool result = int.TryParse(s[1], out rounds); - if (result == false) { Player.SendMessage(p, "You need to specify a valid option!"); return; } - if (s[1] == "0") - Server.zombie.StartGame(1, 0); - else - Server.zombie.StartGame(3, rounds); + if (!int.TryParse(s[1], out rounds)) { + Player.SendMessage(p, "You need to specify a valid option!"); return; + } + ZombieGameStatus status = rounds == 0 ? + ZombieGameStatus.InfiniteRounds : ZombieGameStatus.VariableRounds; + Server.zombie.Start(status, rounds); } else { - Server.zombie.StartGame(2, 0); + Server.zombie.Start(ZombieGameStatus.SingleRound, 0); } } else if (s[0] == "stop") { - if (Server.zombie.ZombieStatus() == 0) { Player.SendMessage(p, "There is no Zombie Survival game currently in progress."); return; } + if (Server.zombie.Status == ZombieGameStatus.NotStarted) { + Player.SendMessage(p, "There is no Zombie Survival game currently in progress."); return; + } Player.GlobalMessage("The current game of Zombie Survival will end this round!"); - Server.zombie.gameStatus = 4; + Server.zombie.Status = ZombieGameStatus.LastRound; } else if (s[0] == "force") { - if (Server.zombie.ZombieStatus() == 0) { Player.SendMessage(p, "There is no Zombie Survival game currently in progress."); return; } + if (Server.zombie.Status == ZombieGameStatus.NotStarted) { + Player.SendMessage(p, "There is no Zombie Survival game currently in progress."); return; + } Server.s.Log("Zombie Survival ended forcefully by " + p.name); Server.zombie.aliveCount = 0; Server.zombie.ResetState(); diff --git a/Commands/World/CmdGoto.cs b/Commands/World/CmdGoto.cs index 0d08ba582..2ed434611 100644 --- a/Commands/World/CmdGoto.cs +++ b/Commands/World/CmdGoto.cs @@ -159,7 +159,7 @@ namespace MCGalaxy.Commands { } } - if (Server.zombie.GameInProgess()) { + if (Server.zombie.RoundInProgress) { if (p.level.name == Server.zombie.currentLevelName) Server.zombie.InfectedPlayerLogin(p); } diff --git a/Commands/other/CmdSpawn.cs b/Commands/other/CmdSpawn.cs index 5f7f9561b..35c234bb6 100644 --- a/Commands/other/CmdSpawn.cs +++ b/Commands/other/CmdSpawn.cs @@ -32,7 +32,7 @@ namespace MCGalaxy.Commands { ushort x = (ushort)(16 + (cpSpawn ? p.checkpointX : p.level.spawnx) * 32); ushort y = (ushort)(32 + (cpSpawn ? p.checkpointY : p.level.spawny) * 32); ushort z = (ushort)(16 + (cpSpawn ? p.checkpointZ : p.level.spawnz) * 32); - if (!p.referee && !p.infected && Server.zombie.GameInProgess()) + if (!p.referee && !p.infected && Server.zombie.RoundInProgress) Server.zombie.InfectPlayer(p); if (p.PlayingTntWars) { diff --git a/Games/ZombieSurvival/ZombieGame.Core.cs b/Games/ZombieSurvival/ZombieGame.Core.cs index 8e00a59bd..57d4bbe7c 100644 --- a/Games/ZombieSurvival/ZombieGame.Core.cs +++ b/Games/ZombieSurvival/ZombieGame.Core.cs @@ -29,31 +29,39 @@ namespace MCGalaxy { public sealed partial class ZombieGame { void MainLoop() { - if (gameStatus == 0) return; + if (Status == ZombieGameStatus.NotStarted) return; if (!initialChangeLevel) { ChangeLevel(); initialChangeLevel = true; } while (true) { - zombieRound = false; + RoundInProgress = false; RoundsDone++; - if (gameStatus == 0) { return; } - else if (gameStatus == 1) { DoRound(); if (ChangeLevels) ChangeLevel();} - else if (gameStatus == 2) { DoRound(); if (ChangeLevels) ChangeLevel(); gameStatus = 0; return; } - else if (gameStatus == 3) - { - if (RoundsDone == MaxRounds) { ResetState(); return; } - else { DoRound(); if (ChangeLevels) ChangeLevel(); } + if (Status == ZombieGameStatus.NotStarted) { + return; + } else if (Status == ZombieGameStatus.InfiniteRounds) { + DoRound(); + if (ChangeLevels) ChangeLevel(); + } else if (Status == ZombieGameStatus.SingleRound) { + DoRound(); + ResetState(); return; + } else if (Status == ZombieGameStatus.VariableRounds) { + if (RoundsDone == MaxRounds) { + ResetState(); return; + } else { + DoRound(); + if (ChangeLevels) ChangeLevel(); + } + } else if (Status == ZombieGameStatus.LastRound) { + ResetState(); return; } - else if (gameStatus == 4) { ResetState(); return; } } } - void DoRound() - { - if (gameStatus == 0) return; + void DoRound() { + if (Status == ZombieGameStatus.NotStarted) return; List players = DoRoundCountdown(); theEnd: @@ -71,7 +79,7 @@ namespace MCGalaxy { Player.GlobalDespawn(player, false); Player.GlobalSpawn(player, player.pos[0], player.pos[1], player.pos[2], player.rot[0], player.rot[1], false); - zombieRound = true; + RoundInProgress = true; int roundMins = random.Next(5, 8); Player.GlobalMessage("The round will last for " + roundMins + " minutes!"); timer = new System.Timers.Timer(roundMins * 60 * 1000); @@ -90,8 +98,8 @@ namespace MCGalaxy { aliveCount = alive.Count; DoCoreGame(players, random); - if (gameStatus == 0) { - gameStatus = 4; return; + if (Status == ZombieGameStatus.NotStarted) { + Status = ZombieGameStatus.LastRound; return; } else { HandOutRewards(); } @@ -117,7 +125,7 @@ namespace MCGalaxy { Thread.Sleep(1000); if (!Server.ZombieModeOn) return null; Player.GlobalMessage("%4Round Start:%f 1..."); Thread.Sleep(1000); if (!Server.ZombieModeOn) return null; - zombieRound = true; + RoundInProgress = true; int nonRefPlayers = 0; List players = new List(); @@ -156,8 +164,9 @@ namespace MCGalaxy { Player.GlobalDespawn(pAlive, false); Player.GlobalSpawn(pAlive, pAlive.pos[0], pAlive.pos[1], pAlive.pos[2], pAlive.rot[0], pAlive.rot[1], false); } - if (Math.Abs(pAlive.pos[0] / 32 - pKiller.pos[0] / 32) <= 1 && Math.Abs(pAlive.pos[1] / 32 - pKiller.pos[1] / 32) <= 1 - && Math.Abs(pAlive.pos[2] / 32 - pKiller.pos[2] / 32) <= 1) { + if (Math.Abs(pAlive.pos[0] - pKiller.pos[0]) <= HitboxPrecision + && Math.Abs(pAlive.pos[1] - pKiller.pos[1]) <= HitboxPrecision + && Math.Abs(pAlive.pos[2] - pKiller.pos[2]) <= HitboxPrecision) { if (!pAlive.infected && pKiller.infected && !pAlive.referee && !pKiller.referee && pKiller != pAlive && pKiller.level.name == currentLevelName && pAlive.level.name == currentLevelName) { pAlive.infected = true; @@ -208,7 +217,7 @@ namespace MCGalaxy { } public void EndRound(object sender, ElapsedEventArgs e) { - if (gameStatus == 0) return; + if (Status == ZombieGameStatus.NotStarted) return; Player.GlobalMessage("%4Round End:%f 5"); Thread.Sleep(1000); Player.GlobalMessage("%4Round End:%f 4"); Thread.Sleep(1000); Player.GlobalMessage("%4Round End:%f 3"); Thread.Sleep(1000); @@ -218,8 +227,8 @@ namespace MCGalaxy { } public void HandOutRewards() { - zombieRound = false; - if (gameStatus == 0) return; + RoundInProgress = false; + if (Status == ZombieGameStatus.NotStarted) return; Player.GlobalMessage(Colors.lime + "The game has ended!"); if(aliveCount == 0) Player.GlobalMessage(Colors.maroon + "Zombies have won this round."); @@ -375,7 +384,8 @@ namespace MCGalaxy { Level1Vote = 0; Level2Vote = 0; Level3Vote = 0; lastLevelVote1 = selectedLevel1; lastLevelVote2 = selectedLevel2; - if (gameStatus == 4 || gameStatus == 0) { return; } + if (Status == ZombieGameStatus.NotStarted || Status == ZombieGameStatus.LastRound) + return; if (initialChangeLevel) { @@ -387,7 +397,8 @@ namespace MCGalaxy { } else { Level1Vote = 1; Level2Vote = 0; Level3Vote = 0; } - if (gameStatus == 4 || gameStatus == 0) { return; } + if (Status == ZombieGameStatus.NotStarted || Status == ZombieGameStatus.LastRound) + return; if (Level1Vote >= Level2Vote) { diff --git a/Games/ZombieSurvival/ZombieGame.Game.cs b/Games/ZombieSurvival/ZombieGame.Game.cs index b74c8e5d7..b724b9ada 100644 --- a/Games/ZombieSurvival/ZombieGame.Game.cs +++ b/Games/ZombieSurvival/ZombieGame.Game.cs @@ -90,7 +90,7 @@ namespace MCGalaxy { } public override void PlayerJoinedServer(Player p) { - if (ZombieStatus() != 0) + if (Status != ZombieGameStatus.NotStarted) Player.SendMessage(p, "There is a Zombie Survival game currently in-progress! " + "Join it by typing /g " + Server.zombie.currentLevelName); } diff --git a/Games/ZombieSurvival/ZombieGame.cs b/Games/ZombieSurvival/ZombieGame.cs index 670bb44f9..224dfaaeb 100644 --- a/Games/ZombieSurvival/ZombieGame.cs +++ b/Games/ZombieSurvival/ZombieGame.cs @@ -35,13 +35,24 @@ namespace MCGalaxy { } } + public enum ZombieGameStatus { NotStarted, InfiniteRounds, SingleRound, VariableRounds, LastRound } + public sealed partial class ZombieGame { + /// The number of rounds that have been played in this game so far. public int RoundsDone = 0; /// The maximum number of rounds that can be played before the game ends. public int MaxRounds = 0; + /// How precise collision detection is between alive and dead players. (Where 1 block = 32 units) + public int HitboxPrecision = 24; + + /// Current round status of the game. + public ZombieGameStatus Status = ZombieGameStatus.NotStarted; + + public bool RoundInProgress = false; + public int aliveCount = 0; public string currentZombieLevel = ""; public static System.Timers.Timer timer; @@ -54,10 +65,8 @@ namespace MCGalaxy { internal bool noRespawn = true, noLevelSaving = true, noPillaring = true; internal string ZombieName = ""; - internal int gameStatus = 0; //0 = not started, 1 = always on, 2 = one time, 3 = certain amount of rounds, 4 = stop game next round internal bool queLevel = false, queZombie = false; internal string nextZombie = "", nextLevel = ""; - internal bool zombieRound = false; internal bool ChangeLevels = true, UseLevelList = false; internal List LevelList = new List(); @@ -69,63 +78,42 @@ namespace MCGalaxy { int infectCombo = 0; public Dictionary Bounties = new Dictionary(); - public void StartGame(int status, int amount) - { - //status: 0 = not started, 1 = always on, 2 = one time, 3 = certain amount of rounds, 4 = stop round next round - - if (status == 0) return; - - //SET ALL THE VARIABLES! + public void Start(ZombieGameStatus status, int amount) { if (UseLevelList && LevelList == null) ChangeLevels = false; Server.ZombieModeOn = true; - gameStatus = status; - zombieRound = false; + Status = status; + RoundInProgress = false; initialChangeLevel = false; MaxRounds = amount + 1; RoundsDone = 0; - //SET ALL THE VARIABLES?!? - //Start the main Zombie thread - Thread t = new Thread(MainLoop); - t.Name = "MCG_ZombieGame"; - t.Start(); + Thread t = new Thread(MainLoop); + t.Name = "MCG_ZombieGame"; + t.Start(); } - public void InfectedPlayerDC() - { - if (gameStatus == 0) return; + public void InfectedPlayerDC() { + if (Status == ZombieGameStatus.NotStarted) return; //This is for when the first zombie disconnects Random random = new Random(); - if ((gameStatus != 0 && zombieRound) && infectd.Count <= 0) - { - int firstinfect = random.Next(alive.Count); - firstinfect = firstinfect - 1; - while (alive[firstinfect].referee || alive[firstinfect].level.name == Server.zombie.currentLevelName) - { - if (firstinfect == alive.Count) - { - firstinfect = 0; - } - else - { - firstinfect++; - } + if ((Status != ZombieGameStatus.NotStarted && RoundInProgress) && infectd.Count <= 0) { + if (alive.Count == 0) return; + int index = random.Next(alive.Count); + + while (alive[index].referee || alive[index].level.name == Server.zombie.currentLevelName) { + if (index >= alive.Count - 1) index = 0; + else index++; } - Player.GlobalMessage(alive[firstinfect].color + alive[firstinfect].name + Server.DefaultColor + " continued the infection!"); - alive[firstinfect].color = Colors.red; - Player.GlobalDespawn(alive[firstinfect], false); - Player.GlobalSpawn(alive[firstinfect], alive[firstinfect].pos[0], alive[firstinfect].pos[1], alive[firstinfect].pos[2], alive[firstinfect].rot[0], alive[firstinfect].rot[1], false); - infectd.Add(alive[firstinfect]); - alive.Remove(alive[firstinfect]); + + Player zombie = alive[index]; + Player.GlobalMessage(zombie.FullName + " %Scontinued the infection!"); + InfectPlayer(zombie); } - return; } - public bool InfectedPlayerLogin(Player p) - { - if (gameStatus == 0) return false; - if (p == null) return false; + public bool InfectedPlayerLogin(Player p) { + if (Status == ZombieGameStatus.NotStarted || p == null) return false; if (p.level.name != Server.zombie.currentLevelName) return false; p.SendMessage("You have joined in the middle of a round. You are now infected!"); p.blockCount = 50; @@ -137,19 +125,9 @@ namespace MCGalaxy { return true; } - public int ZombieStatus() - { - return gameStatus; - } - - public bool GameInProgess() - { - return zombieRound; - } - public void InfectPlayer(Player p) { - if (!zombieRound || p == null) return; + if (!RoundInProgress || p == null) return; infectd.Add(p); alive.Remove(p); p.infected = true; @@ -161,7 +139,7 @@ namespace MCGalaxy { public void DisinfectPlayer(Player p) { - if (!zombieRound || p == null) return; + if (!RoundInProgress || p == null) return; infectd.Remove(p); alive.Add(p); p.infected = false; @@ -206,11 +184,11 @@ namespace MCGalaxy { } public void ResetState() { - gameStatus = 0; + Status = ZombieGameStatus.NotStarted; MaxRounds = 0; initialChangeLevel = false; Server.ZombieModeOn = false; - zombieRound = false; + RoundInProgress = false; } } } diff --git a/MCGalaxy_.csproj b/MCGalaxy_.csproj index 0bdd734c5..f42958923 100644 --- a/MCGalaxy_.csproj +++ b/MCGalaxy_.csproj @@ -180,12 +180,14 @@ + + @@ -242,7 +244,6 @@ - @@ -273,7 +274,6 @@ - diff --git a/Server/Server.Tasks.cs b/Server/Server.Tasks.cs index c1ade7ae6..ca41af9a1 100644 --- a/Server/Server.Tasks.cs +++ b/Server/Server.Tasks.cs @@ -186,7 +186,7 @@ namespace MCGalaxy { if (Server.lava.startOnStartup) Server.lava.Start(); if (Server.startZombieModeOnStartup) - Server.zombie.StartGame(1, 0); + Server.zombie.Start(ZombieGameStatus.InfiniteRounds, 0); //This doesnt use the main map if (Server.UseCTF) ctf = new Auto_CTF();