Search in sources :

Example 26 with ISoliniaItem

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

the class CommandEditItem 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.edititem")) {
            player.sendMessage("You do not have permission to access this command");
            return false;
        }
    }
    if (args.length == 0) {
        return false;
    }
    int itemid = Integer.parseInt(args[0]);
    if (args.length == 1) {
        try {
            ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemid);
            if (item != null) {
                item.sendItemSettingsToSender(sender);
            } else {
                sender.sendMessage("ITEM ID doesnt exist");
            }
            return true;
        } catch (CoreStateInitException e) {
            sender.sendMessage(e.getMessage());
        }
    }
    if (args.length < 3) {
        sender.sendMessage("Insufficient arguments: itemid setting value");
        return false;
    }
    String setting = args[1];
    String value = args[2];
    if (args.length > 3 && setting.toLowerCase().contains("lore")) {
        value = "";
        int current = 0;
        for (String entry : args) {
            current++;
            if (current <= 2)
                continue;
            value = value + entry + " ";
        }
        value = value.trim();
    }
    if (itemid < 1) {
        sender.sendMessage("Invalid item id");
        return false;
    }
    value = value.replaceAll("[^A-Za-z0-9_]", "");
    try {
        ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemid);
        if (item == null) {
            sender.sendMessage("Cannot locate item id: " + itemid);
            return false;
        }
        if (item.isOperatorCreated() && !sender.isOp()) {
            sender.sendMessage("This item was op created and you are not an op. Only ops can edit op items");
            return false;
        }
        StateManager.getInstance().getConfigurationManager().editItem(itemid, setting, value);
        sender.sendMessage("Updating setting on item");
    } catch (InvalidItemSettingException ne) {
        sender.sendMessage("Invalid item setting: " + ne.getMessage());
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) InvalidItemSettingException(com.solinia.solinia.Exceptions.InvalidItemSettingException)

Example 27 with ISoliniaItem

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

the class SoliniaItemFactory method CreateClassItemSet.

