Search in sources :

Example 1 with SpellCastResult

use of am2.api.spell.enums.SpellCastResult in project ArsMagica2 by Mithion.

the class Wall 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;
    int radius = SpellUtils.instance.getModifiedInt_Mul(3, stack, caster, target, world, 0, SpellModifiers.RADIUS);
    double gravity = SpellUtils.instance.getModifiedDouble_Add(0, stack, caster, target, world, 0, SpellModifiers.GRAVITY);
    int duration = SpellUtils.instance.getModifiedInt_Mul(100, stack, caster, target, world, 0, SpellModifiers.DURATION);
    EntitySpellEffect wall = new EntitySpellEffect(world);
    wall.setRadius(radius);
    wall.setTicksToExist(duration);
    wall.setGravity(gravity);
    wall.SetCasterAndStack(caster, SpellUtils.instance.popStackStage(stack));
    wall.setPosition(x, y, z);
    wall.setWall(caster.rotationYaw);
    world.spawnEntityInWorld(wall);
    return SpellCastResult.SUCCESS;
}
Also used : EntitySpellEffect(am2.entities.EntitySpellEffect)

Example 2 with SpellCastResult

use of am2.api.spell.enums.SpellCastResult in project ArsMagica2 by Mithion.

the class Zone 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;
    int radius = SpellUtils.instance.getModifiedInt_Add(2, stack, caster, target, world, 0, SpellModifiers.RADIUS);
    double gravity = SpellUtils.instance.getModifiedDouble_Add(0, stack, caster, target, world, 0, SpellModifiers.GRAVITY);
    int duration = SpellUtils.instance.getModifiedInt_Mul(100, stack, caster, target, world, 0, SpellModifiers.DURATION);
    EntitySpellEffect zone = new EntitySpellEffect(world);
    zone.setRadius(radius);
    zone.setTicksToExist(duration);
    zone.setGravity(gravity);
    zone.SetCasterAndStack(caster, SpellUtils.instance.popStackStage(stack));
    zone.setPosition(x, y, z);
    world.spawnEntityInWorld(zone);
    return SpellCastResult.SUCCESS;
}
Also used : EntitySpellEffect(am2.entities.EntitySpellEffect)

Example 3 with SpellCastResult

use of am2.api.spell.enums.SpellCastResult in project ArsMagica2 by Mithion.

the class Chain 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) {
    MovingObjectPosition mop = item.getMovingObjectPosition(caster, world, 8.0f, true, false);
    double range = SpellUtils.instance.getModifiedDouble_Mul(4, stack, caster, target, world, 0, SpellModifiers.RANGE);
    int num_targets = SpellUtils.instance.getModifiedInt_Add(3, stack, caster, target, world, 0, SpellModifiers.PROCS);
    ArrayList<EntityLivingBase> targets = new ArrayList<EntityLivingBase>();
    if (target != null) {
        mop = new MovingObjectPosition(target);
    }
    if (mop != null && mop.typeOfHit == MovingObjectType.ENTITY && mop.entityHit != null) {
        Entity e = mop.entityHit;
        if (e instanceof EntityDragonPart && ((EntityDragonPart) e).entityDragonObj instanceof EntityLivingBase)
            e = (EntityLivingBase) ((EntityDragonPart) e).entityDragonObj;
        if (e instanceof EntityLivingBase) {
            do {
                targets.add((EntityLivingBase) e);
                List<EntityLivingBase> nearby = world.getEntitiesWithinAABB(EntityLivingBase.class, e.boundingBox.expand(range, range, range));
                EntityLivingBase closest = null;
                for (EntityLivingBase near : nearby) {
                    if (targets.contains(near) || near == caster)
                        continue;
                    if (closest == null || closest.getDistanceSqToEntity(e) > near.getDistanceSqToEntity(e)) {
                        closest = near;
                    }
                }
                e = closest;
            } while (e != null && targets.size() < num_targets);
        }
    }
    ItemStack newItemStack = SpellUtils.instance.popStackStage(stack);
    boolean atLeastOneApplication = false;
    SpellCastResult result = SpellCastResult.SUCCESS;
    EntityLivingBase prevEntity = null;
    for (EntityLivingBase e : targets) {
        if (e == caster)
            continue;
        result = SpellHelper.instance.applyStageToEntity(stack, caster, world, e, 0, giveXP);
        SpellHelper.instance.applyStackStage(newItemStack, caster, e, e.posX, e.posY, e.posZ, 0, world, true, giveXP, 0);
        if (world.isRemote) {
            if (prevEntity == null)
                spawnChainParticles(world, x, y, z, e.posX, e.posY + e.getEyeHeight(), e.posZ, stack);
            else
                spawnChainParticles(world, prevEntity.posX, prevEntity.posY + e.getEyeHeight(), prevEntity.posZ, e.posX, e.posY + e.getEyeHeight(), e.posZ, stack);
        }
        prevEntity = e;
        if (result == SpellCastResult.SUCCESS) {
            atLeastOneApplication = true;
        }
    }
    if (atLeastOneApplication) {
        return SpellCastResult.SUCCESS;
    }
    return result;
}
Also used : Entity(net.minecraft.entity.Entity) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) EntityDragonPart(net.minecraft.entity.boss.EntityDragonPart) EntityLivingBase(net.minecraft.entity.EntityLivingBase) ArrayList(java.util.ArrayList) SpellCastResult(am2.api.spell.enums.SpellCastResult) ItemStack(net.minecraft.item.ItemStack)

Example 4 with SpellCastResult

use of am2.api.spell.enums.SpellCastResult 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;
}
Also used : ISpellComponent(am2.api.spell.component.interfaces.ISpellComponent) ISpellModifier(am2.api.spell.component.interfaces.ISpellModifier) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ISpellShape(am2.api.spell.component.interfaces.ISpellShape) Colour(am2.spell.modifiers.Colour)

Example 5 with SpellCastResult

use of am2.api.spell.enums.SpellCastResult 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;
}
Also used : ISpellComponent(am2.api.spell.component.interfaces.ISpellComponent) ISpellModifier(am2.api.spell.component.interfaces.ISpellModifier) ISpellShape(am2.api.spell.component.interfaces.ISpellShape) Colour(am2.spell.modifiers.Colour)

Aggregations

SpellCastResult (am2.api.spell.enums.SpellCastResult)8 ItemStack (net.minecraft.item.ItemStack)5 Entity (net.minecraft.entity.Entity)4 EntityLivingBase (net.minecraft.entity.EntityLivingBase)4 EntityDragonPart (net.minecraft.entity.boss.EntityDragonPart)4 ISpellModifier (am2.api.spell.component.interfaces.ISpellModifier)3 ISpellShape (am2.api.spell.component.interfaces.ISpellShape)3 EntitySpellEffect (am2.entities.EntitySpellEffect)3 Colour (am2.spell.modifiers.Colour)3 Block (net.minecraft.block.Block)3 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)3 ISpellComponent (am2.api.spell.component.interfaces.ISpellComponent)2 EntitySpellProjectile (am2.entities.EntitySpellProjectile)2 SpellCastingEvent (am2.api.events.SpellCastingEvent)1 ItemSpellBase (am2.api.spell.ItemSpellBase)1 Affinity (am2.api.spell.enums.Affinity)1 AMDataWriter (am2.network.AMDataWriter)1 AMBeam (am2.particles.AMBeam)1 AMParticle (am2.particles.AMParticle)1 ParticleMoveOnHeading (am2.particles.ParticleMoveOnHeading)1