Search in sources :

Example 1 with ISpellComponent

use of am2.api.spell.component.interfaces.ISpellComponent 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 2 with ISpellComponent

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

Example 3 with ISpellComponent

use of am2.api.spell.component.interfaces.ISpellComponent 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 4 with ISpellComponent

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

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

the class TileEntityInscriptionTable method GetUpdatePacketForServer.

private byte[] GetUpdatePacketForServer() {
    AMDataWriter writer = new AMDataWriter();
    writer.add(FULL_UPDATE);
    writer.add(this.currentPlayerUsing == null);
    if (this.currentPlayerUsing != null)
        writer.add(this.currentPlayerUsing.getEntityId());
    writer.add(this.currentRecipe.size());
    for (int i = 0; i < this.currentRecipe.size(); ++i) {
        ISpellPart part = this.currentRecipe.get(i);
        int id = part.getID();
        if (part instanceof ISpellComponent)
            id += SkillManager.COMPONENT_OFFSET;
        else if (part instanceof ISpellModifier)
            id += SkillManager.MODIFIER_OFFSET;
        writer.add(id);
    }
    writer.add(this.shapeGroups.size());
    for (ArrayList<ISpellPart> shapeGroup : this.shapeGroups) {
        int[] groupData = new int[shapeGroup.size()];
        for (int i = 0; i < shapeGroup.size(); ++i) {
            groupData[i] = SkillManager.instance.getShiftedPartID(shapeGroup.get(i));
        }
        writer.add(groupData);
    }
    writer.add(currentSpellName);
    writer.add(currentSpellIsReadOnly);
    return writer.generate();
}
Also used : AMDataWriter(am2.network.AMDataWriter)

Aggregations

ISpellComponent (am2.api.spell.component.interfaces.ISpellComponent)7 ISpellShape (am2.api.spell.component.interfaces.ISpellShape)5 Affinity (am2.api.spell.enums.Affinity)5 ISpellModifier (am2.api.spell.component.interfaces.ISpellModifier)4 ItemStack (net.minecraft.item.ItemStack)4 AMDataWriter (am2.network.AMDataWriter)2 Summon (am2.spell.components.Summon)2 Colour (am2.spell.modifiers.Colour)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 AffinityChangingEvent (am2.api.events.AffinityChangingEvent)1 SkillLearnedEvent (am2.api.events.SkillLearnedEvent)1 SpellRecipeItemsEvent (am2.api.events.SpellRecipeItemsEvent)1 PowerTypes (am2.api.power.PowerTypes)1 ISkillTreeEntry (am2.api.spell.component.interfaces.ISkillTreeEntry)1 ISpellPart (am2.api.spell.component.interfaces.ISpellPart)1 LearnStates (am2.api.spell.enums.LearnStates)1 SkillPointTypes (am2.api.spell.enums.SkillPointTypes)1 TileEntitySpellSealedDoor (am2.blocks.tileentities.TileEntitySpellSealedDoor)1 AffinityData (am2.playerextensions.AffinityData)1