@Override
 public boolean attackEntityFrom(DamageSource par1DamageSource, float par2) {
   EnumUnits unit = getUnitType();
   if ((unit == EnumUnits.KnightShield || unit == EnumUnits.KnightSpear)
       && par1DamageSource.isProjectile()) {
     return super.attackEntityFrom(par1DamageSource, (int) (par2 * .75F));
   } else return super.attackEntityFrom(par1DamageSource, par2);
 }
 /** Returns true if the shield can block this kind of damage */
 public boolean canBlockDamage(ItemStack shield, DamageSource source) {
   boolean flag = source.isUnblockable() && !(source instanceof DamageSourceArmorBreak);
   if (toolMaterial == ToolMaterial.WOOD) {
     return !flag;
   }
   return !flag
       || source.isMagicDamage()
       || source.isFireDamage()
       || (source.isProjectile() && toolMaterial == ToolMaterial.EMERALD);
 }
Exemplo n.º 3
0
  @Override
  public ArmorProperties getProperties(
      EntityLivingBase player, ItemStack stack, DamageSource source, double damage, int slot) {
    int h = getArmorMaterial().getDamageReductionAmount(EntityEquipmentSlot.HEAD);
    int c = getArmorMaterial().getDamageReductionAmount(EntityEquipmentSlot.CHEST);
    int p = getArmorMaterial().getDamageReductionAmount(EntityEquipmentSlot.LEGS);
    int b = getArmorMaterial().getDamageReductionAmount(EntityEquipmentSlot.FEET);

    if (!stack.hasTagCompound()) stack.setTagCompound(new NBTTagCompound());

    if (stack.getTagCompound().getBoolean("destroyed"))
      return new ArmorProperties(0, 1 / damage, 1);

    if (stack.getTagCompound().getByte("all") > 0) {
      h += 1;
      c += 2;
      p += 1;
      b += 1;
    } else if (stack.getTagCompound().getByte("blast") > 0 && source.isExplosion()) {
      h += 2;
      c += 3;
      p += 2;
      b += 2;
    } else if (stack.getTagCompound().getByte("fire") > 0 && source.isFireDamage()) {
      h += 2;
      c += 3;
      p += 2;
      b += 2;
    } else if (stack.getTagCompound().getByte("magic") > 0 && source.isMagicDamage()) {
      h += 2;
      c += 3;
      p += 2;
      b += 2;
    } else if (stack.getTagCompound().getByte("projectile") > 0 && source.isProjectile()) {
      h += 2;
      c += 3;
      p += 2;
      b += 2;
    }

    switch (slot) {
      case 3:
        return new ArmorProperties(0, h / 25D, Integer.MAX_VALUE);
      case 2:
        return new ArmorProperties(1, c / 25D, Integer.MAX_VALUE);
      case 1:
        return new ArmorProperties(1, p / 25D, Integer.MAX_VALUE);
      case 0:
        return new ArmorProperties(0, b / 25D, Integer.MAX_VALUE);
      default:
        return null;
    }
  }
