From 76da92f42e93d26109e733c41bd79a7b55e60014 Mon Sep 17 00:00:00 2001 From: Sam Date: Sun, 24 Jul 2016 21:27:31 +0100 Subject: [PATCH] QuiverPayload added Basic implementation added --- .../src/mineplex/core/game/GameDisplay.java | 2 + .../src/nautilus/game/arcade/GameType.java | 2 + .../game/games/quiver/QuiverPayload.java | 205 ++++++++++++++++++ 3 files changed, 209 insertions(+) create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/quiver/QuiverPayload.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/game/GameDisplay.java b/Plugins/Mineplex.Core/src/mineplex/core/game/GameDisplay.java index 5bc78f8a3..8d9839580 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/game/GameDisplay.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/game/GameDisplay.java @@ -80,6 +80,8 @@ public enum GameDisplay SpeedBuilders("Speed Builders", Material.QUARTZ_BLOCK, (byte) 0, GameCategory.CLASSICS, 60), Valentines("Valentines Vendetta", Material.LEATHER, (byte)0, GameCategory.EXTRA, 61), + + QuiverPayload("One in the Quiver Payload", Material.ARROW, (byte)0, GameCategory.ARCADE, 62), Event("Mineplex Event", Material.CAKE, (byte)0, GameCategory.EVENT, 999), diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java index 5984b025c..e40ce7870 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java @@ -59,6 +59,7 @@ import nautilus.game.arcade.game.games.monstermaze.MonsterMaze; import nautilus.game.arcade.game.games.oldmineware.OldMineWare; import nautilus.game.arcade.game.games.paintball.Paintball; import nautilus.game.arcade.game.games.quiver.Quiver; +import nautilus.game.arcade.game.games.quiver.QuiverPayload; import nautilus.game.arcade.game.games.quiver.QuiverTeams; import nautilus.game.arcade.game.games.quiver.modes.BunnyHop ; import nautilus.game.arcade.game.games.rings.ElytraRings; @@ -154,6 +155,7 @@ public enum GameType OldMineWare(OldMineWare.class, GameDisplay.OldMineWare), Paintball(Paintball.class, GameDisplay.Paintball), Quiver(Quiver.class, GameDisplay.Quiver), + QuiverPayload(QuiverPayload.class, GameDisplay.QuiverPayload), QuiverTeams(QuiverTeams.class, GameDisplay.QuiverTeams), Runner(Runner.class, GameDisplay.Runner), SearchAndDestroy(SearchAndDestroy.class, GameDisplay.SearchAndDestroy), diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/quiver/QuiverPayload.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/quiver/QuiverPayload.java new file mode 100644 index 000000000..cd9a04b6f --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/quiver/QuiverPayload.java @@ -0,0 +1,205 @@ +package nautilus.game.arcade.game.games.quiver; + +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Minecart; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.vehicle.VehicleDamageEvent; +import org.bukkit.event.vehicle.VehicleEnterEvent; +import org.bukkit.event.vehicle.VehicleEntityCollisionEvent; +import org.bukkit.material.MaterialData; +import org.bukkit.util.Vector; + +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.hologram.Hologram; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.GameType; +import nautilus.game.arcade.events.GameStateChangeEvent; +import nautilus.game.arcade.game.GameTeam; +import nautilus.game.arcade.game.TeamGame; +import nautilus.game.arcade.game.games.quiver.kits.KitBarrage; +import nautilus.game.arcade.game.games.quiver.kits.KitBeserker; +import nautilus.game.arcade.game.games.quiver.kits.KitHeadHunter; +import nautilus.game.arcade.game.games.quiver.kits.KitNecromancer; +import nautilus.game.arcade.game.games.quiver.kits.KitNewNinja; +import nautilus.game.arcade.game.games.quiver.kits.KitPyromancer; +import nautilus.game.arcade.kit.Kit; + +public class QuiverPayload extends TeamGame +{ + + private static final double PAYLOAD_CAPTURE_RANGE = 3; + + private Minecart _minecart; + private Hologram _hologram; + private GameTeam _teamDirection; + private Vector _lastDirection; + + public QuiverPayload(ArcadeManager manager) + { + super(manager, GameType.QuiverPayload, new Kit[] { + + new KitBeserker(manager), + new KitNewNinja(manager), + new KitBarrage(manager), + new KitHeadHunter(manager), + new KitPyromancer(manager), + new KitNecromancer(manager), + + }, new String[] { + "Testing Description", + }); + + this.DeathOut = false; + this.DamageTeamSelf = true; + this.TeamArmorHotbar = true; + this.HungerSet = 20; + } + + @Override + @EventHandler + public void ScoreboardUpdate(UpdateEvent event) + { + if (event.getType() != UpdateType.FAST) + { + return; + } + + if (GetTeamList().isEmpty()) + { + return; + } + + Scoreboard.Reset(); + + if (_teamDirection != null) + { + Scoreboard.Write(_teamDirection.getDisplayName()); + } + else + { + Scoreboard.Write("None"); + } + + Scoreboard.Draw(); + } + @EventHandler + public void onGameStateChange(GameStateChangeEvent event) + { + if (event.GetState() == GameState.Live) + { + Location location = WorldData.GetDataLocs("BLACK").get(0); + _minecart = location.getWorld().spawn(location, Minecart.class); + _hologram = new Hologram(Manager.getHologramManager(), location, "None"); + + _minecart.setDisplayBlock(new MaterialData(Material.TNT)); + _hologram.setFollowEntity(_minecart); + } + } + + @EventHandler + public void onUpdate(UpdateEvent event) + { + if (event.getType() != UpdateType.FAST || _minecart == null) + { + return; + } + + Map mostPlayers = new HashMap<>(); + + for (GameTeam gameTeam : GetTeamList()) + { + mostPlayers.put(gameTeam, 0); + } + + for (Player player : UtilPlayer.getNearby(_minecart.getLocation(), PAYLOAD_CAPTURE_RANGE)) + { + GameTeam gameTeam = GetTeam(player); + + mostPlayers.put(gameTeam, mostPlayers.get(gameTeam) + 1); + } + + int mostPlayersCount = 0; + + for (GameTeam gameTeam : mostPlayers.keySet()) + { + int playerCount = mostPlayers.get(gameTeam); + + if (playerCount > mostPlayersCount) + { + _teamDirection = gameTeam; + } + else if (playerCount == mostPlayersCount) + { + _teamDirection = null; + } + } + + //TODO DO NOT HARDCODE + + if (_teamDirection == null) + { + return; + } + + if (_teamDirection.equals(GetTeamList().get(0))) + { + if (_lastDirection == null) + { + _minecart.setVelocity(new Vector(-0.1, 0, 0)); + } + else + { + _minecart.setVelocity(_minecart.getVelocity().normalize().multiply(0.1)); + } + } + else + { + if (_lastDirection == null) + { + _minecart.setVelocity(new Vector(0.1, 0, 0)); + _lastDirection = _minecart.getVelocity(); + } + else + { + _minecart.setVelocity(_minecart.getVelocity().normalize().multiply(0.1)); + _lastDirection = _minecart.getVelocity(); + } + } + } + + @EventHandler + public void onVehicleEntityCollision(VehicleEntityCollisionEvent event) + { + if (event.getVehicle() instanceof Minecart) + { + event.setCollisionCancelled(true); + event.setCancelled(true); + } + } + + @EventHandler + public void onVehicleDamage(VehicleDamageEvent event) + { + if (event.getVehicle() instanceof Minecart) + { + event.setCancelled(true); + } + } + + @EventHandler + public void onVehicleEnter(VehicleEnterEvent event) + { + if (event.getVehicle() instanceof Minecart) + { + event.setCancelled(true); + } + } + +}