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;
}
Aggregations