From 0d406f19928654e6ff11f7a3d1b84c317ca6e766 Mon Sep 17 00:00:00 2001 From: Thanos paravantis Date: Sun, 25 Oct 2015 13:45:35 +0200 Subject: [PATCH] Evolution of Combat: Removed hunger, added 60 second peace time, several gameplay changes. --- .../ChallengeEvolutionOfCombat.java | 167 +++++++++++------- 1 file changed, 104 insertions(+), 63 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeEvolutionOfCombat.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeEvolutionOfCombat.java index e1b2f7863..ab8dc406d 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeEvolutionOfCombat.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenges/ChallengeEvolutionOfCombat.java @@ -24,31 +24,24 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Item; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.inventory.CraftItemEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; import org.bukkit.scheduler.BukkitRunnable; public class ChallengeEvolutionOfCombat extends Challenge { - // The number of seconds until the next amount of hunger is lost. - private static final int HungerLossTimer = 3; - - // The amount of food gained when attacking on another player. - // 2 represents 1 hunger bar. - private static final int CombatHungerGain = 4; - - // The amount of food lost when player is not attacking. - // 2 represents 1 hunger bar. - private static final int CombatHungerLoss = 2; + private static final int PeaceTime = 60; private boolean _firstWeaponCrafted = false; public ChallengeEvolutionOfCombat(MineWare host) { super(host, ChallengeType.LastStanding, "Evolution of Combat", "Find supplies and craft a weapon quicky.", "Then rush on your enemies!", - "Be the last human to stay alive."); + "You have " + PeaceTime + " seconds to prepare."); } @Override @@ -110,13 +103,13 @@ public class ChallengeEvolutionOfCombat extends Challenge int diamondChance = UtilMath.r(200); - if(diamondChance <= 1) + if(diamondChance <= 2) { block.setType(Material.DIAMOND_ORE); } } - // Iron Layer + // Gold Layer else if(i == 2) { @@ -128,15 +121,15 @@ public class ChallengeEvolutionOfCombat extends Challenge block.setData((byte) 5); } - int ironChance = UtilMath.r(100); + int goldChance = UtilMath.r(100); - if(ironChance <= 2) + if(goldChance <= 5) { - block.setType(Material.IRON_ORE); + block.setType(Material.GOLD_ORE); } } - // Coal Layer + // Iron Layer else if(i == 3) { @@ -148,11 +141,11 @@ public class ChallengeEvolutionOfCombat extends Challenge block.setData((byte) 5); } - int coalChance = UtilMath.r(100); + int ironChance = UtilMath.r(100); - if(coalChance <= 5) + if(ironChance <= 5) { - block.setType(Material.COAL_ORE); + block.setType(Material.IRON_ORE); } } @@ -186,9 +179,9 @@ public class ChallengeEvolutionOfCombat extends Challenge } @EventHandler - public void onEntityDamageByEntity1(EntityDamageByEntityEvent event) + public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { - if(!Host.IsLive() || !Host.isChallengeStarted()) + if(!Host.IsLive() || !Host.isChallengeStarted() || event.isCancelled()) return; if(event.getEntity() instanceof Player && event.getDamager() instanceof Player) @@ -198,7 +191,7 @@ public class ChallengeEvolutionOfCombat extends Challenge if(!name.contains("sword")) { - UtilTextMiddle.display("", C.cRed + "You are too weak to attack with your fists.", 5, 30, 5, damager); + UtilTextMiddle.display("", C.cRed + "You can only attack with a sword.", 5, 30, 5, damager); event.setCancelled(true); } } @@ -216,7 +209,7 @@ public class ChallengeEvolutionOfCombat extends Challenge if(name.contains("sword")) { Player player = (Player) event.getInventory().getHolder(); - UtilTextMiddle.display("", C.cGold + player.getName() + " has crafted the first weapon!", 5, 30, 5, UtilServer.getPlayers()); + UtilTextMiddle.display("", C.cGreen + player.getName() + " has crafted the first weapon!", 5, 30, 5, UtilServer.getPlayers()); for(Player others : UtilServer.getPlayers()) { @@ -252,48 +245,23 @@ public class ChallengeEvolutionOfCombat extends Challenge } @EventHandler - public void onEntityDamageByEntity2(EntityDamageByEntityEvent event) + public void onBlockBreak(BlockBreakEvent event) { - if(event.isCancelled() || !Host.IsLive() || !Host.isChallengeStarted()) + if(!Host.IsLive() || !Host.isChallengeStarted()) return; - if(event.getEntity() instanceof Player && event.getDamager() instanceof Player) - { - Player damager = (Player) event.getDamager(); + Block block = event.getBlock(); - int toAdd = damager.getFoodLevel() + CombatHungerGain; - damager.setFoodLevel(toAdd); + if(block.getType() == Material.IRON_ORE) + { + block.setType(Material.AIR); + block.getWorld().dropItemNaturally(block.getLocation(), new ItemStack(Material.IRON_INGOT)); } - } - - private void idleHungerTask() - { - new BukkitRunnable() + else if(block.getType() == Material.GOLD_ORE) { - @Override - public void run() - { - if(!Host.IsLive() || !Host.isChallengeStarted()) - { - cancel(); - return; - } - - for(Player player : Host.GetPlayers(true)) - { - int toRemove = player.getFoodLevel() - CombatHungerLoss; - - if(toRemove >= 0) - player.setFoodLevel(toRemove); - - if(player.getFoodLevel() == 10) - { - UtilTextMiddle.display("", C.cRed + "You must attack others to restore hunger.", 5, 30, 5, player); - player.playSound(player.getLocation(), Sound.ZOMBIE_WOOD, 0.5F, 0.8F); - } - } - } - }.runTaskTimer(Host.getArcadeManager().getPlugin(), 20 * HungerLossTimer, 60 * HungerLossTimer); + block.setType(Material.AIR); + block.getWorld().dropItemNaturally(block.getLocation(), new ItemStack(Material.GOLD_INGOT)); + } } @SuppressWarnings("deprecation") @@ -305,6 +273,69 @@ public class ChallengeEvolutionOfCombat extends Challenge block.setType(Material.AIR); } + private void peaceTimerTask() + { + new BukkitRunnable() + { + int time = PeaceTime; + + @Override + public void run() + { + if(!Host.IsLive() || !Host.isChallengeStarted()) + { + cancel(); + return; + } + + time--; + + if(time <= 0) + { + Host.DamagePvP = true; + UtilTextMiddle.display(C.cWhite + "Combat Time", C.cRed + "Be the last human to stay alive!", 5, 40, 5, UtilServer.getPlayers()); + playTimerSound(); + setTreeOnFire(); + cancel(); + } + else if(time == PeaceTime / 2) + { + UtilTextMiddle.display("", C.cGold + time + " seconds remaining.", 5, 40, 5, UtilServer.getPlayers()); + playTimerSound(); + } + } + }.runTaskTimer(Host.getArcadeManager().getPlugin(), 0L, 20L); + } + + private void setTreeOnFire() + { + Location fire = new Location(Host.WorldData.World, 0, 10, 0); + + for(Location near : UtilShapes.getSphereBlocks(fire, 2, 2, false)) + { + near.getBlock().setType(Material.FIRE); + } + } + + private void playTimerSound() + { + for(Player player : UtilServer.getPlayers()) + { + player.playSound(player.getLocation(), Sound.NOTE_PLING, 1.0F, 1.5F); + } + } + + private void equipWithTools() + { + for(Player player : Host.GetPlayers(true)) + { + PlayerInventory inv = player.getInventory(); + inv.addItem(new ItemStack(Material.STONE_AXE)); + inv.addItem(new ItemStack(Material.STONE_SPADE)); + inv.addItem(new ItemStack(Material.STONE_PICKAXE)); + } + } + @Override public void setupPlayers() { @@ -313,9 +344,11 @@ public class ChallengeEvolutionOfCombat extends Challenge Host.ItemPickup = true; Host.InventoryOpenBlock = true; Host.InventoryClick = true; - Host.DamagePvP = true; + Host.WorldBlockBurn = true; + Host.WorldFireSpread = true; - idleHungerTask(); + equipWithTools(); + peaceTimerTask(); } @Override @@ -327,6 +360,8 @@ public class ChallengeEvolutionOfCombat extends Challenge Host.InventoryOpenBlock = false; Host.InventoryClick = false; Host.DamagePvP = false; + Host.WorldBlockBurn = false; + Host.WorldFireSpread = false; _firstWeaponCrafted = false; @@ -336,7 +371,7 @@ public class ChallengeEvolutionOfCombat extends Challenge { Block treePart = parts.getBlock(); - if(treePart.getType() == Material.LOG || treePart.getType() == Material.LEAVES) + if(treePart.getType() == Material.LOG || treePart.getType() == Material.LEAVES || treePart.getType() == Material.FIRE) { treePart.setType(Material.AIR); } @@ -351,4 +386,10 @@ public class ChallengeEvolutionOfCombat extends Challenge } } } + + @Override + public long getMaxTime() + { + return 120000; + } }