Refactor Wave Crush
This commit is contained in:
parent
b40346417a
commit
ae60d05bbb
@ -29,28 +29,30 @@ import nautilus.game.arcade.game.games.mineware.challenge.NumberTracker;
|
||||
*/
|
||||
public class ChallengeWaveCrush extends Challenge implements NumberTracker
|
||||
{
|
||||
// The amount of waves that started.
|
||||
private int _waveAmount;
|
||||
private static final int MAP_SPAWN_SHIFT = 1;
|
||||
private static final int MAP_HEIGHT = 1;
|
||||
private static final int MAP_SPAWN_HEIGHT = MAP_HEIGHT + 1;
|
||||
private static final int MAP_SPAWN_X = -15;
|
||||
private static final int SPAWN_COORDINATE_MULTIPLE = 2;
|
||||
private static final int MAP_PLATFORM_X_START = -16;
|
||||
private static final int MAP_PLATFORM_X_STOP = 13;
|
||||
|
||||
// The amount of ticks to wait until the first wave starts.
|
||||
private int _firstWaveDelay = 60;
|
||||
private static final int FIRST_WAVE_DELAY = 60; // ticks
|
||||
private static final int NEXT_WAVE_DELAY = 30; // ticks
|
||||
private static final int WAVE_LOCATION_MULTIPLIER = 2;
|
||||
private static final int WAVE_LENGTH_MAX = 5;
|
||||
private static final float WAVE_BLOCK_HITBOX_GROW = 0.7F;
|
||||
private static final int WAVE_BLOCK_VELOCITY_Y = 10;
|
||||
private static final int WAVE_BLOCK_SPAWN_DELAY = 2; // ticks
|
||||
private static final int WAVE_DELAY_DECREMENT_CRITERIA = 3;
|
||||
private static final int COLOR_BLOCK_LENGTH = 2;
|
||||
private static final byte[] COLORS = { 0, 5, 4, 1, 6, 14, 11, 12, 10, 7 };
|
||||
|
||||
// The amount of ticks to wait until the next wave starts.
|
||||
private int _nextWaveDelay;
|
||||
|
||||
// Colors used for map generation.
|
||||
private byte[] _colors = { 0, 5, 4, 1, 6, 14, 11, 12, 10, 7 };
|
||||
|
||||
// Keeps track of the current color.
|
||||
private int _modifiedNextWaveDelay;
|
||||
private int _wavesPassed;
|
||||
private int _colorIndex;
|
||||
|
||||
// Keeps track of the current color platform.
|
||||
private int _colorCounter;
|
||||
|
||||
// The amount of waves every player survived.
|
||||
private Map<Player, Integer> _survivedWaves = new HashMap<>();
|
||||
|
||||
// The arena size used in map generation.
|
||||
private int _arenaStartSize;
|
||||
|
||||
public ChallengeWaveCrush(BawkBawkBattles host)
|
||||
@ -69,16 +71,13 @@ public class ChallengeWaveCrush extends Challenge implements NumberTracker
|
||||
public ArrayList<Location> createSpawns()
|
||||
{
|
||||
ArrayList<Location> spawns = new ArrayList<Location>();
|
||||
int size = getArenaSize() - 1;
|
||||
int size = getArenaSize() - MAP_SPAWN_SHIFT;
|
||||
|
||||
for (int x = -15; x <= -13; x++)
|
||||
for (int z = -size; z <= size; z++)
|
||||
{
|
||||
for (int z = -size; z <= size; z++)
|
||||
if (z % SPAWN_COORDINATE_MULTIPLE == 0)
|
||||
{
|
||||
if (x % 2 == 0 && z % 2 == 0)
|
||||
{
|
||||
spawns.add(getCenter().add(x + 0.5, 2.1, z + 0.5));
|
||||
}
|
||||
spawns.add(getCenter().add(MAP_SPAWN_X, MAP_SPAWN_HEIGHT, z + 0.5));
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,11 +89,11 @@ public class ChallengeWaveCrush extends Challenge implements NumberTracker
|
||||
{
|
||||
_arenaStartSize = getArenaSize();
|
||||
|
||||
for (int x = -16; x <= 13; x++)
|
||||
for (int x = MAP_PLATFORM_X_START; x <= MAP_PLATFORM_X_STOP; x++)
|
||||
{
|
||||
for (int z = -getArenaSize(); z <= getArenaSize(); z++)
|
||||
{
|
||||
for (int y = 0; y <= 1; y++)
|
||||
for (int y = 0; y <= MAP_HEIGHT; y++)
|
||||
{
|
||||
Block block = getCenter().getBlock().getRelative(x, y, z);
|
||||
|
||||
@ -118,7 +117,7 @@ public class ChallengeWaveCrush extends Challenge implements NumberTracker
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
_nextWaveDelay = 30;
|
||||
_modifiedNextWaveDelay = NEXT_WAVE_DELAY;
|
||||
|
||||
for (Player player : getPlayersAlive())
|
||||
{
|
||||
@ -134,7 +133,7 @@ public class ChallengeWaveCrush extends Challenge implements NumberTracker
|
||||
remove(EntityType.FALLING_BLOCK);
|
||||
removeExtraBlocks();
|
||||
|
||||
_waveAmount = 0;
|
||||
_wavesPassed = 0;
|
||||
_survivedWaves.clear();
|
||||
}
|
||||
|
||||
@ -161,23 +160,23 @@ public class ChallengeWaveCrush extends Challenge implements NumberTracker
|
||||
|
||||
if (isPlayerValid(player))
|
||||
{
|
||||
Host.Manager.GetDamage().NewDamageEvent(target, null, null, DamageCause.PROJECTILE, 9999.0, false, false, false, "Falling Block", "Wave Crush");
|
||||
Host.Manager.GetDamage().NewDamageEvent(target, null, null, DamageCause.PROJECTILE, player.getHealth(), false, false, false, "Falling Block", "Wave Crush");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private byte getColor()
|
||||
{
|
||||
if (_colorCounter > 2)
|
||||
if (_colorCounter > COLOR_BLOCK_LENGTH)
|
||||
{
|
||||
_colorCounter = 0;
|
||||
_colorIndex++;
|
||||
|
||||
if (_colorIndex >= _colors.length)
|
||||
if (_colorIndex >= COLORS.length)
|
||||
_colorIndex = 0;
|
||||
}
|
||||
|
||||
return _colors[_colorIndex];
|
||||
return COLORS[_colorIndex];
|
||||
}
|
||||
|
||||
private void startWavesTask()
|
||||
@ -193,22 +192,22 @@ public class ChallengeWaveCrush extends Challenge implements NumberTracker
|
||||
return;
|
||||
}
|
||||
|
||||
_waveAmount++;
|
||||
_wavesPassed++;
|
||||
|
||||
startWave();
|
||||
decreaseWaveDelay();
|
||||
increaseSurvivedWaves();
|
||||
}
|
||||
}.runTaskTimer(Host.Manager.getPlugin(), _firstWaveDelay, _nextWaveDelay);
|
||||
}.runTaskTimer(Host.Manager.getPlugin(), FIRST_WAVE_DELAY, _modifiedNextWaveDelay);
|
||||
}
|
||||
|
||||
private Block getWaveStartBlock()
|
||||
{
|
||||
Block block = getCenter().getBlock().getRelative(13, 1, UtilMath.r(getArenaSize() * 2) - getArenaSize());
|
||||
Block block = getCenter().getBlock().getRelative(MAP_PLATFORM_X_STOP, 1, UtilMath.r(getArenaSize() * WAVE_LOCATION_MULTIPLIER) - getArenaSize());
|
||||
|
||||
while (block.isEmpty())
|
||||
{
|
||||
block = getCenter().getBlock().getRelative(13, 1, UtilMath.r(getArenaSize() * 2) - getArenaSize());
|
||||
block = getCenter().getBlock().getRelative(MAP_PLATFORM_X_STOP, 1, UtilMath.r(getArenaSize() * WAVE_LOCATION_MULTIPLIER) - getArenaSize());
|
||||
}
|
||||
|
||||
return block;
|
||||
@ -218,7 +217,7 @@ public class ChallengeWaveCrush extends Challenge implements NumberTracker
|
||||
{
|
||||
Block startBlock = getWaveStartBlock();
|
||||
|
||||
for (int i = 0; i <= 5; i++)
|
||||
for (int i = 0; i <= WAVE_LENGTH_MAX; i++)
|
||||
{
|
||||
createWaveBlock(startBlock.getLocation().clone().add(0, 0, i).getBlock());
|
||||
}
|
||||
@ -242,20 +241,20 @@ public class ChallengeWaveCrush extends Challenge implements NumberTracker
|
||||
|
||||
Location spawn = currentBlock.getLocation().clone().add(0, 1, 0);
|
||||
FallingBlock waveBlock = getCenter().getWorld().spawnFallingBlock(spawn, currentBlock.getType(), currentBlock.getData());
|
||||
Host.Manager.GetProjectile().AddThrow(waveBlock, null, Host, -1, true, false, true, true, 0.7F);
|
||||
waveBlock.setVelocity(new Vector(0, 10, 0).normalize());
|
||||
Host.Manager.GetProjectile().AddThrow(waveBlock, null, Host, -1, true, false, true, true, WAVE_BLOCK_HITBOX_GROW);
|
||||
waveBlock.setVelocity(new Vector(0, WAVE_BLOCK_VELOCITY_Y, 0).normalize());
|
||||
|
||||
resetBlock(currentBlock);
|
||||
currentBlock = getCenter().getWorld().getBlockAt(currentBlock.getX() - 1, currentBlock.getY(), currentBlock.getZ());
|
||||
}
|
||||
}.runTaskTimer(Host.Manager.getPlugin(), 0, 2);
|
||||
}.runTaskTimer(Host.Manager.getPlugin(), 0, WAVE_BLOCK_SPAWN_DELAY);
|
||||
}
|
||||
|
||||
private void decreaseWaveDelay()
|
||||
{
|
||||
if (_waveAmount % 3 == 0)
|
||||
if (_wavesPassed % WAVE_DELAY_DECREMENT_CRITERIA == 0 && _modifiedNextWaveDelay > 0)
|
||||
{
|
||||
_nextWaveDelay--;
|
||||
_modifiedNextWaveDelay--;
|
||||
}
|
||||
}
|
||||
|
||||
@ -272,11 +271,11 @@ public class ChallengeWaveCrush extends Challenge implements NumberTracker
|
||||
|
||||
private void removeExtraBlocks()
|
||||
{
|
||||
for (int x = -16; x <= 13; x++)
|
||||
for (int x = MAP_PLATFORM_X_START; x <= MAP_PLATFORM_X_STOP; x++)
|
||||
{
|
||||
for (int z = -_arenaStartSize; z <= _arenaStartSize; z++)
|
||||
{
|
||||
Block block = getCenter().getBlock().getRelative(x, 2, z);
|
||||
Block block = getCenter().getBlock().getRelative(x, MAP_SPAWN_HEIGHT, z);
|
||||
|
||||
if (!block.isEmpty())
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user