Search in sources :

Example 66 with CoreStateInitException

use of com.solinia.solinia.Exceptions.CoreStateInitException in project solinia3-core by mixxit.

the class SoliniaLivingEntity method triggerDefensiveProcs.

private void triggerDefensiveProcs(ISoliniaLivingEntity defender, int damage, boolean arrowHit) {
    if (damage < 0)
        return;
    if (arrowHit)
        return;
    try {
        SoliniaEntitySpells effects = StateManager.getInstance().getEntityManager().getActiveEntitySpells(defender.getBukkitLivingEntity());
        if (effects == null)
            return;
        for (SoliniaActiveSpell activeSpell : effects.getActiveSpells()) {
            ISoliniaSpell spell = StateManager.getInstance().getConfigurationManager().getSpell(activeSpell.getSpellId());
            if (spell == null)
                continue;
            if (!spell.isDamageShield())
                continue;
            for (ActiveSpellEffect spelleffect : activeSpell.getActiveSpellEffects()) {
                if (spelleffect.getSpellEffectType().equals(SpellEffectType.DamageShield)) {
                    // hurt enemy with damage shield
                    if (spelleffect.getCalculatedValue() < 0) {
                        EntityDamageSource source = new EntityDamageSource("thorns", ((CraftEntity) defender.getBukkitLivingEntity()).getHandle());
                        source.setMagic();
                        source.ignoresArmor();
                        ((CraftEntity) this.getBukkitLivingEntity()).getHandle().damageEntity(source, spelleffect.getCalculatedValue() * -1);
                        // attacker.damage(spelleffect.getBase() * -1);
                        DecimalFormat df = new DecimalFormat();
                        df.setMaximumFractionDigits(2);
                        if (defender instanceof Player) {
                            ((Player) defender.getBukkitLivingEntity()).spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent("Your damage shield hit " + this.getBukkitLivingEntity().getName() + " for " + df.format(spelleffect.getCalculatedValue() * -1) + "[" + df.format(this.getBukkitLivingEntity().getHealth() - (spelleffect.getCalculatedValue() * -1)) + "/" + df.format(this.getBukkitLivingEntity().getMaxHealth()) + "]"));
                        }
                    }
                }
            }
        }
    } catch (CoreStateInitException e) {
        return;
    }
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaSpell(com.solinia.solinia.Interfaces.ISoliniaSpell) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) DecimalFormat(java.text.DecimalFormat) EntityDamageSource(net.minecraft.server.v1_12_R1.EntityDamageSource)

Example 67 with CoreStateInitException

use of com.solinia.solinia.Exceptions.CoreStateInitException in project solinia3-core by mixxit.

the class SoliniaPlayer method updateMaxHp.

@Override
public void updateMaxHp() {
    if (getBukkitPlayer() != null && getExperience() != null) {
        try {
            ISoliniaLivingEntity solentity = SoliniaLivingEntityAdapter.Adapt(getBukkitPlayer());
            double calculatedhp = solentity.getMaxHP();
            getBukkitPlayer().setMaxHealth(calculatedhp);
            getBukkitPlayer().setHealthScaled(true);
            getBukkitPlayer().setHealthScale(40D);
        } catch (CoreStateInitException e) {
        }
    }
}
Also used : ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException)

Example 68 with CoreStateInitException

use of com.solinia.solinia.Exceptions.CoreStateInitException in project solinia3-core by mixxit.

the class SoliniaPlayer method getTotalResist.

