diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/Evolution.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/Evolution.java index 155de90d1..f7d342e49 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/Evolution.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/Evolution.java @@ -7,17 +7,21 @@ import java.util.Iterator; import mineplex.core.common.util.C; import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilEnt; import mineplex.core.common.util.UtilEvent; import mineplex.core.common.util.UtilEvent.ActionType; -import mineplex.core.common.util.UtilGear; -import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.common.util.UtilParticle.ViewDist; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTextMiddle; -import mineplex.core.itemstack.ItemBuilder; import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.minecraft.game.core.combat.CombatComponent; import mineplex.minecraft.game.core.combat.event.CombatDeathEvent; import mineplex.minecraft.game.core.condition.Condition.ConditionType; import mineplex.minecraft.game.core.condition.ConditionActive; @@ -42,15 +46,17 @@ import nautilus.game.arcade.game.games.evolution.mobs.KitSpider; import nautilus.game.arcade.game.games.evolution.mobs.KitWolf; import nautilus.game.arcade.kit.Kit; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; +import org.bukkit.block.BlockFace; import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; public class Evolution extends SoloGame @@ -70,7 +76,6 @@ public class Evolution extends SoloGame private NautHashMap _evoPlatforms = new NautHashMap(); private ArrayList _evolutionsAvailable = new ArrayList(); - private ArrayList _attemptingEvolve = new ArrayList(); public Evolution(ArcadeManager manager) { @@ -79,7 +84,8 @@ public class Evolution extends SoloGame new Kit[0], new String[] { - "You evolve when you get a kill.", + "You recieve an Evolution token every 2 kills.", + "Use it to Evolve into a new mob.", "Each evolution has unique skills.", "First to get through 10 evolutions wins!" }); @@ -182,6 +188,9 @@ public class Evolution extends SoloGame _tokens.put(player.getName(), new EvoToken(player)); upgradeKit(player, false); + + player.setLevel(0); + player.setExp(0F); } } @@ -286,21 +295,56 @@ public class Evolution extends SoloGame condition.GetCondition().Expire(); } } + + if (increaseScore(event.getPlayer()) >= 10) + { + ScoreboardUpdate(new UpdateEvent(UpdateType.FAST)); - upgradeKit(event.getPlayer(), true); - event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.LEVEL_UP, 1, 0.6F); + event.setCancelled(true); + + End(); + } + else + { + upgradeKit(event.getPlayer(), true); + event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.LEVEL_UP, 1, 0.6F); + } } @EventHandler - public void endEvolve(EvolutionPostEvolveEvent event) + public void endEvolve(final EvolutionPostEvolveEvent event) { try { Manager.GetCondition().GetActiveCondition(event.getPlayer(), ConditionType.CLOAK).Expire(); } catch (NullPointerException ex){} - - event.getPlayer().teleport(GetTeam(event.getPlayer()).GetSpawn()); + + if (getScore(event.getPlayer()) >= 10) + { + End(); + } + + Bukkit.getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugins()[0], new Runnable() + { + @Override + public void run() + { + GetKit(event.getPlayer()).ApplyKit(event.getPlayer()); + } + }, 4); + } + + @EventHandler + public void onDeath(PlayerDeathEvent event) + { + if (!IsLive()) + return; + + if (_evolutionsAvailable.contains(event.getEntity())) + { + _evolutionsAvailable.remove(event.getEntity()); + } } @EventHandler @@ -308,55 +352,55 @@ public class Evolution extends SoloGame { if (!IsLive()) return; - - if (!event.GetLog().GetKiller().IsPlayer()) - return; - - Player killer = UtilPlayer.searchExact(event.GetLog().GetKiller().GetName()); - - if (killer == null || !killer.isOnline()) + + CombatComponent damager = event.GetLog().GetKiller(); + + if (!damager.IsPlayer()) return; - if (!IsAlive(killer)) - return; - - if (killer == event.GetEvent().getEntity()) + Player player = UtilPlayer.searchExact(damager.GetName()); + + if (player == null || !player.isOnline()) return; - increaseScore(killer); - - ScoreboardUpdate(new UpdateEvent(UpdateType.FAST)); - - if (getScore(killer) >= 10) + if (!IsAlive(player)) + return; + + if (((Player) event.GetEvent().getEntity()) == player) + return; + + if (!_evolutionsAvailable.contains(player)) { - End(); + _evolutionsAvailable.add(player); + + player.setLevel(0); + player.setExp(0F); + } + } + + @EventHandler + public void onEgg(PlayerInteractEvent event) + { + if (!IsLive()) + return; + + if (!UtilEvent.isAction(event, ActionType.R_BLOCK) && !UtilEvent.isAction(event, ActionType.L_BLOCK)) + return; + + if (event.getClickedBlock().getType() == Material.DRAGON_EGG) + { + event.setCancelled(true); return; } - - _evolutionsAvailable.add(killer); -// EvoToken token = _tokens.get(killer.getName()); -// -// try -// { -// EvoKit from = _mobKits.get(token.Kills - 1); //Account for the score increase -// EvoKit to = _mobKits.get(token.Kills); -// -// _evolve.addEvolve(killer, from, to); -// } -// catch (IndexOutOfBoundsException ex) -// { -// End(); -// return; -// } } @EventHandler public void updateAvailableEvolutions(UpdateEvent event) - { - if (event.getType() != UpdateType.TICK) + { + if (!IsLive()) return; - if (!IsLive()) + if (event.getType() != UpdateType.TICK) return; Iterator iterator = _evolutionsAvailable.iterator(); @@ -367,87 +411,81 @@ public class Evolution extends SoloGame if (player == null || !player.isOnline()) { iterator.remove(); - return; + continue; } if (!IsAlive(player)) { iterator.remove(); - return; + continue; } - if (!_attemptingEvolve.contains(player)) + if (player.isSneaking()) { - UtilTextMiddle.display("", C.cGreen + C.Bold + "Evolution Available!"); - } - - if (!UtilGear.isMat(player.getInventory().getItem(7), Material.STAINED_CLAY)) - { - player.getInventory().setItem(7, new ItemBuilder(Material.STAINED_CLAY).build()); + if (onEvolveAttempting(player)) + { + iterator.remove(); + continue; + } } else { - //Rainbow effect on the clay - ItemStack item = player.getInventory().getItem(7); - byte data = UtilInv.GetData(item); + if (player.getExp() != 0F) + player.setExp(0F); - data++; + if (player.getLevel() != 0) + player.setLevel(0); - if (data > 15) - data = 0; - - item.setDurability(data); + if (Recharge.Instance.use(player, "Evolve Available", 2000, false, false)) + { + UtilTextMiddle.display("", C.cGreen + C.Bold + "Hold Shift to Evolve", 0, 60, 20, player); + } } } } - @EventHandler - public void onInteractWithEvolve(PlayerInteractEvent event) - { - if (!UtilEvent.isAction(event, ActionType.R)) - return; + //Boolean remove + @SuppressWarnings("deprecation") + private boolean onEvolveAttempting(Player player) + { + //No evolving in midair + if (!player.isOnGround() || !UtilEnt.isGrounded(player) || !UtilBlock.solid(player.getLocation().getBlock().getRelative(BlockFace.DOWN))) + return false; - if (!IsLive()) - return; - - if (event.getItem().getType() != Material.STAINED_CLAY) - return; - - //Make sure it's the 7 slot - if (event.getPlayer().getInventory().getItem(7) != event.getItem()) - return; - - if (_attemptingEvolve.contains(event.getPlayer())) - return; - - _attemptingEvolve.add(event.getPlayer()); - } - - @EventHandler - public void updateAttemptingEvolve(UpdateEvent event) - { - if (event.getType() != UpdateType.TICK) - return; - - if (!IsLive()) - return; - - Iterator iterator = _attemptingEvolve.iterator(); - while (iterator.hasNext()) + if (player.getExp() >= .9999F) { - Player player = iterator.next(); - } - `} + UtilTextMiddle.display("", "", player); + + player.setExp(0F); + player.setLevel(0); - public void increaseScore(Player player) + EvoToken token = _tokens.get(player.getName()); + + EvoKit from = _mobKits.get(token.Level); + EvoKit to = _mobKits.get((token.Level + 1) >= _mobKits.size() ? token.Level : token.Level + 1); //Account for the score increase after evolve + + _evolve.addEvolve(Manager.getHologramManager(), player, from, to); + return true; + } + + player.setExp(Math.min(player.getExp() + .008F, .9999F)); + + UtilTextMiddle.display("", UtilTextMiddle.progress(player.getExp()).trim(), player); + + UtilParticle.PlayParticle(ParticleType.PORTAL, player.getLocation().clone().add(0, 1, 0), 0.5F, 1.0F, 0.5F, 0, 5, ViewDist.NORMAL, UtilServer.getPlayers()); + return false; + } + + private int increaseScore(Player player) { if (!IsAlive(player)) - return; + return 0; if (!_tokens.containsKey(player.getName())) - return; + return 0; _tokens.get(player.getName()).Level++; + return getScore(player); } public int getScore(Player player) @@ -485,6 +523,10 @@ public class Evolution extends SoloGame if (player.isOnline()) AddGems(player, 10, "Participation", false, false); + _tokens.clear(); + _evoPlatforms.clear(); + _evolutionsAvailable.clear(); + _evolve.end(); SetState(GameState.End); AnnounceEnd(players); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/events/EvolutionEndEvent.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/events/EvolutionEndEvent.java index 8fb56f3b9..8db507389 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/events/EvolutionEndEvent.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/events/EvolutionEndEvent.java @@ -1,16 +1,19 @@ package nautilus.game.arcade.game.games.evolution.events; import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; import org.bukkit.event.player.PlayerEvent; -public class EvolutionEndEvent extends PlayerEvent +public class EvolutionEndEvent extends PlayerEvent implements Cancellable { /** * @author Mysticate */ private static HandlerList _handlers = new HandlerList(); + private boolean _cancelled = false; + public EvolutionEndEvent(Player who) { super(who); @@ -26,4 +29,16 @@ public class EvolutionEndEvent extends PlayerEvent { return getHandlerList(); } + + @Override + public boolean isCancelled() + { + return _cancelled; + } + + @Override + public void setCancelled(boolean flag) + { + _cancelled = flag; + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/evolve/EvolveData.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/evolve/EvolveData.java index 30cca9d82..1de5ea85f 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/evolve/EvolveData.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/evolve/EvolveData.java @@ -1,11 +1,21 @@ package nautilus.game.arcade.game.games.evolution.evolve; +import java.util.AbstractMap.SimpleEntry; +import java.util.HashMap; +import java.util.Map.Entry; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilAction; +import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilFirework; import mineplex.core.common.util.UtilParticle; import mineplex.core.common.util.UtilParticle.ParticleType; import mineplex.core.common.util.UtilParticle.ViewDist; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTime; +import mineplex.core.hologram.Hologram; +import mineplex.core.hologram.HologramManager; import nautilus.game.arcade.game.games.evolution.EvoKit; import nautilus.game.arcade.game.games.evolution.events.EvolutionBeginEvent; import nautilus.game.arcade.game.games.evolution.events.EvolutionEndEvent; @@ -30,6 +40,7 @@ import org.bukkit.Bukkit; import org.bukkit.Color; import org.bukkit.FireworkEffect.Type; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.craftbukkit.v1_7_R4.CraftWorld; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; @@ -45,23 +56,40 @@ public class EvolveData private final long _timestamp = System.currentTimeMillis(); private long _endTime = System.currentTimeMillis(); + private final long _preEvolve; + private final long _postEvolve; + private final PlatformToken _token; private boolean _active = true; private final Player _player; + private final Location _eggLoc; + private final SimpleEntry _eggLocData; + + private final Hologram _eggHolo; + private final EvoKit _to; private final EntityInsentient _eFrom; private EntityInsentient _eTo; - public EvolveData(PlatformToken token, Player player, EvoKit from, EvoKit to) + @SuppressWarnings("deprecation") + public EvolveData(HologramManager holo, PlatformToken token, Player player, EvoKit from, EvoKit to) { + _preEvolve = 3200; + _postEvolve = 3400; + _token = token; _player = player; + _eggLoc = player.getLocation().getBlock().getLocation(); + _eggLocData = new SimpleEntry(_eggLoc.getBlock().getType(), _eggLoc.getBlock().getData()); + + _eggHolo = new Hologram(holo, _eggLoc.clone().add(0.5, 1.0, 0.5), C.cYellow + _player.getName()).setViewDistance(20).start(); + _to = to; _eFrom = spawn(from.getEntity(), token.Platform, false); @@ -69,11 +97,24 @@ public class EvolveData Bukkit.getServer().getPluginManager().callEvent(new EvolutionBeginEvent(_player)); setupPlayer(); + setupEgg(); } + private void setupEgg() + { + _eggLoc.getBlock().setType(Material.DRAGON_EGG); + } + + @SuppressWarnings("deprecation") + private void restoreEgg() + { + _eggLoc.getBlock().setType(_eggLocData.getKey()); + _eggLoc.getBlock().setData(_eggLocData.getValue()); + } + private void setupPlayer() { - _player.teleport(_token.Viewing); + _player.teleport(_token.Viewing.clone().add(0.5, 0.0, 0.5)); } //Boolean completed @@ -86,22 +127,29 @@ public class EvolveData } teleport(); +// updateHologram(); //Hasn't ended yet if (_active) - { + { //If 3 seconds past - if (UtilTime.elapsed(_timestamp, 3200)) + if (UtilTime.elapsed(_timestamp, _preEvolve)) { _active = false; _endTime = System.currentTimeMillis(); + EvolutionEndEvent event = new EvolutionEndEvent(_player); + Bukkit.getServer().getPluginManager().callEvent(event); + + if (event.isCancelled()) + { + return true; + } + _eTo = spawn(_to.getEntity(), _token.Platform, false); despawn(_eFrom); - UtilFirework.playFirework(_token.Platform.clone().add(0.0, 1.5, 0.0), Type.BALL, Color.GREEN, false, false); - - Bukkit.getServer().getPluginManager().callEvent(new EvolutionEndEvent(_player)); + UtilFirework.playFirework(_token.Platform.clone().add(0.0, 1.5, 0.0), Type.BALL, Color.GREEN, false, false); } else { @@ -109,18 +157,33 @@ public class EvolveData if (UtilTime.elapsed(_timestamp, 500)) { UtilParticle.PlayParticle(ParticleType.FIREWORKS_SPARK, _token.Platform.clone().add(0.0, 1.0, 0.0), 0.5F, 1.0F, 0.5F, 0, 5, ViewDist.SHORT, _player); + UtilParticle.PlayParticle(ParticleType.PORTAL, _eggLoc, 0.5F, 1.0F, 0.5F, 0, 5, ViewDist.NORMAL, UtilServer.getPlayers()); } } return false; } else { - if (!UtilTime.elapsed(_endTime, 3000)) + if (!UtilTime.elapsed(_endTime, _postEvolve)) return false; despawn(_eTo); + _eggHolo.stop(); - Bukkit.getServer().getPluginManager().callEvent(new EvolutionPostEvolveEvent(_player)); + restoreEgg(); + _player.teleport(_eggLoc); + + UtilParticle.PlayParticle(ParticleType.LARGE_EXPLODE, _eggLoc.clone().add(0.0, 1.0, 0.0), 2.0F, 2.0F, 2.0F, 0, 8, ViewDist.NORMAL, UtilServer.getPlayers()); + knockback(); + + Bukkit.getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugins()[0], new Runnable() + { + @Override + public void run() + { + Bukkit.getServer().getPluginManager().callEvent(new EvolutionPostEvolveEvent(_player)); + } + }, 4); return true; } } @@ -136,6 +199,10 @@ public class EvolveData if (_eTo != null) despawn(_eTo); + _eggHolo.stop(); + restoreEgg(); + + _player.teleport(_eggLoc.clone().add(0.5, 0.0, 0.5)); _ended = true; } @@ -144,6 +211,19 @@ public class EvolveData setupPlayer(); } + private void knockback() + { + HashMap radius = UtilPlayer.getInRadius(_eggLoc, 8.0); + + for (Entry entry : radius.entrySet()) + { + if (entry.getKey() == _player) + continue; + + UtilAction.velocity(entry.getKey(), UtilAlg.getTrajectory2d(_eggLoc, entry.getKey().getLocation()), 1.6 - (entry.getValue() / 10), true, 0.8, 0, 10, true); + } + } + private EntityInsentient spawn(EntityType type, Location loc, boolean invisible) { try diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/evolve/EvolveManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/evolve/EvolveManager.java index f7bf4613f..17a2cd113 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/evolve/EvolveManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/evolve/EvolveManager.java @@ -7,6 +7,7 @@ import java.util.Map.Entry; import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.hologram.HologramManager; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.minecraft.game.core.damage.CustomDamageEvent; @@ -58,12 +59,12 @@ public class EvolveManager implements Listener return _data.containsKey(player.getName()); } - public void addEvolve(Player player, EvoKit from, EvoKit to) + public void addEvolve(HologramManager holo, Player player, EvoKit from, EvoKit to) { if (_data.containsKey(player.getName())) return; - _data.put(player.getName(), new EvolveData(getLocation(), player, from, to)); + _data.put(player.getName(), new EvolveData(holo, getLocation(), player, from, to)); } public EvolveData getEvolve(Player player)