Search in sources :

Example 1 with Region

use of mc.dragons.core.gameobject.region.Region in project DragonsOnline by UniverseCraft.

the class LootTable method getDrops.

/**
 * @param loc
 * @return The items the NPC dropped at a specified location.
 *
 * @implNote Probabilities are factored in to this, so identical
 * 	calls may not produce identical results.
 */
public Set<Item> getDrops(Location loc) {
    if (lootTable == null) {
        return new HashSet<>();
    }
    double multiplier = Dragons.getInstance().getServerOptions().getDropChanceMultiplier();
    Set<Region> regions = regionLoader.getRegionsByLocation(loc);
    Set<Item> drops = new HashSet<>();
    for (Region region : regions) {
        Document regionLoots = (Document) lootTable.get(region.getName());
        if (regionLoots == null) {
            continue;
        }
        for (Entry<String, Object> loot : (Iterable<Entry<String, Object>>) regionLoots.entrySet()) {
            double chance = (double) loot.getValue();
            if (Math.random() < chance * multiplier / 100.0D) {
                ItemClass itemClass = itemClassLoader.getItemClassByClassName(loot.getKey());
                Item item = itemLoader.registerNew(itemClass);
                drops.add(item);
            }
        }
    }
    return drops;
}
Also used : Item(mc.dragons.core.gameobject.item.Item) ItemClass(mc.dragons.core.gameobject.item.ItemClass) Region(mc.dragons.core.gameobject.region.Region) Document(org.bson.Document) HashSet(java.util.HashSet)

Example 2 with Region

use of mc.dragons.core.gameobject.region.Region in project DragonsOnline by UniverseCraft.

the class RegionCommand method updateCorners.

private void updateCorners(CommandSender sender, String[] args) {
    if (!requirePlayer(sender))
        return;
    Region region = lookupRegion(sender, args[0]);
    if (region == null)
        return;
    Player player = player(sender);
    User user = user(sender);
    if (args.length == 2) {
        sender.sendMessage(ChatColor.RED + "Specify corner number! (1 or 2). /region <RegionName> corner <Corner#>");
        return;
    }
    switch(args[2].toLowerCase()) {
        case "1":
        case "a":
            user.getLocalData().append("regionSelCorner1", player.getLocation());
            sender.sendMessage(ChatColor.GREEN + "Corner 1 selection set to " + StringUtil.locToString(player.getLocation()) + ".");
            sender.sendMessage(ChatColor.GREEN + "Changes will not take effect until you set both corners and run /region " + args[1] + " corner go");
            break;
        case "2":
        case "b":
            user.getLocalData().append("regionSelCorner2", player.getLocation());
            sender.sendMessage(ChatColor.GREEN + "Corner 2 selection set to " + StringUtil.locToString(player.getLocation()) + ".");
            sender.sendMessage(ChatColor.GREEN + "Changes will not take effect until you set both corners and run /region " + args[0] + " corner go");
            break;
        case "go":
            Document base = Document.parse(region.getData().toJson());
            Vector corner1 = user.getLocalData().get("regionSelCorner1", Location.class).toVector();
            Vector corner2 = user.getLocalData().get("regionSelCorner2", Location.class).toVector();
            Vector newMin = Vector.getMinimum(corner1, corner2);
            Vector newMax = Vector.getMaximum(corner1, corner2);
            region.updateCorners(newMin.toLocation(player.getWorld()), newMax.toLocation(player.getWorld()));
            sender.sendMessage(ChatColor.GREEN + "Updated region corners successfully. Min=(" + StringUtil.vecToString(newMin) + "), Max=" + StringUtil.vecToString(newMax) + ")");
            AUDIT_LOG.saveEntry(region, user, base, "Updated region corners");
            break;
        default:
            sender.sendMessage(ChatColor.RED + "Invalid usage! /region <RegionName> corner <1|2|go>");
            break;
    }
}
Also used : Player(org.bukkit.entity.Player) User(mc.dragons.core.gameobject.user.User) Region(mc.dragons.core.gameobject.region.Region) Document(org.bson.Document) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 3 with Region

use of mc.dragons.core.gameobject.region.Region in project DragonsOnline by UniverseCraft.

the class RegionCommand method updateSpawnRate.