public static List<Integer> CreateClassItemSet(ISoliniaClass classtype, int armourtier, String partialname, boolean prefixClassName, boolean operatorCreated) throws SoliniaItemException {
    List<Integer> items = new ArrayList<Integer>();
    try {
        // Get the appropriate material for the class and generate the base item
        ISoliniaItem headItem = SoliniaItemFactory.CreateItem(new ItemStack(Material.valueOf(classtype.getDefaultHeadMaterial().toUpperCase())), operatorCreated);
        ISoliniaItem chestItem = SoliniaItemFactory.CreateItem(new ItemStack(Material.valueOf(classtype.getDefaultChestMaterial().toUpperCase())), operatorCreated);
        ISoliniaItem legsItem = SoliniaItemFactory.CreateItem(new ItemStack(Material.valueOf(classtype.getDefaultLegsMaterial().toUpperCase())), operatorCreated);
        ISoliniaItem feetItem = SoliniaItemFactory.CreateItem(new ItemStack(Material.valueOf(classtype.getDefaultFeetMaterial().toUpperCase())), operatorCreated);
        ISoliniaItem handItem = SoliniaItemFactory.CreateItem(new ItemStack(Material.valueOf(classtype.getDefaulthandMaterial().toUpperCase())), operatorCreated);
        ISoliniaItem offhandItem = SoliniaItemFactory.CreateItem(new ItemStack(Material.valueOf(classtype.getDefaultoffHandMaterial().toUpperCase())), operatorCreated);
        items.add(headItem.getId());
        items.add(chestItem.getId());
        items.add(legsItem.getId());
        items.add(feetItem.getId());
        items.add(handItem.getId());
        items.add(offhandItem.getId());
        for (Integer i : items) {
            ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(i);
            List<String> classNames = new ArrayList<String>();
            classNames.add(classtype.getName().toUpperCase());
            item.setAllowedClassNames(classNames);
            item.setWorth(armourtier * 25);
            // Randomise the stats of the class armour so we get more unique content in each dungeon
            int rarityChance = Utils.RandomBetween(1, 100);
            int rarityBonus = 0;
            String rarityName = "";
            if (rarityChance > 80) {
                rarityName = "Uncommon ";
                rarityBonus = 1;
            }
            if (rarityChance > 85) {
                rarityName = "Rare ";
                rarityBonus = 3;
            }
            if (rarityChance > 92) {
                rarityName = "Legendary ";
                rarityBonus = 5;
            }
            if (rarityChance > 96) {
                rarityName = "Mythical ";
                rarityBonus = 6;
            }
            if (rarityChance > 98) {
                rarityName = "Ancient ";
                rarityBonus = 7;
            }
            String className = "";
            if (prefixClassName == true) {
                className = classtype.getClassItemPrefix().toLowerCase();
                className = Utils.FormatAsName(className);
                className += " ";
            }
            item.setDisplayname(rarityName + className + classtype.getItemArmorTypeName(item.getBasename().toUpperCase()) + " " + partialname);
            int tierMin = 0;
            int tierMax = armourtier * 5;
            if (armourtier > 1)
                tierMin = +(5 * armourtier) - 5;
            int lvlMin = 0;
            if (armourtier > 1)
                lvlMin = +(10 * armourtier) - 10;
            if (lvlMin > Utils.getMaxLevel()) {
                lvlMin = Utils.getMaxLevel();
            }
            item.setMinLevel(lvlMin);
            int classStrBonus = classtype.getItemGenerationBonus("strength");
            int classStaBonus = classtype.getItemGenerationBonus("stamina");
            int classAgiBonus = classtype.getItemGenerationBonus("agility");
            int classDexBonus = classtype.getItemGenerationBonus("dexterity");
            int classIntBonus = classtype.getItemGenerationBonus("intelligence");
            int classWisBonus = classtype.getItemGenerationBonus("wisdom");
            int classChaBonus = classtype.getItemGenerationBonus("charisma");
            int classAcBonus = classtype.getItemGenerationBonus("ac");
            if (classStrBonus > 0)
                item.setStrength(Utils.RandomBetween(tierMin, tierMax) + rarityBonus + classStrBonus);
            if (classStaBonus > 0)
                item.setStamina(Utils.RandomBetween(tierMin, tierMax) + rarityBonus + classStaBonus);
            if (classAgiBonus > 0)
                item.setAgility(Utils.RandomBetween(tierMin, tierMax) + rarityBonus + classAgiBonus);
            if (classDexBonus > 0)
                item.setDexterity(Utils.RandomBetween(tierMin, tierMax) + rarityBonus + classDexBonus);
            if (classIntBonus > 0)
                item.setIntelligence(Utils.RandomBetween(tierMin, tierMax) + rarityBonus + classIntBonus);
            if (classWisBonus > 0)
                item.setWisdom(Utils.RandomBetween(tierMin, tierMax) + rarityBonus + classWisBonus);
            if (classChaBonus > 0)
                item.setCharisma(Utils.RandomBetween(tierMin, tierMax) + rarityBonus + classChaBonus);
            // Damage
            if (ConfigurationManager.HandMaterials.contains(item.getBasename().toUpperCase())) {
                if (!item.getBasename().toUpperCase().equals("SHIELD")) {
                    int dmgMin = tierMin;
                    int dmgMax = tierMax;
                    if (dmgMin < 6) {
                        dmgMin = 6;
                    }
                    if (dmgMax < 7)
                        dmgMax = 7;
                    int damage = Utils.RandomBetween(dmgMin, dmgMax) + rarityBonus + classStrBonus;
                    item.setDamage(damage);
                } else {
                    item.setAC(SoliniaItemFactory.generateArmourClass(classAcBonus, armourtier, rarityBonus));
                }
            }
            if (ConfigurationManager.ArmourMaterials.contains(item.getBasename().toUpperCase())) {
                item.setAC(SoliniaItemFactory.generateArmourClass(classAcBonus, armourtier, rarityBonus));
            }
            // mana
            item.setMana(Utils.RandomBetween(0, armourtier + rarityBonus) * 10);
            // hp
            item.setHp(Utils.RandomBetween(0, armourtier + rarityBonus) * 10);
            // resists
            item.setColdResist(Utils.RandomBetween(0, armourtier + rarityBonus));
            item.setFireResist(Utils.RandomBetween(0, armourtier + rarityBonus));
            item.setMagicResist(Utils.RandomBetween(0, armourtier + rarityBonus));
            item.setPoisonResist(Utils.RandomBetween(0, armourtier + rarityBonus));
            item.setDiseaseResist(Utils.RandomBetween(0, armourtier + rarityBonus));
        // TODO class procs?
        }
    } catch (CoreStateInitException e) {
        return new ArrayList<Integer>();
    }
    return items;
}
Also used : ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ArrayList(java.util.ArrayList) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack)

