Search in sources :

Example 41 with ISoliniaNPC

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

the class SoliniaLivingEntity method doSlayChat.

@Override
public void doSlayChat() {
    if (isPlayer())
        return;
    ISoliniaNPC npc;
    try {
        npc = StateManager.getInstance().getConfigurationManager().getNPC(this.getNpcid());
        if (npc.getKillTriggerText() == null || npc.getKillTriggerText().equals(""))
            return;
        this.emote(ChatColor.AQUA + npc.getName() + " says '" + npc.getKillTriggerText() + "'" + ChatColor.RESET);
    } 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 42 with ISoliniaNPC

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

the class SoliniaLivingEntity method setMana.

private void setMana(int amount) {
    if (isPlayer())
        return;
    if (this.getNpcid() < 1)
        return;
    try {
        ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(this.getNpcid());
        if (npc == null)
            return;
        StateManager.getInstance().getEntityManager().setNPCMana(this.getBukkitLivingEntity(), npc, amount);
    } catch (CoreStateInitException e) {
        return;
    }
}
Also used : CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC)

Example 43 with ISoliniaNPC

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

the class SoliniaLivingEntity method Attack.

@Override
public boolean Attack(ISoliniaLivingEntity defender, EntityDamageEvent event, boolean arrowHit, Solinia3CorePlugin plugin) {
    int baseDamage = (int) event.getDamage(DamageModifier.BASE);
    try {
        if (defender.isPlayer() && isPlayer()) {
            ISoliniaPlayer defenderPlayer = SoliniaPlayerAdapter.Adapt((Player) defender.getBukkitLivingEntity());
            ISoliniaPlayer attackerPlayer = SoliniaPlayerAdapter.Adapt((Player) this.getBukkitLivingEntity());
            if (defenderPlayer.getGroup() != null && attackerPlayer.getGroup() != null) {
                if (defenderPlayer.getGroup().getId().equals(attackerPlayer.getGroup().getId())) {
                    Utils.CancelEvent(event);
                    ;
                    return false;
                }
            }
        }
    } catch (CoreStateInitException e) {
    // ignore
    }
    if (isPlayer()) {
        Player player = (Player) this.getBukkitLivingEntity();
        if (player.isSneaking()) {
            try {
                ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(player);
                if (solplayer.getClassObj() != null) {
                    if (solplayer.getClassObj().isSneakFromCrouch()) {
                        player.sendMessage("You cannot concentrate on combat while meditating or sneaking");
                        Utils.CancelEvent(event);
                        ;
                        return false;
                    }
                }
            } catch (CoreStateInitException e) {
            // do nothing
            }
        }
    }
    if (usingValidWeapon() == false) {
        Utils.CancelEvent(event);
        ;
        return false;
    } else {
        if (Utils.IsSoliniaItem(getBukkitLivingEntity().getEquipment().getItemInMainHand())) {
            try {
                ISoliniaItem soliniaitem = StateManager.getInstance().getConfigurationManager().getItem(getBukkitLivingEntity().getEquipment().getItemInMainHand());
                // TODO move this
                if (soliniaitem.getBaneUndead() > 0 && defender.isUndead())
                    baseDamage += soliniaitem.getBaneUndead();
            } catch (CoreStateInitException e) {
                Utils.CancelEvent(event);
                ;
                return false;
            }
        }
    }
    if (baseDamage < 1)
        baseDamage = 1;
    if (defender == null) {
        Utils.CancelEvent(event);
        ;
        return false;
    }
    if (defender.getBukkitLivingEntity().isDead() || this.getBukkitLivingEntity().isDead() || this.getBukkitLivingEntity().getHealth() < 0) {
        Utils.CancelEvent(event);
        ;
        return false;
    }
    if (isInulvnerable()) {
        Utils.CancelEvent(event);
        ;
        return false;
    }
    if (isFeigned()) {
        Utils.CancelEvent(event);
        ;
        return false;
    }
    ItemStack weapon = this.getBukkitLivingEntity().getEquipment().getItemInHand();
    DamageHitInfo my_hit = new DamageHitInfo();
    my_hit.skill = Utils.getSkillForMaterial(weapon.getType().toString()).getSkillname();
    if (arrowHit) {
        my_hit.skill = "ARCHERY";
    }
    // Now figure out damage
    my_hit.damage_done = 1;
    my_hit.min_damage = 0;
    int mylevel = getLevel();
    int hate = 0;
    my_hit.base_damage = baseDamage;
    // amount of hate is based on the damage done
    if (hate == 0 && my_hit.base_damage > 1)
        hate = my_hit.base_damage;
    if (my_hit.base_damage > 0) {
        my_hit.base_damage = getDamageCaps(my_hit.base_damage);
        tryIncreaseSkill(my_hit.skill, 1);
        tryIncreaseSkill("OFFENSE", 1);
        int ucDamageBonus = 0;
        if (getClassObj() != null && getClassObj().isWarriorClass() && getLevel() >= 28) {
            ucDamageBonus = getWeaponDamageBonus(weapon);
            my_hit.min_damage = ucDamageBonus;
            hate += ucDamageBonus;
        }
        // TODO Sinister Strikes
        int hit_chance_bonus = 0;
        // we need this a few times
        my_hit.offense = getOffense(my_hit.skill);
        my_hit.tohit = getTotalToHit(my_hit.skill, hit_chance_bonus);
        doAttack(plugin, defender, my_hit);
    }
    defender.addToHateList(getBukkitLivingEntity().getUniqueId(), hate);
    if (getBukkitLivingEntity().isDead()) {
        Utils.CancelEvent(event);
        ;
        return false;
    }
    if (my_hit.damage_done > 0) {
        triggerDefensiveProcs(defender, my_hit.damage_done, arrowHit);
        try {
            event.setDamage(DamageModifier.ABSORPTION, 0);
        } catch (UnsupportedOperationException e) {
        }
        try {
            event.setDamage(DamageModifier.ARMOR, 0);
        } catch (UnsupportedOperationException e) {
        }
        try {
            event.setDamage(DamageModifier.BASE, my_hit.damage_done);
        } catch (UnsupportedOperationException e) {
        }
        try {
            event.setDamage(DamageModifier.BLOCKING, 0);
        } catch (UnsupportedOperationException e) {
        }
        try {
            event.setDamage(DamageModifier.HARD_HAT, 0);
        } catch (UnsupportedOperationException e) {
        }
        try {
            event.setDamage(DamageModifier.MAGIC, 0);
        } catch (UnsupportedOperationException e) {
        }
        try {
            event.setDamage(DamageModifier.RESISTANCE, 0);
        } catch (UnsupportedOperationException e) {
        }
        DecimalFormat df = new DecimalFormat();
        df.setMaximumFractionDigits(2);
        if (getBukkitLivingEntity() instanceof Player) {
            String name = defender.getBukkitLivingEntity().getName();
            if (defender.getBukkitLivingEntity().getCustomName() != null)
                name = defender.getBukkitLivingEntity().getCustomName();
            if (defender.isPlayer())
                System.out.println("Detected player " + getBukkitLivingEntity().getName() + " vs player " + defender.getName());
            ((Player) getBukkitLivingEntity()).spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent("You hit " + name + " for " + df.format(event.getDamage()) + " " + df.format(defender.getBukkitLivingEntity().getHealth() - event.getDamage()) + "/" + df.format(defender.getBukkitLivingEntity().getMaxHealth()) + " " + my_hit.skill + " damage"));
            if (defender.isNPC()) {
                ISoliniaNPC npc;
                try {
                    npc = StateManager.getInstance().getConfigurationManager().getNPC(defender.getNpcid());
                } catch (CoreStateInitException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            // Only players get this
            if (getDoubleAttackCheck()) {
                if (getBukkitLivingEntity() instanceof Player) {
                    ((Player) getBukkitLivingEntity()).sendMessage(ChatColor.GRAY + "* You double attack!");
                    tryIncreaseSkill("DOUBLEATTACK", 1);
                }
                defender.damage(plugin, my_hit.damage_done, this.getBukkitLivingEntity());
            }
            try {
                if (Utils.IsSoliniaItem(getBukkitLivingEntity().getEquipment().getItemInMainHand())) {
                    try {
                        ISoliniaItem soliniaitem = SoliniaItemAdapter.Adapt(getBukkitLivingEntity().getEquipment().getItemInMainHand());
                        if (soliniaitem != null) {
                            // Check if item has any proc effects
                            if (soliniaitem.getWeaponabilityid() > 0 && event.getCause().equals(DamageCause.ENTITY_ATTACK)) {
                                ISoliniaSpell procSpell = StateManager.getInstance().getConfigurationManager().getSpell(soliniaitem.getWeaponabilityid());
                                if (procSpell != null) {
                                    // Chance to proc
                                    int procChance = getProcChancePct();
                                    int roll = Utils.RandomBetween(0, 100);
                                    if (roll < procChance) {
                                        // TODO - For now apply self and group to attacker, else attach to target
                                        switch(Utils.getSpellTargetType(procSpell.getTargettype())) {
                                            case Self:
                                                procSpell.tryApplyOnEntity(plugin, this.getBukkitLivingEntity(), this.getBukkitLivingEntity());
                                                break;
                                            case Group:
                                                procSpell.tryApplyOnEntity(plugin, this.getBukkitLivingEntity(), this.getBukkitLivingEntity());
                                                break;
                                            default:
                                                procSpell.tryApplyOnEntity(plugin, this.getBukkitLivingEntity(), defender.getBukkitLivingEntity());
                                        }
                                    }
                                }
                            }
                        }
                    } catch (SoliniaItemException e) {
                    // skip
                    }
                }
                // Check if attacker has any WeaponProc effects
                SoliniaEntitySpells effects = StateManager.getInstance().getEntityManager().getActiveEntitySpells(this.getBukkitLivingEntity());
                if (effects != null) {
                    for (SoliniaActiveSpell activeSpell : effects.getActiveSpells()) {
                        ISoliniaSpell spell = StateManager.getInstance().getConfigurationManager().getSpell(activeSpell.getSpellId());
                        if (spell == null)
                            continue;
                        if (!spell.isWeaponProc())
                            continue;
                        for (ActiveSpellEffect spelleffect : activeSpell.getActiveSpellEffects()) {
                            if (spelleffect.getSpellEffectType().equals(SpellEffectType.WeaponProc)) {
                                if (spelleffect.getBase() < 0)
                                    continue;
                                ISoliniaSpell procSpell = StateManager.getInstance().getConfigurationManager().getSpell(spelleffect.getBase());
                                if (spell == null)
                                    continue;
                                // Chance to proc
                                int procChance = getProcChancePct();
                                int roll = Utils.RandomBetween(0, 100);
                                if (roll < procChance) {
                                    boolean itemUseSuccess = procSpell.tryApplyOnEntity(plugin, this.getBukkitLivingEntity(), defender.getBukkitLivingEntity());
                                    if (procSpell.getActSpellCost(this) > 0)
                                        if (itemUseSuccess) {
                                            if (getBukkitLivingEntity() instanceof Player) {
                                                SoliniaPlayerAdapter.Adapt((Player) getBukkitLivingEntity()).reducePlayerMana(procSpell.getActSpellCost(this));
                                            }
                                        }
                                }
                            }
                        }
                    }
                }
            } catch (CoreStateInitException e) {
            }
        }
        if (defender.getBukkitLivingEntity() instanceof Player) {
            ((Player) defender.getBukkitLivingEntity()).spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent("You were hit by " + getBukkitLivingEntity().getCustomName() + " for " + df.format(event.getDamage()) + " " + my_hit.skill + " damage"));
        }
        if (event.getDamage() > getBukkitLivingEntity().getHealth() && hasDeathSave() > 0) {
            Utils.CancelEvent(event);
            removeDeathSaves(plugin);
            getBukkitLivingEntity().sendMessage("* Your death save boon has saved you from death!");
            return false;
        }
        defender.damageHook(event.getDamage(), getBukkitLivingEntity());
        return true;
    } else {
        Utils.CancelEvent(event);
        return false;
    }
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) ISoliniaSpell(com.solinia.solinia.Interfaces.ISoliniaSpell) DecimalFormat(java.text.DecimalFormat) SoliniaItemException(com.solinia.solinia.Exceptions.SoliniaItemException) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ItemStack(org.bukkit.inventory.ItemStack)