private void updateSpawnRate(CommandSender sender, String[] args) {
    Region region = lookupRegion(sender, args[0]);
    if (region == null)
        return;
    if (args.length == 2) {
        sender.sendMessage(ChatColor.GREEN + "Listing spawn rates for region " + args[1]);
        for (Entry<String, Double> entry : region.getSpawnRates().entrySet()) {
            sender.sendMessage(ChatColor.GRAY + entry.getKey() + ": " + ChatColor.GREEN + entry.getValue());
        }
        sender.sendMessage(ChatColor.GRAY + "All other entities have a spawn rate of 0.");
    } else if (args.length == 3) {
        sender.sendMessage(ChatColor.GREEN + "Entity class " + args[3] + " has a spawn rate of " + region.getSpawnRate(args[3]));
    } else {
        Document base = Document.parse(region.getData().toJson());
        double spawnRate = parseDouble(sender, args[3]);
        region.setSpawnRate(args[2], spawnRate);
        sender.sendMessage(ChatColor.GREEN + "Set spawn rate of entity class " + args[2] + " to " + spawnRate);
        AUDIT_LOG.saveEntry(region, user(sender), base, "Set spawn rate of class " + args[2] + " to " + spawnRate);
    }
}
Also used : Region(mc.dragons.core.gameobject.region.Region) Document(org.bson.Document)

Example 4 with Region

use of mc.dragons.core.gameobject.region.Region in project DragonsOnline by UniverseCraft.

the class RegionCommand method displayRegion.

private void displayRegion(CommandSender sender, String[] args) {
    Region region = lookupRegion(sender, args[0]);
    if (region == null)
        return;
    sender.sendMessage(ChatColor.GREEN + "=== Region: " + region.getName() + " ===");
    sender.sendMessage(ChatColor.GRAY + "Database identifier: " + ChatColor.GREEN + region.getIdentifier().toString());
    sender.sendMessage(ChatColor.GRAY + "World: " + ChatColor.GREEN + region.getWorld().getName());
    sender.sendMessage(ChatColor.GRAY + "Min: " + ChatColor.GREEN + StringUtil.locToString(region.getMin()));
    sender.sendMessage(ChatColor.GRAY + "Max: " + ChatColor.GREEN + StringUtil.locToString(region.getMax()));
    sender.sendMessage(ChatColor.GRAY + "Flags: " + ChatColor.GREEN + StringUtil.docToString(region.getFlags()));
    sender.spigot().sendMessage(StringUtil.clickableHoverableText(ChatColor.GRAY + "[Go To Region] ", "/region goto " + region.getName(), "Click to teleport to this region"), ObjectMetadataCommand.getClickableMetadataLink(GameObjectType.REGION, region.getUUID()));
}
Also used : Region(mc.dragons.core.gameobject.region.Region)

Example 5 with Region

use of mc.dragons.core.gameobject.region.Region in project DragonsOnline by UniverseCraft.

the class RegionCommand method updateFlag.

private void updateFlag(CommandSender sender, String[] args) {
    Region region = lookupRegion(sender, args[0]);
    if (region == null)
        return;
    if (args.length == 2) {
        sender.sendMessage(ChatColor.RED + "Specify a flag name! /region <RegionName> flag <FlagName> [Value]");
    } else if (args.length == 3) {
        Object value = region.getFlags().get(args[2]);
        if (value == null) {
            sender.sendMessage(ChatColor.RED + "No flag by that name exists!");
        } else {
            sender.sendMessage(ChatColor.GREEN + "Flag " + args[2] + " has value " + value.toString());
        }
    } else if (args[3].equalsIgnoreCase("REMOVE")) {
    // TODO KJASHD KJLSAYHDLUKJHSAHDJASHLIDUKSAJHDSBAKIULJD<YHGASB DXCKUSAYHJnd
    // Jd))
    } else {
        Document base = Document.parse(region.getData().toJson());
        String value = StringUtil.concatArgs(args, 3);
        region.setFlag(args[2], value);
        sender.sendMessage(ChatColor.GREEN + "Set flag " + args[2] + " to " + value);
        AUDIT_LOG.saveEntry(region, user(sender), base, "Set flag " + args[2] + " to " + value);
    }
}
Also used : Region(mc.dragons.core.gameobject.region.Region) GameObject(mc.dragons.core.gameobject.GameObject) Document(org.bson.Document)

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