Search in sources :

Example 6 with ISpellShape

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

the class SpellUtils method createSpellStack.

public ItemStack createSpellStack(ArrayList<ArrayList<KeyValuePair<ISpellPart, byte[]>>> shapeGroups, ArrayList<KeyValuePair<ISpellPart, byte[]>> spell) {
    ArrayList<KeyValuePair<ISpellPart, byte[]>> recipeCopy = (ArrayList<KeyValuePair<ISpellPart, byte[]>>) spell.clone();
    if (recipeCopy.size() > 0 && !(recipeCopy.get(0).getKey() instanceof ISpellShape))
        recipeCopy.add(0, new KeyValuePair<ISpellPart, byte[]>(SkillManager.instance.missingShape, new byte[0]));
    ItemStack stack = new ItemStack(ItemsCommonProxy.spell);
    boolean hasSummon = false;
    while (recipeCopy.size() > 0) {
        ISpellShape shape;
        ArrayList<Integer> components = new ArrayList<Integer>();
        ArrayListMultimap<Integer, byte[]> modifiers = ArrayListMultimap.create();
        KeyValuePair<ISpellPart, byte[]> part = recipeCopy.get(0);
        recipeCopy.remove(0);
        if (part.getKey() instanceof ISpellShape) {
            shape = (ISpellShape) part.getKey();
            part = recipeCopy.size() > 0 ? recipeCopy.get(0) : null;
            while (part != null && !(part.getKey() instanceof ISpellShape)) {
                recipeCopy.remove(0);
                if (part.getKey() instanceof ISpellComponent) {
                    components.add(SkillManager.instance.getShiftedPartID(part.getKey()));
                    if (part.getKey() instanceof Summon) {
                        hasSummon = true;
                    }
                } else if (part.getKey() instanceof ISpellModifier) {
                    modifiers.put(SkillManager.instance.getShiftedPartID(part.getKey()), part.getValue());
                }
                part = recipeCopy.size() > 0 ? recipeCopy.get(0) : null;
            }
            if (hasSummon) {
                ((Summon) SkillManager.instance.getSkill("Summon")).setSummonType(stack, EntitySkeleton.class);
            }
            SpellUtils.instance.addSpellStageToScroll(stack, shape.getID(), ArrayListToIntArray(components), modifiers);
        }
    }
    for (int i = 0; i < shapeGroups.size(); ++i) {
        ArrayList<KeyValuePair<ISpellPart, byte[]>> shapeGroup = shapeGroups.get(i);
        if (shapeGroup.size() == 0)
            continue;
        int[] sgp = new int[shapeGroup.size()];
        byte[][] sgp_m = new byte[shapeGroup.size()][];
        for (int n = 0; n < shapeGroup.size(); ++n) {
            sgp[n] = SkillManager.instance.getShiftedPartID(shapeGroup.get(n).getKey());
            sgp_m[n] = shapeGroup.get(n).getValue();
        }
        SpellUtils.instance.addShapeGroup(sgp, sgp_m, stack);
    }
    SpellUtils.instance.writeModVersionToStack(stack);
    ItemStack checkStack = constructSpellStack(stack);
    int silkTouchLevel = 0;
    int fortuneLevel = 0;
    for (int i = 0; i < numStages(checkStack); ++i) {
        int st = countModifiers(SpellModifiers.SILKTOUCH_LEVEL, checkStack, 0);
        int fn = countModifiers(SpellModifiers.FORTUNE_LEVEL, checkStack, 0);
        if (st > silkTouchLevel)
            silkTouchLevel = st;
        if (fn > fortuneLevel)
            fortuneLevel = fn;
    }
    if (fortuneLevel > 0) {
        AMEnchantmentHelper.fortuneStack(stack, fortuneLevel);
        AMEnchantmentHelper.lootingStack(stack, fortuneLevel);
    }
    if (silkTouchLevel > 0)
        AMEnchantmentHelper.silkTouchStack(stack, silkTouchLevel);
    return stack;
}
Also used : KeyValuePair(am2.utility.KeyValuePair) Summon(am2.spell.components.Summon) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 7 with ISpellShape

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

the class SpellValidator method splitToStages.

public static ArrayList<ArrayList<ISpellPart>> splitToStages(ArrayList<ISpellPart> currentRecipe) {
    ArrayList<ArrayList<ISpellPart>> segmented = new ArrayList<ArrayList<ISpellPart>>();
    int idx = (currentRecipe.size() > 0 && currentRecipe.get(0) instanceof ISpellShape) ? -1 : 0;
    for (int i = 0; i < currentRecipe.size(); ++i) {
        ISpellPart part = currentRecipe.get(i);
        if (part instanceof ISpellShape)
            idx++;
        if (//while loop not necessary as this will keep up
        segmented.size() - 1 < idx)
            segmented.add(new ArrayList<ISpellPart>());
        segmented.get(idx).add(part);
    }
    return segmented;
}
Also used : ArrayList(java.util.ArrayList) ISpellShape(am2.api.spell.component.interfaces.ISpellShape) ISpellPart(am2.api.spell.component.interfaces.ISpellPart)

Example 8 with ISpellShape

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

the class SpellHelper method applyStackStage.