Example 44 with ISoliniaNPC

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

the class SoliniaLivingEntity method getAgility.

@Override
public int getAgility() {
    if (getNpcid() < 1 && !isPlayer())
        return 1;
    try {
        if (getNpcid() > 0) {
            ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(getNpcid());
            if (npc == null)
                return 1;
            int stat = npc.getLevel() * 5;
            stat += Utils.getTotalEffectStat(this.getBukkitLivingEntity(), "AGILITY");
            if (stat > getMaxStat("AGILITY"))
                stat = getMaxStat("AGILITY");
            return stat;
        }
        if (isPlayer()) {
            ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt((Player) getBukkitLivingEntity());
            if (solplayer == null)
                return 1;
            int stat = 1;
            if (solplayer.getRace() != null)
                stat += solplayer.getRace().getAgility();
            stat += solplayer.getTotalItemStat("AGILITY");
            stat += Utils.getTotalEffectStat(this.getBukkitLivingEntity(), "AGILITY");
            stat += Utils.getTotalAAEffectStat(this.getBukkitLivingEntity(), "AGILITY");
            if (stat > getMaxStat("AGILITY"))
                stat = getMaxStat("AGILITY");
            return stat;
        }
    } catch (CoreStateInitException e) {
        return 1;
    }
    return 1;
}
Also used : CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer)

Example 45 with ISoliniaNPC

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

the class SoliniaLivingEntity method computeToHit.

@Override
public int computeToHit(String skillname) {
    double tohit = getSkill("OFFENSE") + 7;
    tohit += getSkill(skillname.toUpperCase());
    if (isNPC()) {
        try {
            ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(this.getNpcid());
            if (npc != null)
                tohit += npc.getAccuracyRating();
        } catch (CoreStateInitException e) {
        // 
        }
    }
    if (isPlayer()) {
        double reduction = getIntoxication() / 2.0;
        if (reduction > 20.0) {
            reduction = Math.min((110 - reduction) / 100.0, 1.0);
            tohit = reduction * (double) (tohit);
        } else if (isBerserk()) {
            tohit += (getLevel() * 2) / 5;
        }
    }
    return (int) Math.max(tohit, 1);
}
Also used : 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