Search in sources :

Example 1 with CustomArrowEntity

use of com.minecolonies.coremod.entity.CustomArrowEntity in project minecolonies by ldtteam.

the class RangerCombatAI method calculateDamage.

/**
 * Calculates the ranged attack damage
 *
 * @param arrow
 * @return the attack damage
 */
private double calculateDamage(final AbstractArrowEntity arrow) {
    int damage = user.getCitizenData().getCitizenSkillHandler().getLevel(Skill.Agility) / 5;
    final ItemStack heldItem = user.getItemInHand(Hand.MAIN_HAND);
    damage += EnchantmentHelper.getDamageBonus(heldItem, target.getMobType()) / 2.5;
    damage += EnchantmentHelper.getItemEnchantmentLevel(Enchantments.POWER_ARROWS, heldItem);
    damage += user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(ARCHER_DAMAGE);
    if (user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(ARCHER_USE_ARROWS) > 0) {
        int slot = InventoryUtils.findFirstSlotInItemHandlerWith(user.getInventoryCitizen(), item -> item.getItem() instanceof ArrowItem);
        if (slot != -1) {
            if (!ItemStackUtils.isEmpty(user.getInventoryCitizen().extractItem(slot, 1, true))) {
                damage += ARROW_EXTRA_DAMAGE;
                ((CustomArrowEntity) arrow).setOnHitCallback(entityRayTraceResult -> {
                    final int arrowSlot = InventoryUtils.findFirstSlotInItemHandlerWith(user.getInventoryCitizen(), item -> item.getItem() instanceof ArrowItem);
                    if (arrowSlot != -1) {
                        user.getInventoryCitizen().extractItem(arrowSlot, 1, false);
                    }
                    return true;
                });
            }
        }
    }
    if (user.getHealth() <= user.getMaxHealth() * 0.2D) {
        damage *= 2;
    }
    return (RANGER_BASE_DMG + damage) * MineColonies.getConfig().getServer().rangerDamageMult.get();
}
Also used : CustomArrowEntity(com.minecolonies.coremod.entity.CustomArrowEntity) ArrowItem(net.minecraft.item.ArrowItem) ItemStack(net.minecraft.item.ItemStack)

Example 2 with CustomArrowEntity

use of com.minecolonies.coremod.entity.CustomArrowEntity in project minecolonies by ldtteam.

the class RaiderRangedAI method doAttack.

@Override
protected void doAttack(final LivingEntity target) {
    user.getNavigation().stop();
    // Setup arrow
    AbstractArrowEntity arrowEntity = CombatUtils.createArrowForShooter(user);
    arrowEntity.setBaseDamage(user.getAttribute(MOB_ATTACK_DAMAGE).getValue());
    if (flightCounter > 5) {
        ((CustomArrowEntity) arrowEntity).setPlayerArmorPierce();
        arrowEntity.setSecondsOnFire(200);
        arrowEntity.setBaseDamage(10);
    }
    if (user.getDifficulty() > ARROW_PIERCE_DIFFICULTY) {
        arrowEntity.setPierceLevel((byte) 2);
    }
    // Shoot arrow
    CombatUtils.shootArrow(arrowEntity, target, 10.0f);
    // Visuals
    user.swing(Hand.MAIN_HAND);
    SoundEvent attackSound = SoundEvents.SKELETON_SHOOT;
    if (arrowEntity instanceof ICustomAttackSound) {
        attackSound = ((ICustomAttackSound) arrowEntity).getAttackSound();
    }
    user.playSound(attackSound, (float) 1.0D, (float) getRandomPitch());
}
Also used : SoundEvent(net.minecraft.util.SoundEvent) ICustomAttackSound(com.minecolonies.api.entity.ICustomAttackSound) CustomArrowEntity(com.minecolonies.coremod.entity.CustomArrowEntity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity)

Example 3 with CustomArrowEntity

use of com.minecolonies.coremod.entity.CustomArrowEntity in project minecolonies by Minecolonies.

the class RaiderRangedAI method doAttack.

