use of am2.api.spell.enums.SpellCastResult in project ArsMagica2 by Mithion.
the class Beam method beginStackStage.
@Override
public SpellCastResult beginStackStage(ItemSpellBase item, ItemStack stack, EntityLivingBase caster, EntityLivingBase target, World world, double x, double y, double z, int side, boolean giveXP, int useCount) {
boolean shouldApplyEffect = useCount % 10 == 0;
double range = SpellUtils.instance.getModifiedDouble_Add(SpellModifiers.RANGE, stack, caster, target, world, 0);
boolean targetWater = SpellUtils.instance.modifierIsPresent(SpellModifiers.TARGET_NONSOLID_BLOCKS, stack, 0);
MovingObjectPosition mop = item.getMovingObjectPosition(caster, world, range, true, targetWater);
SpellCastResult result = null;
Vec3 beamHitVec = null;
Vec3 spellVec = null;
if (mop == null) {
beamHitVec = MathUtilities.extrapolateEntityLook(world, caster, range);
spellVec = beamHitVec;
} else if (mop.typeOfHit == MovingObjectType.ENTITY) {
if (shouldApplyEffect) {
Entity e = mop.entityHit;
if (e instanceof EntityDragonPart && ((EntityDragonPart) e).entityDragonObj instanceof EntityLivingBase)
e = (EntityLivingBase) ((EntityDragonPart) e).entityDragonObj;
result = SpellHelper.instance.applyStageToEntity(stack, caster, world, e, 0, giveXP);
if (result != SpellCastResult.SUCCESS) {
return result;
}
}
float rng = (float) mop.hitVec.distanceTo(Vec3.createVectorHelper(caster.posX, caster.posY, caster.posZ));
beamHitVec = MathUtilities.extrapolateEntityLook(world, caster, rng);
spellVec = beamHitVec;
} else {
if (shouldApplyEffect) {
result = SpellHelper.instance.applyStageToGround(stack, caster, world, mop.blockX, mop.blockY, mop.blockZ, mop.sideHit, mop.hitVec.xCoord, mop.hitVec.yCoord, mop.hitVec.zCoord, 0, giveXP);
if (result != SpellCastResult.SUCCESS) {
return result;
}
}
beamHitVec = mop.hitVec;
spellVec = Vec3.createVectorHelper(mop.blockX, mop.blockY, mop.blockZ);
}
if (world.isRemote && beamHitVec != null) {
AMBeam beam = (AMBeam) beams.get(caster.getEntityId());
double startX = caster.posX;
double startY = caster.posY + caster.getEyeHeight() - 0.2f;
double startZ = caster.posZ;
Affinity affinity = SpellUtils.instance.mainAffinityFor(stack);
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);
}
}
}
if (beam != null) {
if (beam.isDead || beam.getDistanceSqToEntity(caster) > 4) {
beams.remove(caster.getEntityId());
} else {
beam.setBeamLocationAndTarget(startX, startY, startZ, beamHitVec.xCoord, beamHitVec.yCoord, beamHitVec.zCoord);
}
} else {
if (affinity == Affinity.LIGHTNING) {
AMCore.instance.proxy.particleManager.BoltFromEntityToPoint(world, caster, beamHitVec.xCoord, beamHitVec.yCoord, beamHitVec.zCoord, 1, color == -1 ? affinity.color : color);
} else {
beam = (AMBeam) AMCore.instance.proxy.particleManager.BeamFromEntityToPoint(world, caster, beamHitVec.xCoord, beamHitVec.yCoord, beamHitVec.zCoord, color == -1 ? affinity.color : color);
if (beam != null) {
if (AMCore.instance.proxy.getProxyUtils().isLocalPlayerInFirstPerson())
beam.setFirstPersonPlayerCast();
beams.put(caster.getEntityId(), beam);
}
}
}
for (int i = 0; i < AMCore.config.getGFXLevel() + 1; ++i) {
AMParticle particle = (AMParticle) AMCore.proxy.particleManager.spawn(world, AMParticleIcons.instance.getParticleForAffinity(affinity), beamHitVec.xCoord, beamHitVec.yCoord, beamHitVec.zCoord);
if (particle != null) {
particle.setMaxAge(2);
particle.setParticleScale(0.1f);
particle.setIgnoreMaxAge(false);
if (color != -1)
particle.setRGBColorI(color);
particle.AddParticleController(new ParticleMoveOnHeading(particle, world.rand.nextDouble() * 360, world.rand.nextDouble() * 360, world.rand.nextDouble() * 0.2 + 0.02f, 1, false));
}
}
}
if (result != null && spellVec != null && shouldApplyEffect) {
ItemStack newItemStack = SpellUtils.instance.popStackStage(stack);
return SpellHelper.instance.applyStackStage(newItemStack, caster, target, spellVec.xCoord, spellVec.yCoord, spellVec.zCoord, mop != null ? mop.sideHit : 0, world, true, giveXP, 0);
} else {
return SpellCastResult.SUCCESS_REDUCE_MANA;
}
}
use of am2.api.spell.enums.SpellCastResult in project ArsMagica2 by Mithion.
the class AoE method beginStackStage.
@Override
public SpellCastResult beginStackStage(ItemSpellBase item, ItemStack stack, EntityLivingBase caster, EntityLivingBase target, World world, double x, double y, double z, int side, boolean giveXP, int useCount) {
double radius = SpellUtils.instance.getModifiedDouble_Add(1, stack, caster, target, world, 0, SpellModifiers.RADIUS);
List<Entity> entities = world.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(x - radius, y - radius, z - radius, x + radius, y + radius, z + radius));
boolean appliedToAtLeastOneEntity = false;
for (Entity e : entities) {
if (e == caster || e instanceof EntitySpellProjectile)
continue;
if (e instanceof EntityDragonPart && ((EntityDragonPart) e).entityDragonObj instanceof EntityLivingBase)
e = (EntityLivingBase) ((EntityDragonPart) e).entityDragonObj;
if (SpellHelper.instance.applyStageToEntity(stack, caster, world, e, 0, giveXP) == SpellCastResult.SUCCESS)
appliedToAtLeastOneEntity = true;
}
if (side == 0 || side == 1) {
// top/bottom
if (world.isRemote)
spawnAoEParticles(stack, caster, world, x + 0.5f, y + ((side == 1) ? 0.5f : (target != null ? target.getEyeHeight() : -2.0f)), z + 0.5f, (int) radius);
int gravityMagnitude = SpellUtils.instance.countModifiers(SpellModifiers.GRAVITY, stack, 0);
return applyStageHorizontal(stack, caster, world, (int) Math.floor(x), (int) Math.ceil(y), (int) Math.floor(z), side, (int) Math.floor(radius), gravityMagnitude, giveXP);
} else if (side == 2 || side == 3) {
// if (side == 3) z--;
if (world.isRemote)
spawnAoEParticles(stack, caster, world, x, y, (side == 2) ? z - 0.5f : z + 1.5f, (int) radius);
return applyStageVerticalZ(stack, caster, world, (int) Math.floor(x), (int) Math.ceil(y), (int) Math.floor(z), side, (int) Math.floor(radius), giveXP);
} else if (side == 4 || side == 5) {
// if (side == 5) x--;
if (world.isRemote)
spawnAoEParticles(stack, caster, world, x, y, (side == 5) ? z - 0.5f : z + 1.5f, (int) radius);
return applyStageVerticalX(stack, caster, world, (int) Math.floor(x), (int) Math.ceil(y), (int) Math.floor(z), side, (int) Math.floor(radius), giveXP);
}
if (appliedToAtLeastOneEntity) {
if (world.isRemote)
spawnAoEParticles(stack, caster, world, x, y + 1, z, (int) radius);
return SpellCastResult.SUCCESS;
}
return SpellCastResult.EFFECT_FAILED;
}
use of am2.api.spell.enums.SpellCastResult in project ArsMagica2 by Mithion.
the class AoE method applyStageVerticalZ.
private SpellCastResult applyStageVerticalZ(ItemStack stack, EntityLivingBase caster, World world, int x, int y, int z, int face, int radius, boolean giveXP) {
for (int i = -radius; i <= radius; ++i) {
for (int j = -radius; j <= radius; ++j) {
int searchY = y;
Block block = world.getBlock(x + j, searchY + i, z);
if (block == Blocks.air)
continue;
SpellCastResult result = SpellHelper.instance.applyStageToGround(stack, caster, world, x + j, searchY + i, z, face, x + j, searchY + i, z, 0, giveXP);
if (result != SpellCastResult.SUCCESS)
return result;
}
}
return SpellCastResult.SUCCESS;
}
use of am2.api.spell.enums.SpellCastResult in project ArsMagica2 by Mithion.
the class AoE method applyStageVerticalX.
private SpellCastResult applyStageVerticalX(ItemStack stack, EntityLivingBase caster, World world, int x, int y, int z, int face, int radius, boolean giveXP) {
for (int i = -radius; i <= radius; ++i) {
for (int j = -radius; j <= radius; ++j) {
int searchY = y;
Block block = world.getBlock(x, searchY + i, z + j);
if (block == Blocks.air)
continue;
SpellCastResult result = SpellHelper.instance.applyStageToGround(stack, caster, world, x, searchY + i, z + j, face, x, searchY + i, z + j, 0, giveXP);
if (result != SpellCastResult.SUCCESS)
return result;
}
}
return SpellCastResult.SUCCESS;
}
use of am2.api.spell.enums.SpellCastResult 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;
}
Aggregations