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