Search in sources :

Example 31 with ISoliniaNPC

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

the class SoliniaLivingEntity method setSpeaksAllLanguages.

@Override
public void setSpeaksAllLanguages(boolean speaksAllLanguages) {
    if (isNPC()) {
        try {
            ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(this.getNpcid());
            npc.setSpeaksAllLanguages(speaksAllLanguages);
        } catch (CoreStateInitException e) {
        // 
        }
    }
}
Also used : CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC)

Example 32 with ISoliniaNPC

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

the class SoliniaLivingEntity method doCheckForEnemies.

@Override
public void doCheckForEnemies() {
    if (isPlayer())
        return;
    if (this.getNpcid() < 1)
        return;
    if (getBukkitLivingEntity().isDead())
        return;
    if (!(getBukkitLivingEntity() instanceof Creature))
        return;
    if (((Creature) getBukkitLivingEntity()).getTarget() != null)
        return;
    try {
        ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(this.getNpcid());
        if (npc.getFactionid() == 0)
            return;
        ISoliniaFaction faction = StateManager.getInstance().getConfigurationManager().getFaction(npc.getFactionid());
        if (faction.getName().equals("NEUTRAL") || faction.getName().equals("KOS"))
            return;
        for (Entity entity : getBukkitLivingEntity().getNearbyEntities(10, 10, 10)) {
            if (!(entity instanceof Player))
                continue;
            if (entity.isDead())
                continue;
            Player player = (Player) entity;
            ISoliniaPlayer solPlayer = SoliniaPlayerAdapter.Adapt(player);
            PlayerFactionEntry factionEntry = solPlayer.getFactionEntry(npc.getFactionid());
            if (factionEntry != null) {
                switch(Utils.getFactionStandingType(factionEntry.getFactionId(), factionEntry.getValue())) {
                    case FACTION_THREATENLY:
                    case FACTION_SCOWLS:
                        if (Utils.isEntityInLineOfSight(player, getBukkitLivingEntity())) {
                            ((Creature) getBukkitLivingEntity()).setTarget(player);
                            return;
                        } else {
                            continue;
                        }
                    default:
                        break;
                }
            }
        }
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) Entity(org.bukkit.entity.Entity) CraftEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) Creature(org.bukkit.entity.Creature) EntityCreature(net.minecraft.server.v1_12_R1.EntityCreature) ISoliniaFaction(com.solinia.solinia.Interfaces.ISoliniaFaction) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer)

Example 33 with ISoliniaNPC

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

the class SoliniaLivingEntity method installNpcByMetaName.

private void installNpcByMetaName(String metaid) {
    if (isPlayer())
        return;
    if (!metaid.contains("NPCID_"))
        return;
    int npcId = Integer.parseInt(metaid.substring(6));
    try {
        ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(npcId);
        if (npc == null)
            return;
        setLevel(npc.getLevel());
        setNpcid(npc.getId());
    } catch (CoreStateInitException e) {
        e.printStackTrace();
    }
}
Also used : CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC)

Example 34 with ISoliniaNPC

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

the class SoliniaLivingEntity method getMaxMP.

@Override
public int getMaxMP() {
    if (getClassObj() == null)
        return 1;
    String profession = getClassObj().getName().toUpperCase();
    int wisintagi = 0;
    if (Utils.getCasterClass(profession).equals("W"))
        wisintagi = getWisdom();
    if (Utils.getCasterClass(profession).equals("I"))
        wisintagi = getIntelligence();
    if (Utils.getCasterClass(profession).equals("N"))
        wisintagi = getAgility();
    double maxmana = ((850 * getLevel()) + (85 * wisintagi * getLevel())) / 425;
    double itemMana = getItemMana();
    maxmana += itemMana;
    if (this.getNpcid() > 0) {
        maxmana = maxmana + (50 * getLevel());
        try {
            ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(this.getNpcid());
            if (npc != null) {
                if (npc.isBoss()) {
                    maxmana += (Utils.getBossMPRegenMultipler() * npc.getLevel());
                }
                if (npc.isHeroic()) {
                    maxmana += (Utils.getHeroicMPRegenMultipler() * npc.getLevel());
                }
                if (npc.isRaidboss()) {
                    maxmana += (Utils.getRaidBossMPRegenMultipler() * npc.getLevel());
                }
                if (npc.isRaidheroic()) {
                    maxmana += (Utils.getRaidHeroicMPRegenMultipler() * npc.getLevel());
                }
            }
        } catch (CoreStateInitException e) {
        }
    }
    return (int) Math.floor(maxmana);
}
Also used : CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC)

