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