Woo almost done!
This commit is contained in:
parent
d598f83ec0
commit
7bdbd5a6af
@ -2,12 +2,19 @@ package nautilus.game.arcade.game.games.gladiators;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.UtilAlg;
|
||||
import mineplex.core.common.util.UtilTextBottom;
|
||||
import mineplex.core.common.util.UtilTextMiddle;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
|
||||
/**
|
||||
* Created by William (WilliamTiger).
|
||||
@ -31,6 +38,9 @@ public class Arena
|
||||
private ArrayList<Player> _pastPlayers;
|
||||
|
||||
private ArenaState _state;
|
||||
private long _stateTime;
|
||||
|
||||
private HashMap<Player, ArrayList<ParticleData>> _particles;
|
||||
|
||||
public Arena(Gladiators host, Location mid, ArenaType colour)
|
||||
{
|
||||
@ -44,6 +54,8 @@ public class Arena
|
||||
_isOpenDoor = false;
|
||||
_pastPlayers = new ArrayList<>();
|
||||
_state = ArenaState.EMPTY;
|
||||
_stateTime = System.currentTimeMillis();
|
||||
_particles = new HashMap<>();
|
||||
|
||||
setupSpawns();
|
||||
}
|
||||
@ -53,6 +65,16 @@ public class Arena
|
||||
return _parent;
|
||||
}
|
||||
|
||||
public long getStateTime()
|
||||
{
|
||||
return _stateTime;
|
||||
}
|
||||
|
||||
public void setStateTime(long stateTime)
|
||||
{
|
||||
_stateTime = stateTime;
|
||||
}
|
||||
|
||||
public void setParent(Arena parent)
|
||||
{
|
||||
_parent = parent;
|
||||
@ -230,4 +252,97 @@ public class Arena
|
||||
|
||||
}, 5L);
|
||||
}
|
||||
|
||||
public void update()
|
||||
{
|
||||
if (getPastPlayers().size() <= 0)
|
||||
_state = ArenaState.EMPTY;
|
||||
|
||||
if (_state.equals(ArenaState.EMPTY))
|
||||
return;
|
||||
|
||||
if (_state.equals(ArenaState.WAITING))
|
||||
{
|
||||
for (Player p : getPastPlayers())
|
||||
{
|
||||
UtilTextMiddle.display(C.cAqua + "Please Wait", "The next round will start shortly", 0, 20, 0, p);
|
||||
}
|
||||
}
|
||||
else if (_state.equals(ArenaState.FIGHTING))
|
||||
{
|
||||
if (!UtilTime.elapsed(_stateTime, 60000))
|
||||
return; // 60 seconds before poison
|
||||
|
||||
for (Player p : getPastPlayers())
|
||||
{
|
||||
UtilTextBottom.display(C.cRed + C.Bold + "YOU ARE POISONED! KEEP FIGHTING!", p);
|
||||
_host.Manager.GetDamage().NewDamageEvent(p, null, null, EntityDamageEvent.DamageCause.CUSTOM, 1D, false, true, true, "Health Loss", "Health Loss");
|
||||
}
|
||||
}
|
||||
else if (_state.equals(ArenaState.RUNNING))
|
||||
{
|
||||
for (Player p : getPastPlayers())
|
||||
{
|
||||
UtilTextMiddle.display(C.cGreen + "Next Battle", "Follow the particles", 0, 20, 0, p);
|
||||
}
|
||||
|
||||
if (UtilTime.elapsed(_stateTime, 15000))
|
||||
handleSlowMovers();
|
||||
}
|
||||
}
|
||||
|
||||
public void updateTick()
|
||||
{
|
||||
if (_state.equals(ArenaState.RUNNING))
|
||||
{
|
||||
getPastPlayers().stream().forEach(this::showParticles);
|
||||
}
|
||||
}
|
||||
|
||||
private void showParticles(Player p)
|
||||
{
|
||||
if (!getPastPlayers().contains(p) || !_state.equals(ArenaState.RUNNING))
|
||||
{
|
||||
_particles.remove(p);
|
||||
return;
|
||||
}
|
||||
|
||||
//New Trails
|
||||
if (Recharge.Instance.use(p, "Particle Trail", 3000, false, false))
|
||||
{
|
||||
if (!_particles.containsKey(p))
|
||||
_particles.put(p, new ArrayList<ParticleData>());
|
||||
|
||||
Location end = UtilAlg.findClosest(_mid, _host.WorldData.GetDataLocs("PINK"));
|
||||
|
||||
_particles.get(p).add(new ParticleData(p, end));
|
||||
}
|
||||
|
||||
//Old Trails
|
||||
if (_particles.containsKey(p) && !_particles.get(p).isEmpty())
|
||||
{
|
||||
Iterator<ParticleData> trailIter = _particles.get(p).iterator();
|
||||
|
||||
while (trailIter.hasNext())
|
||||
{
|
||||
ParticleData data = trailIter.next();
|
||||
|
||||
//Returns true if its hit the endpoint
|
||||
if (data.update())
|
||||
trailIter.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleSlowMovers()
|
||||
{
|
||||
Arena next = _host.getArenaByMid(UtilAlg.findClosest(_mid, _host.getAllArenaMidsOfType(_host.getNextColour(_colour))));
|
||||
|
||||
for (Player p : getPastPlayers())
|
||||
{
|
||||
//Teleport after 15 seconds of waiting.
|
||||
|
||||
p.teleport(UtilAlg.getLocationAwayFromPlayers(next.getSpawns(), _host.GetPlayers(true)).clone());
|
||||
}
|
||||
}
|
||||
}
|
@ -10,6 +10,7 @@ import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
@ -424,47 +425,131 @@ public class Gladiators extends SoloGame
|
||||
|
||||
a.openDoor();
|
||||
a.getPastPlayers().get(0).sendMessage("§7§lDEBUG: §3Door has been opened in your arena.");
|
||||
a.setState(ArenaState.RUNNING);
|
||||
a.setStateTime(System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void updateRound(UpdateEvent e)
|
||||
{
|
||||
if (e.getType() != UpdateType.TICK)
|
||||
return;
|
||||
|
||||
boolean allWaiting = true;
|
||||
|
||||
for (Arena a : _gameArenaSet)
|
||||
{
|
||||
if (a.getState() != ArenaState.WAITING)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void alert(UpdateEvent e)
|
||||
public void arenaUpdateTick(UpdateEvent e)
|
||||
{
|
||||
if (e.getType() != UpdateType.SEC)
|
||||
return;
|
||||
|
||||
for (Arena a : _gameArenaSet)
|
||||
a.updateTick();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void arenaUpdate(UpdateEvent e)
|
||||
{
|
||||
if (e.getType() != UpdateType.SEC)
|
||||
return;
|
||||
|
||||
for (Arena a : _gameArenaSet)
|
||||
a.update();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void damageCancel(EntityDamageEvent e)
|
||||
{
|
||||
if (!(e.getEntity() instanceof Player))
|
||||
return;
|
||||
|
||||
Player p = (Player) e.getEntity();
|
||||
|
||||
if (!_playerArenas.containsKey(p))
|
||||
return;
|
||||
|
||||
if (_playerArenas.get(p).getState() != ArenaState.FIGHTING)
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void startCountdown(UpdateEvent e)
|
||||
{
|
||||
if (e.getType() != UpdateType.SEC)
|
||||
return;
|
||||
|
||||
if (_roundState.equals(RoundState.FIGHTING))
|
||||
return;
|
||||
|
||||
if (_roundState.equals(RoundState.STARTING_5))
|
||||
{
|
||||
if (a.getState().equals(ArenaState.WAITING))
|
||||
_roundState = RoundState.STARTING_4;
|
||||
return;
|
||||
}
|
||||
else if (_roundState.equals(RoundState.STARTING_4))
|
||||
{
|
||||
_roundState = RoundState.STARTING_3;
|
||||
return;
|
||||
}
|
||||
else if (_roundState.equals(RoundState.STARTING_3))
|
||||
{
|
||||
_roundState = RoundState.STARTING_2;
|
||||
UtilTextMiddle.display(C.cGreen + "3", C.cGreen + C.Bold + getRoundNotation(), 0, 80, 0);
|
||||
return;
|
||||
}
|
||||
else if (_roundState.equals(RoundState.STARTING_2))
|
||||
{
|
||||
_roundState = RoundState.STARTING_1;
|
||||
UtilTextMiddle.display(C.cYellow + "2", C.cGreen + C.Bold + getRoundNotation(), 0, 80, 0);
|
||||
return;
|
||||
}
|
||||
else if (_roundState.equals(RoundState.STARTING_1))
|
||||
{
|
||||
_roundState = RoundState.STARTED;
|
||||
UtilTextMiddle.display(C.cGold + "1", C.cGreen + C.Bold + getRoundNotation(), 0, 80, 0);
|
||||
return;
|
||||
}
|
||||
else if (_roundState.equals(RoundState.STARTED))
|
||||
{
|
||||
_roundState = RoundState.FIGHTING;
|
||||
UtilTextMiddle.display(C.cRed + "FIGHT", C.cGreen + C.Bold + getRoundNotation(), 0, 80, 0);
|
||||
for (Arena a : _gameArenaSet)
|
||||
{
|
||||
for (Player p : a.getPastPlayers())
|
||||
UtilTextMiddle.display("", C.cRed + "Wait for the round to begin", 0, 60 , 0, p);
|
||||
}
|
||||
else if (a.getState().equals(ArenaState.FIGHTING))
|
||||
{
|
||||
//TODO: poison etc, round end times
|
||||
}
|
||||
else if (a.getState().equals(ArenaState.RUNNING))
|
||||
{
|
||||
//TODO: particles
|
||||
UtilTextMiddle.display(C.cGreen + "Next Battle", "Follow the particle trail", 0, 60, 0, a.getPastPlayers().get(0));
|
||||
if (a.getState().equals(ArenaState.WAITING))
|
||||
{
|
||||
a.setState(ArenaState.FIGHTING);
|
||||
a.setStateTime(System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void roundUpdate(UpdateEvent e)
|
||||
{
|
||||
if (e.getType() != UpdateType.TICK)
|
||||
return;
|
||||
|
||||
if (_roundState.equals(RoundState.FIGHTING))
|
||||
{
|
||||
for (Arena a : _gameArenaSet)
|
||||
if (a.getState() != ArenaState.WAITING)
|
||||
return;
|
||||
|
||||
//All of the arenas are waiting for the next fight.
|
||||
_roundState = RoundState.STARTING_5;
|
||||
|
||||
UtilTextMiddle.display("", C.cGreen + C.Bold + getRoundNotation(), 0, 80 , 0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private String getRoundNotation()
|
||||
{
|
||||
int size = GetPlayers(true).size();
|
||||
|
||||
if (size == 2)
|
||||
return "FINALS";
|
||||
else if (size == 4)
|
||||
return "SEMI-FINALS";
|
||||
else if (size == 8)
|
||||
return "QUARTER-FINALS";
|
||||
else return "ROUND OF " + size;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,56 @@
|
||||
package nautilus.game.arcade.game.games.gladiators;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import mineplex.core.common.util.UtilAlg;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilParticle;
|
||||
|
||||
/**
|
||||
* Created by William (WilliamTiger).
|
||||
* 08/12/15
|
||||
*/
|
||||
public class ParticleData
|
||||
{
|
||||
public Player Player;
|
||||
public Location CurrentLocation;
|
||||
public Vector Velocity;
|
||||
public Location Target;
|
||||
|
||||
public ParticleData(Player player, Location target)
|
||||
{
|
||||
Player = player;
|
||||
|
||||
Velocity = player.getLocation().getDirection();
|
||||
if (Velocity.getY() < 0)
|
||||
Velocity.setY(0);
|
||||
Velocity.normalize();
|
||||
|
||||
CurrentLocation = player.getLocation().add(0, 1, 0);
|
||||
Target = target;
|
||||
}
|
||||
|
||||
public boolean update()
|
||||
{
|
||||
//Turn
|
||||
Velocity.add(UtilAlg.getTrajectory(CurrentLocation, Target).multiply(0.15));
|
||||
|
||||
//Normalize Speed
|
||||
UtilAlg.Normalize(Velocity);
|
||||
|
||||
//Move
|
||||
CurrentLocation.add(Velocity.clone().multiply(0.5));
|
||||
|
||||
//Particle
|
||||
UtilParticle.PlayParticle(UtilParticle.ParticleType.HAPPY_VILLAGER, CurrentLocation, 0.03f, 0.03f, 0.03f, 0, 3,
|
||||
UtilParticle.ViewDist.LONG, Player);
|
||||
|
||||
//Sound
|
||||
CurrentLocation.getWorld().playSound(CurrentLocation, Sound.FIZZ, 0.2f, 3f);
|
||||
|
||||
return UtilMath.offset(CurrentLocation, Target) < 4;
|
||||
}
|
||||
}
|
@ -6,11 +6,11 @@ package nautilus.game.arcade.game.games.gladiators;
|
||||
*/
|
||||
public enum RoundState
|
||||
{
|
||||
WAITING,
|
||||
STARTING_5,
|
||||
STARTING_4,
|
||||
STARTING_3,
|
||||
STARTING_2,
|
||||
STARTING_1,
|
||||
STARTED,
|
||||
FIGHTING;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user