Search in sources :

Example 11 with ItemSpellBase

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;
}
Also used : EntitySpellEffect(am2.entities.EntitySpellEffect)

Example 12 with ItemSpellBase

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;
    }
}
Also used : Entity(net.minecraft.entity.Entity) AMParticle(am2.particles.AMParticle) ISpellModifier(am2.api.spell.component.interfaces.ISpellModifier) Colour(am2.spell.modifiers.Colour) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) EntityDragonPart(net.minecraft.entity.boss.EntityDragonPart) Vec3(net.minecraft.util.Vec3) EntityLivingBase(net.minecraft.entity.EntityLivingBase) SpellCastResult(am2.api.spell.enums.SpellCastResult) Affinity(am2.api.spell.enums.Affinity) AMBeam(am2.particles.AMBeam) ItemStack(net.minecraft.item.ItemStack) ParticleMoveOnHeading(am2.particles.ParticleMoveOnHeading)

Example 13 with ItemSpellBase

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;
}
Also used : Entity(net.minecraft.entity.Entity) EntityDragonPart(net.minecraft.entity.boss.EntityDragonPart) EntitySpellProjectile(am2.entities.EntitySpellProjectile) EntityLivingBase(net.minecraft.entity.EntityLivingBase)

Example 14 with ItemSpellBase

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;
}
Also used : ItemFocusMana(am2.items.ItemFocusMana) ItemFocusCharge(am2.items.ItemFocusCharge) ItemSpellBase(am2.api.spell.ItemSpellBase) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Slot(net.minecraft.inventory.Slot) ItemFocus(am2.items.ItemFocus) ItemStack(net.minecraft.item.ItemStack)

Example 15 with ItemSpellBase

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;
}
Also used : SpellRequirements(am2.spell.SpellUtils.SpellRequirements) ManaCostEvent(am2.api.events.ManaCostEvent) ItemStack(net.minecraft.item.ItemStack) SpellCastingEvent(am2.api.events.SpellCastingEvent)

Aggregations

ItemStack (net.minecraft.item.ItemStack)11 ItemSpellBase (am2.api.spell.ItemSpellBase)5 SpellCastResult (am2.api.spell.enums.SpellCastResult)5 Entity (net.minecraft.entity.Entity)4 EntityLivingBase (net.minecraft.entity.EntityLivingBase)4 EntityDragonPart (net.minecraft.entity.boss.EntityDragonPart)4 EntitySpellEffect (am2.entities.EntitySpellEffect)3 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)3 SpellCastingEvent (am2.api.events.SpellCastingEvent)2 Affinity (am2.api.spell.enums.Affinity)2 EntitySpellProjectile (am2.entities.EntitySpellProjectile)2 ItemSpellBook (am2.items.ItemSpellBook)2 Slot (net.minecraft.inventory.Slot)2 ManaCostEvent (am2.api.events.ManaCostEvent)1 AMVector2 (am2.api.math.AMVector2)1 ISpellModifier (am2.api.spell.component.interfaces.ISpellModifier)1 ISpellShape (am2.api.spell.component.interfaces.ISpellShape)1 ItemFocus (am2.items.ItemFocus)1 ItemFocusCharge (am2.items.ItemFocusCharge)1 ItemFocusMana (am2.items.ItemFocusMana)1