Search in sources :

Example 1 with ISpellShape

use of am2.api.spell.component.interfaces.ISpellShape in project ArsMagica2 by Mithion.

the class SkillData method learn.

@Override
public void learn(ISkillTreeEntry entry) {
    if (entity.worldObj.isRemote) {
        AMDataWriter writer = new AMDataWriter();
        writer.add(SPELL_LEARNED);
        writer.add(this.entity.getEntityId());
        int id = entry.getID();
        if (entry instanceof ISpellComponent)
            id += SkillManager.instance.COMPONENT_OFFSET;
        else if (entry instanceof ISpellModifier)
            id += SkillManager.instance.MODIFIER_OFFSET;
        else if (!(entry instanceof ISpellShape))
            id += SkillManager.instance.TALENT_OFFSET;
        writer.add(id);
        if (entry instanceof ISpellShape)
            writer.add(0);
        else if (entry instanceof ISpellComponent)
            writer.add(1);
        else if (entry instanceof ISpellModifier)
            writer.add(2);
        else
            writer.add(3);
        AMNetHandler.INSTANCE.sendPacketToServer(AMPacketIDs.SYNC_SPELL_KNOWLEDGE, writer.generate());
    } else {
        int id = entry.getID();
        if (entry instanceof ISpellComponent)
            id += SkillManager.instance.COMPONENT_OFFSET;
        else if (entry instanceof ISpellModifier)
            id += SkillManager.instance.MODIFIER_OFFSET;
        else if (!(entry instanceof ISpellShape))
            id += SkillManager.instance.TALENT_OFFSET;
        int type = 3;
        if (entry instanceof ISpellShape)
            type = 0;
        else if (entry instanceof ISpellComponent)
            type = 1;
        else if (entry instanceof ISpellModifier)
            type = 2;
        learn(id, type);
        MinecraftForge.EVENT_BUS.post(new SkillLearnedEvent(player, entry));
    }
}
Also used : ISpellComponent(am2.api.spell.component.interfaces.ISpellComponent) ISpellModifier(am2.api.spell.component.interfaces.ISpellModifier) SkillLearnedEvent(am2.api.events.SkillLearnedEvent) AMDataWriter(am2.network.AMDataWriter) ISpellShape(am2.api.spell.component.interfaces.ISpellShape)

Example 2 with ISpellShape

use of am2.api.spell.component.interfaces.ISpellShape in project ArsMagica2 by Mithion.

the class SpellValidator method validateStage.

private StageValidations validateStage(ArrayList<ISpellPart> stageDefinition, boolean isFinalStage) {
    boolean terminus = false;
    boolean principum = false;
    boolean one_component = !isFinalStage;
    boolean one_shape = false;
    for (ISpellPart part : stageDefinition) {
        if (part instanceof Summon)
            return StageValidations.TERMINUS;
        if (part instanceof ISpellShape) {
            one_shape = true;
            if (((ISpellShape) part).isTerminusShape())
                terminus = true;
            if (((ISpellShape) part).isPrincipumShape())
                principum = true;
            continue;
        }
        if (part instanceof ISpellComponent) {
            one_component = true;
            continue;
        }
    }
    if (principum)
        return StageValidations.PRINCIPUM;
    if (!one_component || !one_shape)
        return StageValidations.NOT_VALID;
    if (terminus)
        return StageValidations.TERMINUS;
    return StageValidations.VALID;
}
Also used : ISpellComponent(am2.api.spell.component.interfaces.ISpellComponent) Summon(am2.spell.components.Summon) ISpellShape(am2.api.spell.component.interfaces.ISpellShape) ISpellPart(am2.api.spell.component.interfaces.ISpellPart)

Example 3 with ISpellShape

use of am2.api.spell.component.interfaces.ISpellShape in project ArsMagica2 by Mithion.

the class SpellHelper method applyStageToEntity.

