From e68cf4edf6521da1105621f3a4dde95b19a10b13 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 14 Mar 2016 10:31:17 +1100 Subject: [PATCH] Cleanup level choosing code, also fix block changes in zombie survival being permanently saved. --- Commands/Fun/CmdZombieGame.cs | 1 + Games/ZombieSurvival/ZombieGame.Core.cs | 86 ++++++++++--------------- Games/ZombieSurvival/ZombieGame.cs | 52 +++++++-------- Levels/Level.cs | 3 +- 4 files changed, 61 insertions(+), 81 deletions(-) diff --git a/Commands/Fun/CmdZombieGame.cs b/Commands/Fun/CmdZombieGame.cs index ccc6a8d3e..5f75544fe 100644 --- a/Commands/Fun/CmdZombieGame.cs +++ b/Commands/Fun/CmdZombieGame.cs @@ -102,6 +102,7 @@ namespace MCGalaxy.Commands } public override void Help(Player p) { + Player.SendMessage(p, "/zg status - shows the current status of the Zombie Survival game."); Player.SendMessage(p, "/zg start 0 - Starts a Zombie Survival game for an unlimited amount of rounds."); Player.SendMessage(p, "/zg start [x] - Starts a Zombie Survival game for [x] amount of rounds."); Player.SendMessage(p, "/zg stop - Stops the Zombie Survival game after the round has finished."); diff --git a/Games/ZombieSurvival/ZombieGame.Core.cs b/Games/ZombieSurvival/ZombieGame.Core.cs index c42276d36..15af32245 100644 --- a/Games/ZombieSurvival/ZombieGame.Core.cs +++ b/Games/ZombieSurvival/ZombieGame.Core.cs @@ -31,7 +31,7 @@ namespace MCGalaxy { void MainLoop() { if (Status == ZombieGameStatus.NotStarted) return; if (!initialChangeLevel) { - ChangeLevel(); + ChooseNextLevel(); initialChangeLevel = true; } @@ -43,7 +43,7 @@ namespace MCGalaxy { return; } else if (Status == ZombieGameStatus.InfiniteRounds) { DoRound(); - if (ChangeLevels) ChangeLevel(); + if (ChangeLevels) ChooseNextLevel(); } else if (Status == ZombieGameStatus.SingleRound) { DoRound(); ResetState(); return; @@ -52,7 +52,7 @@ namespace MCGalaxy { ResetState(); return; } else { DoRound(); - if (ChangeLevels) ChangeLevel(); + if (ChangeLevels) ChooseNextLevel(); } } else if (Status == ZombieGameStatus.LastRound) { ResetState(); return; @@ -286,8 +286,8 @@ namespace MCGalaxy { playersString += p.group.color + p.DisplayName + Colors.white + ", "; } } - - public void ChangeLevel() + + void ChooseNextLevel() { if (queLevel) { @@ -297,40 +297,19 @@ namespace MCGalaxy { { if (ChangeLevels) { - ArrayList al = new ArrayList(); - DirectoryInfo di = new DirectoryInfo("levels/"); - FileInfo[] fi = di.GetFiles("*.lvl"); - foreach (FileInfo fil in fi) - { - al.Add(fil.Name.Split('.')[0]); - } + List levels = GetCandidateLevels(); + if (levels.Count <= 2 && !UseLevelList) { Server.s.Log("You must have more than 2 levels to change levels in Zombie Survival"); return; } - if (al.Count <= 2 && !UseLevelList) { Server.s.Log("You must have more than 2 levels to change levels in Zombie Survival"); return; } + if (levels.Count < 2 && UseLevelList) { Server.s.Log("You must have more than 2 levels in your level list to change levels in Zombie Survival"); return; } - if (LevelList.Count < 2 && UseLevelList) { Server.s.Log("You must have more than 2 levels in your level list to change levels in Zombie Survival"); return; } - - string selectedLevel1 = ""; - string selectedLevel2 = ""; + string selectedLevel1 = "", selectedLevel2 = ""; + Random r = new Random(); LevelChoice: - Random r = new Random(); - int x = 0; - int x2 = 1; - string level = ""; string level2 = ""; - if (!UseLevelList) - { - x = r.Next(0, al.Count); - x2 = r.Next(0, al.Count); - level = al[x].ToString(); - level2 = al[x2].ToString(); - } - else - { - x = r.Next(0, LevelList.Count()); - x2 = r.Next(0, LevelList.Count()); - level = LevelList[x].ToString(); - level2 = LevelList[x2].ToString(); - } + int x = 0, x2 = 1; + string level = "", level2 = ""; + level = levels[r.Next(0, levels.Count)]; + level2 = levels[r.Next(0, levels.Count)]; Level current = Server.mainLevel; if (lastLevelVote1 == level || lastLevelVote2 == level2 || lastLevelVote1 == level2 || lastLevelVote2 == level || current == LevelInfo.Find(level) || currentZombieLevel == level || current == LevelInfo.Find(level2) || currentZombieLevel == level2) @@ -358,33 +337,34 @@ namespace MCGalaxy { if (Status == ZombieGameStatus.NotStarted || Status == ZombieGameStatus.LastRound) return; - if (Level1Vote >= Level2Vote) - { - if (Level3Vote > Level1Vote && Level3Vote > Level2Vote) - { - r = new Random(); - int x3 = r.Next(0, al.Count); - ChangeLevel(al[x3].ToString(), Server.ZombieOnlyServer); + if (Level1Vote >= Level2Vote) { + if (Level3Vote > Level1Vote && Level3Vote > Level2Vote) { + ChangeLevel(levels[r.Next(0, levels.Count)], Server.ZombieOnlyServer); } ChangeLevel(selectedLevel1, Server.ZombieOnlyServer); - } - else - { - if (Level3Vote > Level1Vote && Level3Vote > Level2Vote) - { - r = new Random(); - int x4 = r.Next(0, al.Count); - ChangeLevel(al[x4].ToString(), Server.ZombieOnlyServer); + } else { + if (Level3Vote > Level1Vote && Level3Vote > Level2Vote) { + ChangeLevel(levels[r.Next(0, levels.Count)], Server.ZombieOnlyServer); } ChangeLevel(selectedLevel2, Server.ZombieOnlyServer); } Player[] online = PlayerInfo.Online.Items; - foreach (Player winners in online) { - winners.voted = false; - } + foreach (Player pl in online) + pl.voted = false; } } catch { } } + + List GetCandidateLevels() { + if (UseLevelList) return LevelList; + + List maps = new List(); + DirectoryInfo di = new DirectoryInfo("levels/"); + FileInfo[] fi = di.GetFiles("*.lvl"); + foreach (FileInfo fil in fi) + maps.Add(fil.Name.Split('.')[0]); + return maps; + } } } diff --git a/Games/ZombieSurvival/ZombieGame.cs b/Games/ZombieSurvival/ZombieGame.cs index 1f4dbcf1c..d01a822e8 100644 --- a/Games/ZombieSurvival/ZombieGame.cs +++ b/Games/ZombieSurvival/ZombieGame.cs @@ -25,21 +25,21 @@ using System.Threading; using System.Timers; namespace MCGalaxy { - - public class BountyData { - public Player Origin; - public int Amount; - - public BountyData(Player origin, int amount) { - Origin = origin; Amount = amount; - } - } - - public enum ZombieGameStatus { NotStarted, InfiniteRounds, SingleRound, VariableRounds, LastRound } - + + public class BountyData { + public Player Origin; + public int Amount; + + public BountyData(Player origin, int amount) { + Origin = origin; Amount = amount; + } + } + + 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. + + /// 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. @@ -57,7 +57,7 @@ namespace MCGalaxy { public string currentZombieLevel = ""; public static System.Timers.Timer timer; public bool initialChangeLevel = false; - public string currentLevelName = ""; + public string lastLevelName = "", currentLevelName = ""; public static List alive = new List(); public static List infectd = new List(); static string[] messages = new string[] { "{0} WIKIWOO'D {1}", "{0} stuck their teeth into {1}", @@ -158,21 +158,19 @@ namespace MCGalaxy { Player.GlobalMessage("The next map has been chosen - " + Colors.red + next.ToLower()); Player.GlobalMessage("Please wait while you are transfered."); string oldLevel = Server.mainLevel.name; - if (changeMainLevel) { + if (changeMainLevel) Server.mainLevel = LevelInfo.Find(next.ToLower()); - Player[] online = PlayerInfo.Online.Items; - foreach (Player player in online) { - if (player.level.name != next && player.level.name == currentLevelName) - { - player.SendMessage("Going to the next map!"); - Command.all.Find("goto").Use(player, next); - } + + Player[] online = PlayerInfo.Online.Items; + foreach (Player pl in online) { + if (pl.level.name != next && pl.level.name == lastLevelName) { + pl.SendMessage("Going to the next map!"); + Command.all.Find("goto").Use(pl, next); } - Command.all.Find("unload").Use(null, oldLevel); - } else { - Player.GlobalMessage("Type /goto " + next + " to play the next round of Zombie Survival"); } - return; + if (lastLevelName != "") + Command.all.Find("unload").Use(null, lastLevelName); + lastLevelName = next; } public bool IsInZombieGameLevel(Player p) { diff --git a/Levels/Level.cs b/Levels/Level.cs index 3f608a00a..5811c900f 100644 --- a/Levels/Level.cs +++ b/Levels/Level.cs @@ -278,7 +278,8 @@ namespace MCGalaxy public static event OnLevelLoaded LevelLoaded; public bool ShouldSaveLevelFile() { - if (Server.ZombieModeOn && name == Server.zombie.currentLevelName) return false; + if (Server.ZombieModeOn && (name == Server.zombie.currentLevelName + || name == Server.zombie.lastLevelName)) return false; if (Server.lava.active && Server.lava.HasMap(name)) return false; return true; }