From fa73ab533511f0da1faa2ed45536289c24ac514a Mon Sep 17 00:00:00 2001 From: Chiss Date: Sat, 26 Jul 2014 17:40:17 +1000 Subject: [PATCH] Bridges Tourney stuff --- .../mineplex/core/common/util/UtilTime.java | 2 +- .../src/nautilus/game/arcade/game/Game.java | 5 + .../game/arcade/game/games/bridge/Bridge.java | 158 +++++++++++++----- .../game/arcade/managers/GameManager.java | 2 +- 4 files changed, 122 insertions(+), 45 deletions(-) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilTime.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilTime.java index 6857b11cf..39102ff20 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilTime.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilTime.java @@ -68,7 +68,7 @@ public class UtilTime public static String MakeStr(long time, int trim) { - return convertString(time, trim, TimeUnit.FIT); + return convertString(Math.max(0, time), trim, TimeUnit.FIT); } public static String convertString(long time, int trim, TimeUnit type) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java index 29a2769b7..0f24f3ea7 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java @@ -1030,4 +1030,9 @@ public abstract class Game implements Listener if (team != null) team.SetPlacement(event.GetPlayer(), event.GetState()); } + + public void HandleTimeout() + { + SetState(GameState.End); + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java index 7483c2558..effd6f45a 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java @@ -55,6 +55,7 @@ import nautilus.game.arcade.events.PlayerDeathOutEvent; import nautilus.game.arcade.game.Game; import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.TeamGame; +import nautilus.game.arcade.game.Game.GameState; import nautilus.game.arcade.game.games.bridge.kits.*; import nautilus.game.arcade.kit.Kit; import nautilus.game.arcade.ore.OreHider; @@ -102,9 +103,8 @@ public class Bridge extends TeamGame implements OreObsfucation //Tourney Mode private boolean _tournament; private HashMap _tournamentKills = new HashMap(); + private long _tournamentKillMessageTimer = 0; - //Scoreboard - private ArrayList _lastScoreboard = new ArrayList(); public Bridge(ArcadeManager manager) { @@ -130,15 +130,15 @@ public class Bridge extends TeamGame implements OreObsfucation _ore = new OreHider(); // Flags - GameTimeout = Manager.IsTournamentServer() ? 5400000 : 1800000; - + GameTimeout = Manager.IsTournamentServer() ? 5400000 : 3600000; + DamageSelf = true; ItemDrop = true; ItemPickup = true; InventoryClick = true; - + PrivateBlocks = true; BlockBreak = true; BlockPlace = true; @@ -155,14 +155,14 @@ public class Bridge extends TeamGame implements OreObsfucation DeathDropItems = true; GemMultiplier = 2.5; - + PrepareFreeze = false; - + //Tournament if (Manager.IsTournamentServer()) { QuitOut = false; - + _gameDesc = new String[] { "Gather resources and prepare for combat.", @@ -171,8 +171,8 @@ public class Bridge extends TeamGame implements OreObsfucation "Team with the most kills wins!" }; } - - + + _tournament = Manager.IsTournamentServer(); } @@ -313,22 +313,22 @@ public class Bridge extends TeamGame implements OreObsfucation return ItemStackFactory.Instance.CreateStack(stack.getTypeId(), amount); } - + @EventHandler public void ChestDeny(PlayerInteractEvent event) { if (_bridgesDown) return; - + if (event.getClickedBlock() == null) return; - + if (event.getClickedBlock().getType() != Material.CHEST) return; - + if (!UtilEvent.isAction(event, ActionType.R_BLOCK)) return; - + for (Location loc : WorldData.GetCustomLocs("54")) { if (loc.getBlock().equals(event.getClickedBlock())) @@ -338,16 +338,16 @@ public class Bridge extends TeamGame implements OreObsfucation } } } - + @EventHandler public void ChestDeny(BlockBreakEvent event) { if (_bridgesDown) return; - + if (event.getBlock().getType() != Material.CHEST) return; - + for (Location loc : WorldData.GetCustomLocs("54")) { if (loc.getBlock().equals(event.getBlock())) @@ -525,11 +525,11 @@ public class Bridge extends TeamGame implements OreObsfucation BlockFace faceXZ = BlockFace.SELF; BlockFace faceY = BlockFace.SELF; - + if (Math.random() > 0.20) { int rFace = UtilMath.r(6); - + if (rFace == 0) faceY = BlockFace.UP; else if (rFace == 1) faceY = BlockFace.DOWN; else if (rFace == 2) faceXZ = BlockFace.NORTH; @@ -541,16 +541,16 @@ public class Bridge extends TeamGame implements OreObsfucation { //Height int rFace = UtilMath.r(3); - + if (rFace == 0) faceY = BlockFace.SELF; else if (rFace == 1) faceY = BlockFace.UP; else faceY = BlockFace.DOWN; - + //Flat if (faceY == BlockFace.SELF) { rFace = UtilMath.r(4); - + if (rFace == 0) faceXZ = BlockFace.NORTH_EAST; else if (rFace == 1) faceXZ = BlockFace.NORTH_WEST; else if (rFace == 2) faceXZ = BlockFace.SOUTH_EAST; @@ -559,17 +559,17 @@ public class Bridge extends TeamGame implements OreObsfucation else { rFace = UtilMath.r(4); - + if (rFace == 0) faceXZ = BlockFace.NORTH; else if (rFace == 1) faceXZ = BlockFace.SOUTH; else if (rFace == 2) faceXZ = BlockFace.EAST; else faceXZ = BlockFace.WEST; } } - + if (loc.getBlock().getRelative(faceY).getRelative(faceXZ).getType() != Material.STONE) continue; - + loc = loc.getBlock().getRelative(faceY).getRelative(faceXZ).getLocation(); _ore.AddOre(loc, type); @@ -1113,13 +1113,13 @@ public class Bridge extends TeamGame implements OreObsfucation if (this.GetPlayers(true).size() < 10) { Scoreboard.WriteBlank(); - + for (Player player : team.GetPlayers(true)) { Scoreboard.Write(team.GetColor() + player.getName()); } } - + //Display Players Alive else { @@ -1139,15 +1139,15 @@ public class Bridge extends TeamGame implements OreObsfucation kills = _tournamentKills.get(team); Scoreboard.WriteBlank(); - + Scoreboard.Write(team.GetColor() + " " + team.GetPlayers(true).size() + " Players"); Scoreboard.Write(team.GetColor() + " " + kills + " Kills"); } } - + Scoreboard.WriteBlank(); - - + + long time = _bridgeTime - (System.currentTimeMillis() - this.GetStateTime()); @@ -1158,9 +1158,10 @@ public class Bridge extends TeamGame implements OreObsfucation } else { - Scoreboard.Write(C.cYellow + C.Bold + "FIGHT!"); + Scoreboard.Write(C.cYellow + C.Bold + "Time Left"); + Scoreboard.Write(UtilTime.MakeStr(5400000 - this.GetStateTime(), 0)); } - + Scoreboard.Draw(); } @@ -1199,7 +1200,7 @@ public class Bridge extends TeamGame implements OreObsfucation } } } - + @Override public void EndCheck() { @@ -1218,7 +1219,7 @@ public class Bridge extends TeamGame implements OreObsfucation for (GameTeam team : RejoinTeam.values()) teamsAlive.add(team); } - + if (teamsAlive.size() <= 1) { //Announce Winner @@ -1231,13 +1232,13 @@ public class Bridge extends TeamGame implements OreObsfucation { GameTeam bestTeam = null; int bestKills = 0; - + for (GameTeam team : GetTeamList()) { if (_tournamentKills.containsKey(team)) { int kills = _tournamentKills.get(team); - + if (bestTeam == null || bestKills < kills) { bestTeam = team; @@ -1245,12 +1246,12 @@ public class Bridge extends TeamGame implements OreObsfucation } } } - + if (bestTeam != null) AnnounceEnd(bestTeam); } - - + + for (GameTeam team : GetTeamList()) { if (WinnerTeam != null && team.equals(WinnerTeam)) @@ -1258,14 +1259,85 @@ public class Bridge extends TeamGame implements OreObsfucation for (Player player : team.GetPlayers(false)) AddGems(player, 10, "Winning Team", false); } - + for (Player player : team.GetPlayers(false)) if (player.isOnline()) AddGems(player, 10, "Participation", false); } - + //End SetState(GameState.End); } } + + public void HandleTimeout() + { + if (!_tournament) + { + SetState(GameState.End); + return; + } + + ArrayList bestTeams = new ArrayList(); + int bestKills = 0; + + for (GameTeam team : GetTeamList()) + { + if (_tournamentKills.containsKey(team)) + { + int kills = _tournamentKills.get(team); + + if (bestTeams == null || kills > bestKills) + { + bestTeams.clear(); + bestTeams.add(team); + bestKills = kills; + } + + else if (kills == bestKills) + { + bestTeams.add(team); + } + } + } + + //Many Teams Alive + if (bestTeams.size() > 1) + { + if (UtilTime.elapsed(_tournamentKillMessageTimer, 15000)) + { + _tournamentKillMessageTimer = System.currentTimeMillis(); + + this.Announce(C.cRed + C.Bold + "ALERT: " + ChatColor.RESET + C.Bold + "FIRST TEAM TO TAKE THE LEAD WINS!"); + } + } + + //Team Won + else if (bestTeams.size() == 1) + { + AnnounceEnd(bestTeams.get(0)); + + for (GameTeam team : GetTeamList()) + { + if (WinnerTeam != null && team.equals(WinnerTeam)) + { + for (Player player : team.GetPlayers(false)) + AddGems(player, 10, "Winning Team", false); + } + + for (Player player : team.GetPlayers(false)) + if (player.isOnline()) + AddGems(player, 10, "Participation", false); + } + + //End + SetState(GameState.End); + } + + //No One Wins :'( + else + { + SetState(GameState.End); + } + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameManager.java index b11b82317..87a23365a 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameManager.java @@ -151,7 +151,7 @@ public class GameManager implements Listener { if (UtilTime.elapsed(game.GetStateTime(), game.GameTimeout)) { - game.SetState(GameState.End); + game.HandleTimeout(); } } else if (game.GetState() == GameState.End)