Add max chests

This commit is contained in:
Sam 2017-01-23 19:56:00 +00:00
parent 8102ba2e4b
commit 2c8b8d4fb0
3 changed files with 18 additions and 31 deletions

View File

@ -13,11 +13,11 @@ public class ChestProperties
private final int _spawnRate;
private final int _expireRate;
private final int _spawnRadius;
private final double _percentile;
private final int _maxActive;
private long _lastSpawn;
public ChestProperties(String name, Material blockMaterial, String dataKey, int minAmount, int maxAmount, int spawnRate, int expireRate, int spawnRadius, double percentile)
public ChestProperties(String name, Material blockMaterial, String dataKey, int minAmount, int maxAmount, int spawnRate, int expireRate, int spawnRadius, int maxActive)
{
_name = name;
_blockMaterial = blockMaterial;
@ -27,7 +27,7 @@ public class ChestProperties
_spawnRate = spawnRate;
_expireRate = expireRate;
_spawnRadius = spawnRadius;
_percentile = percentile;
_maxActive = maxActive;
setLastSpawn();
}
@ -72,11 +72,11 @@ public class ChestProperties
return _spawnRadius;
}
public final double getPercentile()
public final int getMaxActive()
{
return _percentile;
return _maxActive;
}
public void setLastSpawn()
{
_lastSpawn = System.currentTimeMillis();

View File

@ -1,6 +1,5 @@
package mineplex.gemhunters.loot;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@ -55,9 +54,7 @@ public class LootModule extends MiniPlugin
private static final String SHEET_FILE_NAME = "GEM_HUNTERS_CHESTS";
private static final String CHEST_MASTER_SHEET_NAME = "CHEST_MASTER";
private static final long CHEST_DESPAWN_TIME_OPENED = TimeUnit.SECONDS.toMillis(15);
private static final String[] IGNORED_COLOURS = { "RED" };
private static final int MAX_SEARCH_ATTEMPTS = 40;
private static final int MAX_CHEST_PLACEMENT_RANGE = 10;
private static final int MAX_CHEST_CHECK_DISTANCE_SQUARED = 4;
private static final LootItemDeserialiser DESERIALISER = new LootItemDeserialiser();
private static final ChestPropertiesDeserialiser CHEST_DESERIALISER = new ChestPropertiesDeserialiser();
@ -68,7 +65,7 @@ public class LootModule extends MiniPlugin
private final Map<String, Set<LootItem>> _chestLoot;
private final Map<String, ChestProperties> _chestProperties;
private final List<SpawnedChest> _spawnedChest;
private final Set<SpawnedChest> _spawnedChest;
private final Map<String, Set<Integer>> _spawnedIndexes;
private final Set<LootItemReward> _itemRewards;
@ -81,7 +78,7 @@ public class LootModule extends MiniPlugin
_worldData = require(WorldDataModule.class);
_chestLoot = new HashMap<>();
_chestProperties = new HashMap<>();
_spawnedChest = new ArrayList<>(200);
_spawnedChest = new HashSet<>(200);
_spawnedIndexes = new HashMap<>(15);
_itemRewards = new HashSet<>();
@ -131,18 +128,8 @@ public class LootModule extends MiniPlugin
}
// Spawn new chests
dataPointLoop: for (String key : _chestProperties.keySet())
for (String key : _chestProperties.keySet())
{
// Some data points are ignored like the chest loot related to
// supply drops.
for (String ignore : IGNORED_COLOURS)
{
if (key.equals(ignore))
{
continue dataPointLoop;
}
}
List<Location> locations = _worldData.getDataLocation(key);
ChestProperties properties = _chestProperties.get(key);
@ -154,7 +141,7 @@ public class LootModule extends MiniPlugin
properties.setLastSpawn();
// Only spawn more chests if we need to
int max = (int) (_spawnedChest.size() * properties.getPercentile());
int max = properties.getMaxActive();
int spawned = 0;
for (SpawnedChest chest : _spawnedChest)
@ -165,12 +152,11 @@ public class LootModule extends MiniPlugin
}
}
// TODO fix this
// If there are too many chests of this type we can ignore it
// if (spawned > max)
// {
// continue;
// }
if (spawned > max)
{
continue;
}
Set<Integer> usedIndexes = _spawnedIndexes.get(key);
@ -204,7 +190,8 @@ public class LootModule extends MiniPlugin
usedIndexes.add(index);
randomLocation = locations.get(index);
Location chestToPlace = UtilAlg.getRandomLocation(randomLocation, MAX_CHEST_PLACEMENT_RANGE, 0, MAX_CHEST_PLACEMENT_RANGE);
int placeRadius = properties.getSpawnRadius();
Location chestToPlace = UtilAlg.getRandomLocation(randomLocation, placeRadius, 0, placeRadius);
Block block = chestToPlace.getBlock();
attempts = 0;

View File

@ -34,9 +34,9 @@ public class ChestPropertiesDeserialiser implements SheetObjectDeserialiser<Ches
int spawnRate = Integer.parseInt(values[4]);
int expireRate = Integer.parseInt(values[5]);
int spawnRadius = Integer.parseInt(values[6]);
double percentile = (double) Integer.parseInt(values.length > 7 ? values[7] : "0") / 100;
int maxActive = Integer.parseInt(values[7]);
return new ChestProperties(name, blockMaterial, dataKey, minAmount, maxAmount, spawnRate, expireRate, spawnRadius, percentile);
return new ChestProperties(name, blockMaterial, dataKey, minAmount, maxAmount, spawnRate, expireRate, spawnRadius, maxActive);
}
}