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;
}
}
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) {
}
}
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);
}
}
Aggregations