diff --git a/MCGalaxy/Commands/Fun/CmdTntWars.cs b/MCGalaxy/Commands/Fun/CmdTntWars.cs index 204b373fd..b43706bc2 100644 --- a/MCGalaxy/Commands/Fun/CmdTntWars.cs +++ b/MCGalaxy/Commands/Fun/CmdTntWars.cs @@ -732,48 +732,27 @@ namespace MCGalaxy.Commands.Fun { //1 if (it.lvl == null) { Player.Message(p, "Level: " + Colors.red + "NONE"); } else { Player.Message(p, "Level: " + Colors.green + it.lvl.name); } - //2 - if (it.GameMode == TntWarsGame.TntWarsGameMode.FFA) { Player.Message(p, "Gamemode: " + Colors.green + "FFA"); } - if (it.GameMode == TntWarsGame.TntWarsGameMode.TDM) { Player.Message(p, "Gamemode: " + Colors.green + "TDM"); } - //3 - if (it.Difficulty == TntWarsGame.TntWarsDifficulty.Easy) { Player.Message(p, "Game difficulty: " + Colors.green + "Easy"); } - if (it.Difficulty == TntWarsGame.TntWarsDifficulty.Normal) { Player.Message(p, "Game difficulty: " + Colors.green + "Normal"); } - if (it.Difficulty == TntWarsGame.TntWarsDifficulty.Hard) { Player.Message(p, "Game difficulty: " + Colors.green + "Hard"); } - if (it.Difficulty == TntWarsGame.TntWarsDifficulty.Extreme) { Player.Message(p, "Game difficulty: " + Colors.green + "Extreme"); } - //4 - if (cfg.MaxPlayerActiveTnt >= 1) { Player.Message(p, "TNT per player at a time: " + Colors.green + cfg.MaxPlayerActiveTnt); } - else if (cfg.MaxPlayerActiveTnt == 0) { Player.Message(p, "TNT per player at a time: " + Colors.green + "unlimited"); } - //5 - if (cfg.InitialGracePeriod) { Player.Message(p, "Grace period: " + Colors.green + "enabled"); } - if (!cfg.InitialGracePeriod) { Player.Message(p, "Grace period: " + Colors.green + "disabled"); } - //6 - Player.Message(p, "Grace period time: " + Colors.green + cfg.GracePeriodSeconds + " seconds"); - //7 - if (cfg.BalanceTeams) { Player.Message(p, "Balance teams: " + Colors.green + "enabled"); } - if (!cfg.BalanceTeams) { Player.Message(p, "Balance teams: " + Colors.green + "disabled"); } - //8 - Player.Message(p, "Score limit: " + Colors.green + it.ScoreLimit + " points"); - //9 - if (cfg.Streaks) { Player.Message(p, "Streaks: " + Colors.green + "enabled"); } - if (!cfg.Streaks) { Player.Message(p, "Streaks: " + Colors.green + "disabled"); } - //10 - if (cfg.MultiKillBonus == 0) { Player.Message(p, "Multikill bonus: " + Colors.green + "disabled"); } - if (cfg.MultiKillBonus != 0) { Player.Message(p, "Multikill bonus: " + Colors.green + "enabled"); } - //11 - Player.Message(p, "Score per kill: " + Colors.green + cfg.ScorePerKill + " points"); - //12 - if (cfg.AssistScore == 0) { Player.Message(p, "Assists: " + Colors.green + "disabled"); } - if (cfg.AssistScore != 0) { Player.Message(p, "Assists : " + Colors.green + "enabled (at " + cfg.AssistScore + " points)"); } - //13 - if (cfg.TeamKills) { Player.Message(p, "Team killing: " + Colors.green + "enabled"); } - if (!cfg.TeamKills) { Player.Message(p, "Team killing: " + Colors.green + "disabled"); } - //14 + + Player.Message(p, "Gamemode: &a{0} %Sat difficulty &a{1}", it.GameMode, it.Difficulty); + Player.Message(p, "TNT per player at a time: &a{0}", + cfg.MaxPlayerActiveTnt == 0 ? "unlimited" : cfg.MaxPlayerActiveTnt.ToString()); + Player.Message(p, "Grace period: {0} %S(for {1} seconds)", + GetBool(cfg.InitialGracePeriod), cfg.GracePeriodSeconds); + Player.Message(p, "Team balancing: {0}%S, Team killing: {1}", + GetBool(cfg.BalanceTeams), GetBool(cfg.TeamKills)); + Player.Message(p, "Score: Limit of &a{0} %Spoints, &a{1} %Spoints per kill", + it.ScoreLimit, cfg.ScorePerKill); + Player.Message(p, "Streaks: {0}%S, Multikill bonus: {1}", + GetBool(cfg.Streaks), GetBool(cfg.MultiKillBonus != 0)); + Player.Message(p, "Assists: {0} %S(at {1} points)", + GetBool(cfg.AssistScore > 0), cfg.AssistScore); it.CheckAllSetUp(p); - //15 break; } } + static string GetBool(bool value) { return value ? "&aEnabled" : "&cDisabled"; } + static void SetSpawn(Player p, ref ushort[] target, string name) { target = new ushort[5]; target[0] = (ushort)p.Pos.BlockX; @@ -959,10 +938,10 @@ namespace MCGalaxy.Commands.Fun { case "check": case "current": case "c": - Player.Message(p, "TNT Wars: {0} is currently {1}", name, target ? "&aenabled" : "&cdisabled"); return false; + Player.Message(p, "TNT Wars: {0} is currently {1}", name, GetBool(target)); return false; default: target = !target; - Player.Message(p, "TNT Wars: {0} is now {1}", name, target ? "&aenabled" : "&cdisabled"); return true; + Player.Message(p, "TNT Wars: {0} is now {1}", name, GetBool(target)); return true; } } diff --git a/MCGalaxy/Commands/Information/CmdWhere.cs b/MCGalaxy/Commands/Information/CmdWhere.cs index e8ee8b485..85353a9cf 100644 --- a/MCGalaxy/Commands/Information/CmdWhere.cs +++ b/MCGalaxy/Commands/Information/CmdWhere.cs @@ -16,6 +16,7 @@ permissions and limitations under the Licenses. */ using System; +using MCGalaxy.Games; namespace MCGalaxy.Commands.Info { public sealed class CmdWhere : Command { @@ -27,7 +28,8 @@ namespace MCGalaxy.Commands.Info { int matches; Player pl = PlayerInfo.FindMatches(p, message, out matches); if (pl == null) return; - if (pl.level.CurrentGame() != null && !(p == null || p.Game.Referee)) { + + if (IGame.GameOn(pl.level) != null && !(p == null || p.Game.Referee)) { Player.Message(p, "You can only use /where on people in games when you are in referee mode."); return; } diff --git a/MCGalaxy/Commands/other/CmdTp.cs b/MCGalaxy/Commands/other/CmdTp.cs index 0f6ea8ed9..882e086e2 100644 --- a/MCGalaxy/Commands/other/CmdTp.cs +++ b/MCGalaxy/Commands/other/CmdTp.cs @@ -117,7 +117,7 @@ namespace MCGalaxy.Commands.Misc { MessageTooHighRank(p, "teleport to", true); return false; } - IGame game = target.level.CurrentGame(); + IGame game = IGame.GameOn(target.level); if (!p.Game.Referee && game != null) { Player.Message(p, "You can only teleport to players in " + "a game when you are in referee mode."); return false; diff --git a/MCGalaxy/Games/Countdown/CountdownGame.cs b/MCGalaxy/Games/Countdown/CountdownGame.cs index 4982bdf83..a5f601084 100644 --- a/MCGalaxy/Games/Countdown/CountdownGame.cs +++ b/MCGalaxy/Games/Countdown/CountdownGame.cs @@ -26,17 +26,6 @@ using MCGalaxy.Network; using BlockID = System.UInt16; namespace MCGalaxy.Games { - - public enum CountdownGameStatus { - /// Countdown is not running. - Disabled, - /// Countdown is running, but no round has begun yet. - Enabled, - /// Timer is counting down to start of round. - RoundCountdown, - /// Round is in progress. - RoundInProgress, - } class CountdownLevelPicker : LevelPicker { public override List GetCandidateMaps() { return new List() { "countdown" }; } diff --git a/MCGalaxy/Games/IGame.cs b/MCGalaxy/Games/IGame.cs index 2fc4af0f3..827f2dde1 100644 --- a/MCGalaxy/Games/IGame.cs +++ b/MCGalaxy/Games/IGame.cs @@ -25,6 +25,17 @@ namespace MCGalaxy.Games { public Level Map; public bool Running; public abstract string GameName { get; } + + public static VolatileArray RunningGames = new VolatileArray(false); + public static IGame GameOn(Level lvl) { + if (lvl == null) return null; + IGame[] games = RunningGames.Items; + + foreach (IGame game in games) { + if (game.Map == lvl) return game; + } + return null; + } public virtual bool HandlesChatMessage(Player p, string message) { return false; } public virtual void PlayerJoinedGame(Player p) { } diff --git a/MCGalaxy/Games/RoundsGame/RoundsGame.cs b/MCGalaxy/Games/RoundsGame/RoundsGame.cs index a54eb7ad2..feca74084 100644 --- a/MCGalaxy/Games/RoundsGame/RoundsGame.cs +++ b/MCGalaxy/Games/RoundsGame/RoundsGame.cs @@ -58,6 +58,7 @@ namespace MCGalaxy.Games { RoundsLeft = rounds; Running = true; HookEventHandlers(); + IGame.RunningGames.Add(this); Thread t = new Thread(RunGame); t.Name = "MCG_" + GameName; @@ -79,6 +80,7 @@ namespace MCGalaxy.Games { try { End(); } catch (Exception ex2) { Logger.LogError(ex2); } } + IGame.RunningGames.Remove(this); } protected virtual string GetStartMap(string forcedMap) { @@ -174,6 +176,7 @@ namespace MCGalaxy.Games { public override void End() { if (!Running) return; Running = false; + IGame.RunningGames.Remove(this); UnhookEventHandlers(); EndGame(); diff --git a/MCGalaxy/Games/TntWars/TntWars.cs b/MCGalaxy/Games/TntWars/TntWars.cs index 52f246f41..47424acbf 100644 --- a/MCGalaxy/Games/TntWars/TntWars.cs +++ b/MCGalaxy/Games/TntWars/TntWars.cs @@ -754,7 +754,7 @@ namespace MCGalaxy.Games } - public void SendPlayerCheckSetupErrors(Player p) + void SendPlayerCheckSetupErrors(Player p) { if (lvl == null) { diff --git a/MCGalaxy/Levels/Level.cs b/MCGalaxy/Levels/Level.cs index e593bc53b..1704f5db8 100644 --- a/MCGalaxy/Levels/Level.cs +++ b/MCGalaxy/Levels/Level.cs @@ -115,14 +115,6 @@ namespace MCGalaxy { return null; } - /// The currently active game running on this map, - /// or null if there is no game running. - public IGame CurrentGame() { - if (Server.zombie.Running && Server.zombie.Map == this) return Server.zombie; - if (Server.lava.Running && Server.lava.Map == this) return Server.lava; - return null; - } - public bool CanJoin(Player p) { if (p == null) return true; diff --git a/MCGalaxy/Player/Player.cs b/MCGalaxy/Player/Player.cs index 78037bb4e..9b99e58b8 100644 --- a/MCGalaxy/Player/Player.cs +++ b/MCGalaxy/Player/Player.cs @@ -121,7 +121,7 @@ namespace MCGalaxy { Team team = Game.Team; prefix += team != null ? "<" + team.Color + team.Name + color + "> " : ""; - IGame game = level == null ? null : level.CurrentGame(); + IGame game = IGame.GameOn(level); if (game != null) game.AdjustPrefix(this, ref prefix); bool isDev = Server.Devs.CaselessContains(truename);