@Override
public int getTotalResist(SpellResistType type) {
    int total = 0;
    // Get resist total from all active effects
    try {
        total += SoliniaLivingEntityAdapter.Adapt(getBukkitPlayer()).getResistsFromActiveEffects(type);
        int effectId = 0;
        switch(type) {
            case RESIST_FIRE:
                effectId = Utils.getEffectIdFromEffectType(SpellEffectType.ResistFire);
                break;
            case RESIST_COLD:
                effectId = Utils.getEffectIdFromEffectType(SpellEffectType.ResistCold);
                break;
            case RESIST_MAGIC:
                effectId = Utils.getEffectIdFromEffectType(SpellEffectType.ResistMagic);
                break;
            case RESIST_POISON:
                effectId = Utils.getEffectIdFromEffectType(SpellEffectType.ResistPoison);
                break;
            case RESIST_DISEASE:
                effectId = Utils.getEffectIdFromEffectType(SpellEffectType.ResistDisease);
                break;
            default:
                break;
        }
        if (effectId > 0) {
            for (SoliniaAARankEffect effect : this.getRanksEffectsOfEffectType(effectId)) {
                total += effect.getBase1();
            }
        }
        int resistAllEffectId = Utils.getEffectIdFromEffectType(SpellEffectType.ResistAll);
        for (SoliniaAARankEffect effect : this.getRanksEffectsOfEffectType(resistAllEffectId)) {
            total += effect.getBase1();
        }
    } catch (CoreStateInitException e) {
    // Skip
    }
    for (ISoliniaItem item : this.getEquippedSoliniaItems()) {
        switch(type) {
            case RESIST_FIRE:
                if (item.getFireResist() > 0) {
                    total += item.getFireResist();
                }
                break;
            case RESIST_COLD:
                if (item.getColdResist() > 0) {
                    total += item.getColdResist();
                }
                break;
            case RESIST_MAGIC:
                if (item.getMagicResist() > 0) {
                    total += item.getMagicResist();
                }
                break;
            case RESIST_POISON:
                if (item.getPoisonResist() > 0) {
                    total += item.getPoisonResist();
                }
                break;
            case RESIST_DISEASE:
                if (item.getDiseaseResist() > 0) {
                    total += item.getDiseaseResist();
                }
                break;
            default:
                break;
        }
    }
    if (total > 255)
        return 255;
    return total;
}
Also used : ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException)

Example 69 with CoreStateInitException

use of com.solinia.solinia.Exceptions.CoreStateInitException in project solinia3-core by mixxit.

the class SoliniaLivingEntity method getDefenseByDefenseSkill.

@Override
public int getDefenseByDefenseSkill() {
    double defense = getSkill("DEFENSE") * 400 / 225;
    defense += (8000 * (getAgility() - 40)) / 36000;
    // defense += itembonuses.AvoidMeleeChance; // item mod2
    if (isNPC()) {
        try {
            ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(this.getNpcid());
            defense += npc.getAvoidanceRating();
        } catch (CoreStateInitException e) {
        // no bonus
        }
    }
    if (isPlayer()) {
        double reduction = getIntoxication() / 2.0;
        if (reduction > 20.0) {
            reduction = Math.min((110 - reduction) / 100.0, 1.0);
            defense = reduction * (double) (defense);
        }
    }
    return (int) Math.max(1, defense);
}
Also used : CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC)

Example 70 with CoreStateInitException

use of com.solinia.solinia.Exceptions.CoreStateInitException in project solinia3-core by mixxit.

the class SoliniaLivingEntity method getStrength.

@Override
public int getStrength() {
    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(), "STRENGTH");
            if (stat > getMaxStat("STRENGTH"))
                stat = getMaxStat("STRENGTH");
            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().getStrength();
            stat += solplayer.getTotalItemStat("STRENGTH");
            stat += Utils.getTotalEffectStat(this.getBukkitLivingEntity(), "STRENGTH");
            stat += Utils.getTotalAAEffectStat(this.getBukkitLivingEntity(), "STRENGTH");
            if (stat > getMaxStat("STRENGTH"))
                stat = getMaxStat("STRENGTH");
            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)

Aggregations

CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)216 Player (org.bukkit.entity.Player)114 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)99 ISoliniaNPC (com.solinia.solinia.Interfaces.ISoliniaNPC)43 CommandSender (org.bukkit.command.CommandSender)42 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)41 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)36 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)36 LivingEntity (org.bukkit.entity.LivingEntity)32 ArrayList (java.util.ArrayList)31 Entity (org.bukkit.entity.Entity)21 ItemStack (org.bukkit.inventory.ItemStack)20 SoliniaItemException (com.solinia.solinia.Exceptions.SoliniaItemException)17 ISoliniaSpell (com.solinia.solinia.Interfaces.ISoliniaSpell)16 EventHandler (org.bukkit.event.EventHandler)16 Timestamp (java.sql.Timestamp)13 TextComponent (net.md_5.bungee.api.chat.TextComponent)12 CraftEntity (org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity)11 CraftLivingEntity (org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity)11 PathEntity (net.minecraft.server.v1_12_R1.PathEntity)10