Exemplo n.º 4
0
  @Override
  public void damageArmor(
      EntityLivingBase entity, ItemStack stack, DamageSource source, int damage, int slot) {
    if (!stack.hasTagCompound()) stack.setTagCompound(new NBTTagCompound());

    if (stack.getItemDamage() >= stack.getMaxDamage() - 2) {
      NBTTagCompound tag = stack.getTagCompound();
      tag.setBoolean("destroyed", true);
      stack.setTagCompound(tag);

      return;
    }

    if (stack.getTagCompound().getByte("all") > 0) stack.damageItem(1, entity);
    else if (stack.getTagCompound().getByte("blast") > 0 && source.isExplosion())
      stack.damageItem(1, entity);
    else if (stack.getTagCompound().getByte("fire") > 0 && source.isFireDamage())
      stack.damageItem(1, entity);
    else if (stack.getTagCompound().getByte("magic") > 0 && source.isMagicDamage())
      stack.damageItem(1, entity);
    else if (stack.getTagCompound().getByte("projectile") > 0 && source.isProjectile())
      stack.damageItem(1, entity);
    else if (!source.isUnblockable()) stack.damageItem(2, entity);
  }
 /**
  * Called when the shield blocks an attack when held in the normal fashion (i.e. non-BG2) used by
  * Deku Shield to damage / destroy the stack and by Mirror Shield to reflect projectiles
  *
  * @return Return the amount of damage remaining, if any; 0 cancels the hurt event
  */
 public float onBlock(EntityPlayer player, ItemStack shield, DamageSource source, float damage) {
   ZSSPlayerInfo.get(player).onAttackBlocked(shield, damage);
   WorldUtils.playSoundAtEntity(player, Sounds.HAMMER, 0.4F, 0.5F);
   float damageBlocked = damage;
   if (toolMaterial == ToolMaterial.WOOD) {
     if (source.isProjectile()
         && !source.isExplosion()
         && source.getSourceOfDamage() instanceof IProjectile) {
       if (ZSSMain.isBG2Enabled
           && player.getHeldItem() == shield
           && shield.getItem() instanceof IArrowCatcher) {
         if (((IArrowCatcher) shield.getItem())
             .catchArrow(shield, player, (IProjectile) source.getSourceOfDamage())) {
           ((InventoryPlayerBattle) player.inventory).hasChanged = true;
         }
       }
     } else if (source instanceof IDamageAoE && ((IDamageAoE) source).isAoEDamage()) {
       damageBlocked *= magicReduction;
     }
     int dmg = Math.round(source.isFireDamage() ? damage + 10.0F : damage - 2.0F);
     if (dmg > 0) {
       shield.damageItem(dmg, player);
       if (shield.stackSize <= 0) {
         ForgeEventFactory.onPlayerDestroyItem(player, shield);
         if (ZSSMain.isBG2Enabled && BattlegearUtils.isPlayerInBattlemode(player)) {
           BattlegearUtils.setPlayerOffhandItem(player, null);
         } else {
           player.destroyCurrentEquippedItem();
         }
       }
     }
   } else if (toolMaterial == ToolMaterial.EMERALD) {
     if (source.isProjectile() && !source.isExplosion() && source.getSourceOfDamage() != null) {
       float chance = (source.isMagicDamage() ? (1F / 3F) : 1.0F);
       if (source.getSourceOfDamage() instanceof IReflectable) {
         ((IReflectable) source.getSourceOfDamage())
             .getReflectChance(shield, player, source.getEntity());
       }
       if (player.worldObj.rand.nextFloat() < chance) {
         Entity projectile = null;
         try {
           projectile =
               source
                   .getSourceOfDamage()
                   .getClass()
                   .getConstructor(World.class)
                   .newInstance(player.worldObj);
         } catch (Exception e) {;
         }
         if (projectile != null) {
           NBTTagCompound data = new NBTTagCompound();
           source.getSourceOfDamage().writeToNBT(data);
           projectile.readFromNBT(data);
           projectile.getEntityData().setBoolean("isReflected", true);
           projectile.posX -= projectile.motionX;
           projectile.posY -= projectile.motionY;
           projectile.posZ -= projectile.motionZ;
           double motionX =
               (double)
                   (-MathHelper.sin(player.rotationYaw / 180.0F * (float) Math.PI)
                       * MathHelper.cos(player.rotationPitch / 180.0F * (float) Math.PI));
           double motionZ =
               (double)
                   (MathHelper.cos(player.rotationYaw / 180.0F * (float) Math.PI)
                       * MathHelper.cos(player.rotationPitch / 180.0F * (float) Math.PI));
           double motionY =
               (double) (-MathHelper.sin(player.rotationPitch / 180.0F * (float) Math.PI));
           TargetUtils.setEntityHeading(
               projectile,
               motionX,
               motionY,
               motionZ,
               1.0F,
               2.0F + (20.0F * player.worldObj.rand.nextFloat()),
               false);
           if (projectile instanceof IReflectable) {
             ((IReflectable) projectile)
                 .onReflected(shield, player, source.getEntity(), source.getSourceOfDamage());
           }
           player.worldObj.spawnEntityInWorld(projectile);
         }
       } else if (source.isUnblockable()
           || (source instanceof IDamageAoE
               && ((IDamageAoE) source).isAoEDamage())) { // failed to reflect projectile
         damageBlocked *= magicReduction;
       }
     }
   } else if (source.isUnblockable()
       || (source instanceof IDamageAoE && ((IDamageAoE) source).isAoEDamage())) {
     damageBlocked *=
         magicReduction; // default shield behavior blocks half damage from AoE magic attacks
   }
   return (damage - damageBlocked);
 }
  @Override
  public boolean attackEntityFrom(DamageSource src, float dmg) {
    if (src.isProjectile() || this.worldObj.isRemote) return false;

    if (src.getEntity() instanceof EntityLivingBase) {
      EntityLivingBase entity = (EntityLivingBase) src.getEntity();
      boolean flag =
          TragicConfig.getBoolean("allowDivinity") && entity.isPotionActive(TragicPotion.Divinity);

      if (rand.nextInt(4) == 0
          && this.getAttackTarget() != entity
          && entity.getCreatureAttribute() != TragicEntities.Synapse) this.setAttackTarget(entity);

      if (flag && this.hurtResistantTime == 0
          || !TragicConfig.getBoolean("allowDivinity")
              && entity.getCreatureAttribute() != TragicEntities.Synapse
              && this.hurtResistantTime == 0
          || entity.getHeldItem() != null
              && entity.getHeldItem().getItem() == TragicItems.SwordOfJustice
          || src.canHarmInCreative()
          || !TragicConfig.getBoolean("overlordDivineWeakness")
          || !TragicConfig.getBoolean("overlordPhases")) {
        this.phaseDamage +=
            MathHelper.clamp_float(
                dmg - this.getTotalArmorValue(), 0F, (float) TragicConfig.getInt("bossDamageCap"));

        if (this.getCurrentPhase() < 4) {
          float f = this.getMaxHealth() / 5;
          switch (this.getCurrentPhase()) {
            case 0:
              f *= 4;
              break;
            case 1:
              f *= 3;
              break;
            case 2:
              f *= 2;
              break;
            case 3:
              break;
            case 4:
              f = 0;
              break;
            default:
              break;
          }

          if (this.getHealth()
                          - MathHelper.clamp_float(
                              dmg - this.getTotalArmorValue(),
                              0F,
                              (float) TragicConfig.getInt("bossDamageCap"))
                      <= f
                  && f > 0
              || this.phaseDamage >= this.getMaxHealth() / 5) {
            this.phaseChange = true;
            dmg = 0;
            this.phaseDamage = 0F;
          }
        }

        if (rand.nextBoolean()
            && this.worldObj
                    .getEntitiesWithinAABB(
                        EntityNanoSwarm.class,
                        this.getEntityBoundingBox().expand(64.0, 64.0, 64.0D))
                    .size()
                < 16
            && this.getCurrentPhase() > 1
            && TragicConfig.getBoolean("allowNanoSwarm")
            && TragicConfig.getBoolean("overlordNanoSwarms")) {
          EntityNanoSwarm swarm = new EntityNanoSwarm(this.worldObj);
          swarm.setPosition(
              this.posX + rand.nextInt(6) - rand.nextInt(6),
              this.posY,
              this.posZ + rand.nextInt(6) - rand.nextInt(6));
          this.worldObj.spawnEntityInWorld(swarm);
        }

        return super.attackEntityFrom(src, dmg);
      }
    }
    return true;
  }