use of am2.api.spell.component.interfaces.ISpellShape in project ArsMagica2 by Mithion.
the class SkillData method learn.
@Override
public void learn(ISkillTreeEntry entry) {
if (entity.worldObj.isRemote) {
AMDataWriter writer = new AMDataWriter();
writer.add(SPELL_LEARNED);
writer.add(this.entity.getEntityId());
int id = entry.getID();
if (entry instanceof ISpellComponent)
id += SkillManager.instance.COMPONENT_OFFSET;
else if (entry instanceof ISpellModifier)
id += SkillManager.instance.MODIFIER_OFFSET;
else if (!(entry instanceof ISpellShape))
id += SkillManager.instance.TALENT_OFFSET;
writer.add(id);
if (entry instanceof ISpellShape)
writer.add(0);
else if (entry instanceof ISpellComponent)
writer.add(1);
else if (entry instanceof ISpellModifier)
writer.add(2);
else
writer.add(3);
AMNetHandler.INSTANCE.sendPacketToServer(AMPacketIDs.SYNC_SPELL_KNOWLEDGE, writer.generate());
} else {
int id = entry.getID();
if (entry instanceof ISpellComponent)
id += SkillManager.instance.COMPONENT_OFFSET;
else if (entry instanceof ISpellModifier)
id += SkillManager.instance.MODIFIER_OFFSET;
else if (!(entry instanceof ISpellShape))
id += SkillManager.instance.TALENT_OFFSET;
int type = 3;
if (entry instanceof ISpellShape)
type = 0;
else if (entry instanceof ISpellComponent)
type = 1;
else if (entry instanceof ISpellModifier)
type = 2;
learn(id, type);
MinecraftForge.EVENT_BUS.post(new SkillLearnedEvent(player, entry));
}
}
use of am2.api.spell.component.interfaces.ISpellShape in project ArsMagica2 by Mithion.
the class SpellValidator method validateStage.
private StageValidations validateStage(ArrayList<ISpellPart> stageDefinition, boolean isFinalStage) {
boolean terminus = false;
boolean principum = false;
boolean one_component = !isFinalStage;
boolean one_shape = false;
for (ISpellPart part : stageDefinition) {
if (part instanceof Summon)
return StageValidations.TERMINUS;
if (part instanceof ISpellShape) {
one_shape = true;
if (((ISpellShape) part).isTerminusShape())
terminus = true;
if (((ISpellShape) part).isPrincipumShape())
principum = true;
continue;
}
if (part instanceof ISpellComponent) {
one_component = true;
continue;
}
}
if (principum)
return StageValidations.PRINCIPUM;
if (!one_component || !one_shape)
return StageValidations.NOT_VALID;
if (terminus)
return StageValidations.TERMINUS;
return StageValidations.VALID;
}
use of am2.api.spell.component.interfaces.ISpellShape in project ArsMagica2 by Mithion.
the class SpellHelper method applyStageToEntity.
public SpellCastResult applyStageToEntity(ItemStack stack, EntityLivingBase caster, World world, Entity target, int stage, boolean shiftAffinityAndXP) {
ISpellShape stageShape = SpellUtils.instance.getShapeForStage(stack, 0);
if (stageShape == null)
return SpellCastResult.MALFORMED_SPELL_STACK;
if ((!AMCore.config.getAllowCreativeTargets()) && target instanceof EntityPlayerMP && ((EntityPlayerMP) target).capabilities.isCreativeMode) {
return SpellCastResult.EFFECT_FAILED;
}
ISpellComponent[] components = SpellUtils.instance.getComponentsForStage(stack, 0);
boolean appliedOneComponent = false;
for (ISpellComponent component : components) {
if (SkillTreeManager.instance.isSkillDisabled(component))
continue;
if (component.applyEffectEntity(stack, world, caster, target)) {
appliedOneComponent = true;
if (world.isRemote) {
int color = -1;
if (SpellUtils.instance.modifierIsPresent(SpellModifiers.COLOR, stack, 0)) {
ISpellModifier[] mods = SpellUtils.instance.getModifiersForStage(stack, 0);
int ordinalCount = 0;
for (ISpellModifier mod : mods) {
if (mod instanceof Colour) {
byte[] meta = SpellUtils.instance.getModifierMetadataFromStack(stack, mod, 0, ordinalCount++);
color = (int) mod.getModifier(SpellModifiers.COLOR, null, null, null, meta);
}
}
}
component.spawnParticles(world, target.posX, target.posY + target.getEyeHeight(), target.posZ, caster, target, world.rand, color);
}
if (shiftAffinityAndXP)
SpellUtils.instance.doAffinityShift(caster, component, stageShape);
}
}
if (appliedOneComponent)
return SpellCastResult.SUCCESS;
else
return SpellCastResult.EFFECT_FAILED;
}
use of am2.api.spell.component.interfaces.ISpellShape in project ArsMagica2 by Mithion.
the class SpellUtils method doAffinityShift.
public void doAffinityShift(EntityLivingBase caster, ISpellComponent component, ISpellShape governingShape) {
if (!(caster instanceof EntityPlayer))
return;
AffinityData aff = AffinityData.For(caster);
EnumSet<Affinity> affList = component.getAffinity();
for (Affinity affinity : affList) {
float shift = component.getAffinityShift(affinity) * aff.getDiminishingReturnsFactor() * 5;
float xp = 0.05f * aff.getDiminishingReturnsFactor();
if (governingShape.isChanneled()) {
shift /= 4;
xp /= 4;
}
if (caster instanceof EntityPlayer) {
if (SkillData.For((EntityPlayer) caster).isEntryKnown(SkillTreeManager.instance.getSkillTreeEntry(SkillManager.instance.getSkill("AffinityGains")))) {
shift *= 1.1f;
xp *= 0.9f;
}
ItemStack chestArmor = ((EntityPlayer) caster).getCurrentArmor(2);
if (chestArmor != null && ArmorHelper.isInfusionPreset(chestArmor, GenericImbuement.magicXP))
xp *= 1.25f;
}
if (shift > 0) {
AffinityChangingEvent event = new AffinityChangingEvent((EntityPlayer) caster, affinity, shift);
MinecraftForge.EVENT_BUS.post(event);
if (!event.isCanceled())
aff.incrementAffinity(affinity, event.amount);
}
if (xp > 0) {
xp *= caster.getAttributeMap().getAttributeInstance(ArsMagicaApi.xpGainModifier).getAttributeValue();
ExtendedProperties.For(caster).addMagicXP(xp);
}
}
aff.addDiminishingReturns(governingShape.isChanneled());
}
use of am2.api.spell.component.interfaces.ISpellShape in project ArsMagica2 by Mithion.
the class SpellHelper method applyStageToGround.
public SpellCastResult applyStageToGround(ItemStack stack, EntityLivingBase caster, World world, int blockX, int blockY, int blockZ, int blockFace, double impactX, double impactY, double impactZ, int stage, boolean consumeMBR) {
ISpellShape stageShape = SpellUtils.instance.getShapeForStage(stack, 0);
if (stageShape == null || stageShape == SkillManager.instance.missingShape) {
return SpellCastResult.MALFORMED_SPELL_STACK;
}
ISpellComponent[] components = SpellUtils.instance.getComponentsForStage(stack, 0);
for (ISpellComponent component : components) {
if (SkillTreeManager.instance.isSkillDisabled(component))
continue;
//special logic for spell sealed doors
if (BlocksCommonProxy.spellSealedDoor.applyComponentToDoor(world, component, blockX, blockY, blockZ))
continue;
if (component.applyEffectBlock(stack, world, blockX, blockY, blockZ, blockFace, impactX, impactY, impactZ, caster)) {
if (world.isRemote) {
int color = -1;
if (SpellUtils.instance.modifierIsPresent(SpellModifiers.COLOR, stack, 0)) {
ISpellModifier[] mods = SpellUtils.instance.getModifiersForStage(stack, 0);
int ordinalCount = 0;
for (ISpellModifier mod : mods) {
if (mod instanceof Colour) {
byte[] meta = SpellUtils.instance.getModifierMetadataFromStack(stack, mod, 0, ordinalCount++);
color = (int) mod.getModifier(SpellModifiers.COLOR, null, null, null, meta);
}
}
}
component.spawnParticles(world, blockX, blockY, blockZ, caster, caster, world.rand, color);
}
if (consumeMBR)
SpellUtils.instance.doAffinityShift(caster, component, stageShape);
}
}
return SpellCastResult.SUCCESS;
}
Aggregations