From ec137eb52ac0be84ca42df40c4ccec4c368827f8 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 23 Apr 2016 17:08:43 +1000 Subject: [PATCH] Do test for round end on main zombie thread instead of separate timer, avoids issues when using /zg force then /zg start again. (Thanks goodlyay) --- Commands/Information/CmdWhois.cs | 2 +- Commands/Information/CmdWhowas.cs | 2 +- Commands/Information/WhoInfo.cs | 4 ++-- Games/ZombieSurvival/ZombieGame.Core.cs | 29 ++++++++++-------------- Games/ZombieSurvival/ZombieGame.Props.cs | 1 - 5 files changed, 16 insertions(+), 22 deletions(-) diff --git a/Commands/Information/CmdWhois.cs b/Commands/Information/CmdWhois.cs index 63b8262e0..2cc0081ce 100644 --- a/Commands/Information/CmdWhois.cs +++ b/Commands/Information/CmdWhois.cs @@ -39,7 +39,7 @@ namespace MCGalaxy.Commands { WhoInfo info = new WhoInfo(); string prefix = who.title == "" ? "" : "[" + who.titlecolor + who.title + who.color + "] "; - info.FullName = prefix + who.DisplayName; + info.FullName = prefix + who.ColoredName; info.Name = who.name; info.Group = who.group; info.Money = who.money; info.Deaths = who.overallDeath; diff --git a/Commands/Information/CmdWhowas.cs b/Commands/Information/CmdWhowas.cs index a1bf55c3a..7de73e7bd 100644 --- a/Commands/Information/CmdWhowas.cs +++ b/Commands/Information/CmdWhowas.cs @@ -51,7 +51,7 @@ namespace MCGalaxy.Commands { string prefix = target.title == "" ? "" : "[" + target.titleColor + target.title + color + "] "; WhoInfo info = new WhoInfo(); - info.FullName = prefix + target.name.TrimEnd('+'); + info.FullName = prefix + color + target.name.TrimEnd('+'); info.Name = target.name; info.Group = group; info.Money = int.Parse(target.money); info.Deaths = int.Parse(target.deaths); diff --git a/Commands/Information/WhoInfo.cs b/Commands/Information/WhoInfo.cs index e10a8334f..6e8e7c038 100644 --- a/Commands/Information/WhoInfo.cs +++ b/Commands/Information/WhoInfo.cs @@ -40,7 +40,7 @@ namespace MCGalaxy.Commands { Player.SendMessage(p, ">> &a" + who.Deaths + " &cdeaths%s, " + Awards.AwardAmount(who.Name) + " awards"); if (who.LoginBlocks >= 0) - Player.SendMessage(p, ">> &bModified &a" + who.TotalBlocks + " &eblocks, &a" + who.LoginBlocks + " &e since login."); + Player.SendMessage(p, ">> &bModified &a" + who.TotalBlocks + " &eblocks, &a" + who.LoginBlocks + " &esince login"); else Player.SendMessage(p, ">> &bModified &a" + who.TotalBlocks + " &eblocks"); @@ -56,7 +56,7 @@ namespace MCGalaxy.Commands { Player.SendMessage(p, ">> First login on &a" + who.First.ToString("yyyy-MM-dd") + "%S, and is currently &aonline"); - Player.SendMessage(p, ">> Logged in &a" + who.Logins + " %Stimes, &c" + who.Kicks + " %Sof which ended in a kick."); + Player.SendMessage(p, ">> Logged in &a" + who.Logins + " %Stimes, &c" + who.Kicks + " %Sof which ended in a kick"); string[] data = Ban.GetBanData(who.Name); if (data != null) Player.SendMessage(p, ">> is banned for " + data[1] + " by " + data[0]); diff --git a/Games/ZombieSurvival/ZombieGame.Core.cs b/Games/ZombieSurvival/ZombieGame.Core.cs index 798cbbd15..7db0d00a3 100644 --- a/Games/ZombieSurvival/ZombieGame.Core.cs +++ b/Games/ZombieSurvival/ZombieGame.Core.cs @@ -91,10 +91,7 @@ namespace MCGalaxy.Games { string suffix = roundMins == 1 ? " %Sminute!" : " %Sminutes!"; CurLevel.ChatLevel("The round will last for &a" + roundMins + suffix); RoundEnd = DateTime.UtcNow.AddMinutes(roundMins); - timer = new System.Timers.Timer(roundMins * 60 * 1000); - timer.Elapsed += new ElapsedEventHandler(EndRound); - timer.Enabled = true; - + Player[] online = PlayerInfo.Online.Items; foreach (Player p in online) { if (p.level == null || p.level != CurLevel || p.Game.Referee) continue; @@ -161,10 +158,19 @@ namespace MCGalaxy.Games { void DoCoreGame(Random random) { Player[] alive = null; string lastTimespan = null; - while ((alive = Alive.Items).Length > 0) { + int lastTime = -1; + + while ((alive = Alive.Items).Length > 0 && Running) { Player[] infected = Infected.Items; - // Update the round time left shown in the top right + // Do round end. int seconds = (int)(RoundEnd - DateTime.UtcNow).TotalSeconds; + if (seconds <= 0) { HandOutRewards(); return; } + if (seconds <= 5 && seconds != lastTime) { + CurLevel.ChatLevel("%4Round End:%f " + seconds); + lastTime = seconds; + } + + // Update the round time left shown in the top right string timespan = GetTimespan(seconds); if (lastTimespan != timespan) { UpdateAllPlayerStatus(timespan); @@ -289,16 +295,6 @@ namespace MCGalaxy.Games { Entities.GlobalDespawn(p, true); Entities.GlobalSpawn(p, true); } - - void EndRound(object sender, ElapsedEventArgs e) { - if (!Running) return; - CurLevel.ChatLevel("%4Round End:%f 5"); Thread.Sleep(1000); - CurLevel.ChatLevel("%4Round End:%f 4"); Thread.Sleep(1000); - CurLevel.ChatLevel("%4Round End:%f 3"); Thread.Sleep(1000); - CurLevel.ChatLevel("%4Round End:%f 2"); Thread.Sleep(1000); - CurLevel.ChatLevel("%4Round End:%f 1"); Thread.Sleep(1000); - HandOutRewards(); - } public void HandOutRewards() { if (!RoundInProgress) return; @@ -314,7 +310,6 @@ namespace MCGalaxy.Games { else if (alive.Length == 1) CurLevel.ChatLevel(Colors.green + "Congratulations to the sole survivor:"); else CurLevel.ChatLevel(Colors.green + "Congratulations to the survivors:"); - timer.Enabled = false; string playersString = ""; Player[] online = null; CurLevel.RoundsPlayed++; diff --git a/Games/ZombieSurvival/ZombieGame.Props.cs b/Games/ZombieSurvival/ZombieGame.Props.cs index 9d3435814..1da3b2bc6 100644 --- a/Games/ZombieSurvival/ZombieGame.Props.cs +++ b/Games/ZombieSurvival/ZombieGame.Props.cs @@ -67,7 +67,6 @@ namespace MCGalaxy.Games { /// Time at which the next round is scheduled to end. public DateTime RoundEnd; - public static System.Timers.Timer timer; public bool initialChangeLevel = false; /// The name of the level that the last round of zombie survival was played on.