use of am2.api.spell.ItemSpellBase in project ArsMagica2 by Mithion.
the class Wave 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) {
if (world.isRemote)
return SpellCastResult.SUCCESS;
double radius = SpellUtils.instance.getModifiedDouble_Add(1, stack, caster, target, world, 0, SpellModifiers.RADIUS);
int duration = SpellUtils.instance.getModifiedInt_Mul(20, stack, caster, target, world, 0, SpellModifiers.DURATION);
double speed = SpellUtils.instance.getModifiedDouble_Add(1f, stack, caster, target, world, 0, SpellModifiers.SPEED) * 0.5f;
int gravityModifiers = SpellUtils.instance.countModifiers(SpellModifiers.GRAVITY, stack, 0);
boolean hasPiercing = SpellUtils.instance.modifierIsPresent(SpellModifiers.PIERCING, stack, 0);
EntitySpellEffect wave = new EntitySpellEffect(world);
wave.setRadius((float) radius);
wave.setTicksToExist(duration);
wave.SetCasterAndStack(caster, SpellUtils.instance.popStackStage(stack));
wave.setPosition(x, y + 1, z);
wave.setWave(caster.rotationYaw, (float) speed);
wave.noClip = hasPiercing;
wave.setGravity(gravityModifiers * 0.5f);
world.spawnEntityInWorld(wave);
return SpellCastResult.SUCCESS;
}
use of am2.api.spell.ItemSpellBase 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.ItemSpellBase 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.ItemSpellBase in project ArsMagica2 by Mithion.
the class ContainerSummoner method mergeSpecialItems.
private boolean mergeSpecialItems(ItemStack stack, Slot slot) {
if (stack.getItem() instanceof ItemFocus) {
if (stack.getItem() instanceof ItemFocusCharge || stack.getItem() instanceof ItemFocusMana) {
for (int b = 0; b < 3; ++b) {
Slot focusSlot = (Slot) inventorySlots.get(b);
if (focusSlot.getHasStack())
continue;
focusSlot.putStack(new ItemStack(stack.getItem(), 1, stack.getItemDamage()));
focusSlot.onSlotChanged();
stack.stackSize--;
if (stack.stackSize == 0) {
slot.putStack(null);
slot.onSlotChanged();
}
return true;
}
}
} else if (stack.getItem() instanceof ItemSpellBase) {
Slot scrollSlot = (Slot) inventorySlots.get(3);
if (scrollSlot.getHasStack())
return false;
ItemStack castStack = new ItemStack(stack.getItem(), 1, stack.getItemDamage());
if (stack.hasTagCompound()) {
castStack.setTagCompound((NBTTagCompound) stack.stackTagCompound.copy());
}
scrollSlot.putStack(castStack);
scrollSlot.onSlotChanged();
stack.stackSize--;
if (stack.stackSize == 0) {
slot.putStack(null);
slot.onSlotChanged();
}
return true;
}
return false;
}
use of am2.api.spell.ItemSpellBase in project ArsMagica2 by Mithion.
the class SpellHelper method preSpellCast.
private SpellCastingEvent.Pre preSpellCast(ItemStack stack, EntityLivingBase caster, boolean isChanneled) {
SpellRequirements reqs = SpellUtils.instance.getSpellRequirements(stack, caster);
float manaCost = reqs.manaCost;
float burnout = reqs.burnout;
ArrayList<ItemStack> reagents = reqs.reagents;
ManaCostEvent mce = new ManaCostEvent(stack, caster, manaCost, burnout);
MinecraftForge.EVENT_BUS.post(mce);
manaCost = mce.manaCost;
burnout = mce.burnout;
SpellCastingEvent.Pre event = new SpellCastingEvent().new Pre(stack, (ItemSpellBase) stack.getItem(), caster, manaCost, burnout, isChanneled);
if (MinecraftForge.EVENT_BUS.post(event)) {
event.castResult = SpellCastResult.EFFECT_FAILED;
return event;
}
event.castResult = SpellCastResult.SUCCESS;
if (!SpellUtils.instance.casterHasAllReagents(caster, reagents))
event.castResult = SpellCastResult.REAGENTS_MISSING;
if (!SpellUtils.instance.casterHasMana(caster, manaCost))
event.castResult = SpellCastResult.NOT_ENOUGH_MANA;
return event;
}
Aggregations