public SpellCastResult applyStageToEntity(ItemStack stack, EntityLivingBase caster, World world, Entity target, int stage, boolean shiftAffinityAndXP) {
    ISpellShape stageShape = SpellUtils.instance.getShapeForStage(stack, 0);
    if (stageShape == null)
        return SpellCastResult.MALFORMED_SPELL_STACK;
    if ((!AMCore.config.getAllowCreativeTargets()) && target instanceof EntityPlayerMP && ((EntityPlayerMP) target).capabilities.isCreativeMode) {
        return SpellCastResult.EFFECT_FAILED;
    }
    ISpellComponent[] components = SpellUtils.instance.getComponentsForStage(stack, 0);
    boolean appliedOneComponent = false;
    for (ISpellComponent component : components) {
        if (SkillTreeManager.instance.isSkillDisabled(component))
            continue;
        if (component.applyEffectEntity(stack, world, caster, target)) {
            appliedOneComponent = true;
            if (world.isRemote) {
                int color = -1;
                if (SpellUtils.instance.modifierIsPresent(SpellModifiers.COLOR, stack, 0)) {
                    ISpellModifier[] mods = SpellUtils.instance.getModifiersForStage(stack, 0);
                    int ordinalCount = 0;
                    for (ISpellModifier mod : mods) {
                        if (mod instanceof Colour) {
                            byte[] meta = SpellUtils.instance.getModifierMetadataFromStack(stack, mod, 0, ordinalCount++);
                            color = (int) mod.getModifier(SpellModifiers.COLOR, null, null, null, meta);
                        }
                    }
                }
                component.spawnParticles(world, target.posX, target.posY + target.getEyeHeight(), target.posZ, caster, target, world.rand, color);
            }
            if (shiftAffinityAndXP)
                SpellUtils.instance.doAffinityShift(caster, component, stageShape);
        }
    }
    if (appliedOneComponent)
        return SpellCastResult.SUCCESS;
    else
        return SpellCastResult.EFFECT_FAILED;
}
Also used : ISpellComponent(am2.api.spell.component.interfaces.ISpellComponent) ISpellModifier(am2.api.spell.component.interfaces.ISpellModifier) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ISpellShape(am2.api.spell.component.interfaces.ISpellShape) Colour(am2.spell.modifiers.Colour)

Example 4 with ISpellShape

use of am2.api.spell.component.interfaces.ISpellShape 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)

Example 5 with ISpellShape

use of am2.api.spell.component.interfaces.ISpellShape in project ArsMagica2 by Mithion.

the class SpellHelper method applyStageToGround.

public SpellCastResult applyStageToGround(ItemStack stack, EntityLivingBase caster, World world, int blockX, int blockY, int blockZ, int blockFace, double impactX, double impactY, double impactZ, int stage, boolean consumeMBR) {
    ISpellShape stageShape = SpellUtils.instance.getShapeForStage(stack, 0);
    if (stageShape == null || stageShape == SkillManager.instance.missingShape) {
        return SpellCastResult.MALFORMED_SPELL_STACK;
    }
    ISpellComponent[] components = SpellUtils.instance.getComponentsForStage(stack, 0);
    for (ISpellComponent component : components) {
        if (SkillTreeManager.instance.isSkillDisabled(component))
            continue;
        //special logic for spell sealed doors
        if (BlocksCommonProxy.spellSealedDoor.applyComponentToDoor(world, component, blockX, blockY, blockZ))
            continue;
        if (component.applyEffectBlock(stack, world, blockX, blockY, blockZ, blockFace, impactX, impactY, impactZ, caster)) {
            if (world.isRemote) {
                int color = -1;
                if (SpellUtils.instance.modifierIsPresent(SpellModifiers.COLOR, stack, 0)) {
                    ISpellModifier[] mods = SpellUtils.instance.getModifiersForStage(stack, 0);
                    int ordinalCount = 0;
                    for (ISpellModifier mod : mods) {
                        if (mod instanceof Colour) {
                            byte[] meta = SpellUtils.instance.getModifierMetadataFromStack(stack, mod, 0, ordinalCount++);
                            color = (int) mod.getModifier(SpellModifiers.COLOR, null, null, null, meta);
                        }
                    }
                }
                component.spawnParticles(world, blockX, blockY, blockZ, caster, caster, world.rand, color);
            }
            if (consumeMBR)
                SpellUtils.instance.doAffinityShift(caster, component, stageShape);
        }
    }
    return SpellCastResult.SUCCESS;
}
Also used : ISpellComponent(am2.api.spell.component.interfaces.ISpellComponent) ISpellModifier(am2.api.spell.component.interfaces.ISpellModifier) ISpellShape(am2.api.spell.component.interfaces.ISpellShape) Colour(am2.spell.modifiers.Colour)

Aggregations

ISpellShape (am2.api.spell.component.interfaces.ISpellShape)9 ISpellComponent (am2.api.spell.component.interfaces.ISpellComponent)5 ISpellModifier (am2.api.spell.component.interfaces.ISpellModifier)4 ItemStack (net.minecraft.item.ItemStack)4 ISpellPart (am2.api.spell.component.interfaces.ISpellPart)2 AMDataWriter (am2.network.AMDataWriter)2 Summon (am2.spell.components.Summon)2 Colour (am2.spell.modifiers.Colour)2 ArrayList (java.util.ArrayList)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 AffinityChangingEvent (am2.api.events.AffinityChangingEvent)1 SkillLearnedEvent (am2.api.events.SkillLearnedEvent)1 SpellCastingEvent (am2.api.events.SpellCastingEvent)1 ItemSpellBase (am2.api.spell.ItemSpellBase)1 ISkillTreeEntry (am2.api.spell.component.interfaces.ISkillTreeEntry)1 Affinity (am2.api.spell.enums.Affinity)1 SpellCastResult (am2.api.spell.enums.SpellCastResult)1 AffinityData (am2.playerextensions.AffinityData)1 MissingShape (am2.spell.shapes.MissingShape)1 KeyValuePair (am2.utility.KeyValuePair)1