Example 28 with ISoliniaItem

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

the class SoliniaNPC method getEquippedSoliniaItems.

@Override
public List<ISoliniaItem> getEquippedSoliniaItems(LivingEntity livingEntity, boolean excludeMainHand) {
    List<ISoliniaItem> items = new ArrayList<ISoliniaItem>();
    try {
        List<ItemStack> itemStacks = new ArrayList<ItemStack>() {

            {
                if (excludeMainHand == false) {
                    add(livingEntity.getEquipment().getItemInMainHand());
                }
                add(livingEntity.getEquipment().getItemInOffHand());
                addAll(Arrays.asList(livingEntity.getEquipment().getArmorContents()));
            }
        };
        for (ItemStack itemstack : itemStacks) {
            if (itemstack == null)
                continue;
            if (Utils.IsSoliniaItem(itemstack)) {
                ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemstack);
                if (item == null)
                    continue;
                if (item.isSpellscroll())
                    continue;
                items.add(item);
                Integer augmentationId = ItemStackUtils.getAugmentationItemId(itemstack);
                ISoliniaItem augItem = null;
                if (augmentationId != null && augmentationId != 0) {
                    augItem = StateManager.getInstance().getConfigurationManager().getItem(augmentationId);
                    items.add(augItem);
                }
            }
        }
    } catch (CoreStateInitException e) {
    }
    return items;
}
Also used : ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ArrayList(java.util.ArrayList) ItemStack(org.bukkit.inventory.ItemStack)

Example 29 with ISoliniaItem

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

the class SoliniaLootDrop method sendLootDropSettingsToSender.

@Override
public void sendLootDropSettingsToSender(CommandSender sender) {
    try {
        sender.sendMessage(ChatColor.GOLD + getName().toUpperCase() + ChatColor.RESET + "[" + getId() + "]:");
        for (ISoliniaLootDropEntry lde : getEntries()) {
            ISoliniaItem i = StateManager.getInstance().getConfigurationManager().getItem(lde.getItemid());
            sender.sendMessage("- [" + lde.getId() + "] " + ChatColor.GOLD + i.getDisplayname() + ChatColor.RESET + "[" + i.getId() + "] - " + lde.getChance() + "% chance Count: " + lde.getCount() + " Always: " + lde.isAlways());
        }
    } catch (CoreStateInitException e) {
        sender.sendMessage(e.getMessage());
    }
}
Also used : ISoliniaLootDropEntry(com.solinia.solinia.Interfaces.ISoliniaLootDropEntry) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException)

Example 30 with ISoliniaItem

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

the class SoliniaPlayer method setInteraction.

