Search in sources :

Example 1 with ICombatItemCapability

use of jackiecrazy.wardance.capability.weaponry.ICombatItemCapability in project WarDance by Jackiecrazy.

the class CombatHandler method pain.

@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void pain(LivingHurtEvent e) {
    if (GeneralConfig.debug)
        WarDance.LOGGER.debug("damage from " + e.getSource() + " received with amount " + e.getAmount());
    LivingEntity uke = e.getEntityLiving();
    uke.removeEffect(WarEffects.DISTRACTION.get());
    uke.removeEffect(WarEffects.FEAR.get());
    uke.removeEffect(WarEffects.SLEEP.get());
    LivingEntity kek = null;
    DamageSource ds = e.getSource();
    if (uke.hasEffect(WarEffects.VULNERABLE.get()) && !CombatUtils.isPhysicalAttack(ds))
        e.setAmount(e.getAmount() + uke.getEffect(WarEffects.VULNERABLE.get()).getAmplifier() + 1);
    if (ds.getDirectEntity() instanceof LivingEntity) {
        kek = (LivingEntity) ds.getDirectEntity();
    }
    uke.getAttribute(Attributes.ARMOR).removeModifier(uuid);
    uke.getAttribute(Attributes.ARMOR).removeModifier(uuid2);
    if (ds instanceof CombatDamageSource) {
        float mult = -((CombatDamageSource) ds).getArmorReductionPercentage();
        if (mult != 0) {
            AttributeModifier armor = new AttributeModifier(uuid2, "temporary armor multiplier", mult, AttributeModifier.Operation.MULTIPLY_TOTAL);
            uke.getAttribute(Attributes.ARMOR).addTransientModifier(armor);
        }
    }
    ItemStack ukemain = uke.getMainHandItem();
    ItemStack ukeoff = uke.getOffhandItem();
    if (ukemain.getCapability(CombatManipulator.CAP).isPresent()) {
        ICombatItemCapability icic = ukemain.getCapability(CombatManipulator.CAP).resolve().get();
        e.setAmount(icic.onBeingHurt(e.getSource(), uke, ukemain, e.getAmount()));
    }
    if (ukeoff.getCapability(CombatManipulator.CAP).isPresent()) {
        ICombatItemCapability icic = ukeoff.getCapability(CombatManipulator.CAP).resolve().get();
        e.setAmount(icic.onBeingHurt(e.getSource(), uke, ukeoff, e.getAmount()));
    }
    ICombatCapability cap = CombatData.getCap(uke);
    cap.setSpiritGrace(ResourceConfig.spiritCD);
    cap.setAdrenalineCooldown(CombatConfig.adrenaline);
    SubtleBonusHandler.update = true;
    StealthUtils.Awareness awareness = StealthUtils.getAwareness(kek, uke);
    if (ds.getEntity() instanceof LivingEntity) {
        LivingEntity seme = ((LivingEntity) ds.getEntity());
        if (seme.getMainHandItem().getCapability(CombatManipulator.CAP).isPresent()) {
            ICombatItemCapability icic = seme.getMainHandItem().getCapability(CombatManipulator.CAP).resolve().get();
            e.setAmount(icic.hurtStart(e.getSource(), seme, uke, seme.getMainHandItem(), e.getAmount()) * icic.damageMultiplier(seme, uke, seme.getMainHandItem()));
            AttributeModifier armor = new AttributeModifier(uuid, "temporary armor removal", -icic.armorIgnoreAmount(e.getSource(), seme, uke, seme.getMainHandItem(), e.getAmount()), AttributeModifier.Operation.ADDITION);
            uke.getAttribute(Attributes.ARMOR).addTransientModifier(armor);
        }
        if (CombatUtils.isPhysicalAttack(e.getSource())) {
            if (awareness != StealthUtils.Awareness.ALERT) {
                e.setAmount((float) (e.getAmount() * CombatUtils.getDamageMultiplier(awareness, CombatUtils.getAttackingItemStack(ds))));
            }
            cap.setMightGrace(0);
        }
        double luckDiff = WarDance.rand.nextFloat() * (GeneralUtils.getAttributeValueSafe(seme, Attributes.LUCK)) - WarDance.rand.nextFloat() * (GeneralUtils.getAttributeValueSafe(uke, Attributes.LUCK));
        e.setAmount(e.getAmount() + (float) luckDiff * GeneralConfig.luck);
    }
    if (cap.getStaggerTime() > 0 && !cap.isFirstStaggerStrike()) {
        e.setAmount(e.getAmount() * CombatConfig.staggerDamage);
        // fatality!
        if (ds.getEntity() instanceof LivingEntity) {
            LivingEntity seme = ((LivingEntity) ds.getEntity());
            if (seme.level instanceof ServerWorld) {
                ((ServerWorld) seme.level).sendParticles(ParticleTypes.ANGRY_VILLAGER, uke.getX(), uke.getY(), uke.getZ(), 5, uke.getBbWidth(), uke.getBbHeight(), uke.getBbWidth(), 0.5f);
            }
            seme.level.playSound(null, uke.getX(), uke.getY(), uke.getZ(), SoundEvents.GENERIC_BIG_FALL, SoundCategory.PLAYERS, 0.25f + WarDance.rand.nextFloat() * 0.5f, 0.75f + WarDance.rand.nextFloat() * 0.5f);
        }
    } else {
        // unfatality!
        e.setAmount(e.getAmount() * CombatConfig.unStaggerDamage);
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) ServerWorld(net.minecraft.world.server.ServerWorld) ICombatCapability(jackiecrazy.wardance.capability.resources.ICombatCapability) StealthUtils(jackiecrazy.wardance.utils.StealthUtils) CombatDamageSource(jackiecrazy.wardance.api.CombatDamageSource) ICombatItemCapability(jackiecrazy.wardance.capability.weaponry.ICombatItemCapability) CombatDamageSource(jackiecrazy.wardance.api.CombatDamageSource) AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 2 with ICombatItemCapability

use of jackiecrazy.wardance.capability.weaponry.ICombatItemCapability in project WarDance by Jackiecrazy.

the class CombatHandler method tanky.

@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void tanky(LivingDamageEvent e) {
    final LivingEntity uke = e.getEntityLiving();
    uke.getAttribute(Attributes.ARMOR).removeModifier(uuid);
    uke.getAttribute(Attributes.ARMOR).removeModifier(uuid2);
    // no food!
    ItemStack active = uke.getItemInHand(uke.getUsedItemHand());
    if (CombatUtils.isPhysicalAttack(e.getSource()) && CombatConfig.foodCool >= 0 && (active.getItem().getUseAnimation(active) == UseAction.EAT || active.getItem().getUseAnimation(active) == UseAction.DRINK) && uke.isUsingItem()) {
        uke.releaseUsingItem();
        if (uke instanceof PlayerEntity && CombatConfig.foodCool > 0) {
            ((PlayerEntity) uke).getCooldowns().addCooldown(active.getItem(), CombatConfig.foodCool);
        }
    }
    if (e.getSource().getEntity() instanceof LivingEntity) {
        LivingEntity seme = ((LivingEntity) e.getSource().getEntity());
        if (CombatUtils.isMeleeAttack(e.getSource())) {
            ItemStack sememain = seme.getMainHandItem();
            if (sememain.getCapability(CombatManipulator.CAP).isPresent()) {
                ICombatItemCapability icic = sememain.getCapability(CombatManipulator.CAP).resolve().get();
                e.setAmount(icic.damageStart(e.getSource(), seme, uke, sememain, e.getAmount()));
            }
            ItemStack ukemain = uke.getMainHandItem();
            ItemStack ukeoff = uke.getOffhandItem();
            if (ukemain.getCapability(CombatManipulator.CAP).isPresent()) {
                ICombatItemCapability icic = ukemain.getCapability(CombatManipulator.CAP).resolve().get();
                e.setAmount(icic.onBeingDamaged(e.getSource(), uke, ukemain, e.getAmount()));
            }
            if (ukeoff.getCapability(CombatManipulator.CAP).isPresent()) {
                ICombatItemCapability icic = ukeoff.getCapability(CombatManipulator.CAP).resolve().get();
                e.setAmount(icic.onBeingDamaged(e.getSource(), uke, ukeoff, e.getAmount()));
            }
        }
    }
    if (CombatData.getCap(uke).getStaggerTime() == 0 && CombatUtils.isPhysicalAttack(e.getSource())) {
        if (e.getSource().getEntity() instanceof LivingEntity && StealthUtils.getAwareness((LivingEntity) e.getSource().getEntity(), uke) == StealthUtils.Awareness.UNAWARE)
            return;
        float amount = e.getAmount();
        // absorption
        amount -= GeneralUtils.getAttributeValueSafe(uke, WarAttributes.ABSORPTION.get());
        e.setAmount(Math.max(0, amount));
    }
    if (e.getAmount() <= 0)
        e.setCanceled(true);
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) ICombatItemCapability(jackiecrazy.wardance.capability.weaponry.ICombatItemCapability) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

ICombatItemCapability (jackiecrazy.wardance.capability.weaponry.ICombatItemCapability)2 LivingEntity (net.minecraft.entity.LivingEntity)2 ItemStack (net.minecraft.item.ItemStack)2 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)2 CombatDamageSource (jackiecrazy.wardance.api.CombatDamageSource)1 ICombatCapability (jackiecrazy.wardance.capability.resources.ICombatCapability)1 StealthUtils (jackiecrazy.wardance.utils.StealthUtils)1 AttributeModifier (net.minecraft.entity.ai.attributes.AttributeModifier)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 ServerWorld (net.minecraft.world.server.ServerWorld)1