diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bouncyballs/Ball.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bouncyballs/Ball.java new file mode 100644 index 000000000..c8ab8f459 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bouncyballs/Ball.java @@ -0,0 +1,285 @@ +package nautilus.game.arcade.game.games.bouncyballs; + +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.UtilMath; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.common.util.UtilParticle.ViewDist; +import mineplex.core.recharge.Recharge; + +import org.bukkit.Color; +import org.bukkit.EntityEffect; +import org.bukkit.Location; +import org.bukkit.Sound; +import org.bukkit.FireworkEffect.Type; +import org.bukkit.entity.Player; +import org.bukkit.entity.Slime; +import org.bukkit.util.Vector; + + +public class Ball +{ + private BouncyBalls _host; + + private Location _ballSpawn; + + private Slime _ball; + private Vector _ballVel; + + //Particle + protected Location _lastParticle = null; + + //Ball Rebound + protected boolean _ignoreReboundForTick = false; + protected Location _lastLoc = null; + + protected int _reboundX = 0; + protected int _reboundY = 0; + protected int _reboundZ = 0; + + public Ball(BouncyBalls monsterLeague, Location ballSpawn) + { + _host = monsterLeague; + + _ballSpawn = ballSpawn; + } + + private void changeBallVelocity(Vector vel, boolean canGoNegativeY) + { + _ballVel = vel; + + if (!canGoNegativeY && UtilEnt.isGrounded(_ball) && _ballVel.getY() <= 0) + _ballVel.setY(0); + + _ballVel.setY(Math.min(_ballVel.getY(), 1)); + + //Rebound Data + _lastLoc = _ball.getLocation(); + } + + public void update() + { + //Spawn Ball + spawnBallUpdate(); + + if (_ball == null) + return; + + //Particles + displayParticles(); + + //Kick + hitPlayerUpdate(); + + //Movement/Rebounds/etc + ballPhysics(); + + if (_ballVel.length() < 0.2) + changeBallVelocity(new Vector( + (Math.random() - 0.5) * 2, + (Math.random() - 0.5) * 2, + (Math.random() - 0.5) * 2), true); + } + + private void displayParticles() + { + while (UtilMath.offset(_ball.getLocation().add(0, 0.5, 0), _lastParticle) > 0.15) + { + _lastParticle.add(UtilAlg.getTrajectory(_lastParticle, _ball.getLocation().add(0,0.5,0)).multiply(0.15)); + +// UtilParticle.PlayParticle(ParticleType.HAPPY_VILLAGER, _lastParticle, -1, 1, 1, 1, 0, +// ViewDist.MAX, UtilServer.getPlayers()); + } + } + + private void spawnBallUpdate() + { + if (_ball == null || !_ball.isValid()) + { + if (_ball != null) + _ball.remove(); + + //Spawn + _host.CreatureAllowOverride = true; + _ball = _ballSpawn.getWorld().spawn(_ballSpawn, Slime.class); + _ball.setSize(2); + + UtilEnt.Vegetate(_ball); + UtilEnt.ghost(_ball, false, false); + _host.CreatureAllowOverride = false; + + _lastParticle = _ball.getLocation(); + + //Random Velocity Downwards + changeBallVelocity(new Vector( + (Math.random() - 0.5) * 2, + (Math.random() - 0.5) * 2, + (Math.random() - 0.5) * 2), true); + + //Effect + UtilFirework.playFirework(_ballSpawn, Type.BALL, Color.WHITE, true, true); + } + } + + private void hitPlayerUpdate() + { + for (Player player : _host.GetPlayers(true)) + { + if (UtilMath.offset(player, _ball) < 1.5 || + UtilMath.offset(player.getEyeLocation(), _ball.getLocation()) < 1.25) + { + if (Recharge.Instance.use(player, "Football Kick", 600, false, false)) + { + //Damage + if (Recharge.Instance.use(player, "Hit by " + _ball.getEntityId(), 1000, false, false)) + { + player.damage(5); + UtilAction.velocity(player, _ballVel, 1, true, 0.4, Math.max(0, _ballVel.getY()), 10, true); + } + else + { + continue; + } + + //Set Ball Velocity + changeBallVelocity(_ballVel.multiply(-1), true); + + //Sound + _ball.getWorld().playSound(_ball.getLocation(), Sound.ZOMBIE_WOOD, 0.5f, 1.5f); + + //Effect + UtilParticle.PlayParticle(ParticleType.SLIME, + _ball.getLocation(), + 0, 0, 0, 0, 5, ViewDist.NORMAL, UtilServer.getPlayers()); + + //Flash Ball + _ball.playEffect(EntityEffect.HURT); + + //Zero Player Vel + UtilAction.zeroVelocity(player); + + //Ignore Rebound + _ignoreReboundForTick = true; + + + + + return; + } + } + } + } + + private void ballPhysics() + { + //Wind Drag +// _ballVel = _ballVel.multiply(0.99); + + //Ground Drag +// if (UtilEnt.isGrounded(_ball)) +// _ballVel = _ballVel.multiply(0.97); + + if (!_ignoreReboundForTick) + { + double lenience = 0.1; + + //Rebound Y + if (_ballVel.getY() > 0.15 && _ball.getLocation().getY() <= _lastLoc.getY() || + _ballVel.getY() < -lenience && _ball.getLocation().getY() >= _lastLoc.getY()) + { + _reboundY++; + + if (_reboundY > 1) + { + _ballVel.setY(_ballVel.getY() * -1); + +// _ballVel = _ballVel.multiply(_ballVel.getY() > 0 ? 0.9 : 0.75); //Lose extra when bouncing on ground. + + //Sound + _ball.getWorld().playSound(_ball.getLocation(), Sound.ZOMBIE_WOOD, 0.5f, 1.5f); + + //Effect + UtilParticle.PlayParticle(ParticleType.LARGE_EXPLODE, _ball.getLocation(), 0, 0, 0, 0, 1, ViewDist.NORMAL, UtilServer.getPlayers()); + + _reboundY = 0; + } + } + else + { + _reboundY = 0; + } + + + if (UtilEnt.isGrounded(_ball)) + { + //lenience = 0.1; + } + + //Rebound X + if (_ballVel.getX() > lenience && _ball.getLocation().getX() <= _lastLoc.getX() || + _ballVel.getX() < -lenience && _ball.getLocation().getX() >= _lastLoc.getX()) + { + _reboundX++; + + if (_reboundX > 1) + { + _ballVel.setX(_ballVel.getX() * -1); +// _ballVel = _ballVel.multiply(0.9); + + //Sound + _ball.getWorld().playSound(_ball.getLocation(), Sound.ZOMBIE_WOOD, 0.5f, 1.5f); + + //Effect + UtilParticle.PlayParticle(ParticleType.LARGE_EXPLODE, _ball.getLocation(), 0, 0, 0, 0, 1, ViewDist.NORMAL, UtilServer.getPlayers()); + + _reboundX = 0; + } + } + else + { + _reboundX = 0; + } + + //Rebound Z + if (_ballVel.getZ() > lenience && _ball.getLocation().getZ() <= _lastLoc.getZ() || + _ballVel.getZ() < -lenience && _ball.getLocation().getZ() >= _lastLoc.getZ()) + { + _reboundZ++; + + if (_reboundZ > 1) + { + _ballVel.setZ(_ballVel.getZ() * -1); +// _ballVel = _ballVel.multiply(0.9); + + //Sound + _ball.getWorld().playSound(_ball.getLocation(), Sound.ZOMBIE_WOOD, 0.5f, 1.5f); + + //Effect + UtilParticle.PlayParticle(ParticleType.LARGE_EXPLODE, _ball.getLocation(), 0, 0, 0, 0, 1, ViewDist.NORMAL, UtilServer.getPlayers()); + + _reboundZ = 0; + } + } + else + { + _reboundZ = 0; + } + } + + //Gravity + if (!UtilEnt.isGrounded(_ball)) + _ballVel.setY(_ballVel.getY() - 0.04); + + //Store Current Location + _lastLoc = _ball.getLocation(); + + _ignoreReboundForTick = false; + + //Move Ball + _ball.setVelocity(_ballVel); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bouncyballs/BouncyBalls.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bouncyballs/BouncyBalls.java new file mode 100644 index 000000000..bfd3cc0a1 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bouncyballs/BouncyBalls.java @@ -0,0 +1,67 @@ +package nautilus.game.arcade.game.games.bouncyballs; + +import java.util.ArrayList; + +import org.bukkit.entity.Arrow; +import org.bukkit.entity.Slime; +import org.bukkit.event.EventHandler; + +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.minecraft.game.core.damage.CustomDamageEvent; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.GameType; +import nautilus.game.arcade.game.SoloGame; +import nautilus.game.arcade.game.games.bouncyballs.kits.*; +import nautilus.game.arcade.game.games.bouncyballs.Ball; +import nautilus.game.arcade.kit.Kit; + +public class BouncyBalls extends SoloGame +{ + private ArrayList _balls = new ArrayList(); + + public BouncyBalls(ArcadeManager manager) + { + super(manager, GameType.BouncyBalls, + + new Kit[] + { + new KitPlayer(manager), + }, + + new String[] + { + "BOUNCE" + }); + + this.HungerSet = 20; + } + + @EventHandler + public void ballUpdate(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK) + return; + + if(GetState() != GameState.Live) + return; + + int ballCount = 10; + ballCount += (System.currentTimeMillis() - getGameLiveTime()) / 5000; + + if (_balls.size() < ballCount) + _balls.add(new Ball(this, WorldData.GetDataLocs("BLUE").get(0))); + + for (Ball ball : _balls) + ball.update(); + } + + @EventHandler + public void arrowDeflect(CustomDamageEvent event) + { + if (!(event.GetDamageeEntity() instanceof Slime)) + return; + + event.SetCancelled("NO DAMAGE"); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bouncyballs/kits/KitPlayer.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bouncyballs/kits/KitPlayer.java new file mode 100644 index 000000000..dc752c593 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bouncyballs/kits/KitPlayer.java @@ -0,0 +1,46 @@ +package nautilus.game.arcade.game.games.bouncyballs.kits; + +import org.bukkit.Material; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.itemstack.ItemStackFactory; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.kit.Kit; +import nautilus.game.arcade.kit.KitAvailability; +import nautilus.game.arcade.kit.Perk; +import nautilus.game.arcade.kit.perks.PerkFletcher; +import nautilus.game.arcade.kit.perks.PerkRopedArrow; + +public class KitPlayer extends Kit +{ + public KitPlayer(ArcadeManager manager) + { + super(manager, "hello", KitAvailability.Gem, + new String[] + { + "hi" + }, + new Perk[] + { + + }, + EntityType.PLAYER, + new ItemStack(Material.BOW)); + + } + + @Override + public void GiveItems(Player player) + { + + } + + @Override + public void SpawnCustom(LivingEntity ent) + { + + } +}