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