Death Tag

This commit is contained in:
Sam 2018-04-30 21:48:21 +01:00 committed by Alexander Meech
parent f495405b49
commit 790d13d1d7

View File

@ -1,15 +1,31 @@
package nautilus.game.arcade.game.games.deathtag; package nautilus.game.arcade.game.games.deathtag;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import mineplex.core.Managers; import mineplex.core.Managers;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilServer;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.visibility.VisibilityManager; import mineplex.core.visibility.VisibilityManager;
import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType; import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.events.GameStateChangeEvent;
@ -26,37 +42,27 @@ import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.NullKit; import nautilus.game.arcade.kit.NullKit;
import nautilus.game.arcade.stats.ComeAtMeBroStatTracker; import nautilus.game.arcade.stats.ComeAtMeBroStatTracker;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class DeathTag extends SoloGame public class DeathTag extends SoloGame
{ {
private static final String[] DESCRIPTION =
{
C.cGreen + "Run" + C.Reset + " from the " + C.cRed + "Undead!",
"If you die, you become " + C.cRed + "Undead!",
C.cYellow + "Last Runner" + C.Reset + " alive wins!"
};
private GameTeam _runners; private GameTeam _runners;
private GameTeam _chasers; private GameTeam _chasers;
private NautHashMap<Player, Location> _deathLocation = new NautHashMap<Player, Location>(); private final Map<Player, Location> _deathLocation = new HashMap<>();
private List<Location> _lights;
private int _currentSpeed = -1; private int _currentSpeed = -1;
private ArrayList<Location> _lights = new ArrayList<Location>();
public DeathTag(ArcadeManager manager) public DeathTag(ArcadeManager manager)
{ {
super(manager, GameType.DeathTag, super(manager, GameType.DeathTag, new Kit[]
new Kit[]
{ {
new KitRunnerBasher(manager), new KitRunnerBasher(manager),
new KitRunnerArcher(manager), new KitRunnerArcher(manager),
@ -64,31 +70,23 @@ public class DeathTag extends SoloGame
new NullKit(manager), new NullKit(manager),
new KitAlphaChaser(manager), new KitAlphaChaser(manager),
new KitChaser(manager), new KitChaser(manager),
}, }, DESCRIPTION);
new String[] StrictAntiHack = true;
{ DeathOut = false;
"Run from the Undead!", HungerSet = 20;
"If you die, you become Undead!", PrepareFreeze = false;
"The last Runner alive wins!" PlayerGameMode = GameMode.ADVENTURE;
}); SplitKitXP = true;
this.StrictAntiHack = true;
this.DeathOut = false;
this.HungerSet = 20;
new CompassModule() new CompassModule()
.setGiveCompassToAlive(true) .setGiveCompassToAlive(true)
.register(this); .register(this);
this.PrepareFreeze = false;
this.PlayerGameMode = GameMode.ADVENTURE; registerStatTrackers(
new ComeAtMeBroStatTracker(this)
SplitKitXP = true; );
registerStatTrackers(new ComeAtMeBroStatTracker(this));
registerChatStats( registerChatStats(
Kills, Kills,
@ -100,15 +98,7 @@ public class DeathTag extends SoloGame
@Override @Override
public void ParseData() public void ParseData()
{ {
_lights = this.WorldData.GetCustomLocs("89"); _lights = WorldData.GetCustomLocs("89");
for (Location loc : _lights)
{
if (Math.random() > 0.5)
loc.getBlock().setType(Material.GOLD_BLOCK);
else
loc.getBlock().setTypeIdAndData(35, (byte)15, false);
}
} }
@Override @Override
@ -121,31 +111,37 @@ public class DeathTag extends SoloGame
if (team.GetColor() == ChatColor.RED) if (team.GetColor() == ChatColor.RED)
{ {
if (kit.GetName().contains("ZOMBIE")) if (kit.GetName().contains("ZOMBIE"))
{
team.GetRestrictedKits().add(kit); team.GetRestrictedKits().add(kit);
} }
}
else else
{ {
if (kit.GetName().contains("Chaser")) if (kit.GetName().contains("Chaser"))
{
team.GetRestrictedKits().add(kit); team.GetRestrictedKits().add(kit);
} }
} }
} }
} }
}
@Override @Override
@EventHandler @EventHandler
public void CustomTeamGeneration(GameStateChangeEvent event) public void CustomTeamGeneration(GameStateChangeEvent event)
{ {
if (event.GetState() != GameState.Recruit) if (event.GetState() != GameState.Recruit)
{
return; return;
}
_runners = this.GetTeamList().get(0); _runners = GetTeamList().get(0);
_runners.SetName("Runners"); _runners.SetName("Runners");
//Undead Team //Undead Team
_chasers = new GameTeam(this, "Chasers", ChatColor.RED, _runners.GetSpawns()); _chasers = new GameTeam(this, "Chasers", ChatColor.RED, _runners.GetSpawns());
_chasers.SetVisible(false); _chasers.SetVisible(false);
GetTeamList().add(_chasers); AddTeam(_chasers);
RestrictKits(); RestrictKits();
} }
@ -157,20 +153,25 @@ public class DeathTag extends SoloGame
} }
@EventHandler @EventHandler
public void UpdateLights(UpdateEvent event) public void updateLights(UpdateEvent event)
{ {
if (!IsLive()) if (event.getType() != UpdateType.SEC || !InProgress())
return;
if (event.getType() != UpdateType.SEC)
return;
for (Location loc : _lights)
{ {
if (loc.getBlock().getType() == Material.GOLD_BLOCK) return;
loc.getBlock().setTypeIdAndData(35, (byte)15, false); }
for (Location location : _lights)
{
Material material = location.getBlock().getType();
if (material == Material.GOLD_BLOCK)
{
location.getBlock().setTypeIdAndData(35, (byte) 15, false);
}
else else
loc.getBlock().setType(Material.GOLD_BLOCK); {
location.getBlock().setType(Material.GOLD_BLOCK);
}
} }
} }
@ -178,13 +179,12 @@ public class DeathTag extends SoloGame
@EventHandler @EventHandler
public void UpdateSpeed(UpdateEvent event) public void UpdateSpeed(UpdateEvent event)
{ {
if (!IsLive()) if (event.getType() != UpdateType.SLOW || !IsLive())
{
return; return;
}
if (event.getType() != UpdateType.SLOW) double ratio = (double) _chasers.GetPlayers(false).size() / (double) GetPlayers(false).size();
return;
double ratio = (double)_chasers.GetPlayers(false).size() / (double)GetPlayers(false).size();
if (_currentSpeed == -1 && ratio > 0.25) if (_currentSpeed == -1 && ratio > 0.25)
{ {
@ -204,71 +204,75 @@ public class DeathTag extends SoloGame
} }
@EventHandler @EventHandler
public void ApplyConditions(UpdateEvent event) public void applyConditions(UpdateEvent event)
{
if (event.getType() != UpdateType.SLOW || !IsLive())
{ {
if (!IsLive())
return;
if (event.getType() != UpdateType.FAST)
return; return;
}
if (_currentSpeed >= 0) if (_currentSpeed >= 0)
{
for (Player player : _runners.GetPlayers(false)) for (Player player : _runners.GetPlayers(false))
{ {
Manager.GetCondition().Factory().Speed("Runner", player, player, 1.9, _currentSpeed, false, false, true); Manager.GetCondition().Factory().Speed("Runner", player, player, 1.9, _currentSpeed, false, false, true);
} }
}
for (Player player : _chasers.GetPlayers(false)) for (Player player : _chasers.GetPlayers(false))
{ {
Manager.GetCondition().Factory().Regen("Undying", player, player, 1.9, 4, false, false, false); Manager.GetCondition().Factory().Regen("Undying", player, player, 1.9, 4, false, false, false);
if (_currentSpeed < 0) if (_currentSpeed < 0)
{
Manager.GetCondition().Factory().Speed("Haste", player, player, 1.9, 0, false, false, true); Manager.GetCondition().Factory().Speed("Haste", player, player, 1.9, 0, false, false, true);
} }
} }
}
@EventHandler @EventHandler
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) public void onPlayerInteractEntity(PlayerInteractEntityEvent event)
{ {
if(event.getRightClicked() instanceof ItemFrame) if (event.getRightClicked() instanceof ItemFrame)
{ {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@EventHandler @EventHandler
public void UpdateChasers(UpdateEvent event) public void updateChasers(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST || !IsLive())
{ {
if (!IsLive())
return;
if (event.getType() != UpdateType.FAST)
return; return;
}
int req = 1 + (int) ((System.currentTimeMillis() - GetStateTime()) / 30000); int req = 1 + (int) ((System.currentTimeMillis() - GetStateTime()) / 30000);
while (_chasers.GetPlayers(true).size() < req && _runners.GetPlayers(true).size() > 0) while (_chasers.GetPlayers(true).size() < req && _runners.GetPlayers(true).size() > 0)
{ {
Player player = _runners.GetPlayers(true).get(UtilMath.r(_runners.GetPlayers(true).size())); Player player = _runners.GetPlayers(true).get(UtilMath.r(_runners.GetPlayers(true).size()));
SetChaser(player, true); setChaser(player, true);
} }
} }
@EventHandler @EventHandler
public void PlayerDeath(PlayerDeathEvent event) public void playerDeath(PlayerDeathEvent event)
{ {
if (_runners.HasPlayer(event.getEntity())) if (_runners.HasPlayer(event.getEntity()))
{ {
_deathLocation.put(event.getEntity(), event.getEntity().getLocation()); _deathLocation.put(event.getEntity(), event.getEntity().getLocation());
SetChaser(event.getEntity(), false); setChaser(event.getEntity(), false);
} }
} }
public void SetChaser(Player player, boolean forced) private void setChaser(Player player, boolean forced)
{ {
//Set them as OUT! //Set them as OUT!
if (GetTeam(player) != null) if (IsPlaying(player))
{
GetTeam(player).SetPlacement(player, PlayerState.OUT); GetTeam(player).SetPlacement(player, PlayerState.OUT);
}
SetPlayerTeam(player, _chasers, true); SetPlayerTeam(player, _chasers, true);
@ -290,8 +294,7 @@ public class DeathTag extends SoloGame
{ {
AddGems(player, 10, "Forced Chaser", false, false); AddGems(player, 10, "Forced Chaser", false, false);
Announce(F.main("Game", F.elem(_runners.GetColor() + player.getName()) + " has become an " + Announce(F.main("Game", F.elem(_runners.GetColor() + player.getName()) + " has become an " + F.elem(_chasers.GetColor() + newKit.GetName()) + "."));
F.elem(_chasers.GetColor() + newKit.GetName()) + "."));
player.getWorld().strikeLightningEffect(player.getLocation()); player.getWorld().strikeLightningEffect(player.getLocation());
} }
@ -310,22 +313,23 @@ public class DeathTag extends SoloGame
player.eject(); player.eject();
if (_deathLocation.containsKey(player)) if (_deathLocation.containsKey(player))
{
player.teleport(_deathLocation.remove(player)); player.teleport(_deathLocation.remove(player));
}
else else
{
player.teleport(_chasers.GetSpawn()); player.teleport(_chasers.GetSpawn());
} }
}
//Re-Give Kit //Re-Give Kit
Manager.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), new Runnable() Manager.runSyncLater(() ->
{
public void run()
{ {
GetKit(player).ApplyKit(player); GetKit(player).ApplyKit(player);
//Refresh on Spawn //Refresh on Spawn
VisibilityManager vm = Managers.require(VisibilityManager.class); VisibilityManager vm = Managers.require(VisibilityManager.class);
Bukkit.getOnlinePlayers().forEach(pl -> vm.refreshVisibility(pl, player)); Bukkit.getOnlinePlayers().forEach(pl -> vm.refreshVisibility(pl, player));
}
}, 0); }, 0);
} }
@ -333,27 +337,38 @@ public class DeathTag extends SoloGame
public void EndCheck() public void EndCheck()
{ {
if (!IsLive()) if (!IsLive())
{
return; return;
}
if (_runners.GetPlayers(true).size() <= 1) if (_runners.GetPlayers(true).size() <= 1)
{ {
ArrayList<Player> places = _runners.GetPlacements(true); List<Player> places = _runners.GetPlacements(true);
if (places.size() >= 1) if (places.size() >= 1)
{
AddGems(places.get(0), 15, "1st Place", false, false); AddGems(places.get(0), 15, "1st Place", false, false);
}
if (places.size() >= 2) if (places.size() >= 2)
{
AddGems(places.get(1), 10, "2nd Place", false, false); AddGems(places.get(1), 10, "2nd Place", false, false);
}
if (places.size() >= 3) if (places.size() >= 3)
{
AddGems(places.get(2), 5, "3rd Place", false, false); AddGems(places.get(2), 5, "3rd Place", false, false);
}
for (Player player : GetPlayers(false)) for (Player player : GetPlayers(false))
{
if (player.isOnline()) if (player.isOnline())
{
AddGems(player, 10, "Participation", false, false); AddGems(player, 10, "Participation", false, false);
}
}
AnnounceEnd(places); AnnounceEnd(places);
SetState(GameState.End); SetState(GameState.End);
} }
} }
@ -362,22 +377,18 @@ public class DeathTag extends SoloGame
@EventHandler @EventHandler
public void ScoreboardUpdate(UpdateEvent event) public void ScoreboardUpdate(UpdateEvent event)
{ {
if (event.getType() != UpdateType.FAST) if (event.getType() != UpdateType.FAST || _runners == null || _chasers == null)
{
return; return;
}
if (_runners == null || _chasers == null)
return;
//Wipe Last
Scoreboard.reset();
Scoreboard.writeNewLine(); Scoreboard.writeNewLine();
Scoreboard.write(_runners.GetPlayers(true).size() + " " +_runners.GetColor() + " Runners"); Scoreboard.write(_runners.GetPlayers(true).size() + " " + _runners.GetColor() + " Runners");
Scoreboard.writeNewLine(); Scoreboard.writeNewLine();
Scoreboard.write(_chasers.GetPlayers(true).size() + " " +_chasers.GetColor() + " Chasers"); Scoreboard.write(_chasers.GetPlayers(true).size() + " " + _chasers.GetColor() + " Chasers");
Scoreboard.draw(); Scoreboard.draw();
} }
@ -385,12 +396,7 @@ public class DeathTag extends SoloGame
@Override @Override
public boolean CanJoinTeam(GameTeam team) public boolean CanJoinTeam(GameTeam team)
{ {
if (team.GetColor() == ChatColor.RED) return team.GetColor() != ChatColor.RED || team.GetSize() < 1 + UtilServer.getPlayers().length / 8;
{
return team.GetSize() < 1 + UtilServer.getPlayers().length/8;
}
return true;
} }
@Override @Override
@ -412,11 +418,15 @@ public class DeathTag extends SoloGame
List<Player> places = _runners.GetPlayers(true); List<Player> places = _runners.GetPlayers(true);
if (places.isEmpty() || !places.get(0).isOnline()) if (places.isEmpty() || !places.get(0).isOnline())
return Arrays.asList(); {
else return Collections.emptyList();
return Arrays.asList(places.get(0));
} }
else else
{
return Collections.singletonList(places.get(0));
}
}
return null; return null;
} }
@ -427,7 +437,7 @@ public class DeathTag extends SoloGame
{ {
return _chasers.GetPlayers(true); return _chasers.GetPlayers(true);
} }
else
return null; return null;
} }
} }