@Override
public void setInteraction(UUID interaction, ISoliniaNPC npc) {
    if (interaction == null) {
        this.interaction = interaction;
        this.getBukkitPlayer().sendMessage(ChatColor.GRAY + "* You are no longer interacting");
        return;
    }
    Entity e = Bukkit.getEntity(interaction);
    if (e == null)
        return;
    if (!(e instanceof LivingEntity))
        return;
    if (((Creature) e).getTarget() != null) {
        if (interaction != null) {
            this.getBukkitPlayer().sendMessage(ChatColor.GRAY + "* You are no longer interacting");
            interaction = null;
        }
        return;
    }
    if (Bukkit.getEntity(interaction) instanceof Wolf) {
        Wolf w = (Wolf) Bukkit.getEntity(interaction);
        if (w.getOwner() != null)
            return;
    }
    this.interaction = interaction;
    if (npc != null) {
        this.getBukkitPlayer().sendMessage(ChatColor.GRAY + "* You are now interacting with " + Bukkit.getEntity(interaction).getName() + " [" + npc.getId() + "] - Anything you type will be heared by the NPC and possibly responded to. Words in pink are trigger words you can type");
        if (npc.getMerchantid() > 0) {
            try {
                StateManager.getInstance().getEntityManager().getLivingEntity((LivingEntity) e).say("i have a [" + ChatColor.LIGHT_PURPLE + "SHOP" + ChatColor.AQUA + "] available if you are interested in buying or selling something", getBukkitPlayer());
            } catch (CoreStateInitException cse) {
            // 
            }
        }
        for (ISoliniaNPCEventHandler eventHandler : npc.getEventHandlers()) {
            if (!eventHandler.getInteractiontype().equals(InteractionType.ITEM))
                continue;
            // See if player has any items that are wanted
            int itemId = Integer.parseInt(eventHandler.getTriggerdata());
            if (itemId == 0)
                continue;
            if (Utils.getPlayerTotalCountOfItemId(getBukkitPlayer(), itemId) < 1)
                continue;
            try {
                ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemId);
                TextComponent tc = new TextComponent();
                tc.setText(ChatColor.YELLOW + "[QUEST] ");
                TextComponent tc2 = new TextComponent();
                tc2.setText(ChatColor.GRAY + "- Click here to give " + item.getDisplayname() + ChatColor.RESET);
                tc2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/npcgive " + itemId));
                tc.addExtra(tc2);
                getBukkitPlayer().spigot().sendMessage(tc);
            } catch (CoreStateInitException eNotInitialised) {
                continue;
            }
        }
    }
}
Also used : ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) TextComponent(net.md_5.bungee.api.chat.TextComponent) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) ISoliniaNPCEventHandler(com.solinia.solinia.Interfaces.ISoliniaNPCEventHandler) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) Wolf(org.bukkit.entity.Wolf)

Aggregations

ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)41 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)37 ItemStack (org.bukkit.inventory.ItemStack)18 Player (org.bukkit.entity.Player)16 SoliniaItemException (com.solinia.solinia.Exceptions.SoliniaItemException)14 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)14 ArrayList (java.util.ArrayList)12 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)7 ISoliniaNPC (com.solinia.solinia.Interfaces.ISoliniaNPC)7 LivingEntity (org.bukkit.entity.LivingEntity)7 TextComponent (net.md_5.bungee.api.chat.TextComponent)5 CommandSender (org.bukkit.command.CommandSender)5 Entity (org.bukkit.entity.Entity)5 EventHandler (org.bukkit.event.EventHandler)5 ISoliniaLootDropEntry (com.solinia.solinia.Interfaces.ISoliniaLootDropEntry)4 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)4 ISoliniaLootDrop (com.solinia.solinia.Interfaces.ISoliniaLootDrop)3 ISoliniaLootTableEntry (com.solinia.solinia.Interfaces.ISoliniaLootTableEntry)3 ISoliniaSpell (com.solinia.solinia.Interfaces.ISoliniaSpell)3 ISoliniaLootTable (com.solinia.solinia.Interfaces.ISoliniaLootTable)2