Refactor Build Race and Chicken Shooting
This commit is contained in:
parent
3f13c5f518
commit
361e857bc7
@ -17,23 +17,26 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.UtilInv;
|
||||
import mineplex.core.common.util.UtilTextMiddle;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import nautilus.game.arcade.game.games.mineware.BawkBawkBattles;
|
||||
import nautilus.game.arcade.game.games.mineware.challenge.Challenge;
|
||||
import nautilus.game.arcade.game.games.mineware.challenge.ChallengeType;
|
||||
import nautilus.game.arcade.game.games.mineware.challenge.LogicTracker;
|
||||
import nautilus.game.arcade.game.games.mineware.tracker.SpeedyBuildersTracker;
|
||||
|
||||
/**
|
||||
* A challenge based on fast block placement.
|
||||
*/
|
||||
public class ChallengeBuildRace extends Challenge implements LogicTracker
|
||||
{
|
||||
private List<Player> _speedTracker = new ArrayList<>();
|
||||
private static final int MAP_SPAWN_SHIFT = 2;
|
||||
private static final int MAP_HEIGHT = 1;
|
||||
private static final double UNPLACEABLE_BLOCK_RADIUS_FROM_PLAYER = 1.5;
|
||||
private static final int BLOCK_TOWER_HEIGHT_LIMIT = 3;
|
||||
|
||||
// The amount of blocks for every hotbar slot.
|
||||
private int _inventoryBlockAmount = 5;
|
||||
private int BLOCK_AMOUNT = 5;
|
||||
|
||||
private Material[] _materials = {
|
||||
private Material[] MATERIALS = {
|
||||
Material.DIRT,
|
||||
Material.STONE,
|
||||
Material.COBBLESTONE,
|
||||
@ -45,6 +48,8 @@ public class ChallengeBuildRace extends Challenge implements LogicTracker
|
||||
Material.GLASS
|
||||
};
|
||||
|
||||
private List<Player> _speedTracker = new ArrayList<>();
|
||||
|
||||
public ChallengeBuildRace(BawkBawkBattles host)
|
||||
{
|
||||
super(
|
||||
@ -61,11 +66,11 @@ public class ChallengeBuildRace extends Challenge implements LogicTracker
|
||||
public ArrayList<Location> createSpawns()
|
||||
{
|
||||
ArrayList<Location> spawns = new ArrayList<Location>();
|
||||
int size = getArenaSize() - 2;
|
||||
int size = getArenaSize() - MAP_SPAWN_SHIFT;
|
||||
|
||||
for (Location location : circle(getCenter(), size, 1, true, false, 0))
|
||||
for (Location location : circle(getCenter(), size, MAP_HEIGHT, true, false, 0))
|
||||
{
|
||||
spawns.add(location.add(0.5, 1.1, 0.5));
|
||||
spawns.add(location.add(0.5, MAP_HEIGHT, 0.5));
|
||||
}
|
||||
|
||||
return spawns;
|
||||
@ -74,7 +79,7 @@ public class ChallengeBuildRace extends Challenge implements LogicTracker
|
||||
@Override
|
||||
public void createMap()
|
||||
{
|
||||
for (Location location : circle(getCenter(), getArenaSize(), 1, false, false, 0))
|
||||
for (Location location : circle(getCenter(), getArenaSize(), MAP_HEIGHT, false, false, 0))
|
||||
{
|
||||
Block block = location.getBlock();
|
||||
setBlock(block, Material.GRASS);
|
||||
@ -86,7 +91,7 @@ public class ChallengeBuildRace extends Challenge implements LogicTracker
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
for (Material allowed : _materials)
|
||||
for (Material allowed : MATERIALS)
|
||||
{
|
||||
Host.BlockPlaceAllow.add(allowed.getId());
|
||||
}
|
||||
@ -103,7 +108,7 @@ public class ChallengeBuildRace extends Challenge implements LogicTracker
|
||||
{
|
||||
_speedTracker.clear();
|
||||
|
||||
for (Material allowed : _materials)
|
||||
for (Material allowed : MATERIALS)
|
||||
{
|
||||
Host.BlockPlaceAllow.remove(allowed.getId());
|
||||
}
|
||||
@ -124,10 +129,6 @@ public class ChallengeBuildRace extends Challenge implements LogicTracker
|
||||
}
|
||||
|
||||
Block block = event.getBlock();
|
||||
addBlock(block);
|
||||
|
||||
// First Check
|
||||
// Checking if the player is trying to get off the map.
|
||||
|
||||
Block bottomVoid1 = block.getRelative(BlockFace.DOWN);
|
||||
Block bottomVoid2 = bottomVoid1.getRelative(BlockFace.DOWN);
|
||||
@ -135,42 +136,42 @@ public class ChallengeBuildRace extends Challenge implements LogicTracker
|
||||
|
||||
if (bottomVoid1.isEmpty() && bottomVoid2.isEmpty() && bottomVoid3.isEmpty())
|
||||
{
|
||||
UtilTextMiddle.display(null, C.cRed + "You can't place blocks that far from the ground.", 5, 40, 5, player);
|
||||
alert(player, C.cRed + "You can't place blocks that far from the ground.");
|
||||
blockBreakEffect(block, true);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Second Check
|
||||
// Checking if the player is trying to trap another player.
|
||||
if (!Data.isModifiedBlock(block.getRelative(BlockFace.DOWN)))
|
||||
{
|
||||
System.out.println("Cancel");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
for (Player others : getPlayersAlive())
|
||||
{
|
||||
if (others.equals(player))
|
||||
continue;
|
||||
|
||||
if (block.getLocation().add(0.5, 0.5, 0.5).distanceSquared(others.getLocation()) <= 1.5)
|
||||
if (UtilMath.offset2d(block.getLocation(), others.getLocation()) < UNPLACEABLE_BLOCK_RADIUS_FROM_PLAYER)
|
||||
{
|
||||
UtilTextMiddle.display(null, C.cRed + "You can't place blocks near other players.", 5, 40, 5, player);
|
||||
alert(player, C.cRed + "You can't place blocks near other players.");
|
||||
blockBreakEffect(block, true);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Third Check
|
||||
// Checking if the player is trying to make a tower up to the sky.
|
||||
|
||||
if (block.getLocation().getY() >= getCenter().getY() + 3)
|
||||
if (block.getLocation().getY() >= getCenter().getY() + BLOCK_TOWER_HEIGHT_LIMIT)
|
||||
{
|
||||
UtilTextMiddle.display("", C.cRed + "You can't build a tower that high.", 5, 40, 5, player);
|
||||
alert(player, C.cRed + "You can't build a tower that high.");
|
||||
blockBreakEffect(block, true);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Last Check
|
||||
// Checking if the player has successfully placed all blocks.
|
||||
addBlock(block);
|
||||
|
||||
ArrayList<ItemStack> items = UtilInv.getItems(player);
|
||||
|
||||
@ -198,7 +199,7 @@ public class ChallengeBuildRace extends Challenge implements LogicTracker
|
||||
long startTime = Settings.getStartTime();
|
||||
long finishTime = System.currentTimeMillis();
|
||||
|
||||
if (finishTime <= startTime + 15000)
|
||||
if (finishTime <= startTime + SpeedyBuildersTracker.GOAL)
|
||||
{
|
||||
_speedTracker.add(player);
|
||||
}
|
||||
@ -206,12 +207,12 @@ public class ChallengeBuildRace extends Challenge implements LogicTracker
|
||||
|
||||
private void setupInventoryContents(Player player)
|
||||
{
|
||||
ArrayList<Material> shuffledMaterials = new ArrayList<Material>(Arrays.asList(_materials));
|
||||
ArrayList<Material> shuffledMaterials = new ArrayList<Material>(Arrays.asList(MATERIALS));
|
||||
Collections.shuffle(shuffledMaterials);
|
||||
|
||||
for (Material material : shuffledMaterials)
|
||||
{
|
||||
ItemStack itemStack = new ItemStack(material, _inventoryBlockAmount);
|
||||
ItemStack itemStack = new ItemStack(material, BLOCK_AMOUNT);
|
||||
player.getInventory().addItem(itemStack);
|
||||
}
|
||||
}
|
||||
|
@ -41,6 +41,29 @@ import nautilus.game.arcade.game.games.mineware.challenge.NumberTracker;
|
||||
*/
|
||||
public class ChallengeChickenShooting extends Challenge implements NumberTracker
|
||||
{
|
||||
private static final int LOCKED_INVENTORY_SLOT = 4;
|
||||
private static final int MAP_SPAWN_SHIFT = 1;
|
||||
private static final int MAP_HEIGHT = 1;
|
||||
|
||||
private static final int SPAWN_COORDINATES_MULTIPLE = 2;
|
||||
private static final int INVENTORY_ARROW_SLOT = 31;
|
||||
private static final int PLAYER_SIZE_LARGE = 40;
|
||||
private static final int PLAYER_SIZE_MID = 20;
|
||||
|
||||
private static final int CHICKEN_SPAWN_SHIFT = 2;
|
||||
private static final int CHICKEN_SPAWN_HEIGHT = 15;
|
||||
private static final int CHICKEN_AMOUNT_MIN = 10;
|
||||
private static final int CHICKEN_AMOUNT_MULTIPLY = 3;
|
||||
private static final double CHICKEN_HEATH = 0.1;
|
||||
private static final double CHICKEN_BABY_SPAWN_CHANCE = 0.3;
|
||||
|
||||
private static final int SCORE_GOAL = 6;
|
||||
private static final int SCORE_COLOR_CHANGE_1 = 1;
|
||||
private static final int SCORE_COLOR_CHANGE_2 = 2;
|
||||
private static final int SCORE_COLOR_CHANGE_3 = 3;
|
||||
private static final int SCORE_COLOR_CHANGE_4 = 4;
|
||||
private static final int SCORE_COLOR_CHANGE_5 = 5;
|
||||
|
||||
private List<Chicken> _chickens = new ArrayList<>();
|
||||
private List<Location> _chickenSpawns = new ArrayList<>();
|
||||
private Map<Player, Integer> _score = new HashMap<>();
|
||||
@ -54,22 +77,22 @@ public class ChallengeChickenShooting extends Challenge implements NumberTracker
|
||||
"Shoot 6 chickens.");
|
||||
|
||||
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_COORDINATES_MULTIPLE == 0 && z % SPAWN_COORDINATES_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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -84,7 +107,7 @@ public class ChallengeChickenShooting 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);
|
||||
|
||||
@ -191,29 +214,35 @@ public class ChallengeChickenShooting extends Challenge implements NumberTracker
|
||||
return;
|
||||
}
|
||||
|
||||
event.AddMod("Ensure Death", null, 10, false);
|
||||
event.AddMod("Ensure Death", null, entity.getHealth(), false);
|
||||
checkCompleted(player, entity);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onUpdate(UpdateEvent event)
|
||||
{
|
||||
if (!isChallengeValid())
|
||||
return;
|
||||
|
||||
UpdateType speed;
|
||||
int alive = getPlayersIn(true).size();
|
||||
|
||||
if (alive >= 40)
|
||||
if (alive >= PLAYER_SIZE_LARGE)
|
||||
{
|
||||
speed = UpdateType.FASTEST;
|
||||
else if (alive >= 20)
|
||||
}
|
||||
else if (alive >= PLAYER_SIZE_MID)
|
||||
{
|
||||
speed = UpdateType.FASTER;
|
||||
}
|
||||
else
|
||||
{
|
||||
speed = UpdateType.FAST;
|
||||
}
|
||||
|
||||
if (event.getType() != speed)
|
||||
return;
|
||||
|
||||
if (!isChallengeValid())
|
||||
return;
|
||||
|
||||
removeChickensOnGround();
|
||||
spawnChicken();
|
||||
}
|
||||
@ -229,7 +258,7 @@ public class ChallengeChickenShooting extends Challenge implements NumberTracker
|
||||
|
||||
private void initializeChickenSpawns()
|
||||
{
|
||||
_chickenSpawns = (ArrayList<Location>) circle(getCenter(), getArenaSize() - 2, 1, false, false, 15);
|
||||
_chickenSpawns = (ArrayList<Location>) circle(getCenter(), getArenaSize() - CHICKEN_SPAWN_SHIFT, 1, false, false, CHICKEN_SPAWN_HEIGHT);
|
||||
}
|
||||
|
||||
private void addBowAndArrow()
|
||||
@ -246,7 +275,7 @@ public class ChallengeChickenShooting extends Challenge implements NumberTracker
|
||||
{
|
||||
PlayerInventory inv = player.getInventory();
|
||||
inv.setItem(Settings.getLockedSlot(), bow);
|
||||
inv.setItem(31, arrow);
|
||||
inv.setItem(INVENTORY_ARROW_SLOT, arrow);
|
||||
|
||||
_score.put(player, 0);
|
||||
}
|
||||
@ -256,7 +285,7 @@ public class ChallengeChickenShooting extends Challenge implements NumberTracker
|
||||
{
|
||||
int score = showAndIncrementScore(player, entity);
|
||||
|
||||
if (score == 6)
|
||||
if (score == SCORE_GOAL)
|
||||
{
|
||||
setCompleted(player);
|
||||
}
|
||||
@ -277,23 +306,23 @@ public class ChallengeChickenShooting extends Challenge implements NumberTracker
|
||||
|
||||
private String selectScoreColor(int score)
|
||||
{
|
||||
if (score == 1)
|
||||
if (score == SCORE_COLOR_CHANGE_1)
|
||||
{
|
||||
return C.cWhiteB + score;
|
||||
}
|
||||
else if (score == 2)
|
||||
else if (score == SCORE_COLOR_CHANGE_2)
|
||||
{
|
||||
return C.cGrayB + score;
|
||||
}
|
||||
else if (score == 3)
|
||||
else if (score == SCORE_COLOR_CHANGE_3)
|
||||
{
|
||||
return C.cGreenB + score;
|
||||
}
|
||||
else if (score == 4)
|
||||
else if (score == SCORE_COLOR_CHANGE_4)
|
||||
{
|
||||
return C.cYellowB + score;
|
||||
}
|
||||
else if (score == 5)
|
||||
else if (score == SCORE_COLOR_CHANGE_5)
|
||||
{
|
||||
return C.cGoldB + score;
|
||||
}
|
||||
@ -321,7 +350,7 @@ public class ChallengeChickenShooting extends Challenge implements NumberTracker
|
||||
|
||||
private void spawnChicken()
|
||||
{
|
||||
if (_chickens.size() < 10 + (getPlayersIn(true).size() * 3))
|
||||
if (_chickens.size() < CHICKEN_AMOUNT_MIN + (getPlayersIn(true).size() * CHICKEN_AMOUNT_MULTIPLY))
|
||||
{
|
||||
Location spawn = UtilMath.randomElement(_chickenSpawns);
|
||||
|
||||
@ -329,10 +358,10 @@ public class ChallengeChickenShooting extends Challenge implements NumberTracker
|
||||
Chicken chicken = (Chicken) spawn.getWorld().spawnEntity(spawn, EntityType.CHICKEN);
|
||||
Host.CreatureAllow = false;
|
||||
|
||||
chicken.setMaxHealth(0.1);
|
||||
chicken.setHealth(0.1);
|
||||
chicken.setMaxHealth(CHICKEN_HEATH);
|
||||
chicken.setHealth(CHICKEN_HEATH);
|
||||
|
||||
if (Math.random() < 0.3)
|
||||
if (Math.random() < CHICKEN_BABY_SPAWN_CHANCE)
|
||||
{
|
||||
chicken.setBaby();
|
||||
}
|
||||
|
@ -16,6 +16,8 @@ import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeBuildRac
|
||||
*/
|
||||
public class SpeedyBuildersTracker extends ChallengeStatTracker
|
||||
{
|
||||
public static final long GOAL = 15000;
|
||||
|
||||
public SpeedyBuildersTracker(Game game)
|
||||
{
|
||||
super(game);
|
||||
|
Loading…
Reference in New Issue
Block a user