Search in sources :

Example 6 with ISoliniaLootTable

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

the class SoliniaNPC method editSetting.

@Override
public void editSetting(String setting, String value) throws InvalidNpcSettingException, NumberFormatException, CoreStateInitException, java.io.IOException {
    switch(setting.toLowerCase()) {
        case "name":
            if (value.equals(""))
                throw new InvalidNpcSettingException("Name is empty");
            if (value.length() > 25)
                throw new InvalidNpcSettingException("Name is longer than 25 characters");
            setName(value);
            break;
        case "mctype":
            setMctype(value);
            break;
        case "level":
            setLevel(Integer.parseInt(value));
            break;
        case "factionid":
            if (Integer.parseInt(value) == 0) {
                setFactionid(Integer.parseInt(value));
                break;
            }
            ISoliniaFaction faction = StateManager.getInstance().getConfigurationManager().getFaction(Integer.parseInt(value));
            if (faction == null)
                throw new InvalidNpcSettingException("Faction ID does not exist");
            setFactionid(Integer.parseInt(value));
            break;
        case "usedisguise":
            setUsedisguise(Boolean.parseBoolean(value));
            break;
        case "disguisetype":
            setDisguisetype(value);
            break;
        case "headitem":
            setHeaditem(value);
            break;
        case "chestitem":
            setChestitem(value);
            break;
        case "legsitem":
            setLegsitem(value);
            break;
        case "feetitem":
            setFeetitem(value);
            break;
        case "handitem":
            setHanditem(value);
            break;
        case "offhanditem":
            setOffhanditem(value);
            break;
        case "clearitems":
            setHeaditem(null);
            setChestitem(null);
            setLegsitem(null);
            setFeetitem(null);
            setHanditem(null);
            setOffhanditem(null);
        case "boss":
            setBoss(Boolean.parseBoolean(value));
            break;
        case "heroic":
            setHeroic(Boolean.parseBoolean(value));
            break;
        case "raidboss":
            setRaidboss(Boolean.parseBoolean(value));
            break;
        case "raidheroic":
            setRaidheroic(Boolean.parseBoolean(value));
            break;
        case "burning":
            setBurning(Boolean.parseBoolean(value));
            break;
        case "invisible":
            setInvisible(Boolean.parseBoolean(value));
            break;
        case "customhead":
            setCustomhead(Boolean.parseBoolean(value));
            break;
        case "customheaddata":
            // fetches custom head texture by a player name
            setCustomheaddata(Utils.getTextureFromName(value));
            break;
        case "customheaddatafromnpc":
            int npcid = Integer.parseInt(value);
            ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(npcid);
            if (npc == null)
                throw new InvalidNpcSettingException("NPCID does not exist");
            // fetches custom head texture by existing npc
            setCustomheaddata(npc.getCustomheaddata());
            break;
        case "deathgrantstitle":
            // fetches custom head texture by a player name
            setDeathGrantsTitle(value);
            break;
        case "merchantid":
            if (Integer.parseInt(value) == 0) {
                setMerchantid(Integer.parseInt(value));
                break;
            }
            if (StateManager.getInstance().getConfigurationManager().getNPCMerchant(Integer.parseInt(value)) == null)
                throw new InvalidNpcSettingException("MerchantID does not exist");
            setMerchantid(Integer.parseInt(value));
            break;
        case "upsidedown":
            setUpsidedown(Boolean.parseBoolean(value));
            break;
        case "loottableid":
            if (Integer.parseInt(value) == 0) {
                setLoottableid(0);
                break;
            }
            ISoliniaLootTable loottable = StateManager.getInstance().getConfigurationManager().getLootTable(Integer.parseInt(value));
            if (loottable == null)
                throw new InvalidNpcSettingException("Loottable ID does not exist");
            setLoottableid(Integer.parseInt(value));
            break;
        case "raceid":
            setRaceid(Integer.parseInt(value));
            break;
        case "classid":
            setClassid(Integer.parseInt(value));
            break;
        case "randomspawn":
            setRandomSpawn(Boolean.parseBoolean(value));
            break;
        case "killtriggertext":
            setKillTriggerText(value);
            break;
        case "ac":
            setAC(Integer.parseInt(value));
        case "randomchattriggertext":
            setRandomchatTriggerText(value);
            break;
        case "guard":
            setGuard(Boolean.parseBoolean(value));
            break;
        case "pet":
            setPet(Boolean.parseBoolean(value));
            break;
        case "roamer":
            setRoamer(Boolean.parseBoolean(value));
            break;
        case "undead":
            setUndead(Boolean.parseBoolean(value));
            break;
        case "animal":
            setAnimal(Boolean.parseBoolean(value));
            break;
        case "summoner":
            setSummoner(Boolean.parseBoolean(value));
            break;
        case "disablespawners":
            disableAllSpawners(Boolean.parseBoolean(value));
            break;
        case "accuracyrating":
            setAccuracyRating(Integer.parseInt(value));
            break;
        case "avoidancerating":
            setAvoidanceRating(Integer.parseInt(value));
            break;
        case "speaksalllanguages":
            setSpeaksAllLanguages(Boolean.parseBoolean(value));
            break;
        default:
            throw new InvalidNpcSettingException("Invalid NPC setting. Valid Options are: name,mctype,health,damage,factionid,usedisguise,disguisetype,headitem,chestitem,legsitem,feetitem,handitem,offhanditem,boss,burning,invisible,customhead,customheaddata,merchantid,upsidedown,loottableid,randomspawn,killtriggertext,randomchattriggertext,guard,roamer,undead,customheaddatafromnpc,summoner,disablespawners,animal,speaksalllanguages");
    }
}
Also used : ISoliniaFaction(com.solinia.solinia.Interfaces.ISoliniaFaction) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) InvalidNpcSettingException(com.solinia.solinia.Exceptions.InvalidNpcSettingException) ISoliniaLootTable(com.solinia.solinia.Interfaces.ISoliniaLootTable)

Example 7 with ISoliniaLootTable

use of com.solinia.solinia.Interfaces.ISoliniaLootTable 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)

Aggregations

ISoliniaLootTable (com.solinia.solinia.Interfaces.ISoliniaLootTable)7 ISoliniaLootTableEntry (com.solinia.solinia.Interfaces.ISoliniaLootTableEntry)4 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)3 ISoliniaLootDrop (com.solinia.solinia.Interfaces.ISoliniaLootDrop)3 ArrayList (java.util.ArrayList)3 ISoliniaFaction (com.solinia.solinia.Interfaces.ISoliniaFaction)2 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)2 ISoliniaLootDropEntry (com.solinia.solinia.Interfaces.ISoliniaLootDropEntry)2 ISoliniaNPC (com.solinia.solinia.Interfaces.ISoliniaNPC)2 SoliniaLootTableEntry (com.solinia.solinia.Models.SoliniaLootTableEntry)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 InvalidLootTableSettingException (com.solinia.solinia.Exceptions.InvalidLootTableSettingException)1 InvalidNpcSettingException (com.solinia.solinia.Exceptions.InvalidNpcSettingException)1 ISoliniaLootTableEntryTypeAdapterFactory (com.solinia.solinia.Factories.ISoliniaLootTableEntryTypeAdapterFactory)1 BufferedReader (java.io.BufferedReader)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 List (java.util.List)1 Random (java.util.Random)1