diff --git a/Plugins/Mineplex.Core/src/mineplex/core/loot/ChestLoot.java b/Plugins/Mineplex.Core/src/mineplex/core/loot/ChestLoot.java index 4dcf4eab3..39b89cfa2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/loot/ChestLoot.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/loot/ChestLoot.java @@ -1,6 +1,7 @@ package mineplex.core.loot; import java.util.ArrayList; +import java.util.Iterator; import mineplex.core.common.util.UtilMath; @@ -32,9 +33,32 @@ public class ChestLoot public ItemStack getLoot() { - int no = UtilMath.r(_totalLoot); + return getLoot(new ArrayList<>()); + } + + public ItemStack getLoot(ArrayList exclude) + { + int totalLoot = _totalLoot; + ArrayList items = (ArrayList) _randomItems.clone(); + + Iterator rItems = items.iterator(); + while (rItems.hasNext()) + { + RandomItem item = rItems.next(); + + for (Material mat : exclude) + { + if (item.getItemStack().getType() == mat) + { + totalLoot -= item.getAmount(); + rItems.remove(); + } + } + } + + int no = UtilMath.r(totalLoot); - for (RandomItem item : _randomItems) + for (RandomItem item : items) { no -= item.getAmount(); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/loot/RandomItem.java b/Plugins/Mineplex.Core/src/mineplex/core/loot/RandomItem.java index c903c6fa3..7e7eef062 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/loot/RandomItem.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/loot/RandomItem.java @@ -48,4 +48,15 @@ public class RandomItem return _item; } + + @Override + public boolean equals(Object obj) + { + if (!(obj instanceof RandomItem)) + return false; + + RandomItem item = (RandomItem) obj; + + return _item.getType() == item.getItemStack().getType(); + } } \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skyfall/BoosterRing.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skyfall/BoosterRing.java index fe248ae2b..0607c8cae 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skyfall/BoosterRing.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skyfall/BoosterRing.java @@ -108,6 +108,8 @@ public class BoosterRing extends Crumbleable implements Listener _hologram = new Hologram(host.getArcadeManager().getHologramManager(), _ringMiddle, ""); _hologram.setViewDistance(300); + + init(); } @EventHandler diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skyfall/Crumbleable.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skyfall/Crumbleable.java index 35c60e998..e50a6bb09 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skyfall/Crumbleable.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skyfall/Crumbleable.java @@ -4,6 +4,8 @@ import java.util.ArrayList; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import mineplex.core.common.util.MapUtil; import mineplex.core.common.util.UtilMath; @@ -18,6 +20,69 @@ public abstract class Crumbleable private boolean _crumble; private ArrayList _initBlocks; + private ArrayList _realBlocks; + + private boolean _onlyTop; + private int _height; + + public Crumbleable() + { + this(false, 0); + } + + public Crumbleable(boolean onlyTop, int height) + { + _onlyTop = onlyTop; + _height = height; + + _realBlocks = new ArrayList<>(); + } + + /** + * Must be called when getBlocks is set + */ + public void init() + { + if (_onlyTop) + { + ArrayList flatMap = new ArrayList<>(); + ArrayList locs = getBlocks(); + int y = Integer.MIN_VALUE; + for (Location loc : locs) + { + if (loc.getBlockY() > y) + y = loc.getBlockY(); + } + + for (Location loc : locs) + { + if (loc.getBlockY() == y) + flatMap.add(loc.clone()); + } + + for (Location loc : flatMap) + { + Block block = loc.getBlock(); + + int i = 0; + + while (block.getType() == Material.AIR && i <= _height) + { + block = block.getRelative(BlockFace.DOWN); + i++; + } + + _realBlocks.add(block.getLocation()); + } + _initBlocks = (ArrayList) _realBlocks.clone(); + } + else + { + _realBlocks = (ArrayList) getBlocks().clone(); + _initBlocks = (ArrayList) getBlocks().clone(); + } + + } /** * @see #crumble(int, Material...) @@ -46,7 +111,7 @@ public abstract class Crumbleable Material material = replacements[UtilMath.r(replacements.length)]; - if (getBlocks().isEmpty()) + if (_realBlocks.isEmpty()) { crumbledAway(); return true; @@ -54,16 +119,16 @@ public abstract class Crumbleable for (int i = 0; i < blocks; i++) { - if (getBlocks().isEmpty()) + if (_realBlocks.isEmpty()) { crumbledAway(); return true; } - Location toRemove = getBlocks().remove(UtilMath.r(getBlocks().size())); - if (toRemove.getBlock().getType() == Material.CHEST && getBlocks().size() > 25) + Location toRemove = _realBlocks.remove(UtilMath.r(_realBlocks.size())); + if (toRemove.getBlock().getType() == Material.CHEST && _realBlocks.size() > 25) { - getBlocks().add(toRemove); + _realBlocks.add(toRemove); continue; } @@ -86,7 +151,7 @@ public abstract class Crumbleable public boolean isCrumbledAway() { - return getBlocks().isEmpty(); + return _realBlocks.isEmpty(); } /** @@ -94,19 +159,21 @@ public abstract class Crumbleable */ public double crumblePercentage() { - if (_initBlocks == null) - _initBlocks = (ArrayList) getBlocks().clone(); - try { - return (getBlocks().size()/(_initBlocks.size()/100))/100; + return (_realBlocks.size()/(_initBlocks.size())); } catch (Exception e) { - return 100; + return 1; } } + public ArrayList getRealBlocks() + { + return _realBlocks; + } + /** * Overrideable method which is called by * {@link #crumble(int, Material...)} or {@link #crumble(int)} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skyfall/Island.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skyfall/Island.java index 5b91b7cad..8f4498362 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skyfall/Island.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skyfall/Island.java @@ -8,15 +8,11 @@ import org.bukkit.block.Block; import org.bukkit.block.Chest; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; -import mineplex.core.Managers; import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilMath; import mineplex.core.loot.ChestLoot; -import mineplex.core.titles.tracks.LuckyTrack; -import mineplex.core.titles.tracks.UnluckyTrack; - -import nautilus.game.arcade.ArcadeManager; /** * The Island Object represents a flying Island
@@ -70,6 +66,8 @@ public class Island extends Crumbleable */ public Island(Location location, ChestLoot loot, int bounds, int height) { + super(true, height); + _location = location; _bounds = bounds; _height = height; @@ -79,6 +77,7 @@ public class Island extends Crumbleable _loot = loot; registerBlocks(); + init(); } public void fillLoot(Block block) @@ -106,6 +105,7 @@ public class Island extends Crumbleable if (Math.random() > 0.95) items++; + ArrayList exclude = new ArrayList<>(); for (int i = 0; i < items; i++) { int trys = 0; @@ -116,7 +116,17 @@ public class Island extends Crumbleable slot = UtilMath.r(27); } - inventory.setItem(slot, _loot.getLoot()); + ItemStack item = _loot.getLoot(exclude); + exclude.add(item.getType()); + inventory.setItem(slot, item); + if (item.getType() == Material.DIAMOND) + { + inventory.setItem(slot + 1, new ItemStack(Material.STICK, 2)); + } + if (item.getType() == Material.BOW) + { + inventory.setItem(slot + 1, new ItemStack(Material.ARROW, UtilMath.r(6) + 1)); + } } } @@ -170,7 +180,7 @@ public class Island extends Crumbleable public void registerBlocks() { - for (Block block : UtilBlock.getInBoundingBox(_location.clone().add(_bounds, 0, _bounds), _location.clone().subtract(_bounds, _height, _bounds))) + for (Block block : UtilBlock.getInBoundingBox(_location.clone().add(_bounds, 0, _bounds), _location.clone().subtract(_bounds, _height, _bounds), false)) { if (block.getType() == Material.CHEST || block.getType() == Material.TRAPPED_CHEST) getChests().add(block.getLocation()); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skyfall/LootTable.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skyfall/LootTable.java index 444ed1bd2..5a2579dfa 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skyfall/LootTable.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skyfall/LootTable.java @@ -1,6 +1,9 @@ package nautilus.game.arcade.game.games.skyfall; +import java.util.ArrayList; + import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; import mineplex.core.common.util.F; import mineplex.core.itemstack.ItemStackFactory; @@ -24,7 +27,6 @@ public class LootTable new RandomItem(Material.MUSHROOM_SOUP, 15, 1, 1), new RandomItem(Material.WHEAT, 30, 1, 6), new RandomItem(Material.APPLE, 30, 1, 4), - new RandomItem(Material.PORK, 30, 1, 4), new RandomItem(Material.ROTTEN_FLESH, 40, 1, 6), new RandomItem(Material.WOOD_AXE, 100), @@ -69,7 +71,6 @@ public class LootTable new RandomItem(Material.PUMPKIN_PIE, 20, 1, 3), new RandomItem(Material.APPLE, 20, 2, 6), - new RandomItem(Material.IRON_INGOT, 30, 1, 2), new RandomItem(Material.DIAMOND, 30) ); @@ -152,4 +153,33 @@ public class LootTable return new LootTable(_unbreakable, items); } + + public LootTable excludes(ArrayList randomItems) + { + int size = _items.length - randomItems.size(); + RandomItem[] items = new RandomItem[size]; + + int i = 0; + + for (RandomItem item : _items) + { + boolean cont = false; + + for (Material other : randomItems) + { + if (item.getItemStack().getType() == other) + { + cont = true; + } + } + + if (cont) + continue; + + items[i] = item; + i++; + } + + return new LootTable(_unbreakable, items); + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skyfall/Skyfall.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skyfall/Skyfall.java index 8910b4a3d..edb873abe 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skyfall/Skyfall.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skyfall/Skyfall.java @@ -104,10 +104,8 @@ public abstract class Skyfall extends Game private static final long CHEST_REFILL_ANNOUNCE_TIME = 1000*60*3; // 3 minutes private static final long ELYTRA_TAKEAWAY = 1000; - private static final long RING_ROT_TIME = 1000*60*3; // 3 Minutes + private static final long ISLAND_ROT_TIME = 1000*60*5; // 3 Minutes - private static int ISLAND_CRUMBLE_RATE = 20; - private static int BIG_ISLAND_CRUMBLE_RATE = 20; private static final int RING_CRUMBLE_RATE = 3; private static final float RING_BOOST_STRENGTH = 2.5F; @@ -123,6 +121,8 @@ public abstract class Skyfall extends Game private static final long EAT_RECHARGE = 500; // 0.5 Second + private int _islandCrumbleRate; + private int _bigIslandBounds; private int _bigIslandHeight; @@ -244,8 +244,7 @@ public abstract class Skyfall extends Game if(event.getMessage().contains("/Rate")) { int rate = Integer.parseInt(event.getMessage().split(" ")[1]); - ISLAND_CRUMBLE_RATE = rate; - BIG_ISLAND_CRUMBLE_RATE = rate; + _islandCrumbleRate = rate; UtilPlayer.message(event.getPlayer(), "Crumble rate changed to " + rate); event.setCancelled(true); return; @@ -395,7 +394,7 @@ public abstract class Skyfall extends Game // if (island.getLocation().getBlockY() >= GetTeamList().get(0).GetSpawns().get(0).getBlockY()) // mats = new Material[] {Material.AIR}; - if (!island.crumble(ISLAND_CRUMBLE_RATE, mats)) + if (!island.crumble(_islandCrumbleRate, mats)) { return islands; } @@ -403,7 +402,7 @@ public abstract class Skyfall extends Game if (_upperIsland.crumblePercentage() <= 0.5) islands.add(_upperIsland); - if (!_upperIsland.crumble(BIG_ISLAND_CRUMBLE_RATE, Material.COAL_BLOCK, Material.ENDER_STONE)) + if (!_upperIsland.crumble(_islandCrumbleRate, Material.COAL_BLOCK, Material.ENDER_STONE)) { _currentCrumble = (_upperIsland.getLocation().getBlockY() - _upperIsland.getHeight()); return islands; @@ -420,7 +419,7 @@ public abstract class Skyfall extends Game if (island.crumblePercentage() <= 0.5) islands.add(island); - if (!island.crumble(ISLAND_CRUMBLE_RATE, Material.COAL_BLOCK, Material.ENDER_STONE)) + if (!island.crumble(_islandCrumbleRate, Material.COAL_BLOCK, Material.ENDER_STONE)) { return islands; } @@ -429,7 +428,7 @@ public abstract class Skyfall extends Game islands.add(_lowerIsland); _currentCrumble = (_lowerIsland.getLocation().getBlockY() - _lowerIsland.getHeight()); - if (_lowerIsland.crumble(BIG_ISLAND_CRUMBLE_RATE, Material.COAL_BLOCK, Material.ENDER_STONE)) + if (_lowerIsland.crumble(_islandCrumbleRate, Material.COAL_BLOCK, Material.ENDER_STONE)) { while (!_lowerIsland.getBoosterRing().isCrumbledAway()) { @@ -740,7 +739,6 @@ public abstract class Skyfall extends Game public void registerBoosters() { - //int blocks = 0; ArrayList boosters = WorldData.GetDataLocs("ORANGE"); for (Location boosterMid : boosters) { @@ -758,13 +756,6 @@ public abstract class Skyfall extends Game ring.setBoostStrength(BIG_RING_BOOST_STRENGTH); } -// blocks += ring.getBlocks().size(); -// int secs = (int) (RING_ROT_TIME / 1000); -// _ringCrumbleRate = blocks / secs; -// -// if (_ringCrumbleRate < 1) -// _ringCrumbleRate = 1; - _boosterRings.add(ring); } } @@ -828,7 +819,7 @@ public abstract class Skyfall extends Game e.printStackTrace(); } } - } + } IslandSorter upperSorter = new IslandSorter(upperIslandMap); IslandSorter lowerSorter = new IslandSorter(lowerIslandMap); @@ -838,6 +829,24 @@ public abstract class Skyfall extends Game _islands.put(_lowerIsland, new TreeMap<>(lowerSorter)); _islands.get(_lowerIsland).putAll(lowerIslandMap); + + int blocks = 0; + + for (Island island : _islands.get(_upperIsland).keySet()) + blocks += island.getRealBlocks().size(); + + for (Island island : _islands.get(_lowerIsland).keySet()) + blocks += island.getRealBlocks().size(); + + blocks += _upperIsland.getRealBlocks().size(); + blocks += _lowerIsland.getRealBlocks().size(); + + + int ticks = (int) (((ISLAND_ROT_TIME / 1000) *20) / 3); + _islandCrumbleRate = blocks / ticks; + + if (_islandCrumbleRate < 1) + _islandCrumbleRate = 1; } public Island getCurrentIsland(Player player)