From 1dec79c0faedd2e1b94501191130b45b8556628f Mon Sep 17 00:00:00 2001 From: Chiss Date: Wed, 3 Sep 2014 12:28:45 +1000 Subject: [PATCH] Minestrike update --- .../game/games/minestrike/MineStrike.java | 185 +++++++++++++++--- .../game/games/minestrike/ShopManager.java | 20 +- .../games/minestrike/items/StrikeItem.java | 2 +- .../items/grenades/FireGrenadeBase.java | 86 ++++++++ .../minestrike/items/grenades/Incendiary.java | 41 +--- .../minestrike/items/grenades/Molotov.java | 9 +- .../minestrike/items/guns/pistol/Glock18.java | 2 +- .../minestrike/items/guns/pistol/P2000.java | 2 +- 8 files changed, 268 insertions(+), 79 deletions(-) create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/FireGrenadeBase.java diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/MineStrike.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/MineStrike.java index 1fe537b7c..24134b6f7 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/MineStrike.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/MineStrike.java @@ -6,7 +6,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Color; import org.bukkit.Effect; @@ -71,6 +70,7 @@ import mineplex.core.recharge.RechargedEvent; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.minecraft.game.core.combat.event.CombatDeathEvent; +import mineplex.minecraft.game.core.condition.Condition.ConditionType; import mineplex.minecraft.game.core.damage.CustomDamageEvent; import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.GameType; @@ -83,6 +83,7 @@ import nautilus.game.arcade.game.GameTeam.PlayerState; import nautilus.game.arcade.game.games.minestrike.data.Bomb; import nautilus.game.arcade.game.games.minestrike.data.Bullet; import nautilus.game.arcade.game.games.minestrike.items.StrikeItem; +import nautilus.game.arcade.game.games.minestrike.items.StrikeItemType; import nautilus.game.arcade.game.games.minestrike.items.equipment.armor.Armor; import nautilus.game.arcade.game.games.minestrike.items.grenades.Grenade; import nautilus.game.arcade.game.games.minestrike.items.guns.Gun; @@ -122,6 +123,8 @@ public class MineStrike extends TeamGame private HashMap _bullets = new HashMap(); private HashMap _grenadesThrown = new HashMap(); + + private HashMap _incendiary = new HashMap(); private Bomb _bomb = null; private Item _bombItem = null; @@ -437,6 +440,11 @@ public class MineStrike extends TeamGame { _grenadesThrown.put(ent, grenade); } + + public void registerIncendiary(Location loc, long endTime) + { + _incendiary.put(loc, endTime); + } public Gun getGunInHand(Player player, ItemStack overrideStack) { @@ -570,7 +578,7 @@ public class MineStrike extends TeamGame Gun gun = getGunInHand(event.getPlayer(), event.getItemDrop().getItemStack()); if (gun != null) { - gun.drop(this, event.getPlayer(), false); + gun.drop(this, event.getPlayer(), false, false); event.getItemDrop().remove(); return; } @@ -579,7 +587,7 @@ public class MineStrike extends TeamGame Grenade grenade = getGrenadeInHand(event.getPlayer(), event.getItemDrop().getItemStack()); if (grenade != null) { - grenade.drop(this, event.getPlayer(), false); + grenade.drop(this, event.getPlayer(), false, false); event.getItemDrop().remove(); return; } @@ -633,9 +641,42 @@ public class MineStrike extends TeamGame toDrop.add(item); } + //Drop Primary + boolean primaryDropped = false; for (StrikeItem item : toDrop) { - item.drop(this, player, true); + if (item.getType() == StrikeItemType.PRIMARY_WEAPON) + { + item.drop(this, player, true, false); + primaryDropped = true; + } + } + + //Drop Remaining + boolean grenadeDropped = false; + for (StrikeItem item : toDrop) + { + //Record Primary Dropped + if (item.getType() == StrikeItemType.PRIMARY_WEAPON) + continue; + + //Pistol + if (item.getType() == StrikeItemType.SECONDARY_WEAPON) + { + item.drop(this, player, true, primaryDropped); + continue; + } + + //Grenade + if (item.getType() == StrikeItemType.GRENADE) + { + item.drop(this, player, true, grenadeDropped); + grenadeDropped = true; + continue; + } + + //Other + item.drop(this, player, true, false); } //Bomb @@ -732,12 +773,18 @@ public class MineStrike extends TeamGame { Arrow arrow = (Arrow)event.getEntity(); - //Particle - UtilParticle.PlayParticle(ParticleType.FIREWORKS_SPARK, arrow.getLocation(), 0, 0, 0, 0, 1); + Bullet bullet = _bullets.get(arrow); - //Sound - arrow.getWorld().playSound(event.getEntity().getLocation(), Sound.ENDERMAN_HIT, 1f, 1f); + //Particle + if (bullet != null && bullet.Shooter != null) + UtilParticle.PlayParticle(bullet.Shooter, ParticleType.FIREWORKS_SPARK, arrow.getLocation(), 0, 0, 0, 0, 1); + + //Hit Block Sound + arrow.getWorld().playSound(arrow.getLocation(), Sound.ENDERMAN_HIT, 1f, 1f); + //Bullet Whiz Sound + bulletWhizzSound(arrow.getLocation(), bullet); + //Block Particle try { @@ -763,32 +810,78 @@ public class MineStrike extends TeamGame e.printStackTrace(); } + _bullets.remove(arrow); arrow.remove(); - } + } }, 0); } - - @EventHandler(priority = EventPriority.MONITOR) - public void bulletFlybySound(UpdateEvent event) + + private void bulletWhizzSound(Location bulletEndLocation, Bullet bullet) { - if (event.getType() != UpdateType.TICK) + if (bullet == null) return; - - for (Player player : UtilServer.getPlayers()) + + long start = System.currentTimeMillis(); + + Location loc = bullet.Origin.clone(); + + HashSet hasPlayedFor = new HashSet(); + + if (bullet.Shooter != null) + hasPlayedFor.add(bullet.Shooter); + + //Move between points, check players + while (UtilMath.offset(loc, bulletEndLocation) > 1) { - for (Entity ent : _bullets.keySet()) + //This is used to calculate whether players are between current/end. + //Add 5 so you still hear the whizz if it hits just infront of you. + double offsetStartToEnd = UtilMath.offset(loc, bulletEndLocation) + 4; + + for (Player player : UtilServer.getPlayers()) { - if (UtilMath.offset(player.getEyeLocation(), ent.getLocation()) < 4) + if (hasPlayedFor.contains(player)) + continue; + + //Remove players who are not between current/end points + if (offsetStartToEnd < UtilMath.offset(player.getEyeLocation(), loc) && + offsetStartToEnd < UtilMath.offset(player.getEyeLocation(), bulletEndLocation)) { - if (_bullets.get(ent).bulletSound()) - { - player.playSound(ent.getLocation(), Sound.BAT_IDLE, (float)(0.2 + UtilMath.offset(player.getEyeLocation(), ent.getLocation()) / 4d), 1f); - } + hasPlayedFor.add(player); + continue; + } + + //Check + if (UtilMath.offset(player.getEyeLocation(), loc) < 4) + { + player.playSound(loc, Sound.BAT_IDLE, (float)(0.5 + Math.random() * 0.5), 1f); + hasPlayedFor.add(player); } } + + //Move Closer + loc.add(UtilAlg.getTrajectory(loc, bulletEndLocation)); } + + bullets++; + whizzTime += (System.currentTimeMillis() - start); } + //XXX Debug + public int bullets = 0; + public long whizzTime = 0; + @EventHandler + public void debugWhizzTime(UpdateEvent event) + { + if (event.getType() != UpdateType.SLOWER) + return; + + System.out.println("Bullets Fired: " + bullets); + System.out.println("Bullet Whizz Time: " + whizzTime); + + bullets = 0; + whizzTime = 0; + } + @EventHandler(priority=EventPriority.HIGH) public void damage(CustomDamageEvent event) { @@ -854,11 +947,16 @@ public class MineStrike extends TeamGame return; } + + //Gun Bullet bullet = _bullets.remove(event.GetProjectile()); if (bullet == null) return; + + //Bullet Whiz Sound + bulletWhizzSound(event.GetDamageePlayer().getEyeLocation(), bullet); //Wipe previous data! event.GetCancellers().clear(); @@ -941,7 +1039,7 @@ public class MineStrike extends TeamGame { Entity bullet = bulletIterator.next(); - if (!bullet.isValid() || bullet.getTicksLived() > 200) + if (!bullet.isValid() || bullet.getTicksLived() > 40) { bulletIterator.remove(); bullet.remove(); @@ -984,7 +1082,7 @@ public class MineStrike extends TeamGame if (gun.isStack(player.getInventory().getItem(slot))) { - gun.drop(this, player, false); + gun.drop(this, player, false, false); player.getInventory().setItem(slot, null); return; } @@ -1534,6 +1632,9 @@ public class MineStrike extends TeamGame for (Entity ent : _bullets.keySet()) ent.remove(); _bullets.clear(); + + //Incendiary + _incendiary.clear(); //Restock Ammo for (Gun gun : _gunsEquipped.keySet()) @@ -1696,6 +1797,44 @@ public class MineStrike extends TeamGame } } } + + @EventHandler + public void speedUpdate(UpdateEvent event) + { + if (!IsLive()) + return; + + if (event.getType() != UpdateType.TICK) + return; + + for (Player player : GetPlayers(true)) + { + if (UtilGear.isMat(player.getItemInHand(), Material.IRON_AXE) || UtilGear.isMat(player.getItemInHand(), Material.IRON_SWORD)) + Manager.GetCondition().Factory().Speed("Knife", player, player, 1.9, 0, false, false, false); + else + Manager.GetCondition().EndCondition(player, ConditionType.SPEED, null); + } + } + + @EventHandler + public void incendiaryUpdate(UpdateEvent event) + { + if (event.getType() != UpdateType.SLOW) + return; + + Iterator fireIterator = _incendiary.keySet().iterator(); + + while (fireIterator.hasNext()) + { + Location loc = fireIterator.next(); + + if (_incendiary.get(loc) < System.currentTimeMillis()) + fireIterator.remove(); + + else + loc.getWorld().playSound(loc, Sound.PIG_DEATH, 1f, 1f); + } + } public void removeScope(Player player) { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/ShopManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/ShopManager.java index 5b31f7427..af766806a 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/ShopManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/ShopManager.java @@ -15,6 +15,7 @@ import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.games.minestrike.items.StrikeItem; import nautilus.game.arcade.game.games.minestrike.items.StrikeItemType; import nautilus.game.arcade.game.games.minestrike.items.equipment.DefusalKit; +import nautilus.game.arcade.game.games.minestrike.items.equipment.armor.Armor; import nautilus.game.arcade.game.games.minestrike.items.equipment.armor.Helmet; import nautilus.game.arcade.game.games.minestrike.items.equipment.armor.Kevlar; import nautilus.game.arcade.game.games.minestrike.items.grenades.*; @@ -29,7 +30,6 @@ import org.bukkit.Color; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; -import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; @@ -60,7 +60,7 @@ public class ShopManager //Pistols slot = 9; - //addItem(team.GetColor() == ChatColor.RED ? new Glock18() : new USP(), player, slot++); + addItem(team.GetColor() == ChatColor.RED ? new Glock18() : new P2000(), player, slot++); addItem(new CZ75(), player, slot++); addItem(new Deagle(), player, slot++); @@ -77,9 +77,10 @@ public class ShopManager addItem(new AWP(), player, slot++); //Grenades - addItem(new FlashBang(), player, 15); - addItem(new HighExplosive(), player, 16); - addItem(new Smoke(), player, 17); + addItem(new FlashBang(), player, 14); + addItem(new HighExplosive(), player, 15); + addItem(new Smoke(), player, 16); + addItem(team.GetColor() == ChatColor.RED ? new Molotov() : new Incendiary(), player, 17); //Gear if (team.GetColor() == ChatColor.AQUA) @@ -133,20 +134,15 @@ public class ShopManager if (item instanceof Kevlar) { - System.out.println("Checking Kevlar"); - - Kevlar armor = (Kevlar)item; - if (armor.isArmor(player.getInventory().getChestplate())) + if (Armor.isArmor(player.getInventory().getChestplate())) { - System.out.println("Checking Kevlar TRUE"); return true; } } if (item instanceof Helmet) { - Helmet armor = (Helmet)item; - if (armor.isArmor(player.getInventory().getHelmet())) + if (Armor.isArmor(player.getInventory().getHelmet())) return true; } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/StrikeItem.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/StrikeItem.java index 646418cd0..c9e65a7db 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/StrikeItem.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/StrikeItem.java @@ -77,7 +77,7 @@ public abstract class StrikeItem return _skin; } - public void drop(MineStrike game, Player player, boolean natural) + public void drop(MineStrike game, Player player, boolean natural, boolean onlyDeregisterAndRemove) { Entity ent; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/FireGrenadeBase.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/FireGrenadeBase.java new file mode 100644 index 000000000..00d525b5e --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/FireGrenadeBase.java @@ -0,0 +1,86 @@ +package nautilus.game.arcade.game.games.minestrike.items.grenades; + +import java.util.HashMap; + +import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilEnt; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilParticle.ParticleType; +import nautilus.game.arcade.game.games.minestrike.MineStrike; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Entity; + +public abstract class FireGrenadeBase extends Grenade +{ + private long _baseTime; + + public FireGrenadeBase(String name, int price, int gemCost, Material skin, long burnTime) + { + super(name, new String[] + { + + }, + price, gemCost, Material.PORK, 1); + + _baseTime = burnTime; + } + + @Override + public boolean updateCustom(MineStrike game, Entity ent) + { + if (UtilEnt.isGrounded(ent)) + { + createFire(game, ent.getLocation()); + + return true; + } + + return false; + } + + private void createFire(final MineStrike game, final Location loc) + { + //Sound + loc.getWorld().playSound(loc, Sound.IRONGOLEM_THROW, 1f, 1f); + + //Particle + UtilParticle.PlayParticle(ParticleType.LAVA, loc.add(0, 0.2, 0), 0.3f, 0f, 0.3f, 0, 30); + + //Fire Blocks + final HashMap blocks = UtilBlock.getInRadius(loc, 3.5d); + for (final Block block : blocks.keySet()) + { + if (block.getType() != Material.AIR) + continue; + + if (!UtilBlock.solid(block.getRelative(BlockFace.DOWN))) + continue; + + UtilServer.getServer().getScheduler().scheduleSyncDelayedTask(game.Manager.GetPlugin(), new Runnable() + { + public void run() + { + game.Manager.GetBlockRestore().Add(block, 51, (byte)0, (long) (_baseTime + blocks.get(block) * _baseTime)); + } + }, 60 - (int)(60d * blocks.get(block))); + } + + //Initial Burn Sound + UtilServer.getServer().getScheduler().scheduleSyncDelayedTask(game.Manager.GetPlugin(), new Runnable() + { + public void run() + { + loc.getWorld().playSound(loc, Sound.PIG_DEATH, 1f, 1f); + } + }, 20); + + //Register + game.registerIncendiary(loc, System.currentTimeMillis() + (_baseTime*2-4000)); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/Incendiary.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/Incendiary.java index 06df38081..cfb9cecf8 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/Incendiary.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/Incendiary.java @@ -1,48 +1,11 @@ package nautilus.game.arcade.game.games.minestrike.items.grenades; -import java.util.HashMap; - -import mineplex.core.common.util.UtilBlock; -import mineplex.core.common.util.UtilEnt; -import mineplex.core.common.util.UtilParticle; -import mineplex.core.common.util.UtilParticle.ParticleType; -import mineplex.core.common.util.UtilPlayer; -import nautilus.game.arcade.game.games.minestrike.MineStrike; - import org.bukkit.Material; -import org.bukkit.Sound; -import org.bukkit.block.Block; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.event.entity.EntityDamageEvent.DamageCause; -public class Incendiary extends Grenade +public class Incendiary extends FireGrenadeBase { public Incendiary() { - super("HE Grenade", new String[] - { - - }, - 300, 0, Material.APPLE, 1); - } - - @Override - public boolean updateCustom(MineStrike game, Entity ent) - { - if (UtilEnt.isGrounded(ent)) - { - createFire(ent.getLocation().getBlock()); - - return true; - } - - return false; - } - - private void createFire(Block block) - { - // TODO Auto-generated method stub - + super("Incendiary", 600, 0, Material.PORK, 10000); } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/Molotov.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/Molotov.java index 44e51979b..f48224fd4 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/Molotov.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/Molotov.java @@ -1,6 +1,11 @@ package nautilus.game.arcade.game.games.minestrike.items.grenades; -public class Molotov -{ +import org.bukkit.Material; +public class Molotov extends FireGrenadeBase +{ + public Molotov() + { + super("Molotov", 400, 0, Material.GRILLED_PORK, 8000); + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/pistol/Glock18.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/pistol/Glock18.java index b29eef007..937761e0c 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/pistol/Glock18.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/pistol/Glock18.java @@ -16,7 +16,7 @@ public class Glock18 extends Gun { }, - 0, 0, //Cost, Gem Cost + 200, 0, //Cost, Gem Cost 20, 6, //Clip Size, Spare Ammo 120, 2000, //ROF, Reload Time 5, 0.01, 3.5, //Damage, Dropoff, Bullet Speed diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/pistol/P2000.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/pistol/P2000.java index 332867422..77f7b0be6 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/pistol/P2000.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/pistol/P2000.java @@ -16,7 +16,7 @@ public class P2000 extends Gun { }, - 0, 0, //Cost, Gem Cost + 200, 0, //Cost, Gem Cost 13, 4, //Clip Size, Spare Ammo 130, 2200, //ROF, Reload Time 6, 0.01, 3.5, //Damage, Dropoff, Bullet Speed