Skip to content
Permalink
Browse files

Add backup armor calculations, for #6

  • Loading branch information...
mcmonkey4eva committed Apr 16, 2016
1 parent 19b826a commit e3e7115808e68441b75bad177397582cb15d266b
Showing with 9 additions and 9 deletions.
  1. +8 −8 src/main/java/org/mcmonkey/sentinel/SentinelTrait.java
  2. +1 −1 src/main/resources/config.yml
@@ -167,13 +167,13 @@ public void setGuarding(UUID uuid) {
}
}

@EventHandler
@EventHandler(priority = EventPriority.HIGH)
public void whenAttacksAreHappening(EntityDamageByEntityEvent event) {
if (!npc.isSpawned()) {
return;
}
if (event.getEntity().getUniqueId().equals(getLivingEntity().getUniqueId())) {
event.setDamage(EntityDamageEvent.DamageModifier.ARMOR, -getArmor() * event.getDamage(EntityDamageEvent.DamageModifier.BASE));
event.setDamage(EntityDamageEvent.DamageModifier.ARMOR, -getArmor(getLivingEntity()) * event.getDamage(EntityDamageEvent.DamageModifier.BASE));
return;
}
if (event.getDamager().getUniqueId().equals(getLivingEntity().getUniqueId())) {
@@ -404,11 +404,11 @@ public double getDamage() {
return damage;
}

public double getArmor() {
public double getArmor(LivingEntity ent) {
if (armor < 0) {
// TODO: Enchantments!
double baseArmor = 0;
ItemStack helmet = getLivingEntity().getEquipment().getHelmet();
ItemStack helmet = ent.getEquipment().getHelmet();
if (helmet != null && helmet.getType() == Material.DIAMOND_HELMET) {
baseArmor += 0.12;
}
@@ -424,7 +424,7 @@ public double getArmor() {
if (helmet != null && helmet.getType() == Material.CHAINMAIL_HELMET) {
baseArmor += 0.08;
}
ItemStack chestplate = getLivingEntity().getEquipment().getChestplate();
ItemStack chestplate = ent.getEquipment().getChestplate();
if (chestplate != null && chestplate.getType() == Material.DIAMOND_CHESTPLATE) {
baseArmor += 0.32;
}
@@ -440,7 +440,7 @@ public double getArmor() {
if (chestplate != null && chestplate.getType() == Material.CHAINMAIL_CHESTPLATE) {
baseArmor += 0.20;
}
ItemStack leggings = getLivingEntity().getEquipment().getLeggings();
ItemStack leggings = ent.getEquipment().getLeggings();
if (leggings != null && leggings.getType() == Material.DIAMOND_LEGGINGS) {
baseArmor += 0.24;
}
@@ -456,7 +456,7 @@ public double getArmor() {
if (leggings != null && leggings.getType() == Material.CHAINMAIL_LEGGINGS) {
baseArmor += 0.16;
}
ItemStack boots = getLivingEntity().getEquipment().getBoots();
ItemStack boots = ent.getEquipment().getBoots();
if (boots != null && boots.getType() == Material.DIAMOND_BOOTS) {
baseArmor += 0.12;
}
@@ -482,7 +482,7 @@ public void punch(LivingEntity entity) {
swingWeapon();
stats_punches++;
if (SentinelPlugin.instance.getConfig().getBoolean("random.workaround damage", false)) {
entity.damage(getDamage());
entity.damage(getDamage() * (1.0 - getArmor(entity)));
}
else {
entity.damage(getDamage(), getLivingEntity());
@@ -37,4 +37,4 @@ random:
update rate: 10

# Do not touch!
config version: 1
config version: 2

0 comments on commit e3e7115

Please sign in to comment.
You can’t perform that action at this time.