Search in sources :

Example 26 with ISoliniaNPC

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

the class SoliniaNPCFactory method CreateNPC.

public static ISoliniaNPC CreateNPC(String name, int level, int factionid, boolean operatorCreated) throws CoreStateInitException {
    SoliniaNPC npc = new SoliniaNPC();
    npc.setId(StateManager.getInstance().getConfigurationManager().getNextNPCId());
    npc.setName(name);
    npc.setLevel(level);
    npc.setFactionid(factionid);
    npc.setOperatorCreated(operatorCreated);
    return StateManager.getInstance().getConfigurationManager().addNPC(npc);
}
Also used : ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) SoliniaNPC(com.solinia.solinia.Models.SoliniaNPC)

Example 27 with ISoliniaNPC

use of com.solinia.solinia.Interfaces.ISoliniaNPC 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 28 with ISoliniaNPC

use of com.solinia.solinia.Interfaces.ISoliniaNPC 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 29 with ISoliniaNPC

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

the class SoliniaLivingEntity method say.

@Override
public void say(String message) {
    if (isPlayer())
        return;
    if (this.getNpcid() < 1)
        return;
    try {
        ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(this.getNpcid());
        if (npc == null)
            return;
        String decoratedMessage = ChatColor.AQUA + npc.getName() + " says '" + message + "'" + ChatColor.RESET;
        StateManager.getInstance().getChannelManager().sendToLocalChannelLivingEntityChat(this, decoratedMessage);
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC)

Example 30 with ISoliniaNPC

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

the class SoliniaLivingEntity method doSummon.

@Override
public void doSummon(Plugin plugin, LivingEntity summoningEntity) {
    if (isPlayer())
        return;
    if (summoningEntity == null || this.livingentity == null)
        return;
    ISoliniaNPC npc;
    try {
        npc = StateManager.getInstance().getConfigurationManager().getNPC(this.getNpcid());
        if (!npc.isSummoner())
            return;
        int chanceToSummon = Utils.RandomBetween(1, 10);
        if (chanceToSummon > 8) {
            if (summoningEntity instanceof Player) {
                this.say("You will not evade me " + ((Player) summoningEntity).getDisplayName() + "!");
            } else {
                this.say("You will not evade me " + summoningEntity.getName() + "!");
            }
            summoningEntity.teleport(getBukkitLivingEntity().getLocation());
        }
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC)

Aggregations

ISoliniaNPC (com.solinia.solinia.Interfaces.ISoliniaNPC)50 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)43 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)19 Player (org.bukkit.entity.Player)16 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)7 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)7 CommandSender (org.bukkit.command.CommandSender)6 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)6 LivingEntity (org.bukkit.entity.LivingEntity)6 ISoliniaNPCEventHandler (com.solinia.solinia.Interfaces.ISoliniaNPCEventHandler)5 ArrayList (java.util.ArrayList)5 InvalidNpcSettingException (com.solinia.solinia.Exceptions.InvalidNpcSettingException)4 Entity (org.bukkit.entity.Entity)4 ISoliniaFaction (com.solinia.solinia.Interfaces.ISoliniaFaction)3 ItemStack (org.bukkit.inventory.ItemStack)3 InvalidNPCEventSettingException (com.solinia.solinia.Exceptions.InvalidNPCEventSettingException)2 SoliniaItemException (com.solinia.solinia.Exceptions.SoliniaItemException)2 ISoliniaLootTable (com.solinia.solinia.Interfaces.ISoliniaLootTable)2 SoliniaNPC (com.solinia.solinia.Models.SoliniaNPC)2 SoliniaNPCEventHandler (com.solinia.solinia.Models.SoliniaNPCEventHandler)2