use of mc.dragons.core.gameobject.region.Region in project DragonsOnline by UniverseCraft.
the class SpawnEntityTask method getSpawnRates.
/**
* Return spawn rates at the given location
*
* <p>May change over time due to changing
* entity distribution
*
* @apiNote Can be run asynchronously
*
* @param center
* @return
*/
private Map<String, Double> getSpawnRates(ReusableDataMap data, Location center, int level) {
int cap = -1;
int radiusCap = -1;
Set<Region> regions = regionLoader.getRegionsByLocation(center);
Map<String, Double> spawnRates = new HashMap<>();
Vector min = center.toVector();
Vector max = center.toVector();
data.set("cap", cap);
data.set("radiusCap", radiusCap);
data.set("min", min);
data.set("max", max);
for (Region region : regions) {
if (Boolean.valueOf(region.getFlags().getString(Region.FLAG_NOSPAWN))) {
return emptySpawnMap;
}
for (Entry<String, Double> entry : (Iterable<Entry<String, Double>>) region.getSpawnRates().entrySet()) {
if (entry.getValue() > spawnRates.getOrDefault(entry.getKey(), 0.0D)) {
spawnRates.put(entry.getKey(), entry.getValue());
}
}
int regionCap = Integer.valueOf(region.getFlags().getString(Region.FLAG_SPAWNCAP));
if (regionCap < cap && regionCap != -1 || cap == -1) {
cap = regionCap;
}
int theRadiusCap = Integer.valueOf(region.getFlags().getString(Region.FLAG_NEARBYSPAWNCAP)).intValue();
if (theRadiusCap < radiusCap && theRadiusCap != -1 || radiusCap == -1) {
radiusCap = theRadiusCap;
}
min = Vector.getMinimum(min, region.getMin().toVector());
max = Vector.getMaximum(max, region.getMax().toVector());
}
Map<String, Double> optimizedSpawnRates = spawnRates.entrySet().stream().sorted(comparingSpawnRateEntryForLevel(level)).collect(Collectors.toMap(Entry::getKey, Entry::getValue, (oldValue, newValue) -> oldValue, java.util.LinkedHashMap::new));
data.set("cap", cap);
data.set("radiusCap", radiusCap);
data.set("min", min);
data.set("max", max);
return optimizedSpawnRates;
}
Aggregations