Made the thing a lot better. Yay! :D

This commit is contained in:
Mysticate 2015-09-24 11:04:05 -04:00
parent 5de016c077
commit 7445fda922
2 changed files with 111 additions and 72 deletions

View File

@ -25,7 +25,8 @@ import mineplex.core.common.util.UtilRadar;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.common.util.UtilTime;
import mineplex.core.recharge.Recharge;
import nautilus.game.arcade.game.Game.GameState;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.game.games.monstermaze.MMMazes.MazePreset;
import nautilus.game.arcade.game.games.monstermaze.MazeMobWaypoint.CardinalDirection;
import nautilus.game.arcade.game.games.monstermaze.events.AbilityUseEvent;
@ -48,6 +49,7 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Snowman;
import org.bukkit.entity.Zombie;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.player.PlayerInteractEvent;
@ -73,7 +75,9 @@ public class Maze implements Listener
private ArrayList<Player> _playersOnPad = new ArrayList<Player>();
private int _phaseTimer = 90;
private double _phaseTimer = 90;
private double _phaseTimerStart = 90;
private int _padDecayTimer = -1;
private Location _nextSafePadLoc;
@ -116,6 +120,8 @@ public class Maze implements Listener
loc.getBlock().setData((byte)3);
}
_center = maze.getCenter();
Bukkit.getPluginManager().registerEvents(this, Host.Manager.getPlugin());
}
public SafePad getSafePad()
@ -131,71 +137,105 @@ public class Maze implements Listener
return _safePad.isOn(player);
}
public void update()
{
@EventHandler
public void updateTick(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
if (!Host.IsLive())
return;
if (_safePad != null) // TODO probably a good idea to check if this will screw up compasses in inventories before the game starts
{
for(Player p : Host.GetPlayers(true))
for (Player p : Host.GetPlayers(true))
{
p.setCompassTarget(_nextSafePadLoc);
UtilRadar.displayRadar(p, Arrays.asList(_safePadRadarData), true);
if(Host.GetState() == GameState.Live)
{
UtilRadar.displayRadar(p, Arrays.asList(_safePadRadarData), true);
}
}
}
if (Host.IsLive())
//Updates
checkPlayersOnSafePad();
move();
bump();
removeMobsOnSafePad();
}
@EventHandler
public void updateFaster(UpdateEvent event)
{
if (event.getType() != UpdateType.FASTER)
return;
if (!Host.IsLive())
return;
decrementPhaseTime();
}
@EventHandler
public void updateSecond(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
return;
if (!Host.IsLive())
return;
decrementSafePadTime();
//Attempt pad spawn
if (_safePad == null && UtilTime.elapsed(_lastBeacon, 3000 + (1000 * UtilMath.r(10))))
{
//checkGoal();
checkPlayersOnSafePad();
move();
bump();
removeMobsOnSafePad();
if (_safePad == null && UtilTime.elapsed(_lastBeacon, 3000 + (1000 * UtilMath.r(10))))
try
{
try
{
spawnSafePad();
}
catch (Exception ex)
{
System.out.println("AN EXCEPTION OCCURED WHILE TRYING TO SPAWN A SAFE PAD!");
}
spawnSafePad();
}
if (_phaseTimer > 15)
catch (Exception ex)
{
for(Player p : Host.GetPlayers(true))
{
p.setExp(0);
}
// UtilTextTop.displayProgress(C.cAqua + C.Bold + "Be the first player to get to the Safe Pad!", 100, Host.GetPlayers(true).toArray(new Player[Host.GetPlayers(true).size()]));
}
else
{
double percentage = _phaseTimer/15d;
for(Player p : Host.GetPlayers(true))
{
p.setExp((float)percentage);
// if(_safePad.isOn(p))
// {
// UtilTextTop.displayProgress(C.cGreen + C.Bold + "Stay on the Safe Pad for " + _phaseTimer + " more seconds!", percentage, p);
// }
// else
// {
// UtilTextTop.displayProgress(C.cRed + C.Bold + "You have " + _phaseTimer + " seconds to get to the Safe Pad!", percentage, p);
// }
}
System.out.println("AN EXCEPTION OCCURED WHILE TRYING TO SPAWN A SAFE PAD!");
}
}
}
@EventHandler
public void updateExperience(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
if (!Host.IsLive())
return;
if (_safePad == null)
{
for (Player p : Host.GetPlayers(true))
{
p.setExp(0F);
}
return;
}
if (_phaseTimer > 15) //Nobody has gotten to it yet
{
float percent = (float) Math.min(Math.max(_phaseTimer * (1 / _phaseTimerStart), 0), .999);
for(Player p : Host.GetPlayers(true))
{
p.setExp(percent);
}
return;
}
float percentage = (float) Math.min(Math.max(_phaseTimer / 15, 0), 1);
for (Player p : Host.GetPlayers(true))
{
p.setExp(percentage);
}
}
private void removeMobsOnSafePad()
{
Iterator<Entity> it = _ents.keySet().iterator();
@ -656,7 +696,7 @@ public class Maze implements Listener
{
if(_phaseTimer == -1) return;
_phaseTimer--;
_phaseTimer -= .25;
if(_phaseTimer == 20) // only gets to this by running out of time naturally, not by player
{
UtilTextMiddle.display("", C.cGreen + C.Bold + _phaseTimer, 5, 40, 5, Host.GetPlayers(true).toArray(new Player[Host.GetPlayers(true).size()]));
@ -713,14 +753,17 @@ public class Maze implements Listener
_playersOnPad.clear();
//_phaseTimer = -1;
_phaseTimer = 90 - (_curSafe * 3);
_phaseTimerStart = 90 - (_curSafe * 3);
_phaseTimer = _phaseTimerStart;
}
}
private void checkPlayersOnSafePad()
{
if(_safePad == null) return;
for(Player p : Host.GetPlayers(true))
if(_safePad == null)
return;
for (Player p : Host.GetPlayers(true))
{
if(_safePad.isOn(p) && !_playersOnPad.contains(p))
{
@ -810,7 +853,7 @@ public class Maze implements Listener
return _ents.keySet();
}
public int getPhaseTimer()
public double getPhaseTimer()
{
return _phaseTimer;
}

View File

@ -34,6 +34,7 @@ import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Snowman;
import org.bukkit.entity.Zombie;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.block.EntityBlockFormEvent;
import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityDamageEvent;
@ -100,13 +101,13 @@ public class MonsterMaze extends SoloGame
event.setCancelled(true);
}
@EventHandler
public void Update(UpdateEvent event)
{
if(event.getType() != UpdateType.TICK) return;
if(_maze == null) return;
_maze.update();
}
// @EventHandler
// public void Update(UpdateEvent event)
// {
// if(event.getType() != UpdateType.TICK) return;
// if(_maze == null) return;
// _maze.update();
// }
@EventHandler
public void GameStateChange(GameStateChangeEvent event)
@ -131,6 +132,10 @@ public class MonsterMaze extends SoloGame
_maze.fillSpawn(150);
}
else if (event.GetState() == GameState.End)
{
HandlerList.unregisterAll(getMaze());
}
}
private void setJumpsLeft(Player player, int jumps)
@ -210,15 +215,6 @@ public class MonsterMaze extends SoloGame
e.setCancelled(true);
}
@EventHandler
public void DecrementPhaseTimer(UpdateEvent event)
{
if(event.getType() != UpdateType.SEC) return;
if(!IsLive()) return;
_maze.decrementPhaseTime();
_maze.decrementSafePadTime();
}
@EventHandler
public void Damage(EntityDamageEvent event)
{
@ -273,7 +269,7 @@ public class MonsterMaze extends SoloGame
if (_maze.getSafePad() != null)
{
Scoreboard.Write(C.cWhite + UtilTime.MakeStr(_maze.getPhaseTimer() * 1000));
Scoreboard.Write(C.cWhite + UtilTime.MakeStr((long) (_maze.getPhaseTimer() * 1000)));
}
else
{