Refactor Lava Run and Milk a Cow
This commit is contained in:
parent
108031acf1
commit
f36244efc6
@ -28,31 +28,31 @@ import nautilus.game.arcade.game.games.mineware.challenge.ChallengeType;
|
||||
*/
|
||||
public class ChallengeLavaRun extends Challenge
|
||||
{
|
||||
// The starting size of the arena, stored to be used later in the code.
|
||||
private static final int CHALLENGE_PLAYERS_MAX = 30;
|
||||
private static final int MAP_HEIGHT = 4;
|
||||
private static final int MAP_SPAWN_HEIGHT = MAP_HEIGHT + 1;
|
||||
private static final int MAP_SPAWN_SHIFT = 3;
|
||||
|
||||
private static final int DELAY_START = 2000; // milliseconds
|
||||
private static final int DELAY_MIN = 1000; // milliseconds
|
||||
private static final int DISSAPEARING_BLOCKS = 10;
|
||||
|
||||
private static final int OBSIDIAN_LARGE_DISTANCE = 4; // blocks
|
||||
private static final int DELAY_BOOST = 1000; // milliseconds
|
||||
private static final int DELAY_SUBTRACT = 100; // milliseconds
|
||||
private static final int DELAY_AFTER_DESTURCTION = 1500; // milliseconds
|
||||
|
||||
private static final float DESTRUCTION_SOUND_VOLUME = 2.0F;
|
||||
private static final float DESTRUCTION_SOUND_PITCH = 1.0F;
|
||||
private static final double DISTANCE_XZ_ADD = 0.5;
|
||||
|
||||
private int _arenaStartSize;
|
||||
|
||||
// The current obsidian block in the platform.
|
||||
private Block _obsidian;
|
||||
|
||||
// The last obsidian location to detect if the new one is too far.
|
||||
private Location _lastObsidianLocation;
|
||||
|
||||
// Keeps track of whether the obsidian should be moved or not.
|
||||
private boolean _shouldMoveObsidian;
|
||||
|
||||
// The list of blocks - including osbidian - generated to make a platform.
|
||||
private List<Block> _platform;
|
||||
|
||||
// The map height of the challenge.
|
||||
private int _mapY = 4;
|
||||
|
||||
// The duration until the platform is regenerated/destroyed.
|
||||
private long _delay;
|
||||
|
||||
// The minimum delay until the platform is destroyed.
|
||||
private long _delayMin;
|
||||
|
||||
// The amount of blocks (or speed) disappearing.
|
||||
private long _modifiedDelay;
|
||||
private long _modifiedDelayMin;
|
||||
private int _disappearingBlocks;
|
||||
|
||||
public ChallengeLavaRun(BawkBawkBattles host)
|
||||
@ -66,7 +66,7 @@ public class ChallengeLavaRun extends Challenge
|
||||
"Run! Run! Run!");
|
||||
|
||||
Settings.setUseMapHeight();
|
||||
Settings.setMaxPlayers(30);
|
||||
Settings.setMaxPlayers(CHALLENGE_PLAYERS_MAX);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -74,13 +74,13 @@ public class ChallengeLavaRun extends Challenge
|
||||
{
|
||||
ArrayList<Location> spawns = new ArrayList<Location>();
|
||||
_arenaStartSize = getArenaSize();
|
||||
int size = getArenaSize() - 3;
|
||||
int size = getArenaSize() - MAP_SPAWN_SHIFT;
|
||||
|
||||
for (int x = -size; x <= size; x++)
|
||||
{
|
||||
for (int z = -size; z <= size; z++)
|
||||
{
|
||||
spawns.add(getCenter().add(x + 0.5, (_mapY + 1.0), z + 0.5));
|
||||
spawns.add(getCenter().add(x + 0.5, MAP_SPAWN_HEIGHT, z + 0.5));
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,10 +96,10 @@ public class ChallengeLavaRun extends Challenge
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
_delay = System.currentTimeMillis() + 2000;
|
||||
_obsidian = createObsidianBlock();
|
||||
_delayMin = 1000;
|
||||
_disappearingBlocks = 10;
|
||||
_modifiedDelay = System.currentTimeMillis() + DELAY_START;
|
||||
_modifiedDelayMin = DELAY_MIN;
|
||||
_disappearingBlocks = DISSAPEARING_BLOCKS;
|
||||
createLava();
|
||||
disguisePlayers();
|
||||
}
|
||||
@ -111,8 +111,8 @@ public class ChallengeLavaRun extends Challenge
|
||||
_lastObsidianLocation = null;
|
||||
_shouldMoveObsidian = false;
|
||||
_platform.clear();
|
||||
_delay = 0;
|
||||
_delayMin = 0;
|
||||
_modifiedDelay = 0;
|
||||
_modifiedDelayMin = 0;
|
||||
_disappearingBlocks = 0;
|
||||
}
|
||||
|
||||
@ -125,7 +125,7 @@ public class ChallengeLavaRun extends Challenge
|
||||
if (!isChallengeValid())
|
||||
return;
|
||||
|
||||
if (_delay > System.currentTimeMillis())
|
||||
if (_modifiedDelay > System.currentTimeMillis())
|
||||
return;
|
||||
|
||||
if (_shouldMoveObsidian)
|
||||
@ -136,18 +136,18 @@ public class ChallengeLavaRun extends Challenge
|
||||
blockBreakEffect(_obsidian, false);
|
||||
playSound();
|
||||
|
||||
_delay = System.currentTimeMillis();
|
||||
_modifiedDelay = System.currentTimeMillis();
|
||||
|
||||
if (UtilMath.offset2d(_obsidian.getLocation(), _lastObsidianLocation) > 4) // Add 1 second if the obsidian is too far.
|
||||
if (UtilMath.offset2d(_obsidian.getLocation(), _lastObsidianLocation) > OBSIDIAN_LARGE_DISTANCE) // Add 1 second if the obsidian is too far.
|
||||
{
|
||||
System.out.println("Increasing delay");
|
||||
_delay += 1000;
|
||||
_modifiedDelay += DELAY_BOOST;
|
||||
}
|
||||
|
||||
if (_delayMin > 0)
|
||||
if (_modifiedDelayMin > 0)
|
||||
{
|
||||
_delayMin -= 100;
|
||||
_delay += _delayMin;
|
||||
_modifiedDelayMin -= DELAY_SUBTRACT;
|
||||
_modifiedDelay += _modifiedDelayMin;
|
||||
}
|
||||
|
||||
_disappearingBlocks++;
|
||||
@ -157,7 +157,7 @@ public class ChallengeLavaRun extends Challenge
|
||||
{
|
||||
if (isPlatformEmpty())
|
||||
{
|
||||
_delay = System.currentTimeMillis() + 1500;
|
||||
_modifiedDelay = System.currentTimeMillis() + DELAY_AFTER_DESTURCTION;
|
||||
_lastObsidianLocation = _obsidian.getLocation();
|
||||
_shouldMoveObsidian = true;
|
||||
}
|
||||
@ -189,7 +189,7 @@ public class ChallengeLavaRun extends Challenge
|
||||
if (event.GetDamagerEntity(true) != null)
|
||||
return;
|
||||
|
||||
event.AddMod("Ensure Death", null, 9999, false);
|
||||
event.AddMod("Ensure Death", null, event.GetDamageePlayer().getHealth(), false);
|
||||
}
|
||||
|
||||
private void generatePlatform()
|
||||
@ -200,7 +200,7 @@ public class ChallengeLavaRun extends Challenge
|
||||
{
|
||||
for (int z = -getArenaSize(); z <= getArenaSize(); z++)
|
||||
{
|
||||
Block block = getCenter().getBlock().getRelative(x, _mapY, z);
|
||||
Block block = getCenter().getBlock().getRelative(x, MAP_HEIGHT, z);
|
||||
setBlock(block, Material.GLASS);
|
||||
_platform.add(block);
|
||||
addBlock(block);
|
||||
@ -210,13 +210,13 @@ public class ChallengeLavaRun extends Challenge
|
||||
|
||||
private void createLava()
|
||||
{
|
||||
int size = getArenaSize() + 3;
|
||||
int size = getArenaSize() + MAP_SPAWN_SHIFT;
|
||||
|
||||
for (int x = -size; x <= size; x++)
|
||||
{
|
||||
for (int z = -size; z <= size; z++)
|
||||
{
|
||||
for (int y = 0; y < _mapY; y++)
|
||||
for (int y = 0; y < MAP_HEIGHT; y++)
|
||||
{
|
||||
Block block = getCenter().getBlock().getRelative(x, y, z);
|
||||
setBlock(block, Material.STATIONARY_LAVA);
|
||||
@ -228,7 +228,7 @@ public class ChallengeLavaRun extends Challenge
|
||||
|
||||
private Block createObsidianBlock()
|
||||
{
|
||||
Block block = getCenter().add(UtilMath.r(_arenaStartSize), _mapY, UtilMath.r(_arenaStartSize)).getBlock();
|
||||
Block block = getCenter().add(UtilMath.r(_arenaStartSize), MAP_HEIGHT, UtilMath.r(_arenaStartSize)).getBlock();
|
||||
setBlock(block, Material.OBSIDIAN);
|
||||
return block;
|
||||
}
|
||||
@ -247,7 +247,7 @@ public class ChallengeLavaRun extends Challenge
|
||||
{
|
||||
for (Player player : getPlayersAlive())
|
||||
{
|
||||
player.playSound(player.getLocation(), Sound.NOTE_PIANO, 2.0F, 1.0F);
|
||||
player.playSound(player.getLocation(), Sound.NOTE_PIANO, DESTRUCTION_SOUND_VOLUME, DESTRUCTION_SOUND_PITCH);
|
||||
}
|
||||
}
|
||||
|
||||
@ -272,7 +272,7 @@ public class ChallengeLavaRun extends Challenge
|
||||
|
||||
for (Block part : _platform)
|
||||
{
|
||||
distance.put(part, part.getLocation().add(0.5, 0, 0.5).distance(_obsidian.getLocation()));
|
||||
distance.put(part, part.getLocation().add(DISTANCE_XZ_ADD, 0, DISTANCE_XZ_ADD).distance(_obsidian.getLocation()));
|
||||
}
|
||||
|
||||
Collections.sort(_platform, new Comparator<Block>()
|
||||
|
@ -37,13 +37,22 @@ import nautilus.game.arcade.game.games.mineware.challenge.NumberTracker;
|
||||
*/
|
||||
public class ChallengeMilkACow extends Challenge implements NumberTracker
|
||||
{
|
||||
private Villager _farmer;
|
||||
private Map<Cow, ArrayList<String>> _milkedCows = new HashMap<>();
|
||||
private Map<Cow, Hologram> _milkedCowsHolograms = new HashMap<>();
|
||||
private Map<Player, Integer> _score = new HashMap<>();
|
||||
private boolean _aquaColor;
|
||||
private static final int SCORE_GOAL = 5;
|
||||
private static final int LOCKED_INVENTORY_SLOT = 4;
|
||||
private static final int MAP_SPAWN_SHIFT = 1;
|
||||
private static final int SPAWN_COORDINATE_MULTIPLE = 2;
|
||||
private static final int MAP_HEIGHT = 1;
|
||||
|
||||
String[] _humanNames = new String[] {
|
||||
private static final double COW_NAMES_CHANCE = 0.3;
|
||||
private static final int COW_SPAWN_AMOUNT = 7;
|
||||
private static final int COW_SPAWN_LOCATION_MULTIPLIER = 2;
|
||||
|
||||
private static final float MILK_DELIVERY_SOUND_VOLUME = 2.0F;
|
||||
private static final float MILK_DELIVERY_SOUND_PITCH = 0.0F;
|
||||
|
||||
private static final int SCORE_DISPLAY_LOCATION_HEIGHT_ADD = 2;
|
||||
|
||||
private static final String[] HUMAN_NAMES = new String[] {
|
||||
"Tom",
|
||||
"Steve",
|
||||
"John",
|
||||
@ -54,7 +63,7 @@ public class ChallengeMilkACow extends Challenge implements NumberTracker
|
||||
"Jim"
|
||||
};
|
||||
|
||||
String[] _cowNames = new String[] {
|
||||
private static final String[] COW_NAMES = new String[] {
|
||||
"Moosly",
|
||||
"Mooington",
|
||||
"Mooley",
|
||||
@ -65,32 +74,38 @@ public class ChallengeMilkACow extends Challenge implements NumberTracker
|
||||
"Moozzle",
|
||||
};
|
||||
|
||||
private Villager _farmer;
|
||||
private Map<Cow, ArrayList<String>> _milkedCows = new HashMap<>();
|
||||
private Map<Cow, Hologram> _milkedCowsHolograms = new HashMap<>();
|
||||
private Map<Player, Integer> _score = new HashMap<>();
|
||||
private boolean _aquaColor;
|
||||
|
||||
public ChallengeMilkACow(BawkBawkBattles host)
|
||||
{
|
||||
super(
|
||||
host,
|
||||
ChallengeType.FirstComplete,
|
||||
"Milk a Cow",
|
||||
"Milk 5 different cows.",
|
||||
"Milk " + SCORE_GOAL + " different cows.",
|
||||
"Deliver the milk to the villager!");
|
||||
|
||||
Settings.setUseMapHeight();
|
||||
Settings.setLockInventory(4);
|
||||
Settings.setLockInventory(LOCKED_INVENTORY_SLOT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<Location> createSpawns()
|
||||
{
|
||||
ArrayList<Location> spawns = new ArrayList<Location>();
|
||||
int size = getArenaSize() - 1;
|
||||
int size = getArenaSize() - MAP_SPAWN_SHIFT;
|
||||
|
||||
for (int x = -(size); x <= size; x++)
|
||||
{
|
||||
for (int z = -(size); z <= size; z++)
|
||||
{
|
||||
if (x % 2 == 0 && z % 2 == 0)
|
||||
if (x % SPAWN_COORDINATE_MULTIPLE == 0 && z % SPAWN_COORDINATE_MULTIPLE == 0)
|
||||
{
|
||||
spawns.add(getCenter().add(x + 0.5, 1.1, z + 0.5));
|
||||
spawns.add(getCenter().add(x + 0.5, MAP_HEIGHT, z + 0.5));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -105,7 +120,7 @@ public class ChallengeMilkACow extends Challenge implements NumberTracker
|
||||
{
|
||||
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);
|
||||
|
||||
@ -233,14 +248,14 @@ public class ChallengeMilkACow extends Challenge implements NumberTracker
|
||||
|
||||
spawnFarmerJoe();
|
||||
|
||||
String[] chosenNames = _humanNames;
|
||||
String[] chosenNames = HUMAN_NAMES;
|
||||
|
||||
if (UtilMath.r(5) == 0)
|
||||
if (Math.random() < COW_NAMES_CHANCE)
|
||||
{
|
||||
chosenNames = _cowNames;
|
||||
chosenNames = COW_NAMES;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
for (int i = 0; i <= COW_SPAWN_AMOUNT; i++)
|
||||
{
|
||||
spawnCow(chosenNames, i);
|
||||
}
|
||||
@ -275,7 +290,10 @@ public class ChallengeMilkACow extends Challenge implements NumberTracker
|
||||
|
||||
private Location getRandomLocation()
|
||||
{
|
||||
return getCenter().add(UtilMath.r(((getArenaSize() * 2) - 1) - (getArenaSize() - 1)), 1, UtilMath.r((getArenaSize() * 2) - 1) - (getArenaSize() - 1));
|
||||
return getCenter().add(
|
||||
UtilMath.r(((getArenaSize() * COW_SPAWN_LOCATION_MULTIPLIER) - 1) - (getArenaSize() - 1)),
|
||||
1,
|
||||
UtilMath.r((getArenaSize() * COW_SPAWN_LOCATION_MULTIPLIER) - 1) - (getArenaSize() - 1));
|
||||
}
|
||||
|
||||
private void milkCow(Player player, LivingEntity entity)
|
||||
@ -317,7 +335,7 @@ public class ChallengeMilkACow extends Challenge implements NumberTracker
|
||||
private void deliverMilk(Player player)
|
||||
{
|
||||
player.setItemInHand(new ItemStack(Material.BUCKET));
|
||||
player.playSound(player.getLocation(), Sound.ORB_PICKUP, 2, 0);
|
||||
player.playSound(player.getLocation(), Sound.ORB_PICKUP, MILK_DELIVERY_SOUND_VOLUME, MILK_DELIVERY_SOUND_PITCH);
|
||||
}
|
||||
|
||||
private int incrementScore(Player player)
|
||||
@ -329,7 +347,7 @@ public class ChallengeMilkACow extends Challenge implements NumberTracker
|
||||
|
||||
private void displayScore(LivingEntity entity, Player player, int score)
|
||||
{
|
||||
Location displayLoc = entity.getLocation().add(0, 2.0, 0);
|
||||
Location displayLoc = entity.getLocation().add(0, SCORE_DISPLAY_LOCATION_HEIGHT_ADD, 0);
|
||||
displayCount(player, displayLoc, selectScoreColor(score));
|
||||
}
|
||||
|
||||
@ -349,7 +367,7 @@ public class ChallengeMilkACow extends Challenge implements NumberTracker
|
||||
|
||||
private void checkCompletion(Player player, int score)
|
||||
{
|
||||
if (score >= 5)
|
||||
if (score >= SCORE_GOAL)
|
||||
{
|
||||
setCompleted(player);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user