Search in sources :

Example 1 with AffinityChangingEvent

use of am2.api.events.AffinityChangingEvent in project ArsMagica2 by Mithion.

the class SpellUtils method doAffinityShift.

public void doAffinityShift(EntityLivingBase caster, ISpellComponent component, ISpellShape governingShape) {
    if (!(caster instanceof EntityPlayer))
        return;
    AffinityData aff = AffinityData.For(caster);
    EnumSet<Affinity> affList = component.getAffinity();
    for (Affinity affinity : affList) {
        float shift = component.getAffinityShift(affinity) * aff.getDiminishingReturnsFactor() * 5;
        float xp = 0.05f * aff.getDiminishingReturnsFactor();
        if (governingShape.isChanneled()) {
            shift /= 4;
            xp /= 4;
        }
        if (caster instanceof EntityPlayer) {
            if (SkillData.For((EntityPlayer) caster).isEntryKnown(SkillTreeManager.instance.getSkillTreeEntry(SkillManager.instance.getSkill("AffinityGains")))) {
                shift *= 1.1f;
                xp *= 0.9f;
            }
            ItemStack chestArmor = ((EntityPlayer) caster).getCurrentArmor(2);
            if (chestArmor != null && ArmorHelper.isInfusionPreset(chestArmor, GenericImbuement.magicXP))
                xp *= 1.25f;
        }
        if (shift > 0) {
            AffinityChangingEvent event = new AffinityChangingEvent((EntityPlayer) caster, affinity, shift);
            MinecraftForge.EVENT_BUS.post(event);
            if (!event.isCanceled())
                aff.incrementAffinity(affinity, event.amount);
        }
        if (xp > 0) {
            xp *= caster.getAttributeMap().getAttributeInstance(ArsMagicaApi.xpGainModifier).getAttributeValue();
            ExtendedProperties.For(caster).addMagicXP(xp);
        }
    }
    aff.addDiminishingReturns(governingShape.isChanneled());
}
Also used : AffinityChangingEvent(am2.api.events.AffinityChangingEvent) AffinityData(am2.playerextensions.AffinityData) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Affinity(am2.api.spell.enums.Affinity) ItemStack(net.minecraft.item.ItemStack)

Aggregations

AffinityChangingEvent (am2.api.events.AffinityChangingEvent)1 Affinity (am2.api.spell.enums.Affinity)1 AffinityData (am2.playerextensions.AffinityData)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1