public SpellCastResult applyStackStage(ItemStack stack, EntityLivingBase caster, EntityLivingBase target, double x, double y, double z, int side, World world, boolean consumeMBR, boolean giveXP, int ticksUsed) {
    if (caster.isPotionActive(BuffList.silence.id))
        return SpellCastResult.SILENCED;
    ItemStack parsedStack = SpellUtils.instance.constructSpellStack(stack);
    if (SpellUtils.instance.numStages(parsedStack) == 0) {
        return SpellCastResult.SUCCESS;
    }
    ISpellShape shape = SpellUtils.instance.getShapeForStage(parsedStack, 0);
    ItemSpellBase item = (ItemSpellBase) parsedStack.getItem();
    if (SkillTreeManager.instance.isSkillDisabled(shape))
        return SpellCastResult.EFFECT_FAILED;
    if (!(caster instanceof EntityPlayer)) {
        consumeMBR = false;
    }
    SpellCastingEvent.Pre checkEvent = null;
    if (consumeMBR) {
        checkEvent = preSpellCast(parsedStack, caster, false);
        if (checkEvent.castResult != SpellCastResult.SUCCESS) {
            if (checkEvent.castResult == SpellCastResult.NOT_ENOUGH_MANA && caster.worldObj.isRemote && caster instanceof EntityPlayer) {
                AMCore.proxy.flashManaBar();
            }
            SpellCastingEvent.Post event = new SpellCastingEvent().new Post(parsedStack, (ItemSpellBase) parsedStack.getItem(), caster, checkEvent.manaCost, checkEvent.burnout, false, checkEvent.castResult);
            MinecraftForge.EVENT_BUS.post(event);
            return checkEvent.castResult;
        }
    }
    SpellCastResult result = SpellCastResult.MALFORMED_SPELL_STACK;
    if (shape != null) {
        result = shape.beginStackStage(item, parsedStack, caster, target, world, x, y, z, side, giveXP, ticksUsed);
        if (!world.isRemote) {
            AMDataWriter writer = new AMDataWriter();
            writer.add(parsedStack);
            writer.add(caster.getEntityId());
            if (target != null) {
                writer.add(true);
                writer.add(target.getEntityId());
            } else {
                writer.add(false);
            }
            writer.add(x).add(y).add(z);
            writer.add(side);
            writer.add(ticksUsed);
            AMNetHandler.INSTANCE.sendPacketToAllClientsNear(world.provider.dimensionId, x, y, z, 32, AMPacketIDs.SPELL_CAST, writer.generate());
        }
    }
    float manaCost = 0;
    float burnout = 0;
    if (consumeMBR) {
        manaCost = checkEvent.manaCost;
        burnout = checkEvent.burnout;
        if (result == SpellCastResult.SUCCESS_REDUCE_MANA) {
            result = SpellCastResult.SUCCESS;
            manaCost *= 0.2f;
            burnout *= 0.2f;
        }
    }
    if (result == SpellCastResult.SUCCESS) {
        if (consumeMBR) {
            ExtendedProperties.For(caster).deductMana(manaCost);
            ExtendedProperties.For(caster).addBurnout(burnout);
        }
        if (world.isRemote) {
            String sfx = shape.getSoundForAffinity(SpellUtils.instance.mainAffinityFor(parsedStack), parsedStack, null);
            if (sfx != null) {
                if (!shape.isChanneled()) {
                    world.playSound(caster.posX, caster.posY, caster.posZ, sfx, 0.4f, world.rand.nextFloat() * 0.1F + 0.9F, false);
                } else {
                //SoundHelper.instance.loopSound(world, (float)x, (float)y, (float)z, sfx, 0.6f);
                }
            }
        }
    }
    SpellCastingEvent.Post event = new SpellCastingEvent().new Post(parsedStack, (ItemSpellBase) parsedStack.getItem(), caster, manaCost, burnout, false, result);
    MinecraftForge.EVENT_BUS.post(event);
    return result;
}
Also used : ItemSpellBase(am2.api.spell.ItemSpellBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SpellCastResult(am2.api.spell.enums.SpellCastResult) ItemStack(net.minecraft.item.ItemStack) SpellCastingEvent(am2.api.events.SpellCastingEvent) ISpellShape(am2.api.spell.component.interfaces.ISpellShape) AMDataWriter(am2.network.AMDataWriter)

Example 9 with ISpellShape

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

the class SpellBase method getItemStackDisplayName.

@Override
public String getItemStackDisplayName(ItemStack par1ItemStack) {
    if (par1ItemStack.stackTagCompound == null)
        return "\247bMalformed Spell";
    ISpellShape shape = SpellUtils.instance.getShapeForStage(par1ItemStack, 0);
    if (shape instanceof MissingShape) {
        return "Unnamed Spell";
    }
    String clsName = shape.getClass().getName();
    return clsName.substring(clsName.lastIndexOf('.') + 1) + " Spell";
}
Also used : MissingShape(am2.spell.shapes.MissingShape) ISpellShape(am2.api.spell.component.interfaces.ISpellShape)

Example 10 with ISpellShape

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

the class SpellBase method onPlayerStoppedUsing.

@Override
public void onPlayerStoppedUsing(ItemStack stack, World world, EntityPlayer player, int ticksUsed) {
    ItemStack classicStack = SpellUtils.instance.constructSpellStack(stack);
    ISpellShape shape = SpellUtils.instance.getShapeForStage(classicStack, 0);
    if (shape != null) {
        if (!shape.isChanneled())
            SpellHelper.instance.applyStackStage(stack, player, null, player.posX, player.posY, player.posZ, 0, world, true, true, 0);
        if (world.isRemote && shape.isChanneled()) {
        //SoundHelper.instance.stopSound(shape.getSoundForAffinity(SpellUtils.instance.mainAffinityFor(stack), stack, null));
        }
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) ISpellShape(am2.api.spell.component.interfaces.ISpellShape)

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