Improve Performance, add dynamic rot rate, change some loot and islands only rot on the top

This commit is contained in:
Sarah 2017-03-20 19:18:33 +01:00
parent 4f9cf987bd
commit f8f7c04f58
7 changed files with 193 additions and 40 deletions

View File

@ -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<Material> exclude)
{
int totalLoot = _totalLoot;
ArrayList<RandomItem> items = (ArrayList<RandomItem>) _randomItems.clone();
Iterator<RandomItem> 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();

View File

@ -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();
}
}

View File

@ -108,6 +108,8 @@ public class BoosterRing extends Crumbleable implements Listener
_hologram = new Hologram(host.getArcadeManager().getHologramManager(), _ringMiddle, "");
_hologram.setViewDistance(300);
init();
}
@EventHandler

View File

@ -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<Location> _initBlocks;
private ArrayList<Location> _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<Location> flatMap = new ArrayList<>();
ArrayList<Location> 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<Location>) _realBlocks.clone();
}
else
{
_realBlocks = (ArrayList<Location>) getBlocks().clone();
_initBlocks = (ArrayList<Location>) 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<Location>) getBlocks().clone();
try
{
return (getBlocks().size()/(_initBlocks.size()/100))/100;
return (_realBlocks.size()/(_initBlocks.size()));
}
catch (Exception e)
{
return 100;
return 1;
}
}
public ArrayList<Location> getRealBlocks()
{
return _realBlocks;
}
/**
* Overrideable method which is called by
* {@link #crumble(int, Material...)} or {@link #crumble(int)}

View File

@ -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 <br/>
@ -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<Material> 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());

View File

@ -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<Material> 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);
}
}

View File

@ -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<Location> 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)