Example 35 with ISoliniaNPC

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

the class Solinia3CorePlayerListener method onMerchantInventoryClick.

private void onMerchantInventoryClick(InventoryClickEvent event) {
    int merchantid = 0;
    int npcid = 0;
    ISoliniaNPCMerchant merchant = null;
    ISoliniaNPC npc = null;
    int page = 0;
    int nextpage = 0;
    try {
        merchantid = Utils.getInventoryMerchantID(event.getInventory());
        npcid = Utils.getInventoryNPCID(event.getInventory());
        page = Utils.getInventoryPage(event.getInventory());
        nextpage = Utils.getInventoryPage(event.getInventory());
    } catch (Exception e) {
        event.getView().getPlayer().sendMessage(e.getMessage());
        e.printStackTrace();
        Utils.CancelEvent(event);
        ;
        return;
    }
    if (merchantid == 0 || npcid == 0) {
        event.getView().getPlayer().sendMessage("Could not find npc " + npcid + " or merchant " + merchantid + " or page " + page);
        System.out.println("Could not find npc " + npcid + " or merchant " + merchantid);
        Utils.CancelEvent(event);
        ;
        return;
    }
    try {
        merchant = StateManager.getInstance().getConfigurationManager().getNPCMerchant(merchantid);
        npc = StateManager.getInstance().getConfigurationManager().getNPC(npcid);
    } catch (CoreStateInitException e) {
        event.getView().getPlayer().sendMessage("Cannot sell/buy right now");
        Utils.CancelEvent(event);
        ;
        return;
    }
    // event.getView().getPlayer().sendMessage("Detected Merchant Inventory Click for Merchant:" + merchantid + " Slot: " + event.getSlot() + " Raw Slot: " + event.getRawSlot());
    if (event.getRawSlot() < 0) {
        Utils.CancelEvent(event);
        ;
        return;
    }
    if (event.getCursor() == null || event.getCursor().getType().equals(Material.AIR)) {
        // event.getView().getPlayer().sendMessage("Detected AIR Cursor, assuming picking up");
        if (event.getRawSlot() > 26) {
            try {
                ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(event.getCurrentItem());
                if (item == null) {
                    event.getView().getPlayer().sendMessage("Merchants are not interested in this item");
                    Utils.CancelEvent(event);
                    ;
                    return;
                }
                if (item.isTemporary()) {
                    event.getView().getPlayer().sendMessage("Merchants are not interested in temporary items");
                    Utils.CancelEvent(event);
                    ;
                    return;
                }
            // Picked up sellable item
            } catch (CoreStateInitException e) {
                Utils.CancelEvent(event);
                ;
                event.getView().getPlayer().sendMessage("Cannot sell/buy right now");
                return;
            }
            return;
        } else {
            ItemStack pickingUpItem = event.getCurrentItem();
            if (pickingUpItem.getType().equals(Material.BARRIER)) {
                // event.getView().getPlayer().sendMessage("Ignoring barrier");
                Utils.CancelEvent(event);
                ;
                return;
            }
            // Do not allow movement of UI movers
            if (event.getRawSlot() == 18 || event.getRawSlot() == 26) {
                // event.getView().getPlayer().sendMessage("Moving Left or Right");
                if (event.getRawSlot() == 18) {
                    if ((page - 1) > 0) {
                        event.getView().getPlayer().closeInventory();
                        npc.sendMerchantItemListToPlayer((Player) event.getView().getPlayer(), page - 1);
                    }
                }
                if (event.getRawSlot() == 26) {
                    if (nextpage != 0) {
                        event.getView().getPlayer().closeInventory();
                        npc.sendMerchantItemListToPlayer((Player) event.getView().getPlayer(), nextpage + 1);
                    }
                }
                Utils.CancelEvent(event);
                ;
                return;
            }
            // Do not allow movement of identifiers
            if (event.getRawSlot() == 19) {
                // event.getView().getPlayer().sendMessage("Ignoring identifier block");
                Utils.CancelEvent(event);
                ;
                return;
            }
            // Picking up merchant item
            // event.getView().getPlayer().sendMessage("Picking up merchant item");
            event.setCursor(event.getCurrentItem());
            Utils.CancelEvent(event);
            ;
            return;
        }
    }
    if (event.getCursor() != null && !event.getCursor().getType().equals(Material.AIR)) {
        // Clicking item in cursor onto a slot
        if (event.getRawSlot() > 26) {
            // Dropping own item or buying
            if (event.getCursor().getItemMeta().getDisplayName().startsWith("Display Item: ")) {
                try {
                    if (!event.getCurrentItem().getType().equals(Material.AIR)) {
                        event.getView().getPlayer().sendMessage("You must place the item you wish to buy on an empty slot");
                        event.setCursor(new ItemStack(Material.AIR));
                        Utils.CancelEvent(event);
                        ;
                        return;
                    }
                    ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(event.getCursor());
                    int individualprice = item.getWorth();
                    // Total price
                    int price = individualprice * event.getCursor().getAmount();
                    if (price > StateManager.getInstance().getEconomy().getBalance((Player) event.getView().getPlayer())) {
                        event.getView().getPlayer().sendMessage("You do not have sufficient balance to buy this item in that quantity.");
                        event.setCursor(new ItemStack(Material.AIR));
                        Utils.CancelEvent(event);
                        ;
                        return;
                    }
                    EconomyResponse responsewithdraw = StateManager.getInstance().getEconomy().withdrawPlayer(Bukkit.getOfflinePlayer(((Player) event.getView().getPlayer()).getUniqueId()), price);
                    if (responsewithdraw.transactionSuccess()) {
                        ItemStack purchase = item.asItemStack();
                        event.setCursor(new ItemStack(Material.AIR));
                        Utils.CancelEvent(event);
                        ;
                        event.getClickedInventory().setItem(event.getSlot(), purchase);
                        event.getView().getPlayer().sendMessage(ChatColor.YELLOW + "* You pay $" + price + " for " + event.getCursor().getAmount() + " " + item.getDisplayname());
                        return;
                    } else {
                        System.out.println("Error withdrawing money from your account " + String.format(responsewithdraw.errorMessage));
                        event.getView().getPlayer().sendMessage(ChatColor.YELLOW + "* Error withdrawing money from your account " + String.format(responsewithdraw.errorMessage));
                        event.setCursor(new ItemStack(Material.AIR));
                        Utils.CancelEvent(event);
                        ;
                        return;
                    }
                } catch (CoreStateInitException e) {
                    event.getView().getPlayer().sendMessage("Cannot buy items from the merchant right now");
                    event.setCursor(new ItemStack(Material.AIR));
                    Utils.CancelEvent(event);
                    ;
                    return;
                }
            } else {
                // Dropping own item
                return;
            }
        } else {
            // Selling items or dropping item back
            if (event.getCursor().getItemMeta().getDisplayName().startsWith("Display Item: ")) {
                // Returning store item
                event.setCursor(new ItemStack(Material.AIR));
                Utils.CancelEvent(event);
                ;
                return;
            } else {
                try {
                    ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(event.getCursor());
                    int individualprice = item.getWorth();
                    // Total price
                    int price = individualprice * event.getCursor().getAmount();
                    EconomyResponse responsedeposit = StateManager.getInstance().getEconomy().depositPlayer((Player) event.getView().getPlayer(), price);
                    if (responsedeposit.transactionSuccess()) {
                        // Add to buy back list
                        // StateManager.getInstance().getEntityManager().addTemporaryMerchantItem(npc.getId(), item.getId(), event.getCursor().getAmount());
                        event.getView().getPlayer().sendMessage(ChatColor.YELLOW + "* You recieve $" + price + " as payment");
                        event.setCursor(new ItemStack(Material.AIR));
                        Utils.CancelEvent(event);
                        ;
                        return;
                    } else {
                        System.out.println("Error depositing money to users account " + String.format(responsedeposit.errorMessage));
                        event.getView().getPlayer().sendMessage(ChatColor.YELLOW + "* Error depositing money to your account " + String.format(responsedeposit.errorMessage));
                        Utils.CancelEvent(event);
                        ;
                        return;
                    }
                } catch (CoreStateInitException e) {
                    event.getView().getPlayer().sendMessage("Cannot sell item to merchant right now");
                    Utils.CancelEvent(event);
                    ;
                    return;
                }
            }
        }
    }
    event.getView().getPlayer().sendMessage("Please alert an admin of this message code: GMMI1");
    Utils.CancelEvent(event);
    ;
    return;
}
Also used : Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPCMerchant(com.solinia.solinia.Interfaces.ISoliniaNPCMerchant) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) EconomyResponse(net.milkbowl.vault.economy.EconomyResponse) ItemStack(org.bukkit.inventory.ItemStack) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) SoliniaItemException(com.solinia.solinia.Exceptions.SoliniaItemException)

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