Search in sources :

Example 1 with EntityDamageSource

use of net.minecraft.server.v1_12_R1.EntityDamageSource 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 2 with EntityDamageSource

use of net.minecraft.server.v1_12_R1.EntityDamageSource in project solinia3-core by mixxit.

the class SoliniaActiveSpell method applyBackstab.

private void applyBackstab(SpellEffect spellEffect, ISoliniaSpell soliniaSpell, int casterLevel) {
    if (getLivingEntity().isDead())
        return;
    if (Bukkit.getEntity(getSourceUuid()) == null)
        return;
    Entity sourceEntity = Bukkit.getEntity(getSourceUuid());
    if (sourceEntity == null)
        return;
    if (!(sourceEntity instanceof LivingEntity))
        return;
    LivingEntity sourceLivingEntity = (LivingEntity) sourceEntity;
    try {
        ISoliniaLivingEntity solSourceEntity = SoliniaLivingEntityAdapter.Adapt(sourceLivingEntity);
        if (solSourceEntity == null)
            return;
        int backstabSkill = solSourceEntity.getSkill("BACKSTAB");
        if (backstabSkill < 1)
            backstabSkill = 1;
        EntityDamageSource source = new EntityDamageSource("thorns", ((CraftEntity) Bukkit.getEntity(getSourceUuid())).getHandle());
        source.setMagic();
        source.ignoresArmor();
        int weaponDamage = 0;
        // Offhand item only
        ItemStack mainitem = sourceLivingEntity.getEquipment().getItemInOffHand();
        if (mainitem != null) {
            try {
                ISoliniaItem item = SoliniaItemAdapter.Adapt(mainitem);
                if (item != null)
                    if (item.getDamage() > 0) {
                        weaponDamage = item.getDamage();
                    }
            } catch (SoliniaItemException e) {
            }
        }
        if (weaponDamage < 1)
            weaponDamage = 1;
        int hpToRemove = weaponDamage;
        // back stab formula
        if (solSourceEntity.isBehindEntity(this.getLivingEntity()))
            hpToRemove = (int) Math.floor((2 + backstabSkill / 50) * weaponDamage);
        ((CraftEntity) getLivingEntity()).getHandle().damageEntity(source, hpToRemove);
        solSourceEntity.tryIncreaseSkill("BACKSTAB", 1);
    } catch (CoreStateInitException e) {
    }
}
Also used : CraftLivingEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity) 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) PathEntity(net.minecraft.server.v1_12_R1.PathEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ItemStack(org.bukkit.inventory.ItemStack) SoliniaItemException(com.solinia.solinia.Exceptions.SoliniaItemException) EntityDamageSource(net.minecraft.server.v1_12_R1.EntityDamageSource)

Example 3 with EntityDamageSource

use of net.minecraft.server.v1_12_R1.EntityDamageSource in project solinia3-core by mixxit.

the class SoliniaActiveSpell method applyCurrentHpOnceSpellEffect.

private void applyCurrentHpOnceSpellEffect(SpellEffect spellEffect, ISoliniaSpell soliniaSpell, int caster_level) {
    if (getLivingEntity().isDead())
        return;
    if (Bukkit.getEntity(getSourceUuid()) == null)
        return;
    Entity sourceEntity = Bukkit.getEntity(getSourceUuid());
    if (sourceEntity == null)
        return;
    if (!(sourceEntity instanceof LivingEntity))
        return;
    LivingEntity sourceLivingEntity = (LivingEntity) sourceEntity;
    int instrument_mod = 0;
    try {
        ISoliniaLivingEntity sourceSoliniaLivingEntity = SoliniaLivingEntityAdapter.Adapt(sourceLivingEntity);
        if (sourceSoliniaLivingEntity != null) {
            instrument_mod = sourceSoliniaLivingEntity.getInstrumentMod(this.getSpell());
        }
    } catch (CoreStateInitException e) {
    // just skip it
    }
    // HP spells also get calculated based on the caster and the recipient
    int hpToAdd = soliniaSpell.calcSpellEffectValue(spellEffect, sourceLivingEntity, getLivingEntity(), caster_level, getTicksLeft(), instrument_mod);
    // hpToRemove should really be called hpToAdd
    if (hpToAdd < 0) {
        // Criticals
        try {
            ISoliniaLivingEntity sourceSoliniaLivingEntity = SoliniaLivingEntityAdapter.Adapt(sourceLivingEntity);
            ISoliniaLivingEntity targetSoliniaLivingEntity = SoliniaLivingEntityAdapter.Adapt(getLivingEntity());
            if (sourceSoliniaLivingEntity != null && targetSoliniaLivingEntity != null) {
                // reverse to positive then pass it back reversed
                hpToAdd = (sourceSoliniaLivingEntity.getActSpellDamage(soliniaSpell, (hpToAdd * -1), spellEffect, targetSoliniaLivingEntity) * -1);
            }
        } catch (CoreStateInitException e) {
        // just carry on without the crit bonus
        }
        hpToAdd = hpToAdd * -1;
        EntityDamageSource source = new EntityDamageSource("thorns", ((CraftEntity) Bukkit.getEntity(getSourceUuid())).getHandle());
        source.setMagic();
        source.ignoresArmor();
        ((CraftEntity) getLivingEntity()).getHandle().damageEntity(source, hpToAdd);
        // getLivingEntity().damage(hpToRemove, Bukkit.getEntity(getSourceUuid()));
        if (soliniaSpell.isLifetapSpell()) {
            if (!(sourceEntity instanceof LivingEntity))
                return;
            int amount = (int) Math.round(sourceLivingEntity.getHealth()) + hpToAdd;
            if (amount > sourceLivingEntity.getMaxHealth()) {
                amount = (int) Math.round(sourceLivingEntity.getMaxHealth());
            }
            if (amount < 0)
                amount = 0;
            sourceLivingEntity.setHealth(amount);
        }
    } else // Heal
    {
        // Criticals
        try {
            ISoliniaLivingEntity sourceSoliniaLivingEntity = SoliniaLivingEntityAdapter.Adapt(sourceLivingEntity);
            ISoliniaLivingEntity targetSoliniaLivingEntity = SoliniaLivingEntityAdapter.Adapt(getLivingEntity());
            if (sourceSoliniaLivingEntity != null && targetSoliniaLivingEntity != null) {
                hpToAdd = sourceSoliniaLivingEntity.getActSpellHealing(soliniaSpell, hpToAdd, spellEffect, targetSoliniaLivingEntity);
            }
        } catch (CoreStateInitException e) {
        // just carry on without the crit bonus
        }
        int amount = (int) Math.round(getLivingEntity().getHealth()) + hpToAdd;
        if (amount > getLivingEntity().getMaxHealth()) {
            amount = (int) Math.round(getLivingEntity().getMaxHealth());
        }
        if (amount < 0)
            amount = 0;
        getLivingEntity().setHealth(amount);
    }
}
Also used : CraftLivingEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity) 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) PathEntity(net.minecraft.server.v1_12_R1.PathEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) EntityDamageSource(net.minecraft.server.v1_12_R1.EntityDamageSource)

Aggregations

CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)3 EntityDamageSource (net.minecraft.server.v1_12_R1.EntityDamageSource)3 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)2 PathEntity (net.minecraft.server.v1_12_R1.PathEntity)2 CraftEntity (org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity)2 CraftLivingEntity (org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity)2 Entity (org.bukkit.entity.Entity)2 LivingEntity (org.bukkit.entity.LivingEntity)2 SoliniaItemException (com.solinia.solinia.Exceptions.SoliniaItemException)1 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)1 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)1 ISoliniaSpell (com.solinia.solinia.Interfaces.ISoliniaSpell)1 DecimalFormat (java.text.DecimalFormat)1 TextComponent (net.md_5.bungee.api.chat.TextComponent)1 Player (org.bukkit.entity.Player)1 ItemStack (org.bukkit.inventory.ItemStack)1