diff --git a/MCGalaxy/Commands/Fun/CmdTntWars.cs b/MCGalaxy/Commands/Fun/CmdTntWars.cs index c5f6e37b0..4775235be 100644 --- a/MCGalaxy/Commands/Fun/CmdTntWars.cs +++ b/MCGalaxy/Commands/Fun/CmdTntWars.cs @@ -75,7 +75,7 @@ namespace MCGalaxy.Commands.Fun { string prop = args[1], value = args[2]; if (prop.CaselessEq("spawn")) { - if (gameCfg.Mode == TntWarsGameMode.FFA) { + if (gameCfg.Mode == TWGameMode.FFA) { Player.Message(p, "&cCannot set spawns in Free For All mode"); return; } @@ -105,14 +105,14 @@ namespace MCGalaxy.Commands.Fun { Player.Message(p, "TNT Wars: Grace period is now {0} seconds", value); } else if (prop.CaselessEq("gamemode")) { if (value.CaselessEq("tdm")) { - if (gameCfg.Mode == TntWarsGameMode.FFA) { + if (gameCfg.Mode == TWGameMode.FFA) { if (p.level != game.Map) { Player.Message(p, "Changed gamemode to Team Deathmatch"); } game.ModeTDM(); } else { Player.Message(p, "&cGamemode is already Team Deathmatch"); return; } } else if (value.CaselessEq("ffa")) { - if (gameCfg.Mode == TntWarsGameMode.TDM) { + if (gameCfg.Mode == TWGameMode.TDM) { if (p.level != game.Map) { Player.Message(p, "Changed gamemode to Free For All"); } game.ModeFFA(); } else { @@ -122,7 +122,7 @@ namespace MCGalaxy.Commands.Fun { Help(p, "other"); return; } } else if (prop.CaselessEq("difficulty")) { - TntWarsDifficulty diff = TntWarsDifficulty.Easy; + TWDifficulty diff = TWDifficulty.Easy; if (!CommandParser.GetEnum(p, value, "Difficulty", ref diff)) return; SetDifficulty(game, diff, p); } else if (prop.CaselessEq("score")) { @@ -290,7 +290,7 @@ namespace MCGalaxy.Commands.Fun { return false; } - static void SetDifficulty(TWGame game, TntWarsDifficulty diff, Player p) { + static void SetDifficulty(TWGame game, TWDifficulty diff, Player p) { if (p.level != game.Map) Player.Message(p, "TNT Wars: Changed difficulty to {0}", diff); game.SetDifficulty(diff); diff --git a/MCGalaxy/Commands/Fun/ZombieSurvival/CmdZombieSurvival.cs b/MCGalaxy/Commands/Fun/ZombieSurvival/CmdZombieSurvival.cs index fd2f202e9..a4f80e121 100644 --- a/MCGalaxy/Commands/Fun/ZombieSurvival/CmdZombieSurvival.cs +++ b/MCGalaxy/Commands/Fun/ZombieSurvival/CmdZombieSurvival.cs @@ -59,13 +59,13 @@ namespace MCGalaxy.Commands.Fun { if (!CommandParser.GetBool(p, args[1], ref lCfg.Pillaring)) return; Player.Message(p, "Set pillaring allowed to &b" + lCfg.Pillaring); - ZSGame.Instance.UpdateAllStatus2(); + game.UpdateAllStatus2(); } else if (prop.CaselessEq("build")) { if (!CommandParser.GetEnum(p, args[1], "Build type", ref lCfg.BuildType)) return; p.level.UpdateBlockPermissions(); Player.Message(p, "Set build type to &b" + lCfg.BuildType); - ZSGame.Instance.UpdateAllStatus2(); + game.UpdateAllStatus2(); } else if (prop.CaselessEq("minround")) { if (!ParseTimespan(p, "min round time", args, ref lCfg.MinRoundTime)) return; } else if (prop.CaselessEq("maxround")) { diff --git a/MCGalaxy/Games/Countdown/CountdownGame.Round.cs b/MCGalaxy/Games/Countdown/CountdownGame.Round.cs index 0986cb8b3..dfeb65511 100644 --- a/MCGalaxy/Games/Countdown/CountdownGame.Round.cs +++ b/MCGalaxy/Games/Countdown/CountdownGame.Round.cs @@ -49,7 +49,7 @@ namespace MCGalaxy.Games { if (!Running) return; RoundInProgress = true; - MessageAllStatus(); + UpdateAllStatus(); RemoveSquares(); } @@ -217,7 +217,7 @@ namespace MCGalaxy.Games { RoundInProgress = false; Remaining.Clear(); squaresLeft.Clear(); - MessageAllStatus(); + UpdateAllStatus(); if (winner != null) { winner.SendMessage("Congratulations, you won this round of countdown!"); diff --git a/MCGalaxy/Games/Countdown/CountdownGame.cs b/MCGalaxy/Games/Countdown/CountdownGame.cs index 52008c2eb..0f735fd2e 100644 --- a/MCGalaxy/Games/Countdown/CountdownGame.cs +++ b/MCGalaxy/Games/Countdown/CountdownGame.cs @@ -175,19 +175,12 @@ namespace MCGalaxy.Games { UpdatePlayersLeft(); } - void MessageAllStatus() { - UpdateAllStatus1(); - UpdateAllStatus2(); + protected override string FormatStatus1(Player p) { + return RoundInProgress ? squaresLeft.Count + " squares left" : ""; } - void UpdateAllStatus1() { - string msg = RoundInProgress ? squaresLeft.Count + " squares left" : ""; - MessageMap(CpeMessageType.Status1, msg); - } - - void UpdateAllStatus2() { - string msg = RoundInProgress ? Remaining.Count + " players left" : ""; - MessageMap(CpeMessageType.Status2, msg); + protected override string FormatStatus2(Player p) { + return RoundInProgress ? Remaining.Count + " players left" : ""; } } } diff --git a/MCGalaxy/Games/IGame.cs b/MCGalaxy/Games/IGame.cs index 827f2dde1..bf15aeb49 100644 --- a/MCGalaxy/Games/IGame.cs +++ b/MCGalaxy/Games/IGame.cs @@ -45,7 +45,8 @@ namespace MCGalaxy.Games { public abstract void End(); public abstract void EndRound(); - protected void ResetHUD(Player p) { + + protected void ResetStatus(Player p) { p.SendCpeMessage(CpeMessageType.Status1, ""); p.SendCpeMessage(CpeMessageType.Status2, ""); p.SendCpeMessage(CpeMessageType.Status3, ""); @@ -60,5 +61,30 @@ namespace MCGalaxy.Games { p.SendCpeMessage(type, message); } } + + protected virtual string FormatStatus1(Player p) { return ""; } + protected virtual string FormatStatus2(Player p) { return ""; } + protected virtual string FormatStatus3(Player p) { return ""; } + + public void UpdateAllStatus1() { UpdateAllStatus(CpeMessageType.Status1); } + public void UpdateAllStatus2() { UpdateAllStatus(CpeMessageType.Status2); } + public void UpdateAllStatus3() { UpdateAllStatus(CpeMessageType.Status3); } + + public void UpdateAllStatus() { + UpdateAllStatus1(); + UpdateAllStatus2(); + UpdateAllStatus3(); + } + + void UpdateAllStatus(CpeMessageType status) { + Player[] online = PlayerInfo.Online.Items; + foreach (Player p in online) { + if (p.level != Map) continue; + + string msg = status == CpeMessageType.Status1 ? FormatStatus1(p) : + (status == CpeMessageType.Status2 ? FormatStatus2(p) : FormatStatus3(p)); + p.SendCpeMessage(CpeMessageType.Status1, msg); + } + } } } diff --git a/MCGalaxy/Games/RoundsGame/RoundsGame.Plugin.cs b/MCGalaxy/Games/RoundsGame/RoundsGame.Plugin.cs index 849c0f6c3..b38f1dac5 100644 --- a/MCGalaxy/Games/RoundsGame/RoundsGame.Plugin.cs +++ b/MCGalaxy/Games/RoundsGame/RoundsGame.Plugin.cs @@ -56,10 +56,13 @@ namespace MCGalaxy.Games { protected void HandleJoinedCommon(Player p, Level prevLevel, Level level, ref bool announce) { if (prevLevel == Map && level != Map) { if (Picker.Voting) Picker.ResetVoteMessage(p); - ResetHUD(p); + ResetStatus(p); PlayerLeftGame(p); } else if (level == Map) { if (Picker.Voting) Picker.SendVoteMessage(p); + p.SendCpeMessage(CpeMessageType.Status1, FormatStatus1(p)); + p.SendCpeMessage(CpeMessageType.Status2, FormatStatus2(p)); + p.SendCpeMessage(CpeMessageType.Status3, FormatStatus3(p)); } if (level != Map) return; diff --git a/MCGalaxy/Games/RoundsGame/RoundsGame.cs b/MCGalaxy/Games/RoundsGame/RoundsGame.cs index 4a9077a44..f6dd64da9 100644 --- a/MCGalaxy/Games/RoundsGame/RoundsGame.cs +++ b/MCGalaxy/Games/RoundsGame/RoundsGame.cs @@ -195,7 +195,7 @@ namespace MCGalaxy.Games { pl.Game.PledgeSurvive = false; TabList.Update(pl, true); - ResetHUD(pl); + ResetStatus(pl); pl.SetPrefix(); } @@ -209,6 +209,6 @@ namespace MCGalaxy.Games { LastMap = ""; if (Map != null) Map.AutoUnload(); Map = null; - } + } } } diff --git a/MCGalaxy/Games/TntWars/TWConfig.cs b/MCGalaxy/Games/TntWars/TWConfig.cs index 49abbd224..37eea7730 100644 --- a/MCGalaxy/Games/TntWars/TWConfig.cs +++ b/MCGalaxy/Games/TntWars/TWConfig.cs @@ -31,10 +31,10 @@ namespace MCGalaxy.Games { protected override string GameName { get { return "TNT Wars"; } } protected override string PropsPath { get { return "properties/tntwars.properties"; } } - [ConfigEnum("Mode", null, TntWarsGameMode.TDM, typeof(TntWarsGameMode))] - public TntWarsGameMode Mode = TntWarsGameMode.TDM; - [ConfigEnum("Difficulty", null, TntWarsDifficulty.Normal, typeof(TntWarsDifficulty))] - public TntWarsDifficulty Difficulty = TntWarsDifficulty.Normal; + [ConfigEnum("Mode", null, TWGameMode.TDM, typeof(TWGameMode))] + public TWGameMode Mode = TWGameMode.TDM; + [ConfigEnum("Difficulty", null, TWDifficulty.Normal, typeof(TWDifficulty))] + public TWDifficulty Difficulty = TWDifficulty.Normal; } public sealed class TWMapConfig { diff --git a/MCGalaxy/Games/TntWars/TWGame.Plugin.cs b/MCGalaxy/Games/TntWars/TWGame.Plugin.cs index 9203c2ec3..0a7c34030 100644 --- a/MCGalaxy/Games/TntWars/TWGame.Plugin.cs +++ b/MCGalaxy/Games/TntWars/TWGame.Plugin.cs @@ -58,7 +58,7 @@ namespace MCGalaxy.Games { if (p.level != Map || message.Length == 0 || message[0] != ':') return; TWTeam team = TeamOf(p); - if (team == null || Config.Mode != TntWarsGameMode.TDM) return; + if (team == null || Config.Mode != TWGameMode.TDM) return; message = message.Substring(1); // "To Team &c-" + ColoredName + "&c- %S" + message); @@ -80,7 +80,7 @@ namespace MCGalaxy.Games { } TWTeam team = TeamOf(p); - if (team == null || Config.Mode != TntWarsGameMode.TDM) return; + if (team == null || Config.Mode != TWGameMode.TDM) return; Vec3U16 coords = team.SpawnPos; pos = Position.FromFeetBlockCoords(coords.X, coords.Y, coords.Z); @@ -133,8 +133,8 @@ namespace MCGalaxy.Games { int delay = 1250; switch (Config.Difficulty) { - case TntWarsDifficulty.Easy: delay = 3250; break; - case TntWarsDifficulty.Normal: delay = 2250; break; + case TWDifficulty.Easy: delay = 3250; break; + case TWDifficulty.Normal: delay = 2250; break; } AddTntCheck(Map.PosToInt(x, y, z), p); @@ -167,9 +167,9 @@ namespace MCGalaxy.Games { int power = 2, threshold = 3; switch (Config.Difficulty) { - case TntWarsDifficulty.Easy: threshold = 7; break; - case TntWarsDifficulty.Normal: threshold = 5; break; - case TntWarsDifficulty.Extreme: power = 3; break; + case TWDifficulty.Easy: threshold = 7; break; + case TWDifficulty.Normal: threshold = 5; break; + case TWDifficulty.Extreme: power = 3; break; } if ((C.Data.Data >> 4) < threshold) { @@ -209,9 +209,9 @@ namespace MCGalaxy.Games { void KillPlayers(Player killer, TWData data, List inRange) { List killed = new List(); int damage = 1, kills = 0, penalty = 0; - TntWarsDifficulty diff = Config.Difficulty; + TWDifficulty diff = Config.Difficulty; - if (diff == TntWarsDifficulty.Hard || diff == TntWarsDifficulty.Extreme) { + if (diff == TWDifficulty.Hard || diff == TWDifficulty.Extreme) { damage = 2; } @@ -284,7 +284,7 @@ namespace MCGalaxy.Games { data.ScoreMultiplier = cfg.StreakThreeMultiplier; data.LastKillStreakAnnounced = cfg.StreakThreeAmount; - if (diff == TntWarsDifficulty.Hard || diff == TntWarsDifficulty.Extreme) { + if (diff == TWDifficulty.Hard || diff == TWDifficulty.Extreme) { data.Health += 2; } else { data.Health += 1; diff --git a/MCGalaxy/Games/TntWars/TWGame.Round.cs b/MCGalaxy/Games/TntWars/TWGame.Round.cs index 86a5ccd11..cb4af7373 100644 --- a/MCGalaxy/Games/TntWars/TWGame.Round.cs +++ b/MCGalaxy/Games/TntWars/TWGame.Round.cs @@ -56,28 +56,28 @@ namespace MCGalaxy.Games { //Announcing Etc. // TODO: tidy up string Gamemode = "Free For All"; - if (Config.Mode == TntWarsGameMode.TDM) Gamemode = "Team Deathmatch"; + if (Config.Mode == TWGameMode.TDM) Gamemode = "Team Deathmatch"; string difficulty = "Normal"; string HitsToDie = "2"; string explosiontime = "medium"; string explosionsize = "normal"; switch (Config.Difficulty) { - case TntWarsDifficulty.Easy: + case TWDifficulty.Easy: difficulty = "Easy"; explosiontime = "long"; break; - case TntWarsDifficulty.Normal: + case TWDifficulty.Normal: difficulty = "Normal"; break; - case TntWarsDifficulty.Hard: + case TWDifficulty.Hard: HitsToDie = "1"; difficulty = "Hard"; break; - case TntWarsDifficulty.Extreme: + case TWDifficulty.Extreme: HitsToDie = "1"; explosiontime = "short"; explosionsize = "big"; @@ -93,7 +93,7 @@ namespace MCGalaxy.Games { ", team killing is &3" + teamkillling + " %Sand you can place &3" + cfg.MaxPlayerActiveTnt + " %STNT at a time and there is a score limit of &3" + cfg.ScoreRequired + "%S!!"); - if (Config.Mode == TntWarsGameMode.TDM) { + if (Config.Mode == TWGameMode.TDM) { Map.Message("Start your message with ':' to send it to team only!"); } @@ -103,7 +103,7 @@ namespace MCGalaxy.Games { bool won = false; while (Running && !won) { - if (Config.Mode == TntWarsGameMode.TDM) { + if (Config.Mode == TWGameMode.TDM) { won = Red.Score >= cfg.ScoreRequired || Blue.Score >= cfg.ScoreRequired; } else { all = allPlayers.Items; @@ -163,7 +163,7 @@ namespace MCGalaxy.Games { PlayerActions.Respawn(p); } - if (Config.Mode == TntWarsGameMode.TDM) { + if (Config.Mode == TWGameMode.TDM) { if (Red.Score > Blue.Score) { int amount = Red.Score - Blue.Score; Map.Message(Red.ColoredName + " %Swon &cTNT Wars %Sby &f" + amount + " %Spoints!"); diff --git a/MCGalaxy/Games/TntWars/TWGame.cs b/MCGalaxy/Games/TntWars/TWGame.cs index b5440b3a1..d0598eee4 100644 --- a/MCGalaxy/Games/TntWars/TWGame.cs +++ b/MCGalaxy/Games/TntWars/TWGame.cs @@ -34,8 +34,8 @@ using BlockID = System.UInt16; namespace MCGalaxy.Games { - public enum TntWarsGameMode { FFA, TDM }; - public enum TntWarsDifficulty { + public enum TWGameMode { FFA, TDM }; + public enum TWDifficulty { Easy, // 2 Hits to die, Tnt has long delay Normal, // 2 Hits to die, Tnt has normal delay Hard, // 1 Hit to die, Tnt has short delay @@ -50,8 +50,8 @@ namespace MCGalaxy.Games { public Player HarmedBy; // For Assists public string OrigCol; - public void Reset(TntWarsDifficulty diff) { - bool easyish = diff == TntWarsDifficulty.Easy || diff == TntWarsDifficulty.Normal; + public void Reset(TWDifficulty diff) { + bool easyish = diff == TWDifficulty.Easy || diff == TWDifficulty.Normal; Score = 0; Health = easyish ? 2 : 1; KillStreak = 0; @@ -122,7 +122,7 @@ namespace MCGalaxy.Games { } public override void OutputStatus(Player p) { - if (Config.Mode == TntWarsGameMode.TDM) { + if (Config.Mode == TWGameMode.TDM) { Player.Message(p, "{0} team score: &f{1}/{2} points", Red.ColoredName, Red.Score, cfg.ScoreRequired); Player.Message(p, "{0} team score: &f{1}/{2} points", @@ -189,7 +189,7 @@ namespace MCGalaxy.Games { public void ModeTDM() { - Config.Mode = TntWarsGameMode.TDM; + Config.Mode = TWGameMode.TDM; MessageMap(CpeMessageType.Announcement, "&4Gamemode changed to &fTeam Deathmatch"); Player[] players = allPlayers.Items; @@ -206,7 +206,7 @@ namespace MCGalaxy.Games { } public void ModeFFA() { - Config.Mode = TntWarsGameMode.FFA; + Config.Mode = TWGameMode.FFA; MessageMap(CpeMessageType.Announcement, "&4Gamemode changed to &fFree For All"); ResetTeams(); @@ -218,13 +218,13 @@ namespace MCGalaxy.Games { Config.Save(); } - public void SetDifficulty(TntWarsDifficulty diff) { + public void SetDifficulty(TWDifficulty diff) { Config.Difficulty = diff; MessageMap(CpeMessageType.Announcement, "&4Difficulty changed to &f" + diff); Config.Save(); - bool teamKill = diff >= TntWarsDifficulty.Hard; + bool teamKill = diff >= TWDifficulty.Hard; if (cfg.TeamKills == teamKill) return; cfg.TeamKills = teamKill; @@ -284,14 +284,14 @@ namespace MCGalaxy.Games { public void ChangeScore(Player p, int amount) { Get(p).Score += amount; - if (Config.Mode != TntWarsGameMode.TDM) return; + if (Config.Mode != TWGameMode.TDM) return; TWTeam team = TeamOf(p); if (team != null) team.Score += amount; } public bool TeamKill(Player p1, Player p2) { - return Config.Mode == TntWarsGameMode.TDM && TeamOf(p1) == TeamOf(p2); + return Config.Mode == TWGameMode.TDM && TeamOf(p1) == TeamOf(p2); } } } diff --git a/MCGalaxy/Games/ZombieSurvival/ZSGame.Plugin.cs b/MCGalaxy/Games/ZombieSurvival/ZSGame.Plugin.cs index 34001984a..2e80084fd 100644 --- a/MCGalaxy/Games/ZombieSurvival/ZSGame.Plugin.cs +++ b/MCGalaxy/Games/ZombieSurvival/ZSGame.Plugin.cs @@ -82,7 +82,7 @@ namespace MCGalaxy.Games { void HandleMoneyChanged(Player p) { if (p.level != Map) return; - UpdateStatus3(p, Get(p).Infected); + p.SendCpeMessage(CpeMessageType.Status3, FormatStatus3(p)); } void HandleEntitySpawned(Entity entity, ref string name, ref string skin, ref string model, Player dst) { @@ -124,9 +124,6 @@ namespace MCGalaxy.Games { ZSData data = Get(p); p.SetPrefix(); - p.SendCpeMessage(CpeMessageType.Status1, FormatStatus1()); - p.SendCpeMessage(CpeMessageType.Status2, FormatStatus2()); - UpdateStatus3(p, data.Infected); if (RoundInProgress) { Player.Message(p, "You joined in the middle of a round. &cYou are now infected!"); diff --git a/MCGalaxy/Games/ZombieSurvival/ZSGame.Round.cs b/MCGalaxy/Games/ZombieSurvival/ZSGame.Round.cs index 431264444..01fbd7a37 100644 --- a/MCGalaxy/Games/ZombieSurvival/ZSGame.Round.cs +++ b/MCGalaxy/Games/ZombieSurvival/ZSGame.Round.cs @@ -311,7 +311,7 @@ namespace MCGalaxy.Games { } RespawnPlayer(pl); - UpdateStatus3(pl, data.Infected); + pl.SendCpeMessage(CpeMessageType.Status3, FormatStatus3(pl)); } } diff --git a/MCGalaxy/Games/ZombieSurvival/ZSGame.cs b/MCGalaxy/Games/ZombieSurvival/ZSGame.cs index 04f64fbf3..9165c9cca 100644 --- a/MCGalaxy/Games/ZombieSurvival/ZSGame.cs +++ b/MCGalaxy/Games/ZombieSurvival/ZSGame.cs @@ -160,7 +160,7 @@ namespace MCGalaxy.Games { ResetInvisibility(p, data); UpdateAllStatus1(); - UpdateStatus3(p, infected); + p.SendCpeMessage(CpeMessageType.Status3, FormatStatus3(p)); } void ResetInvisibility(Player p, ZSData data) { @@ -253,19 +253,6 @@ namespace MCGalaxy.Games { return Running && Config.Maps.CaselessContains(name); } - void UpdateAllStatus1() { - MessageMap(CpeMessageType.Status1, FormatStatus1()); - } - - internal void UpdateAllStatus2() { - MessageMap(CpeMessageType.Status2, FormatStatus2()); - } - - void UpdateStatus3(Player p, bool infected) { - string status = FormatStatus3(p, infected); - p.SendCpeMessage(CpeMessageType.Status3, status); - } - static string GetTimeLeft(int seconds) { if (seconds < 0) return ""; if (seconds <= 10) return "10s left"; @@ -274,7 +261,7 @@ namespace MCGalaxy.Games { return ((seconds + 59) / 60) + "m left"; } - string FormatStatus1() { + protected override string FormatStatus1(Player p) { int left = (int)(RoundEnd - DateTime.UtcNow).TotalSeconds; string timespan = GetTimeLeft(left); @@ -283,15 +270,15 @@ namespace MCGalaxy.Games { return string.Format(format, Alive.Count, Map.MapName, timespan); } - string FormatStatus2() { + protected override string FormatStatus2(Player p) { string pillar = "%SPillaring " + (Map.Config.Pillaring ? "&aYes" : "&cNo"); string type = "%S, Type is &a" + Map.Config.BuildType; return pillar + type; } - static string FormatStatus3(Player p, bool infected) { + protected override string FormatStatus3(Player p) { string money = "&a" + p.money + " %S" + ServerConfig.Currency; - string state = ", you are " + (infected ? "&cdead" : "&aalive"); + string state = ", you are " + (Get(p).Infected ? "&cdead" : "&aalive"); return money + state; } }