diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java index c60f4c16c..7cefa2340 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java @@ -238,7 +238,11 @@ public enum GameType MOBA(MobaClassic.class, GameDisplay.MOBA), MOBATraining(MobaTraining.class, GameDisplay.MOBATraining), - BattleRoyale(BattleRoyaleSolo.class, GameDisplay.BattleRoyale), + BattleRoyale(BattleRoyaleSolo.class, GameDisplay.BattleRoyale, new Pair[] + { + Pair.create(MinecraftVersion.Version1_8, "http://file.mineplex.com/ResStrikeGames18.zip"), + Pair.create(MinecraftVersion.Version1_9, "http://file.mineplex.com/ResStrikeGames19.zip") + }, false), Event(EventGame.class, GameDisplay.Event, new GameType[]{ GameType.BaconBrawl, GameType.Barbarians, GameType.Bridge, GameType.Build, GameType.Build, diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/battleroyale/BattleRoyale.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/battleroyale/BattleRoyale.java index e1cbaab7c..c4695a3b7 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/battleroyale/BattleRoyale.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/battleroyale/BattleRoyale.java @@ -12,6 +12,7 @@ import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilTextBottom; import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilWorld; +import mineplex.core.itemstack.ItemBuilder; import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; @@ -20,6 +21,9 @@ import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.GameType; import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.game.Game; +import nautilus.game.arcade.game.games.minestrike.GunModule; +import nautilus.game.arcade.game.games.minestrike.items.guns.GunStats; +import nautilus.game.arcade.game.modules.StrikeGamesModule; import nautilus.game.arcade.game.modules.chest.ChestLootModule; import nautilus.game.arcade.game.modules.chest.ChestLootPool; import nautilus.game.arcade.game.modules.compass.CompassModule; @@ -29,6 +33,8 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.WorldBorder; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.entity.Chicken; import org.bukkit.entity.EnderDragon; import org.bukkit.entity.Player; @@ -59,12 +65,18 @@ public abstract class BattleRoyale extends Game private final Map _playerData = new HashMap<>(70); + protected GunModule _gunModule; + protected WorldBorder _border; + private boolean _colouredMessage; public BattleRoyale(ArcadeManager manager, GameType gameType, Kit[] kits, String[] gameDesc) { super(manager, gameType, kits, gameDesc); + // TODO REMOVE THIS + TeleportsDisqualify = false; + PrepareTime = PREPARE_TIME; PrepareFreeze = false; Damage = false; @@ -74,6 +86,7 @@ public abstract class BattleRoyale extends Game HungerSet = 20; DeathTeleport = false; WorldChunkUnload = true; + GameTimeout = TimeUnit.MINUTES.toMillis(40); ItemDrop = true; ItemPickup = true; @@ -83,33 +96,81 @@ public abstract class BattleRoyale extends Game InventoryOpenBlock = true; InventoryOpenChest = true; - new CompassModule() + BlockBreakAllow.add(Material.GLASS.getId()); + BlockBreakAllow.add(Material.STAINED_GLASS.getId()); + BlockBreakAllow.add(Material.THIN_GLASS.getId()); + BlockBreakAllow.add(Material.STAINED_GLASS_PANE.getId()); + BlockBreakAllow.add(Material.LEAVES.getId()); + + _gunModule = new GunModule(this); + _gunModule.EnableCleaning = false; + _gunModule.EnableDrop = false; + _gunModule.EnablePickup = false; + _gunModule.BlockRegeneration = false; + _gunModule.EnableNormalArmor = true; + + new StrikeGamesModule(_gunModule) .register(this); - new ChestLootModule() - .registerChestType("Standard", - - // Swords - new ChestLootPool() - .addItem(new ItemStack(Material.WOOD_SWORD)) - .addItem(new ItemStack(Material.STONE_SWORD)) - , - // Armour - new ChestLootPool() - .addItem(new ItemStack(Material.LEATHER_HELMET)) - .addItem(new ItemStack(Material.LEATHER_CHESTPLATE)) - .addItem(new ItemStack(Material.LEATHER_LEGGINGS)) - .addItem(new ItemStack(Material.LEATHER_BOOTS)) - ) + new CompassModule() .register(this); } @Override public void ParseData() { - ChestLootModule chestModule = getModule(ChestLootModule.class); + new ChestLootModule() + .spawnNearbyDataPoints() + .registerChestType("Standard", WorldData.GetDataLocs("ORANGE"), - chestModule.setSpawnsForType("Standard", WorldData.GetDataLocs("ORANGE")); + // Guns + new ChestLootPool() + .addItem(buildFromGun(GunStats.GLOCK_18)) + .addItem(buildFromGun(GunStats.CZ75)) + .addItem(buildFromGun(GunStats.DEAGLE)) + .addItem(buildFromGun(GunStats.P250)) + .addItem(buildFromGun(GunStats.P2000)) + .addItem(buildFromGun(GunStats.AK47), 0.2) + .addItem(buildFromGun(GunStats.M4A4), 0.2) + .setProbability(0.4) + , + + // Weapons + new ChestLootPool() + .addItem(new ItemStack(Material.WOOD_SWORD)) + .addItem(new ItemStack(Material.STONE_SWORD), 0.3) + .setProbability(0.5) + , + + // Armour + new ChestLootPool() + .addItem(new ItemStack(Material.LEATHER_HELMET)) + .addItem(new ItemStack(Material.LEATHER_CHESTPLATE)) + .addItem(new ItemStack(Material.LEATHER_LEGGINGS)) + .addItem(new ItemStack(Material.LEATHER_BOOTS)) + , + + // Food + new ChestLootPool() + .addItem(new ItemStack(Material.RAW_FISH), 1, 3) + .addItem(new ItemStack(Material.RAW_BEEF), 1, 3) + .addItem(new ItemStack(Material.RAW_CHICKEN), 1, 3) + .addItem(new ItemStack(Material.MUTTON), 1, 3) + .addItem(new ItemStack(Material.MELON), 1, 3) + .addItem(new ItemStack(Material.BREAD), 1, 2, 0.4) + .addItem(new ItemStack(Material.COOKED_FISH), 0.2) + .addItem(new ItemStack(Material.COOKED_BEEF), 0.2) + .addItem(new ItemStack(Material.COOKED_CHICKEN), 0.2) + .addItem(new ItemStack(Material.COOKED_MUTTON), 0.2) + .addItem(new ItemStack(Material.COOKIE), 0.2) + , + + // Misc + new ChestLootPool() + .addItem(new ItemStack(Material.STICK), 1, 2) + .setProbability(0.2) + ) + .register(this); WorldData.MinX = -MAX_CORD; WorldData.MinZ = -MAX_CORD; @@ -119,6 +180,13 @@ public abstract class BattleRoyale extends Game _border = WorldData.World.getWorldBorder(); } + private ItemStack buildFromGun(GunStats gunStats) + { + return new ItemBuilder(gunStats.getSkin()) + .setTitle(C.cWhiteB + gunStats.getName()) + .build(); + } + @EventHandler public void prepare(GameStateChangeEvent event) { @@ -229,6 +297,17 @@ public abstract class BattleRoyale extends Game while (attempts++ < 20) { Location location = UtilAlg.getRandomLocation(GetSpectatorLocation(), 200, 0, 200); + Block block = location.getBlock(); + + while (!UtilBlock.solid(block)) + { + block = block.getRelative(BlockFace.DOWN); + } + + if (block.isLiquid()) + { + continue; + } if (UtilBlock.airFoliage(UtilBlock.getHighest(location.getWorld(), location.getBlock()))) { @@ -266,6 +345,8 @@ public abstract class BattleRoyale extends Game return; } + _colouredMessage = !_colouredMessage; + Iterator iterator = _playerData.keySet().iterator(); while (iterator.hasNext()) @@ -287,27 +368,25 @@ public abstract class BattleRoyale extends Game continue; } - UtilTextBottom.display((player.getTicksLived() % 5 == 0 ? C.cGreenB : C.cWhiteB) + "PRESS YOUR SNEAK KEY TO DISMOUNT YOUR DRAGON", player); + UtilTextBottom.display((_colouredMessage ? C.cGreenB : C.cWhiteB) + "PRESS YOUR SNEAK KEY TO DISMOUNT YOUR DRAGON", player); if (dragon.getPassenger() == null || chicken.getPassenger() == null) { - Recharge.Instance.useForce(player, "Fall Damage", TimeUnit.SECONDS.toMillis(10)); - UtilParticle.PlayParticleToAll(ParticleType.WITCH_MAGIC, player.getLocation(), 5, 5, 5, 0.01F, 100, ViewDist.NORMAL); - player.playSound(player.getLocation(), Sound.BLAZE_DEATH, 1, 0.6F); - dragon.remove(); - chicken.remove(); + if (!UtilTime.elapsed(GetStateTime(), 4000)) + { + player.sendMessage(F.main("Game", "Did you accidentally press sneak? Don't worry I'll put you back on your dragon.")); + dragon.setPassenger(chicken); + chicken.setPassenger(player); + continue; + } + + dismountDragon(player, royalePlayer); iterator.remove(); } } if (!Damage && UtilTime.elapsed(GetStateTime(), MAX_DRAGON_TIME)) { - _playerData.forEach((player, battleRoyalePlayer) -> - { - Recharge.Instance.useForce(player, "Fall Damage", TimeUnit.SECONDS.toMillis(10)); - player.sendMessage(F.main("Game", "You were too slow!")); - battleRoyalePlayer.getDragon().remove(); - battleRoyalePlayer.getChicken().remove(); - }); + _playerData.forEach(this::dismountDragon); _playerData.clear(); Announce(C.cRedB + "Grace Period Over!", false); @@ -323,6 +402,16 @@ public abstract class BattleRoyale extends Game } } + private void dismountDragon(Player player, BattleRoyalePlayer royalePlayer) + { + // Recharge this so that players won't take fall damage for the next 10 seconds + Recharge.Instance.useForce(player, "Fall Damage", TimeUnit.SECONDS.toMillis(10)); + player.playSound(player.getLocation(), Sound.BLAZE_DEATH, 1, 0.6F); + UtilParticle.PlayParticleToAll(ParticleType.WITCH_MAGIC, player.getLocation(), 5, 5, 5, 0.01F, 100, ViewDist.NORMAL); + royalePlayer.getDragon().remove(); + royalePlayer.getChicken().remove(); + } + @EventHandler public void fallDamage(CustomDamageEvent event) { @@ -344,4 +433,10 @@ public abstract class BattleRoyale extends Game event.blockList().clear(); } } + + @EventHandler + public void damageToLevel(CustomDamageEvent event) + { + event.SetDamageToLevel(false); + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/battleroyale/BattleRoyaleSolo.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/battleroyale/BattleRoyaleSolo.java index 0e1fca782..b41d01379 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/battleroyale/BattleRoyaleSolo.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/battleroyale/BattleRoyaleSolo.java @@ -1,7 +1,6 @@ package nautilus.game.arcade.game.games.battleroyale; import mineplex.core.common.util.C; -import mineplex.core.common.util.UtilWorld; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import nautilus.game.arcade.ArcadeManager; @@ -11,6 +10,7 @@ import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.games.moba.kit.KitPlayer; import nautilus.game.arcade.kit.Kit; import org.bukkit.ChatColor; +import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -70,8 +70,9 @@ public class BattleRoyaleSolo extends BattleRoyale Scoreboard.writeNewLine(); int size = (int) _border.getSize(); + Location center = _border.getCenter(); Scoreboard.write(C.cRedB + "World Border"); - Scoreboard.write(UtilWorld.locToStrClean(_border.getCenter())); + Scoreboard.write("(" + center.getBlockX() + ", " + center.getBlockZ() + ")"); Scoreboard.write(size + " Blocks Wide"); Scoreboard.draw(); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/modes/StrikeGames.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/modes/StrikeGames.java index 304140edd..cfb326659 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/modes/StrikeGames.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/modes/StrikeGames.java @@ -1,31 +1,5 @@ package nautilus.game.arcade.game.games.survivalgames.modes; -import java.util.HashMap; -import java.util.Iterator; - -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.Chest; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.enchantment.EnchantItemEvent; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.ItemSpawnEvent; -import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.player.PlayerDropItemEvent; -import org.bukkit.event.player.PlayerEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerItemConsumeEvent; -import org.bukkit.event.player.PlayerItemDamageEvent; -import org.bukkit.event.player.PlayerPickupItemEvent; -import org.bukkit.event.player.PlayerToggleSneakEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.PlayerInventory; -import org.bukkit.inventory.meta.ItemMeta; - import mineplex.core.common.util.F; import mineplex.core.common.util.UtilEvent; import mineplex.core.common.util.UtilEvent.ActionType; @@ -36,29 +10,28 @@ import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.loot.RandomItem; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; -import mineplex.minecraft.game.core.damage.CustomDamageEvent; import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.GameType; import nautilus.game.arcade.events.GameStateChangeEvent; -import nautilus.game.arcade.events.PlayerKitGiveEvent; -import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.games.minestrike.GunModule; -import nautilus.game.arcade.game.games.minestrike.items.StrikeItemType; -import nautilus.game.arcade.game.games.minestrike.items.grenades.FlashBang; -import nautilus.game.arcade.game.games.minestrike.items.grenades.Grenade; -import nautilus.game.arcade.game.games.minestrike.items.grenades.HighExplosive; -import nautilus.game.arcade.game.games.minestrike.items.grenades.Incendiary; -import nautilus.game.arcade.game.games.minestrike.items.grenades.Molotov; -import nautilus.game.arcade.game.games.minestrike.items.grenades.Smoke; -import nautilus.game.arcade.game.games.minestrike.items.guns.Gun; import nautilus.game.arcade.game.games.minestrike.items.guns.GunStats; -import nautilus.game.arcade.game.games.minestrike.items.guns.GunType; -import nautilus.game.arcade.game.games.minestrike.items.guns.Shotgun; import nautilus.game.arcade.game.games.survivalgames.SoloSurvivalGames; import nautilus.game.arcade.game.games.survivalgames.SupplyChestOpenEvent; import nautilus.game.arcade.game.games.survivalgames.kit.KitLooter; import nautilus.game.arcade.game.games.survivalgames.modes.kit.KitPlayer; +import nautilus.game.arcade.game.modules.StrikeGamesModule; import nautilus.game.arcade.kit.Kit; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.Chest; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.ItemSpawnEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; /** * StrikeGames @@ -68,12 +41,8 @@ import nautilus.game.arcade.kit.Kit; public class StrikeGames extends SoloSurvivalGames { - private GunModule _gunModule; - private long _peacePhase; private boolean _peace = false; - - private HashMap _helmets; public StrikeGames(ArcadeManager manager) { @@ -83,19 +52,20 @@ public class StrikeGames extends SoloSurvivalGames }, GameType.StrikeGames); Damage = false; - - _helmets = new HashMap<>(); - + _peacePhase = 20000; HungerSet = 20; - _gunModule = new GunModule(this); - _gunModule.EnableCleaning = false; - _gunModule.EnableDrop = false; - _gunModule.EnablePickup = false; - _gunModule.BlockRegeneration = false; - _gunModule.EnableNormalArmor = true; + GunModule gunModule = new GunModule(this); + gunModule.EnableCleaning = false; + gunModule.EnableDrop = false; + gunModule.EnablePickup = false; + gunModule.BlockRegeneration = false; + gunModule.EnableNormalArmor = true; + + new StrikeGamesModule(gunModule) + .register(this); } @EventHandler @@ -119,20 +89,6 @@ public class StrikeGames extends SoloSurvivalGames Damage = true; } - @EventHandler - public void eatingGrenades(PlayerItemConsumeEvent event) - { - if (event.getItem().getType() == Material.POTATO_ITEM - || event.getItem().getType() == Material.CARROT_ITEM - || event.getItem().getType() == Material.APPLE - || event.getItem().getType() == Material.PORK - || event.getItem().getType() == Material.GRILLED_PORK) - { - event.setCancelled(true); - } - - } - @EventHandler(priority = EventPriority.LOWEST) public void DeathmatchDamage(UpdateEvent event) { @@ -163,39 +119,6 @@ public class StrikeGames extends SoloSurvivalGames Announce(F.main("Game", "A Peace Phase of " + F.time((_peacePhase/1000) + "") + " seconds has started!")); } - @EventHandler(priority=EventPriority.HIGHEST) - public void addHelmet(PlayerToggleSneakEvent event) - { - if (!IsLive()) - return; - - if (!IsAlive(event.getPlayer())) - return; - - if (_gunModule.getScoped().containsKey(event.getPlayer())) - return; - - if (event.getPlayer().getInventory().getHelmet() != null) - _helmets.put(event.getPlayer(), event.getPlayer().getInventory().getHelmet()); - } - - @EventHandler(priority=EventPriority.HIGHEST) - public void pumpkinDrop(PlayerDeathEvent event) - { - Iterator itemIterator = event.getDrops().iterator(); - while (itemIterator.hasNext()) - { - ItemStack item = itemIterator.next(); - if (item.getType() == Material.PUMPKIN - || item.getType() == Material.PUMPKIN_STEM) - { - itemIterator.remove(); - } - } - if (_helmets.containsKey(event.getEntity())) - event.getDrops().add(_helmets.get(event.getEntity())); - } - @EventHandler public void disableCrafting(PlayerInteractEvent event) { @@ -205,13 +128,6 @@ public class StrikeGames extends SoloSurvivalGames if (event.getClickedBlock().getType() == Material.WORKBENCH) event.setCancelled(true); } - - @EventHandler - public void weaponEnchantment(EnchantItemEvent event) - { - if (!UtilItem.isArmor(event.getItem())) - event.setCancelled(true); - } public void setupLoot() { @@ -414,131 +330,6 @@ public class StrikeGames extends SoloSurvivalGames getSupplyBlocks().remove(block); } - @EventHandler - public void addEquipment(InventoryClickEvent event) - { - if (event.getCurrentItem() == null) - return; - - if (!(event.getWhoClicked() instanceof Player)) - return; - - Player player = (Player) event.getWhoClicked(); - - if (!(event.getClickedInventory() instanceof PlayerInventory)) - { - ItemStack stack = event.getCurrentItem(); - for (GunStats stat : GunStats.values()) - { - if (stat.getSkin() == stack.getType()) - { - Gun gun = null; - if (stat.getGunType() == GunType.SHOTGUN) - { - gun = new Shotgun(stat, _gunModule); - } - else - { - gun = new Gun(stat, _gunModule); - } - gun.setStack(stack); - gun.updateWeaponName(player, null, false); - gun.addID(); - _gunModule.registerGun(gun, player); - return; - } - } - - Grenade grenade = null; - - if (stack.getType() == Material.APPLE) - { - grenade = new HighExplosive(); - } - else if (stack.getType() == Material.CARROT_ITEM) - { - grenade = new FlashBang(); - } - else if (stack.getType() == Material.POTATO_ITEM) - { - grenade = new Smoke(); - } - else if (stack.getType() == Material.PORK) - { - grenade = new Incendiary(); - } - else if (stack.getType() == Material.GRILLED_PORK) - { - grenade = new Molotov(); - } - - if (grenade != null) - { - ItemMeta meta = stack.getItemMeta(); - meta.setDisplayName(grenade.getName()); - stack.setItemMeta(meta); - grenade.setStack(stack); - _gunModule.registerGrenade(grenade, player); - } - } - } - - @EventHandler - public void triggerPickup(PlayerPickupItemEvent event) - { - - if (!InProgress()) - return; - - if (!IsAlive(event.getPlayer())) - return; - - //Guns - Gun gun = _gunModule.getDroppedGuns().get(event.getItem()); - if (gun != null) - { - _gunModule.deregisterDroppedGun(gun); - _gunModule.registerGun(gun, event.getPlayer()); - gun.setStack(event.getItem().getItemStack()); - } - - //Grenades - Grenade grenade = _gunModule.getDroppedGrenades().get(event.getItem()); - if (grenade != null) - { - _gunModule.deregisterDroppedGrenade(grenade); - _gunModule.registerGrenade(grenade, event.getPlayer()); - grenade.setStack(event.getItem().getItemStack()); - } - } - - @EventHandler - public void triggerDrop(PlayerDropItemEvent event) - { - if (!InProgress()) - return; - - //Guns - Gun gun = _gunModule.getGunInHand(event.getPlayer(), event.getItemDrop().getItemStack()); - if (gun != null) - { - gun.drop(_gunModule, event.getPlayer(), false, false); - event.getItemDrop().remove(); - event.getPlayer().setItemInHand(null); - return; - } - - //Grenades - Grenade grenade = _gunModule.getGrenadeInHand(event.getPlayer(), event.getItemDrop().getItemStack()); - if (grenade != null) - { - grenade.drop(_gunModule, event.getPlayer(), false, false); - event.getItemDrop().remove(); - event.getPlayer().setItemInHand(null); - return; - } - } - @EventHandler @Override public void ItemSpawn(ItemSpawnEvent event) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/StrikeGamesModule.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/StrikeGamesModule.java new file mode 100644 index 000000000..a398eba40 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/StrikeGamesModule.java @@ -0,0 +1,220 @@ +package nautilus.game.arcade.game.modules; + +import mineplex.core.common.util.UtilItem; +import nautilus.game.arcade.game.games.minestrike.GunModule; +import nautilus.game.arcade.game.games.minestrike.items.grenades.FlashBang; +import nautilus.game.arcade.game.games.minestrike.items.grenades.Grenade; +import nautilus.game.arcade.game.games.minestrike.items.grenades.HighExplosive; +import nautilus.game.arcade.game.games.minestrike.items.grenades.Incendiary; +import nautilus.game.arcade.game.games.minestrike.items.grenades.Molotov; +import nautilus.game.arcade.game.games.minestrike.items.grenades.Smoke; +import nautilus.game.arcade.game.games.minestrike.items.guns.Gun; +import nautilus.game.arcade.game.games.minestrike.items.guns.GunStats; +import nautilus.game.arcade.game.games.minestrike.items.guns.GunType; +import nautilus.game.arcade.game.games.minestrike.items.guns.Shotgun; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.enchantment.EnchantItemEvent; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerItemConsumeEvent; +import org.bukkit.event.player.PlayerPickupItemEvent; +import org.bukkit.event.player.PlayerToggleSneakEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.HashMap; +import java.util.Map; + +public class StrikeGamesModule extends Module +{ + + private final Map _helmets; + private final GunModule _gunModule; + + public StrikeGamesModule(GunModule gunModule) + { + _gunModule = gunModule; + _helmets = new HashMap<>(); + } + + @EventHandler + public void eatingGrenades(PlayerItemConsumeEvent event) + { + Material material = event.getItem().getType(); + + switch (material) + { + case POTATO_ITEM: + case CARROT_ITEM: + case APPLE: + case PORK: + case GRILLED_PORK: + event.setCancelled(true); + break; + } + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void addHelmet(PlayerToggleSneakEvent event) + { + Player player = event.getPlayer(); + ItemStack helmet = player.getInventory().getHelmet(); + + if (!getGame().IsLive() || !getGame().IsAlive(player) || _gunModule.getScoped().containsKey(player) || helmet == null) + { + return; + } + + _helmets.put(event.getPlayer(), helmet); + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void pumpkinDrop(PlayerDeathEvent event) + { + Player player = event.getEntity(); + + event.getDrops().removeIf(item -> item.getType() == Material.PUMPKIN || item.getType() == Material.PUMPKIN_STEM); + + if (_helmets.containsKey(player)) + { + event.getDrops().add(_helmets.get(player)); + } + } + + @EventHandler + public void weaponEnchantment(EnchantItemEvent event) + { + if (!UtilItem.isArmor(event.getItem())) + { + event.setCancelled(true); + } + } + + @EventHandler + public void addEquipment(InventoryClickEvent event) + { + if (event.getCurrentItem() == null || !(event.getWhoClicked() instanceof Player) || event.getClickedInventory() instanceof PlayerInventory) + { + return; + } + + Player player = (Player) event.getWhoClicked(); + ItemStack stack = event.getCurrentItem(); + for (GunStats stat : GunStats.values()) + { + if (stat.getSkin() == stack.getType()) + { + Gun gun; + if (stat.getGunType() == GunType.SHOTGUN) + { + gun = new Shotgun(stat, _gunModule); + } + else + { + gun = new Gun(stat, _gunModule); + } + gun.setStack(stack); + gun.updateWeaponName(player, null, false); + gun.addID(); + _gunModule.registerGun(gun, player); + return; + } + } + + Grenade grenade = null; + + switch (stack.getType()) + { + case APPLE: + grenade = new HighExplosive(); + break; + case CARROT_ITEM: + grenade = new FlashBang(); + break; + case POTATO_ITEM: + grenade = new Smoke(); + break; + case PORK: + grenade = new Incendiary(); + break; + case GRILLED_PORK: + grenade = new Molotov(); + break; + } + + if (grenade == null) + { + return; + } + + ItemMeta meta = stack.getItemMeta(); + meta.setDisplayName(grenade.getName()); + stack.setItemMeta(meta); + grenade.setStack(stack); + _gunModule.registerGrenade(grenade, player); + } + + @EventHandler + public void triggerPickup(PlayerPickupItemEvent event) + { + if (!getGame().InProgress() || !getGame().IsAlive(event.getPlayer())) + { + return; + } + + //Guns + Gun gun = _gunModule.getDroppedGuns().get(event.getItem()); + if (gun != null) + { + _gunModule.deregisterDroppedGun(gun); + _gunModule.registerGun(gun, event.getPlayer()); + gun.setStack(event.getItem().getItemStack()); + } + + //Grenades + Grenade grenade = _gunModule.getDroppedGrenades().get(event.getItem()); + if (grenade != null) + { + _gunModule.deregisterDroppedGrenade(grenade); + _gunModule.registerGrenade(grenade, event.getPlayer()); + grenade.setStack(event.getItem().getItemStack()); + } + } + + @EventHandler + public void triggerDrop(PlayerDropItemEvent event) + { + if (!getGame().InProgress()) + { + return; + } + + Player player = event.getPlayer(); + ItemStack itemStack = event.getItemDrop().getItemStack(); + + //Guns + Gun gun = _gunModule.getGunInHand(player, itemStack); + + if (gun != null) + { + gun.drop(_gunModule, player, false, false); + event.getItemDrop().remove(); + player.setItemInHand(null); + return; + } + + //Grenades + Grenade grenade = _gunModule.getGrenadeInHand(player, itemStack); + if (grenade != null) + { + grenade.drop(_gunModule, player, false, false); + event.getItemDrop().remove(); + player.setItemInHand(null); + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/chest/ChestLootModule.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/chest/ChestLootModule.java index b57c21cad..4ebeecc89 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/chest/ChestLootModule.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/chest/ChestLootModule.java @@ -1,5 +1,6 @@ package nautilus.game.arcade.game.modules.chest; +import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilEvent; import mineplex.core.common.util.UtilEvent.ActionType; @@ -44,6 +45,8 @@ public class ChestLootModule extends Module private long _destroyAfterOpened; private boolean _autoRotateChests = true; + private boolean _spawnNearby; + private int _spawnNearbyRadius = 8; public ChestLootModule() { @@ -51,27 +54,14 @@ public class ChestLootModule extends Module _chests = new HashMap<>(); } - public ChestLootModule registerChestType(String name, ChestLootPool... pools) + public ChestLootModule registerChestType(String name, List chestLocations, ChestLootPool... pools) { - return registerChestType(name, 1, pools); + return registerChestType(name, chestLocations, 1, pools); } - public ChestLootModule registerChestType(String name, double spawnChance, ChestLootPool... pools) + public ChestLootModule registerChestType(String name, List chestLocations, double spawnChance, ChestLootPool... pools) { - _chestTypes.add(new ChestType(name, spawnChance, pools)); - return this; - } - - public ChestLootModule setSpawnsForType(String typeName, List locations) - { - for (ChestType type : _chestTypes) - { - if (type.Name.equals(typeName)) - { - type.ChestSpawns = locations; - } - } - + _chestTypes.add(new ChestType(name, chestLocations, spawnChance, pools)); return this; } @@ -87,6 +77,19 @@ public class ChestLootModule extends Module return this; } + public ChestLootModule spawnNearbyDataPoints() + { + _spawnNearby = true; + return this; + } + + public ChestLootModule spawnNearbyDataPoints(int radius) + { + _spawnNearby = true; + _spawnNearbyRadius = radius; + return this; + } + @EventHandler(priority = EventPriority.HIGHEST) public void populateChests(GameStateChangeEvent event) { @@ -109,6 +112,19 @@ public class ChestLootModule extends Module if (chestType.SpawnChance == 1 || Math.random() < chestType.SpawnChance) { Block block = location.getBlock(); + + if (_spawnNearby) + { + Location nearby = getNearbyLocation(location); + + if (nearby == null) + { + continue; + } + + block = nearby.getBlock(); + } + block.setType(Material.CHEST); if (_autoRotateChests) @@ -144,12 +160,7 @@ public class ChestLootModule extends Module ChestMetadata metadata = getFromBlock(block); - if (metadata == null) - { - return; - } - - if (metadata.Opened) + if (metadata == null || metadata.Opened) { return; } @@ -220,6 +231,30 @@ public class ChestLootModule extends Module return 0; } + private Location getNearbyLocation(Location center) + { + int attempts = 0; + while (attempts++ < 20) + { + Location newLocation = UtilAlg.getRandomLocation(center, _spawnNearbyRadius, 1, _spawnNearbyRadius); + + if (isSuitable(newLocation.getBlock())) + { + return newLocation; + } + } + + return null; + } + + private boolean isSuitable(Block block) + { + Block up = block.getRelative(BlockFace.UP); + Block down = block.getRelative(BlockFace.DOWN); + + return block.getType() == Material.AIR && up.getType() == Material.AIR && down.getType() != Material.AIR && !UtilBlock.liquid(down) && !UtilBlock.liquid(up) && !UtilBlock.liquid(block); + } + private class ChestMetadata { @@ -236,25 +271,29 @@ public class ChestLootModule extends Module void populateChest(Chest chest) { - for (ChestLootPool pool : Type.Pool) + for (ChestLootPool pool : Type.Pools) { - pool.populateChest(chest); + if (pool.getProbability() == 1 || Math.random() < pool.getProbability()) + { + pool.populateChest(chest); + } } } } - public class ChestType + private class ChestType { String Name; double SpawnChance; - List Pool; + List Pools; List ChestSpawns; - public ChestType(String name, double spawnChance, ChestLootPool... pools) + ChestType(String name, List chestLocations, double spawnChance, ChestLootPool... pools) { Name = name; SpawnChance = spawnChance; - Pool = Arrays.asList(pools); + Pools = Arrays.asList(pools); + ChestSpawns = chestLocations; } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/chest/ChestLootPool.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/chest/ChestLootPool.java index 973597748..8683a66c0 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/chest/ChestLootPool.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/chest/ChestLootPool.java @@ -14,12 +14,14 @@ public class ChestLootPool private List _items; private int _minimumPerChest; private int _maximumPerChest; + private double _rarity; public ChestLootPool() { _items = new ArrayList<>(); _minimumPerChest = 1; _maximumPerChest = 1; + _rarity = 1; } public ChestLootPool addItem(ItemStack itemStack) @@ -50,6 +52,12 @@ public class ChestLootPool return this; } + public ChestLootPool setProbability(double probability) + { + _rarity = probability; + return this; + } + public void populateChest(Chest chest) { Inventory inventory = chest.getBlockInventory(); @@ -91,4 +99,9 @@ public class ChestLootPool return null; } + + public double getProbability() + { + return _rarity; + } } \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameFlagManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameFlagManager.java index a2819e252..ce46fb56a 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameFlagManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameFlagManager.java @@ -1096,9 +1096,14 @@ public class GameFlagManager implements Listener return; } - if (game.WorldWaterDamage <= 0 && !game.WorldData.GetCustomLocs("WATER_DAMAGE").isEmpty()) + if (game.WorldWaterDamage <= 0) { - game.WorldWaterDamage = 4; + if (!game.WorldData.GetCustomLocs("WATER_DAMAGE").isEmpty()) + { + game.WorldWaterDamage = 4; + } + + return; } for (Player player : game.GetPlayers(true))