From 4deb62d8b8956be678b4674dfd6f7d7ef842dd66 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 7 Jul 2018 17:25:05 +1000 Subject: [PATCH] minor game bugfixes --- MCGalaxy/Commands/Fun/CmdTntWars.cs | 4 +-- MCGalaxy/Games/IGame.cs | 26 ++++++++++++++----- .../Games/RoundsGame/RoundsGame.Plugin.cs | 4 +-- MCGalaxy/Games/RoundsGame/RoundsGame.cs | 1 + MCGalaxy/Games/TntWars/TWConfig.cs | 2 +- MCGalaxy/Games/TntWars/TWGame.Plugin.cs | 6 ++--- MCGalaxy/Games/TntWars/TWGame.Round.cs | 6 ++++- MCGalaxy/Games/TntWars/TWGame.cs | 25 ++++++++++++++++-- .../Games/ZombieSurvival/ZSGame.Plugin.cs | 3 +-- MCGalaxy/Games/ZombieSurvival/ZSGame.Round.cs | 2 +- MCGalaxy/Games/ZombieSurvival/ZSGame.cs | 2 +- 11 files changed, 58 insertions(+), 23 deletions(-) diff --git a/MCGalaxy/Commands/Fun/CmdTntWars.cs b/MCGalaxy/Commands/Fun/CmdTntWars.cs index 4775235be..ac0770065 100644 --- a/MCGalaxy/Commands/Fun/CmdTntWars.cs +++ b/MCGalaxy/Commands/Fun/CmdTntWars.cs @@ -91,7 +91,7 @@ namespace MCGalaxy.Commands.Fun { } else if (prop.CaselessEq("tnt")) { int amount = 1; if (!CommandParser.GetInt(p, value, "TNT at a time", ref amount, 0)) return; - cfg.MaxPlayerActiveTnt = amount; + cfg.MaxActiveTnt = amount; Player.Message(p, "TNT Wars: Number of TNTs placeable by a player at a time is now {0}", amount == 0 ? "unlimited" : value); @@ -152,7 +152,7 @@ namespace MCGalaxy.Commands.Fun { Player.Message(p, "Gamemode: &a{0} %Sat difficulty &a{1}", gameCfg.Mode, gameCfg.Difficulty); Player.Message(p, "TNT per player at a time: &a{0}", - cfg.MaxPlayerActiveTnt == 0 ? "unlimited" : cfg.MaxPlayerActiveTnt.ToString()); + cfg.MaxActiveTnt == 0 ? "unlimited" : cfg.MaxActiveTnt.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}", diff --git a/MCGalaxy/Games/IGame.cs b/MCGalaxy/Games/IGame.cs index bf15aeb49..afd1ad71a 100644 --- a/MCGalaxy/Games/IGame.cs +++ b/MCGalaxy/Games/IGame.cs @@ -31,8 +31,8 @@ namespace MCGalaxy.Games { if (lvl == null) return null; IGame[] games = RunningGames.Items; - foreach (IGame game in games) { - if (game.Map == lvl) return game; + foreach (IGame game in games) { + if (game.Map == lvl) return game; } return null; } @@ -65,9 +65,9 @@ namespace MCGalaxy.Games { 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 UpdateAllStatus1() { UpdateAllStatus(CpeMessageType.Status1); } + public void UpdateAllStatus2() { UpdateAllStatus(CpeMessageType.Status2); } public void UpdateAllStatus3() { UpdateAllStatus(CpeMessageType.Status3); } public void UpdateAllStatus() { @@ -78,13 +78,25 @@ namespace MCGalaxy.Games { void UpdateAllStatus(CpeMessageType status) { Player[] online = PlayerInfo.Online.Items; - foreach (Player p in online) { + 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); + p.SendCpeMessage(status, msg); } } + + protected void UpdateStatus1(Player p) { + p.SendCpeMessage(CpeMessageType.Status1, FormatStatus1(p)); + } + + protected void UpdateStatus2(Player p) { + p.SendCpeMessage(CpeMessageType.Status2, FormatStatus2(p)); + } + + protected void UpdateStatus3(Player p) { + p.SendCpeMessage(CpeMessageType.Status3, FormatStatus3(p)); + } } } diff --git a/MCGalaxy/Games/RoundsGame/RoundsGame.Plugin.cs b/MCGalaxy/Games/RoundsGame/RoundsGame.Plugin.cs index b38f1dac5..a5c79fc55 100644 --- a/MCGalaxy/Games/RoundsGame/RoundsGame.Plugin.cs +++ b/MCGalaxy/Games/RoundsGame/RoundsGame.Plugin.cs @@ -60,9 +60,7 @@ namespace MCGalaxy.Games { 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)); + UpdateStatus1(p); UpdateStatus2(p); UpdateStatus3(p); } if (level != Map) return; diff --git a/MCGalaxy/Games/RoundsGame/RoundsGame.cs b/MCGalaxy/Games/RoundsGame/RoundsGame.cs index 3bf8d25a0..992e6694a 100644 --- a/MCGalaxy/Games/RoundsGame/RoundsGame.cs +++ b/MCGalaxy/Games/RoundsGame/RoundsGame.cs @@ -201,6 +201,7 @@ namespace MCGalaxy.Games { if (pl.level != Map) continue; pl.Game.RatedMap = false; pl.Game.PledgeSurvive = false; + PlayerLeftGame(pl); TabList.Update(pl, true); ResetStatus(pl); diff --git a/MCGalaxy/Games/TntWars/TWConfig.cs b/MCGalaxy/Games/TntWars/TWConfig.cs index 37eea7730..352485a30 100644 --- a/MCGalaxy/Games/TntWars/TWConfig.cs +++ b/MCGalaxy/Games/TntWars/TWConfig.cs @@ -45,7 +45,7 @@ namespace MCGalaxy.Games { public int GracePeriodSeconds = 30; [ConfigInt("max-active-tnt", null, 1)] - public int MaxPlayerActiveTnt = 1; + public int MaxActiveTnt = 1; [ConfigBool("team-balance", null, true)] public bool BalanceTeams = true; diff --git a/MCGalaxy/Games/TntWars/TWGame.Plugin.cs b/MCGalaxy/Games/TntWars/TWGame.Plugin.cs index 0a7c34030..9ce5bc0e5 100644 --- a/MCGalaxy/Games/TntWars/TWGame.Plugin.cs +++ b/MCGalaxy/Games/TntWars/TWGame.Plugin.cs @@ -115,12 +115,12 @@ namespace MCGalaxy.Games { if (InZone(x, y, z, tntFreeZones)) { Player.Message(p, "TNT cannot be placed in this area"); return false; } - if (data.TNTCounter == 0) return false; + if (cfg.MaxActiveTnt == 0) return true; - if (data.TNTCounter == cfg.MaxPlayerActiveTnt) { + if (data.TNTCounter == cfg.MaxActiveTnt) { Player.Message(p, "TNT Wars: Maximum amount of TNT placed"); return false; } - if (data.TNTCounter > cfg.MaxPlayerActiveTnt) { + if (data.TNTCounter > cfg.MaxActiveTnt) { Player.Message(p, "TNT Wars: You are past the maximum amount of TNT that can be placed!"); return false; } return true; diff --git a/MCGalaxy/Games/TntWars/TWGame.Round.cs b/MCGalaxy/Games/TntWars/TWGame.Round.cs index a8f228f14..3b2a45b19 100644 --- a/MCGalaxy/Games/TntWars/TWGame.Round.cs +++ b/MCGalaxy/Games/TntWars/TWGame.Round.cs @@ -53,6 +53,10 @@ namespace MCGalaxy.Games { PlayerActions.Respawn(p); } + Red.Score = 0; Blue.Score = 0; + UpdateAllStatus1(); + UpdateAllStatus2(); + //Announcing Etc. // TODO: tidy up string Gamemode = "Free For All"; @@ -90,7 +94,7 @@ namespace MCGalaxy.Games { Chat.MessageGlobal("&cTNT Wars %Son " + Map.ColoredName + " %Shas started &3" + Gamemode + " %Swith a difficulty of &3" + difficulty + " %S(&3" + HitsToDie + " %Shits to die, a &3" + explosiontime + " %Sexplosion delay and with a &3" + explosionsize + " %Sexplosion size)" + - ", team killing is &3" + teamkillling + " %Sand you can place &3" + cfg.MaxPlayerActiveTnt + ", team killing is &3" + teamkillling + " %Sand you can place &3" + cfg.MaxActiveTnt + " %STNT at a time and there is a score limit of &3" + cfg.ScoreRequired + "%S!!"); if (Config.Mode == TWGameMode.TDM) { diff --git a/MCGalaxy/Games/TntWars/TWGame.cs b/MCGalaxy/Games/TntWars/TWGame.cs index e298fce61..9122d3e19 100644 --- a/MCGalaxy/Games/TntWars/TWGame.cs +++ b/MCGalaxy/Games/TntWars/TWGame.cs @@ -112,6 +112,10 @@ namespace MCGalaxy.Games { this.cfg = cfg; Red.SpawnPos = cfg.RedSpawn; Blue.SpawnPos = cfg.BlueSpawn; + + if (!Running) return; + UpdateAllStatus1(); + UpdateAllStatus2(); } protected override List GetPlayers() { @@ -283,14 +287,31 @@ namespace MCGalaxy.Games { public void ChangeScore(Player p, int amount) { Get(p).Score += amount; - if (Config.Mode != TWGameMode.TDM) return; + UpdateStatus2(p); + if (Config.Mode != TWGameMode.TDM) return; TWTeam team = TeamOf(p); - if (team != null) team.Score += amount; + if (team == null) return; + + team.Score += amount; + UpdateAllStatus1(); } public bool TeamKill(Player p1, Player p2) { return Config.Mode == TWGameMode.TDM && TeamOf(p1) == TeamOf(p2); } + + protected override string FormatStatus1(Player p) { + if (Config.Mode != TWGameMode.TDM) return ""; + + return Red.ColoredName + ": &f" + Red.Score + "/" + cfg.ScoreRequired + ", " + + Blue.ColoredName + ": &f" + Blue.Score + "/" + cfg.ScoreRequired; + } + + protected override string FormatStatus2(Player p) { + TWData data = Get(p); + return "&aHealth: &f" + data.Health + " HP, &eScore: &f" + + data.Score + "/" + cfg.ScoreRequired + " points"; + } } } diff --git a/MCGalaxy/Games/ZombieSurvival/ZSGame.Plugin.cs b/MCGalaxy/Games/ZombieSurvival/ZSGame.Plugin.cs index 2e80084fd..df8faac8d 100644 --- a/MCGalaxy/Games/ZombieSurvival/ZSGame.Plugin.cs +++ b/MCGalaxy/Games/ZombieSurvival/ZSGame.Plugin.cs @@ -35,7 +35,6 @@ namespace MCGalaxy.Games { OnTabListEntryAddedEvent.Register(HandleTabListEntryAdded, Priority.High); OnMoneyChangedEvent.Register(HandleMoneyChanged, Priority.High); OnBlockChangeEvent.Register(HandleBlockChange, Priority.High); - OnSendingHeartbeatEvent.Register(HandleSendingHeartbeat, Priority.High); OnPlayerConnectEvent.Register(HandlePlayerConnect, Priority.High); OnPlayerMoveEvent.Register(HandlePlayerMove, Priority.High); @@ -82,7 +81,7 @@ namespace MCGalaxy.Games { void HandleMoneyChanged(Player p) { if (p.level != Map) return; - p.SendCpeMessage(CpeMessageType.Status3, FormatStatus3(p)); + UpdateStatus3(p); } void HandleEntitySpawned(Entity entity, ref string name, ref string skin, ref string model, Player dst) { diff --git a/MCGalaxy/Games/ZombieSurvival/ZSGame.Round.cs b/MCGalaxy/Games/ZombieSurvival/ZSGame.Round.cs index 89d776ab7..2f8fe542d 100644 --- a/MCGalaxy/Games/ZombieSurvival/ZSGame.Round.cs +++ b/MCGalaxy/Games/ZombieSurvival/ZSGame.Round.cs @@ -308,7 +308,7 @@ namespace MCGalaxy.Games { } RespawnPlayer(pl); - pl.SendCpeMessage(CpeMessageType.Status3, FormatStatus3(pl)); + UpdateStatus3(pl); } } diff --git a/MCGalaxy/Games/ZombieSurvival/ZSGame.cs b/MCGalaxy/Games/ZombieSurvival/ZSGame.cs index 9165c9cca..5cafd22c4 100644 --- a/MCGalaxy/Games/ZombieSurvival/ZSGame.cs +++ b/MCGalaxy/Games/ZombieSurvival/ZSGame.cs @@ -160,7 +160,7 @@ namespace MCGalaxy.Games { ResetInvisibility(p, data); UpdateAllStatus1(); - p.SendCpeMessage(CpeMessageType.Status3, FormatStatus3(p)); + UpdateStatus3(p); } void ResetInvisibility(Player p, ZSData data) {