Search in sources :

Example 16 with Region

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;
}
Also used : NPCLoader(mc.dragons.core.gameobject.npc.NPCLoader) UserLoader(mc.dragons.core.gameobject.user.UserLoader) BukkitUtil.await(mc.dragons.core.util.BukkitUtil.await) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) NPCClass(mc.dragons.core.gameobject.npc.NPCClass) Set(java.util.Set) HashMap(java.util.HashMap) ReusableDataMap(mc.dragons.core.util.dataholder.ReusableDataMap) Collectors(java.util.stream.Collectors) Dragons(mc.dragons.core.Dragons) NPCClassLoader(mc.dragons.core.gameobject.npc.NPCClassLoader) Vector(org.bukkit.util.Vector) GameMode(org.bukkit.GameMode) GameObjectType(mc.dragons.core.gameobject.GameObjectType) RegionLoader(mc.dragons.core.gameobject.region.RegionLoader) Location(org.bukkit.Location) BlockUtil(mc.dragons.core.util.BlockUtil) Map(java.util.Map) Entry(java.util.Map.Entry) Region(mc.dragons.core.gameobject.region.Region) Comparator(java.util.Comparator) Collections(java.util.Collections) NPC(mc.dragons.core.gameobject.npc.NPC) Bukkit(org.bukkit.Bukkit) HashMap(java.util.HashMap) Region(mc.dragons.core.gameobject.region.Region) Vector(org.bukkit.util.Vector)

Aggregations

Region (mc.dragons.core.gameobject.region.Region)16 Player (org.bukkit.entity.Player)8 User (mc.dragons.core.gameobject.user.User)5 Document (org.bson.Document)5 GameObject (mc.dragons.core.gameobject.GameObject)4 NPC (mc.dragons.core.gameobject.npc.NPC)4 Location (org.bukkit.Location)4 Dragons (mc.dragons.core.Dragons)3 GameObjectType (mc.dragons.core.gameobject.GameObjectType)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 Collectors (java.util.stream.Collectors)2 Floor (mc.dragons.core.gameobject.floor.Floor)2 Item (mc.dragons.core.gameobject.item.Item)2 RegionLoader (mc.dragons.core.gameobject.region.RegionLoader)2 BlockUtil (mc.dragons.core.util.BlockUtil)2 Bukkit (org.bukkit.Bukkit)2 ChatColor (org.bukkit.ChatColor)2