Refactor Red Light, Green Light and Volley Pig
This commit is contained in:
parent
e0d133ab67
commit
ab4174cfb9
@ -515,10 +515,15 @@ public abstract class Challenge implements Listener
|
||||
|
||||
Host.Manager.GetCondition().Factory().Cloak(reason, player, player, 7777, true, false);
|
||||
}
|
||||
|
||||
|
||||
protected void alert(Player player, String message)
|
||||
{
|
||||
UtilTextMiddle.display(null, message, TITLE_FADE_IN_TICKS, TITLE_STAY_TICKS, TITLE_FADE_OUT_TICKS, player);
|
||||
alert(player, message, TITLE_STAY_TICKS);
|
||||
}
|
||||
|
||||
protected void alert(Player player, String message, int stayTicks)
|
||||
{
|
||||
UtilTextMiddle.display(null, message, TITLE_FADE_IN_TICKS, stayTicks, TITLE_FADE_OUT_TICKS, player);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
|
@ -26,7 +26,6 @@ import mineplex.core.common.util.UtilEnt;
|
||||
import mineplex.core.common.util.UtilFirework;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilTextMiddle;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import nautilus.game.arcade.game.games.mineware.BawkBawkBattles;
|
||||
@ -38,40 +37,46 @@ import nautilus.game.arcade.game.games.mineware.challenge.ChallengeType;
|
||||
*/
|
||||
public class ChallengeRedLightGreenLight extends Challenge
|
||||
{
|
||||
// The villager that is located at the end of the race.
|
||||
private Villager _villager;
|
||||
private static final int MAP_SPAWN_SHIFT = 1;
|
||||
private static final int MAP_HEIGHT = 2;
|
||||
private static final int MAP_X_START = -36;
|
||||
private static final int MAP_X_STOP = 23;
|
||||
private static final int VILLAGER_X = MAP_X_STOP - 4;
|
||||
|
||||
// The villager X coordinate that marks the finish line.
|
||||
private int _villagerX = 28;
|
||||
private static final int MIN_TIME_BEFORE_RED = 1500; // milliseconds
|
||||
private static final int MIN_TIME_BEFORE_GREEN = 2500; // milliseconds
|
||||
|
||||
// Minimum time until red light is triggered.
|
||||
private int _minTimeBeforeRed = 1500;
|
||||
private static final int COOLDOWN_EXPIRE_TICKS = 35;
|
||||
private static final int SLOW_EFFECT_AMPLIFIER = 2;
|
||||
private static final int COLOR_TILE_SIZE = 6;
|
||||
|
||||
private static final int KNOCKBACK_HEIGHT = MAP_HEIGHT + 3;
|
||||
private static final double KNOCKBACK_POWER = 1.5;
|
||||
private static final double KNOCKBACK_Y = 0.4;
|
||||
private static final int KNOCKBACK_Y_MAX = 10;
|
||||
|
||||
private static final int CANNOT_MOVE_RANDOMIZER = 2;
|
||||
private static final int CAN_MOVE_RANDOMIZER = 3;
|
||||
|
||||
private static final float STATUS_SOUND_VOLUME = 2.0F;
|
||||
private static final float STATUS_SOUND_PITCH = 1.0F;
|
||||
private static final int DELAY_UNTIL_KNOCKBACK = 1500; // milliseconds
|
||||
private static final int CUSTOM_TITLE_STAY_TICKS = 60;
|
||||
|
||||
private static final int FIREWORK_MULTIPLIER = 2;
|
||||
private static final int FIREWORK_INCREMENTATION = 4;
|
||||
private static final int FIREWORK_X = MAP_X_STOP - 1;
|
||||
private static final int FIREWORK_Y = MAP_HEIGHT + 8;
|
||||
|
||||
private static final byte[] COLORS = { 0, 5, 4, 1, 6, 14, 11, 12 };
|
||||
|
||||
// Time since last red light was triggered.
|
||||
private long _timeSinceLastRed;
|
||||
|
||||
// Minimum time until green light is triggered.
|
||||
private int _minTimeBeforeGreen = 2500;
|
||||
|
||||
// Time since last green was triggered.
|
||||
private long _timeSinceLastGreen;
|
||||
|
||||
// Determines if the players can move or not.
|
||||
private Villager _villager;
|
||||
private boolean _canMove;
|
||||
|
||||
// After that time, if the player moves on red light, knockback is applied.
|
||||
private long _timeBeforeAction;
|
||||
|
||||
// Contains all players with a knockback cooldown.
|
||||
private List<Player> _cooldown = new ArrayList<>();
|
||||
|
||||
// Colors used for map generation.
|
||||
private byte[] _colors = { 0, 5, 4, 1, 6, 14, 11, 12 };
|
||||
|
||||
// Keeps track of the current color.
|
||||
private int _colorIndex;
|
||||
|
||||
// Keeps track of the current color platform.
|
||||
private int _colorCounter;
|
||||
|
||||
public ChallengeRedLightGreenLight(BawkBawkBattles host)
|
||||
@ -91,17 +96,11 @@ public class ChallengeRedLightGreenLight extends Challenge
|
||||
public ArrayList<Location> createSpawns()
|
||||
{
|
||||
ArrayList<Location> spawns = new ArrayList<Location>();
|
||||
int size = getArenaSize() - 1;
|
||||
int size = getArenaSize() - MAP_SPAWN_SHIFT;
|
||||
|
||||
for (int x = -31; x <= -30; x++)
|
||||
for (int z = -size; z <= size; z++)
|
||||
{
|
||||
for (int z = -size; z <= size; z++)
|
||||
{
|
||||
if (x % 2 == 0 && z % 2 == 0)
|
||||
{
|
||||
spawns.add(getCenter().add(x + 0.5, 2.1, z + 0.5));
|
||||
}
|
||||
}
|
||||
spawns.add(getCenter().add(-35, MAP_HEIGHT, z + 0.5));
|
||||
}
|
||||
|
||||
return spawns;
|
||||
@ -110,13 +109,13 @@ public class ChallengeRedLightGreenLight extends Challenge
|
||||
@Override
|
||||
public void createMap()
|
||||
{
|
||||
for (int x = -31; x <= 32; x++)
|
||||
for (int x = MAP_X_START; x <= MAP_X_STOP; x++)
|
||||
{
|
||||
for (int z = -getArenaSize(); z <= getArenaSize(); z++)
|
||||
{
|
||||
Block block = getCenter().getBlock().getRelative(x, 1, z);
|
||||
|
||||
if (x == _villagerX)
|
||||
if (x == VILLAGER_X)
|
||||
{
|
||||
setBlock(block, Material.COAL_BLOCK);
|
||||
}
|
||||
@ -138,7 +137,7 @@ public class ChallengeRedLightGreenLight extends Challenge
|
||||
spawnVillager();
|
||||
changeMoveState(true);
|
||||
|
||||
addEffect(PotionEffectType.SLOW, 2);
|
||||
addEffect(PotionEffectType.SLOW, SLOW_EFFECT_AMPLIFIER);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -148,7 +147,7 @@ public class ChallengeRedLightGreenLight extends Challenge
|
||||
{
|
||||
_villager.remove();
|
||||
}
|
||||
|
||||
|
||||
_villager = null;
|
||||
_canMove = false;
|
||||
_timeBeforeAction = 0;
|
||||
@ -180,7 +179,7 @@ public class ChallengeRedLightGreenLight extends Challenge
|
||||
if (!isPlayerValid(player))
|
||||
return;
|
||||
|
||||
if (player.getLocation().getX() > getCenter().getX() + _villagerX)
|
||||
if (player.getLocation().getX() > getCenter().getX() + VILLAGER_X)
|
||||
{
|
||||
setCompleted(player);
|
||||
}
|
||||
@ -210,27 +209,27 @@ public class ChallengeRedLightGreenLight extends Challenge
|
||||
|
||||
private byte getColor()
|
||||
{
|
||||
if (_colorCounter > 7)
|
||||
if (_colorCounter >= COLOR_TILE_SIZE)
|
||||
{
|
||||
_colorCounter = 0;
|
||||
_colorIndex++;
|
||||
|
||||
if (_colorIndex >= _colors.length)
|
||||
if (_colorIndex >= COLORS.length)
|
||||
_colorIndex = 0;
|
||||
}
|
||||
|
||||
return _colors[_colorIndex];
|
||||
return COLORS[_colorIndex];
|
||||
}
|
||||
|
||||
private void spawnVillager()
|
||||
{
|
||||
Host.CreatureAllow = true;
|
||||
|
||||
Location spawn = getCenter().add(_villagerX, 2, 0);
|
||||
Location spawn = getCenter().add(VILLAGER_X, MAP_HEIGHT, 0);
|
||||
_villager = (Villager) getCenter().getWorld().spawnEntity(spawn, EntityType.VILLAGER);
|
||||
|
||||
UtilEnt.Vegetate(_villager);
|
||||
UtilEnt.CreatureLook(_villager, getCenter().add(0, 2, 0));
|
||||
UtilEnt.CreatureLook(_villager, Host.GetSpectatorLocation());
|
||||
UtilEnt.ghost(_villager, true, false);
|
||||
|
||||
Host.CreatureAllow = false;
|
||||
@ -238,7 +237,7 @@ public class ChallengeRedLightGreenLight extends Challenge
|
||||
|
||||
private void addCooldown(Player player)
|
||||
{
|
||||
UtilAction.velocity(player, UtilAlg.getTrajectory2d(player.getLocation(), getCenter().add(-32, 5, 0)), 1.5, true, 0.4, 0, 10, true);
|
||||
UtilAction.velocity(player, UtilAlg.getTrajectory2d(player.getLocation(), getCenter().add(MAP_X_START, KNOCKBACK_HEIGHT, 0)), KNOCKBACK_POWER, true, KNOCKBACK_Y, 0, KNOCKBACK_Y_MAX, true);
|
||||
_cooldown.add(player);
|
||||
}
|
||||
|
||||
@ -257,7 +256,7 @@ public class ChallengeRedLightGreenLight extends Challenge
|
||||
|
||||
_cooldown.remove(player);
|
||||
}
|
||||
}.runTaskLater(Host.Manager.getPlugin(), 35);
|
||||
}.runTaskLater(Host.Manager.getPlugin(), COOLDOWN_EXPIRE_TICKS);
|
||||
}
|
||||
|
||||
private void determineMoveState()
|
||||
@ -274,9 +273,9 @@ public class ChallengeRedLightGreenLight extends Challenge
|
||||
|
||||
private void toggleCannotMoveState()
|
||||
{
|
||||
if (_timeSinceLastRed + _minTimeBeforeRed < System.currentTimeMillis())
|
||||
if (_timeSinceLastRed + MIN_TIME_BEFORE_RED < System.currentTimeMillis())
|
||||
{
|
||||
if (UtilMath.r(2) == 0)
|
||||
if (UtilMath.r(CANNOT_MOVE_RANDOMIZER) == 0)
|
||||
{
|
||||
changeMoveState(false);
|
||||
}
|
||||
@ -285,9 +284,9 @@ public class ChallengeRedLightGreenLight extends Challenge
|
||||
|
||||
private void toggleCanMoveState()
|
||||
{
|
||||
if (_timeSinceLastGreen + _minTimeBeforeGreen < System.currentTimeMillis())
|
||||
if (_timeSinceLastGreen + MIN_TIME_BEFORE_GREEN < System.currentTimeMillis())
|
||||
{
|
||||
if (UtilMath.r(3) == 0)
|
||||
if (UtilMath.r(CAN_MOVE_RANDOMIZER) == 0)
|
||||
{
|
||||
changeMoveState(true);
|
||||
}
|
||||
@ -323,14 +322,14 @@ public class ChallengeRedLightGreenLight extends Challenge
|
||||
for (Player player : getPlayersIn(true))
|
||||
{
|
||||
UtilPlayer.message(player, F.main("Green Light", "You can now move."));
|
||||
player.getWorld().playSound(player.getLocation(), Sound.SUCCESSFUL_HIT, 2F, 1F);
|
||||
player.getWorld().playSound(player.getLocation(), Sound.SUCCESSFUL_HIT, STATUS_SOUND_VOLUME, STATUS_SOUND_PITCH);
|
||||
}
|
||||
}
|
||||
|
||||
private void cannotMoveEffect()
|
||||
{
|
||||
_timeSinceLastGreen = System.currentTimeMillis();
|
||||
_timeBeforeAction = System.currentTimeMillis() + 1500;
|
||||
_timeBeforeAction = System.currentTimeMillis() + DELAY_UNTIL_KNOCKBACK;
|
||||
_canMove = false;
|
||||
spawnFirework(Color.RED);
|
||||
|
||||
@ -342,16 +341,16 @@ public class ChallengeRedLightGreenLight extends Challenge
|
||||
for (Player player : getPlayersIn(true))
|
||||
{
|
||||
UtilPlayer.message(player, F.main("Red Light", "Freeze!"));
|
||||
UtilTextMiddle.display(null, ChatColor.RED + "Freeze!", 5, 60, 5, player);
|
||||
player.getWorld().playSound(player.getLocation(), Sound.NOTE_BASS, 2F, 1F);
|
||||
alert(player, ChatColor.RED + "Freeze!", CUSTOM_TITLE_STAY_TICKS);
|
||||
player.getWorld().playSound(player.getLocation(), Sound.NOTE_BASS, STATUS_SOUND_VOLUME, STATUS_SOUND_PITCH);
|
||||
}
|
||||
}
|
||||
|
||||
private void spawnFirework(Color color)
|
||||
{
|
||||
for (int i = -getArenaSize(); i < getArenaSize() * 2; i += 4)
|
||||
for (int i = -getArenaSize(); i < getArenaSize() * FIREWORK_MULTIPLIER; i += FIREWORK_INCREMENTATION)
|
||||
{
|
||||
UtilFirework.playFirework(getCenter().add(30, 10, i), Type.BALL_LARGE, color, false, false);
|
||||
UtilFirework.playFirework(getCenter().add(FIREWORK_X, FIREWORK_Y, i), Type.BALL_LARGE, color, false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -379,8 +379,8 @@ public class ChallengeVolleyPig extends TeamChallenge
|
||||
|
||||
private void displayProgress()
|
||||
{
|
||||
double red = _redSide / SCORE_GOAL;
|
||||
double blue = _blueSide / SCORE_GOAL;
|
||||
double red = _redSide / (double) SCORE_GOAL;
|
||||
double blue = _blueSide / (double) SCORE_GOAL;
|
||||
boolean redFirst = red < blue;
|
||||
String progressBar = (redFirst ? C.cRed : C.cBlue) + "";
|
||||
int colorChange = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user