Search in sources :

Example 6 with ISoliniaLootDropEntry

use of com.solinia.solinia.Interfaces.ISoliniaLootDropEntry in project solinia3-core by mixxit.

the class SoliniaLivingEntity method dropLoot.

@Override
public void dropLoot() {
    if (isPlayer())
        return;
    try {
        if (getNpcid() > 0) {
            ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(getNpcid());
            if (npc.getLoottableid() == 0)
                return;
            ISoliniaLootTable table = StateManager.getInstance().getConfigurationManager().getLootTable(npc.getLoottableid());
            List<ISoliniaLootDropEntry> absoluteitems = new ArrayList<ISoliniaLootDropEntry>();
            List<ISoliniaLootDropEntry> rollitems = new ArrayList<ISoliniaLootDropEntry>();
            for (ISoliniaLootTableEntry entry : StateManager.getInstance().getConfigurationManager().getLootTable(table.getId()).getEntries()) {
                ISoliniaLootDrop droptable = StateManager.getInstance().getConfigurationManager().getLootDrop(entry.getLootdropid());
                for (ISoliniaLootDropEntry dropentry : StateManager.getInstance().getConfigurationManager().getLootDrop(droptable.getId()).getEntries()) {
                    if (dropentry.isAlways() == true) {
                        absoluteitems.add(dropentry);
                        continue;
                    }
                    rollitems.add(dropentry);
                }
            }
            if (absoluteitems.size() == 0 && rollitems.size() == 0)
                return;
            int dropcount = StateManager.getInstance().getWorldPerkDropCountModifier();
            Random r = new Random();
            int randomInt = r.nextInt(100) + 1;
            if (rollitems.size() > 0) {
                // Based on the chance attempt to drop this item
                for (int i = 0; i < dropcount; i++) {
                    ISoliniaLootDropEntry droptableentry = rollitems.get(new Random().nextInt(rollitems.size()));
                    ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(droptableentry.getItemid());
                    randomInt = r.nextInt(100) + 1;
                    // Handle unique item checking also
                    if (item.isArtifact() == true && item.isArtifactFound() == true)
                        continue;
                    if (randomInt <= droptableentry.getChance()) {
                        // Handle unique item setting also
                        if (item.isArtifact() == true && item.isArtifactFound() == false)
                            item.setArtifactFound(true);
                        getBukkitLivingEntity().getLocation().getWorld().dropItem(getBukkitLivingEntity().getLocation(), item.asItemStack());
                    }
                }
            }
            // Always drop these items
            if (absoluteitems.size() > 0) {
                for (int i = 0; i < absoluteitems.size(); i++) {
                    ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(absoluteitems.get(i).getItemid());
                    for (int c = 0; c < absoluteitems.get(i).getCount(); c++) {
                        // Handle unique item checking also
                        if (item.isArtifact() == true && item.isArtifactFound() == true)
                            continue;
                        getBukkitLivingEntity().getLocation().getWorld().dropItem(getBukkitLivingEntity().getLocation(), item.asItemStack());
                        // Handle unique item setting also
                        if (item.isArtifact() == true && item.isArtifactFound() == false)
                            item.setArtifactFound(true);
                    }
                }
            }
        } else {
        /*
				 * This is no longer needed now we have loot drops int itemDropMinimum = 95; if
				 * (Utils.RandomChance(itemDropMinimum)) { if (getBukkitLivingEntity()
				 * instanceof Monster)
				 * getBukkitLivingEntity().getWorld().dropItem(this.getBukkitLivingEntity().
				 * getLocation(),SoliniaItemFactory.GenerateRandomLoot().asItemStack()); }
				 */
        }
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : ISoliniaLootDropEntry(com.solinia.solinia.Interfaces.ISoliniaLootDropEntry) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) Random(java.util.Random) ISoliniaLootTableEntry(com.solinia.solinia.Interfaces.ISoliniaLootTableEntry) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) ArrayList(java.util.ArrayList) ISoliniaLootTable(com.solinia.solinia.Interfaces.ISoliniaLootTable) ISoliniaLootDrop(com.solinia.solinia.Interfaces.ISoliniaLootDrop)

Example 7 with ISoliniaLootDropEntry

use of com.solinia.solinia.Interfaces.ISoliniaLootDropEntry in project solinia3-core by mixxit.

the class CommandAddLootDropItem method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player) && !(sender instanceof CommandSender))
        return false;
    if (sender instanceof Player) {
        Player player = (Player) sender;
        if (!player.isOp() && !player.hasPermission("solinia.addlootdropitem")) {
            player.sendMessage("You do not have permission to access this command");
            return false;
        }
    }
    if (args.length < 5) {
        sender.sendMessage("Insufficient arguments: lootdropid itemid count always chance");
        return false;
    }
    int lootdropid = Integer.parseInt(args[0]);
    int itemid = Integer.parseInt(args[1]);
    int count = Integer.parseInt(args[2]);
    boolean always = Boolean.parseBoolean(args[3]);
    int chance = Integer.parseInt(args[4]);
    try {
        if (StateManager.getInstance().getConfigurationManager().getLootDrop(lootdropid) == null) {
            sender.sendMessage("LootDrop does not exist");
            return true;
        }
        if (StateManager.getInstance().getConfigurationManager().getLootDrop(lootdropid).isOperatorCreated() && !sender.isOp()) {
            sender.sendMessage("This lootdrop was op created and you are not an op. Only ops can edit op lootdrop items");
            return false;
        }
        if (StateManager.getInstance().getConfigurationManager().getItem(itemid) == null) {
            sender.sendMessage("Item does not exist");
            return true;
        }
        for (ISoliniaLootDropEntry lde : StateManager.getInstance().getConfigurationManager().getLootDrop(lootdropid).getEntries()) {
            if (lde.getItemid() == itemid) {
                sender.sendMessage("Item already exists in lootdrop definition");
                return true;
            }
        }
        SoliniaLootFactory.CreateLootDropItem(lootdropid, itemid, count, always, chance, sender.isOp());
        sender.sendMessage("Item added to loot drop");
    } catch (CoreStateInitException e) {
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : ISoliniaLootDropEntry(com.solinia.solinia.Interfaces.ISoliniaLootDropEntry) Player(org.bukkit.entity.Player) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender)

Aggregations

ISoliniaLootDropEntry (com.solinia.solinia.Interfaces.ISoliniaLootDropEntry)7 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)5 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)4 ISoliniaLootDrop (com.solinia.solinia.Interfaces.ISoliniaLootDrop)4 ISoliniaLootTableEntry (com.solinia.solinia.Interfaces.ISoliniaLootTableEntry)3 ISoliniaLootTable (com.solinia.solinia.Interfaces.ISoliniaLootTable)2 ArrayList (java.util.ArrayList)2 InvalidLootDropSettingException (com.solinia.solinia.Exceptions.InvalidLootDropSettingException)1 ISoliniaFaction (com.solinia.solinia.Interfaces.ISoliniaFaction)1 ISoliniaNPC (com.solinia.solinia.Interfaces.ISoliniaNPC)1 SoliniaLootDropEntry (com.solinia.solinia.Models.SoliniaLootDropEntry)1 Random (java.util.Random)1 CommandSender (org.bukkit.command.CommandSender)1 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)1 Player (org.bukkit.entity.Player)1