Staggered game teleports/start
This commit is contained in:
parent
27f554ab61
commit
f4cd2fcbb9
@ -71,12 +71,12 @@ public abstract class Game implements Listener
|
||||
//State
|
||||
private GameState _gameState = GameState.Loading;
|
||||
private long _gameStateTime = System.currentTimeMillis();
|
||||
|
||||
private boolean _prepareCountdown = false;
|
||||
|
||||
private int _countdown = -1;
|
||||
private boolean _countdownForce = false;
|
||||
|
||||
private int _playerCount = 0;
|
||||
|
||||
private String _customWinLine = "";
|
||||
|
||||
//Kits
|
||||
@ -274,16 +274,6 @@ public abstract class Game implements Listener
|
||||
_countdownForce = value;
|
||||
}
|
||||
|
||||
public int GetPlayerCountAtStart()
|
||||
{
|
||||
return _playerCount;
|
||||
}
|
||||
|
||||
public void SetPlayerCountAtStart(int count)
|
||||
{
|
||||
_playerCount = count;
|
||||
}
|
||||
|
||||
public NautHashMap<GameTeam, ArrayList<Player>> GetTeamPreferences()
|
||||
{
|
||||
return _teamPreference;
|
||||
@ -561,7 +551,7 @@ public abstract class Game implements Listener
|
||||
}
|
||||
|
||||
_playerKit.put(player, kit);
|
||||
|
||||
|
||||
kit.Selected(player);
|
||||
|
||||
if (announce)
|
||||
@ -569,7 +559,7 @@ public abstract class Game implements Listener
|
||||
player.playSound(player.getLocation(), Sound.ORB_PICKUP, 2f, 1f);
|
||||
UtilPlayer.message(player, F.main("Kit", "You equipped " + F.elem(kit.GetFormattedName() + " Kit") + "."));
|
||||
}
|
||||
|
||||
|
||||
if (InProgress())
|
||||
kit.ApplyKit(player);
|
||||
}
|
||||
@ -858,32 +848,35 @@ public abstract class Game implements Listener
|
||||
public void AnnounceGame()
|
||||
{
|
||||
for (Player player : UtilServer.getPlayers())
|
||||
{
|
||||
player.playSound(player.getLocation(), Sound.LEVEL_UP, 2f, 1f);
|
||||
|
||||
for (int i=0 ; i<6-GetDesc().length ; i++)
|
||||
UtilPlayer.message(player, "");
|
||||
|
||||
UtilPlayer.message(player, ArcadeFormat.Line);
|
||||
|
||||
UtilPlayer.message(player, C.cGreen + "Game - " + C.cYellow+ C.Bold + this.GetName());
|
||||
UtilPlayer.message(player, "");
|
||||
|
||||
for (String line : this.GetDesc())
|
||||
{
|
||||
UtilPlayer.message(player, C.cWhite + "- " + line);
|
||||
}
|
||||
|
||||
UtilPlayer.message(player, "");
|
||||
UtilPlayer.message(player, C.cGreen + "Map - " + C.cYellow + C.Bold + WorldData.MapName + ChatColor.RESET + C.cGray + " created by " + C.cYellow+ C.Bold + WorldData.MapAuthor);
|
||||
|
||||
UtilPlayer.message(player, ArcadeFormat.Line);
|
||||
}
|
||||
|
||||
AnnounceGame(player);
|
||||
|
||||
if (AnnounceSilence)
|
||||
Manager.GetChat().Silence(9000, false);
|
||||
}
|
||||
|
||||
public void AnnounceGame(Player player)
|
||||
{
|
||||
player.playSound(player.getLocation(), Sound.LEVEL_UP, 2f, 1f);
|
||||
|
||||
for (int i=0 ; i<6-GetDesc().length ; i++)
|
||||
UtilPlayer.message(player, "");
|
||||
|
||||
UtilPlayer.message(player, ArcadeFormat.Line);
|
||||
|
||||
UtilPlayer.message(player, C.cGreen + "Game - " + C.cYellow+ C.Bold + this.GetName());
|
||||
UtilPlayer.message(player, "");
|
||||
|
||||
for (String line : this.GetDesc())
|
||||
{
|
||||
UtilPlayer.message(player, C.cWhite + "- " + line);
|
||||
}
|
||||
|
||||
UtilPlayer.message(player, "");
|
||||
UtilPlayer.message(player, C.cGreen + "Map - " + C.cYellow + C.Bold + WorldData.MapName + ChatColor.RESET + C.cGray + " created by " + C.cYellow+ C.Bold + WorldData.MapAuthor);
|
||||
|
||||
UtilPlayer.message(player, ArcadeFormat.Line);
|
||||
}
|
||||
|
||||
public void AnnounceEnd(GameTeam team)
|
||||
{
|
||||
for (Player player : UtilServer.getPlayers())
|
||||
@ -1019,4 +1012,14 @@ public abstract class Game implements Listener
|
||||
|
||||
_helpIndex = (_helpIndex + 1)%_help.length;
|
||||
}
|
||||
|
||||
public void StartPrepareCountdown()
|
||||
{
|
||||
_prepareCountdown = true;
|
||||
}
|
||||
|
||||
public boolean CanStartPrepareCountdown()
|
||||
{
|
||||
return _prepareCountdown;
|
||||
}
|
||||
}
|
||||
|
@ -57,9 +57,9 @@ public class GameTeam
|
||||
private Creature _teamEntity = null;
|
||||
|
||||
private HashSet<Kit> _kitRestrict = new HashSet<Kit>();
|
||||
|
||||
|
||||
private int _spawnDistance = 0;
|
||||
|
||||
|
||||
private boolean _visible = true;
|
||||
|
||||
public GameTeam(String name, ChatColor color, ArrayList<Location> spawns)
|
||||
@ -87,40 +87,40 @@ public class GameTeam
|
||||
public Location GetSpawn()
|
||||
{
|
||||
ArrayList<Location> valid = new ArrayList<Location>();
|
||||
|
||||
|
||||
Location best = null;
|
||||
double bestDist = 0;
|
||||
|
||||
|
||||
for (Location loc : _spawns)
|
||||
{
|
||||
double closestPlayer = -1;
|
||||
|
||||
|
||||
for (Player player : GetPlayers(true))
|
||||
{
|
||||
double playerDist = UtilMath.offset(player.getLocation(), loc);
|
||||
|
||||
|
||||
if (closestPlayer == -1 || playerDist < closestPlayer)
|
||||
closestPlayer = playerDist;
|
||||
}
|
||||
|
||||
|
||||
if (best == null || closestPlayer > bestDist)
|
||||
{
|
||||
best = loc;
|
||||
bestDist = closestPlayer;
|
||||
}
|
||||
|
||||
|
||||
if (closestPlayer > _spawnDistance)
|
||||
{
|
||||
valid.add(loc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (valid.size() > 0)
|
||||
valid.get(UtilMath.r(valid.size()));
|
||||
|
||||
|
||||
if (best != null)
|
||||
return best;
|
||||
|
||||
|
||||
return _spawns.get(UtilMath.r(_spawns.size()));
|
||||
}
|
||||
|
||||
@ -150,22 +150,22 @@ public class GameTeam
|
||||
for (Player player : _players.keySet())
|
||||
if (player.getName().equals(name))
|
||||
return player;
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public boolean HasPlayer(Player player)
|
||||
{
|
||||
return _players.containsKey(player);
|
||||
}
|
||||
|
||||
|
||||
public boolean HasPlayer(String name, boolean alive)
|
||||
{
|
||||
for (Player player : _players.keySet())
|
||||
if (player.getName().equals(name))
|
||||
if (!alive || (alive && _players.get(player) == PlayerState.IN))
|
||||
return true;
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -178,7 +178,7 @@ public class GameTeam
|
||||
{
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
|
||||
_players.put(player, state);
|
||||
}
|
||||
|
||||
@ -207,13 +207,18 @@ public class GameTeam
|
||||
return GetColor() + "§l" + GetName();
|
||||
}
|
||||
|
||||
public void SpawnTeleport(Player player)
|
||||
{
|
||||
player.leaveVehicle();
|
||||
player.eject();
|
||||
player.teleport(GetSpawn());
|
||||
}
|
||||
|
||||
public void SpawnTeleport()
|
||||
{
|
||||
for (Player player : GetPlayers(true))
|
||||
{
|
||||
player.leaveVehicle();
|
||||
player.eject();
|
||||
player.teleport(GetSpawn());
|
||||
SpawnTeleport(player);
|
||||
}
|
||||
}
|
||||
|
||||
@ -226,7 +231,7 @@ public class GameTeam
|
||||
{
|
||||
if (kit.GetAvailability() == KitAvailability.Null)
|
||||
return false;
|
||||
|
||||
|
||||
return !_kitRestrict.contains(kit);
|
||||
}
|
||||
|
||||
@ -268,7 +273,7 @@ public class GameTeam
|
||||
if (GetColor() == ChatColor.RED) return (byte)14;
|
||||
else return (byte)15;
|
||||
}
|
||||
|
||||
|
||||
public Color GetColorBase()
|
||||
{
|
||||
if (GetColor() == ChatColor.WHITE) return Color.WHITE;
|
||||
@ -302,7 +307,7 @@ public class GameTeam
|
||||
{
|
||||
_spawns = spawns;
|
||||
}
|
||||
|
||||
|
||||
public void SetSpawnRequirement(int value)
|
||||
{
|
||||
_spawnDistance = value;
|
||||
@ -312,7 +317,7 @@ public class GameTeam
|
||||
{
|
||||
_visible = b;
|
||||
}
|
||||
|
||||
|
||||
public boolean GetVisible()
|
||||
{
|
||||
return _visible;
|
||||
|
@ -101,6 +101,8 @@ public abstract class Kit implements Listener
|
||||
perk.Apply(player);
|
||||
|
||||
GiveItems(player);
|
||||
|
||||
UtilInv.Update(player);
|
||||
}
|
||||
|
||||
public abstract void GiveItems(Player player);
|
||||
|
@ -1,5 +1,6 @@
|
||||
package nautilus.game.arcade.managers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
@ -119,26 +120,29 @@ public class GameManager implements Listener
|
||||
}
|
||||
else if (game.GetState() == GameState.Prepare)
|
||||
{
|
||||
if (UtilTime.elapsed(game.GetStateTime(), 9000))
|
||||
if (game.CanStartPrepareCountdown())
|
||||
{
|
||||
for (Player player : UtilServer.getPlayers())
|
||||
player.playSound(player.getLocation(), Sound.NOTE_PLING, 2f, 2f);
|
||||
|
||||
if (game.GetPlayers(true).size() < 2)
|
||||
if (UtilTime.elapsed(game.GetStateTime(), 9000))
|
||||
{
|
||||
game.Announce(C.cWhite + C.Bold + game.GetName() + " ended, not enough players!");
|
||||
game.SetState(GameState.Dead);
|
||||
for (Player player : UtilServer.getPlayers())
|
||||
player.playSound(player.getLocation(), Sound.NOTE_PLING, 2f, 2f);
|
||||
|
||||
if (game.GetPlayers(true).size() < 2)
|
||||
{
|
||||
game.Announce(C.cWhite + C.Bold + game.GetName() + " ended, not enough players!");
|
||||
game.SetState(GameState.Dead);
|
||||
}
|
||||
else
|
||||
{
|
||||
game.SetState(GameState.Live);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
game.SetState(GameState.Live);
|
||||
for (Player player : UtilServer.getPlayers())
|
||||
player.playSound(player.getLocation(), Sound.NOTE_STICKS, 1f, 1f);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Player player : UtilServer.getPlayers())
|
||||
player.playSound(player.getLocation(), Sound.NOTE_STICKS, 1f, 1f);
|
||||
}
|
||||
}
|
||||
else if (game.GetState() == GameState.Live)
|
||||
{
|
||||
@ -466,32 +470,48 @@ public class GameManager implements Listener
|
||||
@EventHandler
|
||||
public void PlayerPrepare(GameStateChangeEvent event)
|
||||
{
|
||||
Game game = event.GetGame();
|
||||
final Game game = event.GetGame();
|
||||
|
||||
if (event.GetState() != GameState.Prepare)
|
||||
return;
|
||||
|
||||
//Teleport
|
||||
for (GameTeam team : game.GetTeamList())
|
||||
team.SpawnTeleport();
|
||||
|
||||
//Save Initial Player Count
|
||||
game.SetPlayerCountAtStart(game.GetPlayers(true).size());
|
||||
|
||||
//Announce
|
||||
game.AnnounceGame();
|
||||
|
||||
final ArrayList<Player> players = game.GetPlayers(true);
|
||||
|
||||
//Prepare Players
|
||||
for (Player player : game.GetPlayers(true))
|
||||
for (int i=0 ; i<players.size() ; i++)
|
||||
{
|
||||
Manager.Clear(player);
|
||||
UtilInv.Clear(player);
|
||||
final Player player = players.get(i);
|
||||
|
||||
final GameTeam team = game.GetTeam(player);
|
||||
|
||||
UtilServer.getServer().getScheduler().runTaskLater(Manager.GetPlugin(), new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
//Teleport
|
||||
if (team != null)
|
||||
team.SpawnTeleport(player);
|
||||
|
||||
Manager.Clear(player);
|
||||
UtilInv.Clear(player);
|
||||
|
||||
game.ValidateKit(player, game.GetTeam(player));
|
||||
game.ValidateKit(player, game.GetTeam(player));
|
||||
|
||||
if (game.GetKit(player) != null)
|
||||
game.GetKit(player).ApplyKit(player);
|
||||
if (game.GetKit(player) != null)
|
||||
game.GetKit(player).ApplyKit(player);
|
||||
}
|
||||
}, i);
|
||||
}
|
||||
|
||||
//Announce Game after every player is TP'd in
|
||||
UtilServer.getServer().getScheduler().runTaskLater(Manager.GetPlugin(), new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
game.AnnounceGame();
|
||||
game.StartPrepareCountdown();
|
||||
}
|
||||
}, players.size());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
Loading…
Reference in New Issue
Block a user