Search in sources :

Example 6 with Summon

use of am2.spell.components.Summon 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)

Aggregations

Summon (am2.spell.components.Summon)5 ISpellPart (am2.api.spell.component.interfaces.ISpellPart)2 Binding (am2.spell.shapes.Binding)2 KeyValuePair (am2.utility.KeyValuePair)2 EntityCreature (net.minecraft.entity.EntityCreature)2 ISpellComponent (am2.api.spell.component.interfaces.ISpellComponent)1 ISpellModifier (am2.api.spell.component.interfaces.ISpellModifier)1 ISpellShape (am2.api.spell.component.interfaces.ISpellShape)1 BuffEffectMagicShield (am2.buffs.BuffEffectMagicShield)1 BuffEffectShrink (am2.buffs.BuffEffectShrink)1 DummyEntityPlayer (am2.utility.DummyEntityPlayer)1 Constructor (java.lang.reflect.Constructor)1 ArrayList (java.util.ArrayList)1 EntityLiving (net.minecraft.entity.EntityLiving)1 ItemStack (net.minecraft.item.ItemStack)1 PotionEffect (net.minecraft.potion.PotionEffect)1