@Override
protected void doAttack(final LivingEntity target) {
    user.getNavigation().stop();
    // Setup arrow
    AbstractArrowEntity arrowEntity = CombatUtils.createArrowForShooter(user);
    arrowEntity.setBaseDamage(user.getAttribute(MOB_ATTACK_DAMAGE).getValue());
    if (flightCounter > 5) {
        ((CustomArrowEntity) arrowEntity).setPlayerArmorPierce();
        arrowEntity.setSecondsOnFire(200);
        arrowEntity.setBaseDamage(10);
    }
    if (user.getDifficulty() > ARROW_PIERCE_DIFFICULTY) {
        arrowEntity.setPierceLevel((byte) 2);
    }
    // Shoot arrow
    CombatUtils.shootArrow(arrowEntity, target, 10.0f);
    // Visuals
    user.swing(Hand.MAIN_HAND);
    SoundEvent attackSound = SoundEvents.SKELETON_SHOOT;
    if (arrowEntity instanceof ICustomAttackSound) {
        attackSound = ((ICustomAttackSound) arrowEntity).getAttackSound();
    }
    user.playSound(attackSound, (float) 1.0D, (float) getRandomPitch());
}
Also used : SoundEvent(net.minecraft.util.SoundEvent) ICustomAttackSound(com.minecolonies.api.entity.ICustomAttackSound) CustomArrowEntity(com.minecolonies.coremod.entity.CustomArrowEntity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity)

Example 4 with CustomArrowEntity

use of com.minecolonies.coremod.entity.CustomArrowEntity in project minecolonies by Minecolonies.

the class RangerCombatAI method calculateDamage.

/**
 * Calculates the ranged attack damage
 *
 * @param arrow
 * @return the attack damage
 */
private double calculateDamage(final AbstractArrowEntity arrow) {
    int damage = user.getCitizenData().getCitizenSkillHandler().getLevel(Skill.Agility) / 5;
    final ItemStack heldItem = user.getItemInHand(Hand.MAIN_HAND);
    damage += EnchantmentHelper.getDamageBonus(heldItem, target.getMobType()) / 2.5;
    damage += EnchantmentHelper.getItemEnchantmentLevel(Enchantments.POWER_ARROWS, heldItem);
    damage += user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(ARCHER_DAMAGE);
    if (user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(ARCHER_USE_ARROWS) > 0) {
        int slot = InventoryUtils.findFirstSlotInItemHandlerWith(user.getInventoryCitizen(), item -> item.getItem() instanceof ArrowItem);
        if (slot != -1) {
            if (!ItemStackUtils.isEmpty(user.getInventoryCitizen().extractItem(slot, 1, true))) {
                damage += ARROW_EXTRA_DAMAGE;
                ((CustomArrowEntity) arrow).setOnHitCallback(entityRayTraceResult -> {
                    final int arrowSlot = InventoryUtils.findFirstSlotInItemHandlerWith(user.getInventoryCitizen(), item -> item.getItem() instanceof ArrowItem);
                    if (arrowSlot != -1) {
                        user.getInventoryCitizen().extractItem(arrowSlot, 1, false);
                    }
                    return true;
                });
            }
        }
    }
    if (user.getHealth() <= user.getMaxHealth() * 0.2D) {
        damage *= 2;
    }
    return (RANGER_BASE_DMG + damage) * MineColonies.getConfig().getServer().rangerDamageMult.get();
}
Also used : CustomArrowEntity(com.minecolonies.coremod.entity.CustomArrowEntity) ArrowItem(net.minecraft.item.ArrowItem) ItemStack(net.minecraft.item.ItemStack)

Aggregations

CustomArrowEntity (com.minecolonies.coremod.entity.CustomArrowEntity)4 ICustomAttackSound (com.minecolonies.api.entity.ICustomAttackSound)2 AbstractArrowEntity (net.minecraft.entity.projectile.AbstractArrowEntity)2 ArrowItem (net.minecraft.item.ArrowItem)2 ItemStack (net.minecraft.item.ItemStack)2 SoundEvent (net.minecraft.util.SoundEvent)2