Improve chicken spawning on chicken shooting
This commit is contained in:
parent
f8ff99fc58
commit
ddad17855f
@ -37,6 +37,7 @@ import nautilus.game.arcade.game.games.mineware.challenge.NumberTracker;
|
|||||||
public class ChallengeChickenShooting extends Challenge implements NumberTracker
|
public class ChallengeChickenShooting extends Challenge implements NumberTracker
|
||||||
{
|
{
|
||||||
private ArrayList<Chicken> _chickens = new ArrayList<Chicken>();
|
private ArrayList<Chicken> _chickens = new ArrayList<Chicken>();
|
||||||
|
private ArrayList<Location> _chickenSpawns = new ArrayList<Location>();
|
||||||
private HashMap<Player, Integer> _score = new HashMap<Player, Integer>();
|
private HashMap<Player, Integer> _score = new HashMap<Player, Integer>();
|
||||||
|
|
||||||
public ChallengeChickenShooting(BawkBawkBattles host)
|
public ChallengeChickenShooting(BawkBawkBattles host)
|
||||||
@ -102,6 +103,8 @@ public class ChallengeChickenShooting extends Challenge implements NumberTracker
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initializeChickenSpawns();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -111,25 +114,7 @@ public class ChallengeChickenShooting extends Challenge implements NumberTracker
|
|||||||
|
|
||||||
Host.DamagePvE = true;
|
Host.DamagePvE = true;
|
||||||
|
|
||||||
ItemStack bow = new ItemBuilder(Material.BOW)
|
addBowAndArrow();
|
||||||
.setUnbreakable(true)
|
|
||||||
.addEnchantment(Enchantment.ARROW_INFINITE, 1)
|
|
||||||
.addItemFlags(ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_UNBREAKABLE)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
ItemStack arrow = new ItemStack(Material.ARROW);
|
|
||||||
|
|
||||||
for (Player player : getPlayersAlive())
|
|
||||||
{
|
|
||||||
// It's better to add the items without setItem() method, to minimize for-loops.
|
|
||||||
|
|
||||||
PlayerInventory inv = player.getInventory();
|
|
||||||
inv.setItem(Settings.getLockedSlot(), bow);
|
|
||||||
inv.setItem(31, arrow);
|
|
||||||
|
|
||||||
_score.put(player, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -198,20 +183,14 @@ public class ChallengeChickenShooting extends Challenge implements NumberTracker
|
|||||||
}
|
}
|
||||||
|
|
||||||
event.AddMod("Ensure Death", null, 10, false);
|
event.AddMod("Ensure Death", null, 10, false);
|
||||||
|
checkCompleted(player, entity);
|
||||||
int score = showAndIncrementScore(player, entity);
|
|
||||||
|
|
||||||
if (score == 6)
|
|
||||||
{
|
|
||||||
setCompleted(player);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onUpdate(UpdateEvent event)
|
public void onUpdate(UpdateEvent event)
|
||||||
{
|
{
|
||||||
UpdateType speed;
|
UpdateType speed;
|
||||||
int alive = getPlayersIn(false).size();
|
int alive = getPlayersIn(true).size();
|
||||||
|
|
||||||
if (alive >= 40)
|
if (alive >= 40)
|
||||||
speed = UpdateType.FASTEST;
|
speed = UpdateType.FASTEST;
|
||||||
@ -236,13 +215,42 @@ public class ChallengeChickenShooting extends Challenge implements NumberTracker
|
|||||||
if (!isChallengeValid())
|
if (!isChallengeValid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Player player = event.getPlayer();
|
_score.remove(event.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
if (_score.containsKey(player))
|
private void initializeChickenSpawns()
|
||||||
|
{
|
||||||
|
_chickenSpawns = (ArrayList<Location>) circle(getCenter(), getArenaSize() - 2, 1, false, false, 15);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addBowAndArrow()
|
||||||
|
{
|
||||||
|
ItemStack bow = new ItemBuilder(Material.BOW)
|
||||||
|
.setUnbreakable(true)
|
||||||
|
.addEnchantment(Enchantment.ARROW_INFINITE, 1)
|
||||||
|
.addItemFlags(ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_UNBREAKABLE)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
ItemStack arrow = new ItemStack(Material.ARROW);
|
||||||
|
|
||||||
|
for (Player player : getPlayersAlive())
|
||||||
{
|
{
|
||||||
_score.remove(player);
|
PlayerInventory inv = player.getInventory();
|
||||||
}
|
inv.setItem(Settings.getLockedSlot(), bow);
|
||||||
|
inv.setItem(31, arrow);
|
||||||
|
|
||||||
|
_score.put(player, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkCompleted(Player player, LivingEntity entity)
|
||||||
|
{
|
||||||
|
int score = showAndIncrementScore(player, entity);
|
||||||
|
|
||||||
|
if (score == 6)
|
||||||
|
{
|
||||||
|
setCompleted(player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int showAndIncrementScore(Player player, LivingEntity entity)
|
private int showAndIncrementScore(Player player, LivingEntity entity)
|
||||||
@ -252,12 +260,40 @@ public class ChallengeChickenShooting extends Challenge implements NumberTracker
|
|||||||
Location location = player.getEyeLocation();
|
Location location = player.getEyeLocation();
|
||||||
location.add(UtilAlg.getTrajectory(location, entity.getEyeLocation()).multiply(Math.min(7, entity.getLocation().distance(location))));
|
location.add(UtilAlg.getTrajectory(location, entity.getEyeLocation()).multiply(Math.min(7, entity.getLocation().distance(location))));
|
||||||
|
|
||||||
displayCount(player, location, (score >= 6 ? C.cDGreen : score >= 4 ? C.cGreen : score >= 2 ? C.cRed : C.cDRed) + score);
|
displayCount(player, location, selectScoreColor(score));
|
||||||
|
|
||||||
_score.put(player, score);
|
_score.put(player, score);
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String selectScoreColor(int score)
|
||||||
|
{
|
||||||
|
if (score == 1)
|
||||||
|
{
|
||||||
|
return C.cWhiteB + score;
|
||||||
|
}
|
||||||
|
else if (score == 2)
|
||||||
|
{
|
||||||
|
return C.cGrayB + score;
|
||||||
|
}
|
||||||
|
else if (score == 3)
|
||||||
|
{
|
||||||
|
return C.cGreenB + score;
|
||||||
|
}
|
||||||
|
else if (score == 4)
|
||||||
|
{
|
||||||
|
return C.cYellowB + score;
|
||||||
|
}
|
||||||
|
else if (score == 5)
|
||||||
|
{
|
||||||
|
return C.cGoldB + score;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return C.cRedB + score;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void removeChickensOnGround()
|
private void removeChickensOnGround()
|
||||||
{
|
{
|
||||||
Iterator<Chicken> iterator = _chickens.iterator();
|
Iterator<Chicken> iterator = _chickens.iterator();
|
||||||
@ -276,9 +312,9 @@ public class ChallengeChickenShooting extends Challenge implements NumberTracker
|
|||||||
|
|
||||||
private void spawnChicken()
|
private void spawnChicken()
|
||||||
{
|
{
|
||||||
if (_chickens.size() < 11 + (getPlayersAlive().size() * 2))
|
if (_chickens.size() < 10 + (getPlayersIn(true).size() * 3))
|
||||||
{
|
{
|
||||||
Location spawn = getRandomLocation();
|
Location spawn = UtilMath.randomElement(_chickenSpawns);
|
||||||
|
|
||||||
Host.CreatureAllow = true;
|
Host.CreatureAllow = true;
|
||||||
Chicken chicken = (Chicken) spawn.getWorld().spawnEntity(spawn, EntityType.CHICKEN);
|
Chicken chicken = (Chicken) spawn.getWorld().spawnEntity(spawn, EntityType.CHICKEN);
|
||||||
@ -287,17 +323,15 @@ public class ChallengeChickenShooting extends Challenge implements NumberTracker
|
|||||||
chicken.setMaxHealth(0.1);
|
chicken.setMaxHealth(0.1);
|
||||||
chicken.setHealth(0.1);
|
chicken.setHealth(0.1);
|
||||||
|
|
||||||
|
if (Math.random() < 0.3)
|
||||||
|
{
|
||||||
|
chicken.setBaby();
|
||||||
|
}
|
||||||
|
|
||||||
_chickens.add(chicken);
|
_chickens.add(chicken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Location getRandomLocation()
|
|
||||||
{
|
|
||||||
int random = UtilMath.r(getArenaSize() * 2) - (getArenaSize());
|
|
||||||
|
|
||||||
return getCenter().add(random, 15, random);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Number getData(Player player)
|
public Number getData(Player player)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user