Search in sources :

Example 11 with ISpellComponent

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

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

the class SpellUtils method mainAffinityFor.

public Affinity mainAffinityFor(ItemStack stack) {
    if (!stack.hasTagCompound())
        return Affinity.NONE;
    if (stack.stackTagCompound.hasKey(ForcedAffinity)) {
        int aff = stack.stackTagCompound.getInteger(ForcedAffinity);
        return Affinity.values()[aff];
    }
    HashMap<Integer, Integer> affinityFrequency = new HashMap<Integer, Integer>();
    for (int i = 0; i < numStages(stack); ++i) {
        for (ISpellComponent comp : getComponentsForStage(stack, i)) {
            EnumSet<Affinity> affList = comp.getAffinity();
            for (Affinity affinity : affList) {
                if (!affinityFrequency.containsKey(affinity.ordinal())) {
                    affinityFrequency.put(affinity.ordinal(), 1);
                } else {
                    int old = affinityFrequency.get(affinity.ordinal());
                    affinityFrequency.put(affinity.ordinal(), old + 1);
                }
            }
        }
    }
    int highestCount = 0;
    int highestID = 0;
    for (Integer key : affinityFrequency.keySet()) {
        int count = affinityFrequency.get(key);
        if (count > highestCount) {
            highestID = key;
            highestCount = count;
        }
    }
    return Affinity.values()[highestID];
}
Also used : HashMap(java.util.HashMap) Affinity(am2.api.spell.enums.Affinity)

Example 13 with ISpellComponent

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

the class TileEntitySpellSealedDoor method analyzeSpellForKey.

public void analyzeSpellForKey() {
    ItemStack spell = this.inventory[3];
    if (spell == null)
        return;
    //if we're here, we have a spell to analyze!
    key.clear();
    int stages = SpellUtils.instance.numStages(spell);
    for (int i = 0; i < stages; ++i) {
        ISpellComponent[] components = SpellUtils.instance.getComponentsForStage(spell, i);
        for (ISpellComponent comp : components) {
            key.add(comp);
        }
    }
}
Also used : ISpellComponent(am2.api.spell.component.interfaces.ISpellComponent) ItemStack(net.minecraft.item.ItemStack)

Example 14 with ISpellComponent

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

the class ItemSpellPart method registerIcons.

@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister IIconRegister) {
    ArrayList<Integer> parts = SkillManager.instance.getAllShapes();
    parts.addAll(SkillManager.instance.getAllComponents());
    parts.addAll(SkillManager.instance.getAllModifiers());
    parts.addAll(SkillManager.instance.getAllTalents());
    int count = 0;
    for (Integer i : parts) {
        if (i == null)
            continue;
        ISkillTreeEntry entry = SkillManager.instance.getSkill(i);
        String subfolder = "";
        if (entry instanceof ISpellShape)
            subfolder = "shapes";
        else if (entry instanceof ISpellComponent)
            subfolder = "components";
        else if (entry instanceof ISpellModifier)
            subfolder = "modifiers";
        else
            subfolder = "skills";
        String skillName = SkillManager.instance.getSkillName(entry);
        IIcon IIcon = ResourceManager.RegisterTexture(String.format("spells/%s/%s.png", subfolder, skillName), IIconRegister);
        SpellIconManager.instance.registerIcon(skillName, IIcon);
    }
}
Also used : ISpellComponent(am2.api.spell.component.interfaces.ISpellComponent) IIcon(net.minecraft.util.IIcon) ISkillTreeEntry(am2.api.spell.component.interfaces.ISkillTreeEntry) ISpellModifier(am2.api.spell.component.interfaces.ISpellModifier) ISpellShape(am2.api.spell.component.interfaces.ISpellShape) SideOnly(cpw.mods.fml.relauncher.SideOnly)

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