From 5298fa341e17887071fa88340f9079a4a07cb8cf Mon Sep 17 00:00:00 2001 From: Mysticate Date: Sat, 8 Aug 2015 16:13:54 -0400 Subject: [PATCH] Removed the revolving thing. --- .../packethandler/PacketPlayOutCamera.java | 5 + .../game/games/evolution/Evolution.java | 73 +++++--- .../games/evolution/evolve/EvolveData.java | 170 +++++++++--------- .../games/evolution/evolve/EvolveManager.java | 25 ++- .../games/evolution/evolve/PlatformToken.java | 20 +++ .../game/games/evolution/mobs/KitCreeper.java | 1 - .../mobs/perks/PerkSulphurBombEVO.java | 2 +- 7 files changed, 172 insertions(+), 124 deletions(-) create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/evolve/PlatformToken.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/packethandler/PacketPlayOutCamera.java b/Plugins/Mineplex.Core/src/mineplex/core/packethandler/PacketPlayOutCamera.java index aaf3c94c1..11dd54051 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/packethandler/PacketPlayOutCamera.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/packethandler/PacketPlayOutCamera.java @@ -14,6 +14,11 @@ public class PacketPlayOutCamera extends Packet { } + public PacketPlayOutCamera(int id) + { + a = id; + } + public PacketPlayOutCamera(Entity paramEntity) { this.a = paramEntity.getEntityId(); 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 a151e4843..28c7315f8 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 @@ -2,16 +2,19 @@ package nautilus.game.arcade.game.games.evolution; import java.util.ArrayList; import java.util.Collections; +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.UtilMath; import mineplex.core.common.util.UtilPlayer; import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.minecraft.game.core.combat.event.CombatDeathEvent; -import mineplex.minecraft.game.core.condition.ConditionActive; import mineplex.minecraft.game.core.condition.Condition.ConditionType; +import mineplex.minecraft.game.core.condition.ConditionActive; import mineplex.minecraft.game.core.damage.CustomDamageEvent; import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.GameType; @@ -42,7 +45,7 @@ import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.util.Vector; public class Evolution extends SoloGame { @@ -52,8 +55,9 @@ public class Evolution extends SoloGame private NautHashMap _tokens = new NautHashMap(); - private ArrayList _evoPlatforms = new ArrayList(); - + //Platform location, viewing location. + private NautHashMap _evoPlatforms = new NautHashMap(); + public Evolution(ArcadeManager manager) { super(manager, GameType.Evolution, @@ -121,13 +125,37 @@ public class Evolution extends SoloGame @Override public void ParseData() { - for (Location loc : WorldData.GetDataLocs("RED")) - { - loc.getBlock().setType(Material.AIR); - _evoPlatforms.add(loc); + for (Location platform : WorldData.GetDataLocs("RED")) + { + platform.getBlock().setType(Material.AIR); + + Iterator green = WorldData.GetDataLocs("GREEN").iterator(); + while (green.hasNext()) + { + Location viewing = green.next(); + + viewing.getBlock().setType(Material.AIR); + + if (UtilMath.offset2d(platform, viewing) > 8.0) + continue; + + green.remove(); + _evoPlatforms.put(platform, loadAngle(platform, viewing)); + break; + } } } + private Location loadAngle(Location platform, Location viewing) + { + Vector b = UtilAlg.getTrajectory(viewing, platform).normalize(); + + viewing.setPitch(UtilAlg.GetPitch(b)); + viewing.setYaw(UtilAlg.GetYaw(b)); + + return viewing; + } + //Double Kit @EventHandler(priority = EventPriority.MONITOR) public void storeTokens(GameStateChangeEvent event) @@ -139,14 +167,14 @@ public class Evolution extends SoloGame { _tokens.put(player.getName(), new EvoToken(player)); - upgradeKit(player, false); + upgradeKit(player, true); } } @EventHandler(priority = EventPriority.LOWEST) public void endNoEvolve(GameStateChangeEvent event) { - if (event.GetState() != GameState.Live) + if (event.GetState() != GameState.Prepare) return; if (_evoPlatforms.size() <= 0) @@ -156,7 +184,7 @@ public class Evolution extends SoloGame return; } - _evolve = new EvolveManager(this, _evoPlatforms.get(0)); + _evolve = new EvolveManager(this, _evoPlatforms); } @EventHandler @@ -171,25 +199,13 @@ public class Evolution extends SoloGame _evolve.tick(); } - @EventHandler - public void moveEvolve(PlayerMoveEvent event) - { - if (!IsLive()) - return; - - if (!_evolve.isEvolving(event.getPlayer())) - return; - - _evolve.getEvolve(event.getPlayer()).teleport(false); - } - @Override public boolean HasKit(Player player, Kit kit) { if (GetKit(player) == null) return false; - if (GetKit(player) == (kit)) + if (GetKit(player) == kit) return true; return false; @@ -255,6 +271,9 @@ public class Evolution extends SoloGame public void startEvolve(EvolutionBeginEvent event) { Recharge.Instance.Get(event.getPlayer()).clear(); + + event.getPlayer().teleport(GetTeam(event.getPlayer()).GetSpawn()); + Manager.GetCondition().Factory().Cloak("Evolving", event.getPlayer(), null, 10, true, true); } @EventHandler @@ -270,7 +289,7 @@ public class Evolution extends SoloGame condition.GetCondition().Expire(); } } - + upgradeKit(event.getPlayer(), true); } @@ -330,9 +349,6 @@ public class Evolution extends SoloGame End(); return; } - - killer.teleport(GetTeam(killer).GetSpawn()); - Manager.GetCondition().Factory().Cloak("Evolving", killer, null, 10, true, true); } //Boolean ending @@ -397,6 +413,7 @@ public class Evolution extends SoloGame if (player.isOnline()) AddGems(player, 10, "Participation", false, false); + _evolve.end(); SetState(GameState.End); AnnounceEnd(players); } 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 adc7825a3..38760c6f8 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,10 +1,6 @@ package nautilus.game.arcade.game.games.evolution.evolve; -import java.lang.reflect.Method; - import mineplex.core.common.util.C; -import mineplex.core.common.util.UtilAction; -import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilEnt; import mineplex.core.common.util.UtilFirework; import mineplex.core.common.util.UtilParticle; @@ -18,7 +14,6 @@ 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; import nautilus.game.arcade.game.games.evolution.events.EvolutionPostEvolveEvent; -import net.minecraft.server.v1_7_R4.Entity; import net.minecraft.server.v1_7_R4.EntityBlaze; import net.minecraft.server.v1_7_R4.EntityChicken; import net.minecraft.server.v1_7_R4.EntityCreeper; @@ -40,62 +35,70 @@ import org.bukkit.Color; import org.bukkit.FireworkEffect.Type; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_7_R4.CraftWorld; -import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_7_R4.entity.CraftZombie; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.entity.Zombie; -import org.bukkit.util.Vector; public class EvolveData { + private boolean _ended = false; + private final long _timestamp = System.currentTimeMillis(); private long _endTime = System.currentTimeMillis(); private final EvolveManager _manager; + private final PlatformToken _token; private boolean _active = true; private final Player _player; private final EvoKit _to; + private String _evolveTop; private final EntityInsentient _eFrom; private EntityInsentient _eTo; - private String _evolveTop; - private Zombie _zombie; - private int _ticks = 0; - - public EvolveData(EvolveManager manager, Player player, EvoKit from, EvoKit to) + + public EvolveData(EvolveManager manager, PlatformToken token, Player player, EvoKit from, EvoKit to) { _manager = manager; + _token = token; _player = player; _to = to; _evolveTop = C.cWhite + "You evolved into " + ("aeiou".indexOf(_to.GetName().toLowerCase().substring(0, 1)) == -1 ? "a " : "an ") + C.cGreen + C.Bold + _to.GetName(); - _eFrom = spawn(from.getEntity()); - - setupZombie(); + _eFrom = spawn(from.getEntity(), token.Platform, false); + + _zombie = setupZombie(); Bukkit.getServer().getPluginManager().callEvent(new EvolutionBeginEvent(_player)); - - setupPlayer(); + + Bukkit.getScheduler().scheduleSyncDelayedTask(_manager.Host.Manager.getPlugin(), new Runnable() + { + @Override + public void run() + { + setupPlayer(); + } + }, 2); } - private void setupZombie() + private Zombie setupZombie() { _manager.Host.CreatureAllowOverride = true; - Zombie zombie = _manager.getLocation().getWorld().spawn(_manager.getLocation(), Zombie.class); + Zombie zombie = _token.Viewing.getWorld().spawn(_token.Viewing, Zombie.class); _manager.Host.CreatureAllowOverride = false; - - UtilEnt.Vegetate(zombie, true); - UtilEnt.ghost(zombie, false, true); - _zombie = zombie; + UtilEnt.Vegetate(zombie, true); + UtilEnt.ghost(zombie, true, true); + + zombie.teleport(_token.Viewing); + + return zombie; } private void setupPlayer() @@ -104,31 +107,41 @@ public class EvolveData PacketPlayOutCamera packet = new PacketPlayOutCamera(_zombie); UtilPlayer.sendPacket(_player, packet); } + + private void endPlayer() + { + //Stop spectating + PacketPlayOutCamera packet = new PacketPlayOutCamera(_player); + UtilPlayer.sendPacket(_player, packet); + } //Boolean completed public boolean tick() { - _ticks++; - teleport(false); - + //Failsafe + if (_ended) + { + return true; + } + //Hasn't ended yet if (_active) - { + { + handleAnimation(_eFrom); + //If 2 seconds past if (UtilTime.elapsed(_timestamp, 2400)) { _active = false; _endTime = System.currentTimeMillis(); - _eTo = spawn(_to.getEntity()); + _eTo = spawn(_to.getEntity(), _token.Platform, false); despawn(_eFrom); - UtilFirework.playFirework(_manager.getLocation().clone().add(0.0, 1.5, 0.0), Type.BALL, Color.GREEN, false, false); + UtilFirework.playFirework(_token.Platform.clone().add(0.0, 1.5, 0.0), Type.BALL, Color.GREEN, false, false); UtilTextMiddle.display(null, _evolveTop, _player); - - _manager.Host.SetKit(_player, _manager.Host.GetKit(_player), false); - + Bukkit.getServer().getPluginManager().callEvent(new EvolutionEndEvent(_player)); } else @@ -136,89 +149,63 @@ public class EvolveData //Play particles if (UtilTime.elapsed(_timestamp, 500)) { - UtilParticle.PlayParticle(ParticleType.FIREWORKS_SPARK, new Location(_eFrom.world.getWorld(), _eFrom.locX, _eFrom.locY + 1.0, _eFrom.locZ), 0.5F, 1.0F, 0.5F, 0, 5, ViewDist.SHORT, _player); + 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); } } return false; } else { + handleAnimation(_eTo); + if (!UtilTime.elapsed(_endTime, 2400)) return false; despawn(_eTo); - //Stop spectating - PacketPlayOutCamera packet = new PacketPlayOutCamera(_player); - UtilPlayer.sendPacket(_player, packet); + endPlayer(); _zombie.remove(); - + Bukkit.getServer().getPluginManager().callEvent(new EvolutionPostEvolveEvent(_player)); return true; } } - public void teleport(boolean teleport) - { - if (_player.getFireTicks() > 0) - _player.setFireTicks(0); - - _player.setFallDistance(0); - _player.setHealth(20.0); + //Force end. (Game ended) + public void end() + { + _active = false; - ((CraftPlayer) _player).getHandle().p(0); + if (_eFrom != null) + despawn(_eFrom); - double sizeMod = 3.5; - double speed = 15d; - double oX = -Math.sin(_ticks/speed) * 2 * sizeMod; - double oY = 3; - double oZ = Math.cos(_ticks/speed) * 2 * sizeMod; - - if (teleport) - { - _zombie.teleport(_manager.getLocation().clone().add(oX, oY, oZ)); - setupPlayer(); - } - else - { - UtilAction.velocity(_zombie, - UtilAlg.getTrajectory(_zombie.getLocation(), _manager.getLocation().clone().add(oX, oY, oZ)), - 0.4, false, 0, 0.0, 0.0, false); - } + if (_eTo != null) + despawn(_eTo); - EntityZombie eB = ((CraftZombie) _zombie).getHandle(); + endPlayer(); - Vector to = UtilAlg.getTrajectory(_zombie.getEyeLocation(), _manager.getLocation()).normalize(); + _zombie.remove(); - try - { - float pitch = UtilAlg.GetPitch(to); - float yaw = UtilAlg.GetYaw(to); - - eB.lastYaw = yaw; - eB.yaw = yaw; - - eB.lastPitch = pitch; - eB.pitch = pitch; - - Method method = Entity.class.getDeclaredMethod("b", float.class, float.class); - method.setAccessible(true); - method.invoke(eB, yaw, pitch); - method.setAccessible(false); - } - catch (Exception ex) - { - ex.printStackTrace(); - } + _ended = true; + } + + private void handleAnimation(EntityInsentient entity) + { + setupPlayer(); +// float yaw = entity.yaw; +// yaw += 2; +// +// _token.Platform.setYaw(yaw); +// entity.setLocation(_token.Platform.getX(), _token.Platform.getY(), _token.Platform.getZ(), yaw, entity.pitch); } - private EntityInsentient spawn(EntityType type) + private EntityInsentient spawn(EntityType type, Location loc, boolean invisible) { try { - EntityInsentient entity = getEntity(type).getConstructor(World.class).newInstance(((CraftWorld) _manager.getLocation().getWorld()).getHandle()); - entity.setLocation(_manager.getLocation().getX(), _manager.getLocation().getY(), _manager.getLocation().getZ(), 0.0F, 0.0F); + EntityInsentient entity = getEntity(type).getConstructor(World.class).newInstance(((CraftWorld) loc.getWorld()).getHandle()); + entity.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch()); PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(entity); entity.setCustomNameVisible(false); @@ -227,6 +214,13 @@ public class EvolveData ((EntitySlime) entity).setSize(3); } + if (invisible) + { + entity.Invisible = true; + } + + entity.ghost = true; + UtilPlayer.sendPacket(_player, packet); return entity; } 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 c015b574a..90e825240 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 @@ -1,9 +1,11 @@ package nautilus.game.arcade.game.games.evolution.evolve; +import java.util.ArrayList; import java.util.Iterator; import java.util.Map.Entry; import mineplex.core.common.util.NautHashMap; +import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; import nautilus.game.arcade.game.games.evolution.EvoKit; import nautilus.game.arcade.game.games.evolution.Evolution; @@ -15,19 +17,22 @@ public class EvolveManager { public final Evolution Host; - private final Location _evolveLoc; + private final NautHashMap _evolveLocs; private NautHashMap _data = new NautHashMap(); - public EvolveManager(Evolution evolution, Location evolveLoc) + public EvolveManager(Evolution evolution, NautHashMap evolveLocs) { Host = evolution; - _evolveLoc = evolveLoc; + _evolveLocs = evolveLocs; } - public Location getLocation() + private PlatformToken getLocation() { - return _evolveLoc; + ArrayList> locs = new ArrayList>(_evolveLocs.entrySet()); + Entry entry = locs.get(UtilMath.r(locs.size())); + + return new PlatformToken(entry.getKey(), entry.getValue()); } public boolean isEvolving(Player player) @@ -40,7 +45,7 @@ public class EvolveManager if (_data.containsKey(player.getName())) return; - _data.put(player.getName(), new EvolveData(this, player, from, to)); + _data.put(player.getName(), new EvolveData(this, getLocation(), player, from, to)); } public EvolveData getEvolve(Player player) @@ -76,4 +81,12 @@ public class EvolveManager } } } + + public void end() + { + for (EvolveData data : _data.values()) + { + data.end(); + } + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/evolve/PlatformToken.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/evolve/PlatformToken.java new file mode 100644 index 000000000..4921724a5 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/evolve/PlatformToken.java @@ -0,0 +1,20 @@ +package nautilus.game.arcade.game.games.evolution.evolve; + +import org.bukkit.Location; + +public class PlatformToken +{ + /** + * @author Mysticate + * August 8, 2015 + */ + + public final Location Platform; + public final Location Viewing; + + public PlatformToken(Location platform, Location viewing) + { + Platform = platform.clone(); + Viewing = viewing.clone(); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/mobs/KitCreeper.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/mobs/KitCreeper.java index e01a23bf9..780600f3c 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/mobs/KitCreeper.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/mobs/KitCreeper.java @@ -27,7 +27,6 @@ public class KitCreeper extends EvoKit { new PerkSulphurBombEVO() }, EntityType.CREEPER); - } @Override diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/mobs/perks/PerkSulphurBombEVO.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/mobs/perks/PerkSulphurBombEVO.java index 7bf7af344..55cd2c4aa 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/mobs/perks/PerkSulphurBombEVO.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/mobs/perks/PerkSulphurBombEVO.java @@ -50,7 +50,7 @@ public class PerkSulphurBombEVO extends Perk implements IThrown if (!UtilEvent.isAction(event, ActionType.R)) return; - if (!UtilInv.IsItem(event.getItem(), Material.DIAMOND_AXE, (byte) 0)) + if (!UtilInv.IsItem(event.getItem(), Material.IRON_AXE, (byte) 0)) return; Player player = event.getPlayer();