and the files

This commit is contained in:
Cheese 2015-11-20 11:50:33 +11:00
parent c4745c18b6
commit 1cc92cea1b
2 changed files with 317 additions and 0 deletions

View File

@ -0,0 +1,304 @@
package nautilus.game.arcade.game.games.monsterleague;
import java.util.HashMap;
import mineplex.core.common.util.UtilAction;
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.UtilTime;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.recharge.Recharge;
import nautilus.game.arcade.game.GameTeam;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
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 MonsterLeague _host;
private Location _ballSpawn;
private Slime _ball;
private Vector _ballVel;
private long _ballDeadTime = -1;
private HashMap<Player, BallKickLog> _kickLog = new HashMap<Player, BallKickLog>();
private HashMap<GameTeam, Player> _lastKickTeamPlayer = new HashMap<GameTeam, Player>();
private GameTeam _lastKickTeam = null;
private Player _lastKickPlayer = null;
//Ball Rebound
protected Location _lastLoc = null;
public Ball(MonsterLeague monsterLeague, Location ballSpawn)
{
_host = monsterLeague;
_ballSpawn = ballSpawn;
}
private BallKickLog getKickLog(Player player)
{
if (!_kickLog.containsKey(player))
_kickLog.put(player, new BallKickLog());
return _kickLog.get(player);
}
private void changeBallVelocity(Vector vel)
{
_ballVel = vel;
if (UtilEnt.isGrounded(_ball) && _ballVel.getY() <= 0)
_ballVel.setY(0);
_ballVel.setY(Math.min(_ballVel.getY(), 1));
//Rebound Data
_lastLoc = _ball.getLocation();
}
public void update()
{
//New Ball Needed
checkNewBallNeeded();
//Spawn Ball
spawnBallUpdate();
if (_ball == null)
return;
//Particles
displayParticles();
//Kick
kickBallUpdate();
//Movement/Rebounds/etc
ballPhysics();
//Goal
scoreGoalUpdate();
}
private void checkNewBallNeeded()
{
if (_ballDeadTime == -1 && (_ball == null || !_ball.isValid()))
{
if (_ball != null)
_ball.remove();
_ballDeadTime = System.currentTimeMillis();
}
}
private void displayParticles()
{
if (_lastKickTeam == null)
return;
if (_lastKickTeam.GetColor() == ChatColor.BLUE)
{
for (int i = 0 ; i < 3 ; i++)
UtilParticle.PlayParticle(ParticleType.RED_DUST, _ball.getLocation().add(0.0, 0.5, 0.0), -1, 1, 1, 1, 0,
ViewDist.NORMAL, UtilServer.getPlayers());
}
else if (_lastKickTeam.GetColor() == ChatColor.RED)
{
for (int i = 0 ; i < 3 ; i++)
UtilParticle.PlayParticle(ParticleType.RED_DUST, _ball.getLocation().add(0.0, 0.5, 0.0), 0, 0, 0, 0, 1,
ViewDist.NORMAL, UtilServer.getPlayers());
}
else if (_lastKickTeam.GetColor() == ChatColor.GREEN) //XXX CHANGE COLOR OF DUST
{
for (int i = 0 ; i < 3 ; i++)
UtilParticle.PlayParticle(ParticleType.RED_DUST, _ball.getLocation().add(0.0, 0.5, 0.0), 0, 0, 0, 0, 1,
ViewDist.NORMAL, UtilServer.getPlayers());
}
else if (_lastKickTeam.GetColor() == ChatColor.YELLOW) //XXX CHANGE COLOR OF DUST
{
for (int i = 0 ; i < 3 ; i++)
UtilParticle.PlayParticle(ParticleType.RED_DUST, _ball.getLocation().add(0.0, 0.5, 0.0), 0, 0, 0, 0, 1,
ViewDist.NORMAL, UtilServer.getPlayers());
}
}
private void spawnBallUpdate()
{
if (_ballDeadTime > 0 && UtilTime.elapsed(_ballDeadTime, 4000))
{
//Spawn
_host.CreatureAllowOverride = true;
_ball = _ballSpawn.getWorld().spawn(_ballSpawn, Slime.class);
_ball.setSize(2);
UtilEnt.Vegetate(_ball);
UtilEnt.ghost(_ball, true, false);
_host.CreatureAllowOverride = false;
//Set Ball to Alive
_ballDeadTime = -1;
//Velocity Downwards
changeBallVelocity(new Vector(0,-0.1,0));
//Effect
UtilFirework.playFirework(_ballSpawn, Type.BALL, Color.WHITE, true, true);
}
}
private void kickBallUpdate()
{
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))
{
//Set Ball Velocity
changeBallVelocity(player.getLocation().getDirection().add(new Vector(0, 0.4, 0)));
//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);
//Record Kick
getKickLog(player).addKick();;
//Record
_lastKickPlayer = player;
_lastKickTeam = _host.GetTeam(player);
_lastKickTeamPlayer.put(_lastKickTeam, player);
}
}
}
}
private void ballPhysics()
{
//Wind Drag
_ballVel = _ballVel.multiply(0.99);
//Ground Drag
if (UtilEnt.isGrounded(_ball))
_ballVel = _ballVel.multiply(0.98);
//Rebound Y
if (UtilEnt.isGrounded(_ball))
{
if (_ballVel.getY() < -0.1)
{
_ballVel.setY(_ballVel.getY() * -0.65);
}
}
//Gravity
if (!UtilEnt.isGrounded(_ball))
_ballVel.setY(_ballVel.getY() - 0.04);
//Rebound X
if (_ballVel.getX() > 0 && _ball.getLocation().getX() <= _lastLoc.getX() ||
_ballVel.getX() < 0 && _ball.getLocation().getX() >= _lastLoc.getX())
{
_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());
}
//Rebound Z
if (_ballVel.getZ() > 0 && _ball.getLocation().getZ() <= _lastLoc.getZ() ||
_ballVel.getZ() < 0 && _ball.getLocation().getZ() >= _lastLoc.getZ())
{
_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());
}
//Store Current Location
_lastLoc = _ball.getLocation();
//Move Ball
_ball.setVelocity(_ballVel);
}
private boolean scoreGoalUpdate()
{
for (GameTeam team : _host.GetTeamList())
{
if (!_host.getGoalRegions().containsKey(team))
continue;
if (_host.getGoalRegions().get(team).contains(_ball.getLocation().getBlock()))
{
//Score
_host.scoreGoal(team, this);
//Effect
UtilFirework.playFirework(_ball.getLocation(), Type.BALL, team.GetColorBase(), true, true);
//Clean
_ball.remove();
_ball = null;
_kickLog.clear();
_lastLoc = null;
_lastKickTeamPlayer.clear();
_lastKickTeam = null;
_lastKickPlayer = null;
return true;
}
}
return false;
}
public Player getLastKicker(GameTeam team)
{
if (_lastKickTeamPlayer.containsKey(team))
return _lastKickTeamPlayer.get(team);
return _lastKickPlayer;
}
}

View File

@ -0,0 +1,13 @@
package nautilus.game.arcade.game.games.monsterleague;
import java.util.ArrayList;
public class BallKickLog
{
ArrayList<Long> _kicks = new ArrayList<Long>();
public void addKick()
{
_kicks.add(0, System.currentTimeMillis());
}
}