Search in sources :

Example 1 with ISpellModifier

use of am2.api.spell.component.interfaces.ISpellModifier in project ArsMagica2 by Mithion.

the class TileEntityCraftingAltar method matchCurrentRecipe.

private boolean matchCurrentRecipe() {
    ISpellPart part = SpellRecipeManager.instance.getPartByRecipe(currentAddedItems);
    if (part == null)
        return false;
    ArrayList<KeyValuePair<ISpellPart, byte[]>> currentShapeGroupList = getShapeGroupToAddTo();
    if (part instanceof Summon)
        handleSummonShape();
    if (part instanceof Binding)
        handleBindingShape();
    byte[] metaData = new byte[0];
    if (part instanceof ISpellModifier) {
        metaData = ((ISpellModifier) part).getModifierMetadata(currentAddedItems.toArray(new ItemStack[currentAddedItems.size()]));
        if (metaData == null) {
            metaData = new byte[0];
        }
    }
    //we're now creating the body of the spell
    if (currentShapeGroupList == null) {
        spellDef.add(new KeyValuePair<ISpellPart, byte[]>(part, metaData));
    } else {
        currentShapeGroupList.add(new KeyValuePair<ISpellPart, byte[]>(part, metaData));
    }
    return true;
}
Also used : Binding(am2.spell.shapes.Binding) KeyValuePair(am2.utility.KeyValuePair) Summon(am2.spell.components.Summon) ISpellModifier(am2.api.spell.component.interfaces.ISpellModifier) ISpellPart(am2.api.spell.component.interfaces.ISpellPart)

Example 2 with ISpellModifier

use of am2.api.spell.component.interfaces.ISpellModifier in project ArsMagica2 by Mithion.

the class EntitySpellEffect method wallUpdate.

private void wallUpdate() {
    if (worldObj.isRemote) {
        if (spellStack == null) {
            spellStack = this.dataWatcher.getWatchableObjectItemStack(22);
            if (spellStack == null) {
                return;
            }
        }
        double dist = this.dataWatcher.getWatchableObjectFloat(WATCHER_RADIUS);
        int color = 0xFFFFFF;
        if (SpellUtils.instance.modifierIsPresent(SpellModifiers.COLOR, spellStack, 0)) {
            ISpellModifier[] mods = SpellUtils.instance.getModifiersForStage(spellStack, 0);
            int ordinalCount = 0;
            for (ISpellModifier mod : mods) {
                if (mod instanceof Colour) {
                    byte[] meta = SpellUtils.instance.getModifierMetadataFromStack(spellStack, mod, 0, ordinalCount++);
                    color = (int) mod.getModifier(SpellModifiers.COLOR, null, null, null, meta);
                }
            }
        }
        double px = Math.cos(3.141 / 180 * (rotationYaw + 90)) * 0.1f;
        double pz = Math.sin(3.141 / 180 * (rotationYaw + 90)) * 0.1f;
        double py = 0.1f;
        for (float i = 0; i < dist; i += 0.5f) {
            double x = this.posX - Math.cos(3.141 / 180 * (rotationYaw)) * i;
            double z = this.posZ - Math.sin(3.141 / 180 * (rotationYaw)) * i;
            AMParticle effect = (AMParticle) AMCore.instance.proxy.particleManager.spawn(worldObj, AMParticleIcons.instance.getParticleForAffinity(SpellUtils.instance.mainAffinityFor(spellStack)), x, posY, z);
            if (effect != null) {
                effect.setIgnoreMaxAge(false);
                effect.setMaxAge(20);
                effect.addRandomOffset(1, 1, 1);
                effect.setParticleScale(0.15f);
                effect.setRGBColorI(color);
                if (dataWatcher.getWatchableObjectInt(WATCHER_TYPE) == TYPE_WALL) {
                    effect.AddParticleController(new ParticleFloatUpward(effect, 0, 0.07f, 1, false));
                } else {
                    effect.setAffectedByGravity();
                    effect.setDontRequireControllers();
                    effect.addVelocity(px, py, pz);
                }
            }
            x = this.posX - Math.cos(Math.toRadians(rotationYaw)) * -i;
            z = this.posZ - Math.sin(Math.toRadians(rotationYaw)) * -i;
            effect = (AMParticle) AMCore.instance.proxy.particleManager.spawn(worldObj, AMParticleIcons.instance.getParticleForAffinity(SpellUtils.instance.mainAffinityFor(spellStack)), x, posY, z);
            if (effect != null) {
                effect.setIgnoreMaxAge(false);
                effect.addRandomOffset(1, 1, 1);
                effect.setMaxAge(20);
                effect.setParticleScale(0.15f);
                effect.setRGBColorI(color);
                if (dataWatcher.getWatchableObjectInt(WATCHER_TYPE) == TYPE_WALL) {
                    effect.AddParticleController(new ParticleFloatUpward(effect, 0, 0.07f, 1, false));
                } else {
                    effect.setAffectedByGravity();
                    effect.setDontRequireControllers();
                    effect.addVelocity(px, py, pz);
                }
            }
        }
    } else {
        ticksToEffect--;
        if (spellStack == null) {
            if (!worldObj.isRemote) {
                this.setDead();
            }
            return;
        }
        if (dummycaster == null) {
            dummycaster = DummyEntityPlayer.fromEntityLiving(new EntityDummyCaster(worldObj));
        }
        if (ticksToEffect <= 0) {
            ticksToEffect = maxTicksToEffect_wall;
            float radius = this.dataWatcher.getWatchableObjectFloat(WATCHER_RADIUS);
            List<Entity> possibleTargets = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(posX - radius, posY - 1, posZ - radius, posX + radius, posY + 3, posZ + radius));
            ItemStack newStack = SpellUtils.instance.popStackStage(spellStack);
            for (Entity e : possibleTargets) {
                if (e == this || e == dummycaster || e.getEntityId() == casterEntityID)
                    continue;
                if (e instanceof EntityDragonPart && ((EntityDragonPart) e).entityDragonObj instanceof EntityLivingBase)
                    e = (EntityLivingBase) ((EntityDragonPart) e).entityDragonObj;
                AMVector3 target = new AMVector3(e);
                double dirX = Math.cos(3.141 / 180 * (rotationYaw));
                double dirZ = Math.sin(3.141 / 180 * (rotationYaw));
                AMVector3 a = new AMVector3(this.posX - dirX * radius, this.posY, this.posZ - dirZ * radius);
                AMVector3 b = new AMVector3(this.posX - dirX * -radius, this.posY, this.posZ - dirZ * -radius);
                AMVector3 closest = new AMLineSegment(a, b).closestPointOnLine(target);
                closest.y = 0;
                target.y = 0;
                double hDistance = closest.distanceTo(target);
                double vDistance = Math.abs(this.posY - e.posY);
                if (e instanceof EntityLivingBase && hDistance < 0.75f && vDistance < 2) {
                    //commented out in favor of line below so as to apply subsequent shapes as well
                    //uncomment and comment out below line to revert to direct target only, but mark wave/wall as terminus
                    //SpellHelper.instance.applyStageToEntity(spellStack, dummycaster, worldObj, e, 0, false);
                    SpellHelper.instance.applyStackStage(spellStack, dummycaster, (EntityLivingBase) e, this.posX, this.posY, this.posZ, 0, worldObj, false, false, 0);
                }
            }
        }
    }
}
Also used : AMLineSegment(am2.api.math.AMLineSegment) Entity(net.minecraft.entity.Entity) ISpellModifier(am2.api.spell.component.interfaces.ISpellModifier) Colour(am2.spell.modifiers.Colour) AMVector3(am2.api.math.AMVector3) EntityDragonPart(net.minecraft.entity.boss.EntityDragonPart) EntityLivingBase(net.minecraft.entity.EntityLivingBase) ItemStack(net.minecraft.item.ItemStack)

Example 3 with ISpellModifier

use of am2.api.spell.component.interfaces.ISpellModifier in project ArsMagica2 by Mithion.

the class EntitySpellEffect method blizzardUpdate.

private void blizzardUpdate() {
    float radius = this.dataWatcher.getWatchableObjectFloat(WATCHER_RADIUS);
    if (worldObj.isRemote) {
        if (spellStack == null) {
            spellStack = this.dataWatcher.getWatchableObjectItemStack(22);
            if (spellStack == null) {
                return;
            }
        }
        int color = 0xFFFFFF;
        if (SpellUtils.instance.modifierIsPresent(SpellModifiers.COLOR, spellStack, 0)) {
            ISpellModifier[] mods = SpellUtils.instance.getModifiersForStage(spellStack, 0);
            int ordinalCount = 0;
            for (ISpellModifier mod : mods) {
                if (mod instanceof Colour) {
                    byte[] meta = SpellUtils.instance.getModifierMetadataFromStack(spellStack, mod, 0, ordinalCount++);
                    color = (int) mod.getModifier(SpellModifiers.COLOR, null, null, null, meta);
                }
            }
        }
        for (int i = 0; i < 20; ++i) {
            double x = this.posX - radius + (rand.nextDouble() * radius * 2);
            double z = this.posZ - radius + (rand.nextDouble() * radius * 2);
            double y = this.posY + 10;
            AMParticle particle = (AMParticle) AMCore.proxy.particleManager.spawn(worldObj, "snowflakes", x, y, z);
            if (particle != null) {
                particle.setMaxAge(20);
                particle.setParticleScale(0.1f);
                particle.addVelocity(rand.nextDouble() * 0.2f - 0.1f, 0, rand.nextDouble() * 0.2f - 0.1f);
                particle.setAffectedByGravity();
                particle.setRGBColorI(color);
                particle.setDontRequireControllers();
                particle.noClip = false;
            }
        }
        double x = this.posX - radius + (rand.nextDouble() * radius * 2);
        double z = this.posZ - radius + (rand.nextDouble() * radius * 2);
        double y = this.posY + rand.nextDouble();
        AMParticle particle = (AMParticle) AMCore.proxy.particleManager.spawn(worldObj, "smoke", x, y, z);
        if (particle != null) {
            particle.setParticleScale(2.0f);
            particle.setMaxAge(20);
            //particle.setRGBColorF(0.5f, 0.92f, 0.92f);
            particle.setRGBColorF(0.5098f, 0.7843f, 0.7843f);
            particle.SetParticleAlpha(0.6f);
            particle.AddParticleController(new ParticleFleePoint(particle, new AMVector3(x, y, z), 0.1f, 3f, 1, false));
        }
    //TODO: SoundHelper.instance.loopSound(worldObj, (float)posX, (float)posY, (float)posZ, "arsmagica2:spell.loop.air", 1.0f);
    } else {
        List<Entity> possibleTargets = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, AxisAlignedBB.getBoundingBox(posX - radius, posY - 1, posZ - radius, posX + radius, posY + 3, posZ + radius));
        for (Entity e : possibleTargets) {
            if (e != dummycaster) {
                if (e instanceof EntityDragonPart && ((EntityDragonPart) e).entityDragonObj instanceof EntityLivingBase)
                    e = (EntityLivingBase) ((EntityDragonPart) e).entityDragonObj;
                if (e instanceof EntityLivingBase)
                    ((EntityLivingBase) e).addPotionEffect(new BuffEffectFrostSlowed(80, 3));
                float damage = 1 * this.dataWatcher.getWatchableObjectFloat(WATCHER_DAMAGEBONUS);
                double lastVelX = e.motionX;
                double lastVelY = e.motionY;
                double lastVelZ = e.motionZ;
                if (SpellHelper.instance.attackTargetSpecial(null, e, DamageSources.causeEntityFrostDamage(dummycaster), damage) && !(e instanceof EntityPlayer))
                    e.hurtResistantTime = 15;
                e.addVelocity(-(e.motionX - lastVelX), -(e.motionY - lastVelY), -(e.motionZ - lastVelZ));
            }
        }
        if (rand.nextInt(10) < 2) {
            int pX = (int) (posX - radius + rand.nextInt((int) Math.ceil(radius) * 2));
            int pY = (int) posY + rand.nextInt(2);
            int pZ = (int) (posZ - radius + rand.nextInt((int) Math.ceil(radius) * 2));
            if (worldObj.isAirBlock(pX, pY, pZ) && !worldObj.isAirBlock(pX, pY - 1, pZ) && worldObj.getBlock(pX, pY, pZ).isOpaqueCube())
                worldObj.setBlock(pX, pY, pZ, Blocks.snow);
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) ISpellModifier(am2.api.spell.component.interfaces.ISpellModifier) Colour(am2.spell.modifiers.Colour) AMVector3(am2.api.math.AMVector3) EntityDragonPart(net.minecraft.entity.boss.EntityDragonPart) BuffEffectFrostSlowed(am2.buffs.BuffEffectFrostSlowed) EntityLivingBase(net.minecraft.entity.EntityLivingBase) DummyEntityPlayer(am2.utility.DummyEntityPlayer) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 4 with ISpellModifier

use of am2.api.spell.component.interfaces.ISpellModifier 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));
    }
}
Also used : ISpellComponent(am2.api.spell.component.interfaces.ISpellComponent) ISpellModifier(am2.api.spell.component.interfaces.ISpellModifier) SkillLearnedEvent(am2.api.events.SkillLearnedEvent) AMDataWriter(am2.network.AMDataWriter) ISpellShape(am2.api.spell.component.interfaces.ISpellShape)

Example 5 with ISpellModifier

use of am2.api.spell.component.interfaces.ISpellModifier in project ArsMagica2 by Mithion.

the class EntityThrownRock method onUpdate.

@Override
public void onUpdate() {
    super.onUpdate();
    if (this.target != null && this.posY > this.target.y) {
        double deltaX = this.posX - target.x;
        double deltaY = this.posY - target.y;
        double deltaZ = this.posZ - target.z;
        double angle = Math.atan2(deltaZ, deltaX);
        double hDist = Math.sqrt(deltaX * deltaX + deltaZ * deltaZ);
        double vAngle = Math.atan2(deltaY, hDist);
        motionX = -Math.cos(angle) * 0.2;
        motionZ = -Math.sin(angle) * 0.2;
        motionY = -Math.sin(vAngle) * 2.5;
    }
    if (!getIsMoonstoneMeteor() && !getIsShootingStar()) {
        if (!worldObj.isRemote && (throwingEntity == null || throwingEntity.isDead)) {
            setDead();
        } else {
            ticksExisted++;
            int maxTicksToLive = maxTicksToExist > -1 ? maxTicksToExist : 100;
            if (ticksExisted >= maxTicksToLive && !worldObj.isRemote) {
                setDead();
                return;
            }
        }
    }
    if (getIsShootingStar()) {
        motionY -= 0.1f;
        if (motionY < -2f)
            motionY = -2f;
    }
    if (worldObj.isRemote) {
        if (getIsMoonstoneMeteor()) {
            AMParticle fire = (AMParticle) AMCore.proxy.particleManager.spawn(worldObj, "explosion_2", posX, posY, posZ);
            if (fire != null) {
                fire.setMaxAge(20);
                fire.setRGBColorF(1, 1, 1);
                fire.setParticleScale(2.0f);
                fire.AddParticleController(new ParticleHoldPosition(fire, 20, 1, false));
                fire.AddParticleController(new ParticleColorShift(fire, 1, false).SetShiftSpeed(0.1f).SetColorTarget(0.01f, 0.01f, 0.01f).SetEndOnReachingTargetColor().setKillParticleOnFinish(false));
            }
        } else if (getIsShootingStar()) {
            int color = -1;
            if (getSpellStack() != null) {
                if (SpellUtils.instance.modifierIsPresent(SpellModifiers.COLOR, getSpellStack(), 0)) {
                    ISpellModifier[] mods = SpellUtils.instance.getModifiersForStage(getSpellStack(), 0);
                    int ordinalCount = 0;
                    for (ISpellModifier mod : mods) {
                        if (mod instanceof Colour) {
                            byte[] meta = SpellUtils.instance.getModifierMetadataFromStack(getSpellStack(), mod, 0, ordinalCount++);
                            color = (int) mod.getModifier(SpellModifiers.COLOR, null, null, null, meta);
                        }
                    }
                }
            }
            for (float i = 0; i < Math.abs(motionY); i += 0.1f) {
                AMParticle star = (AMParticle) AMCore.proxy.particleManager.spawn(worldObj, "ember", posX + motionX * i, posY + motionY * i, posZ + motionZ * i);
                if (star != null) {
                    star.setMaxAge(22);
                    float clr = rand.nextFloat();
                    float clrMod = Minecraft.getMinecraft().theWorld.rand.nextFloat();
                    int finalColor = -1;
                    if (color == -1)
                        finalColor = MathUtilities.colorFloatsToInt(0.24f * clrMod, 0.58f * clrMod, 0.71f * clrMod);
                    else {
                        float[] colors = MathUtilities.colorIntToFloats(color);
                        for (int c = 0; c < colors.length; ++c) colors[c] = colors[c] * clrMod;
                        finalColor = MathUtilities.colorFloatsToInt(colors[0], colors[1], colors[2]);
                    }
                    star.setRGBColorI(finalColor);
                    star.AddParticleController(new ParticleHoldPosition(star, 20, 1, false));
                    star.AddParticleController(new ParticleChangeSize(star, 0.5f, 0.05f, 20, 1, false));
                }
            }
        }
    }
    Vec3 vec3d = Vec3.createVectorHelper(posX, posY, posZ);
    Vec3 vec3d1 = Vec3.createVectorHelper(posX + motionX, posY + motionY, posZ + motionZ);
    MovingObjectPosition movingobjectposition = worldObj.rayTraceBlocks(vec3d, vec3d1);
    vec3d = Vec3.createVectorHelper(posX, posY, posZ);
    vec3d1 = Vec3.createVectorHelper(posX + motionX, posY + motionY, posZ + motionZ);
    if (movingobjectposition != null) {
        vec3d1 = Vec3.createVectorHelper(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord);
    }
    Entity entity = null;
    List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.addCoord(motionX, motionY, motionZ).expand(1.0D, 1.0D, 1.0D));
    double d = 0.0D;
    for (int j = 0; j < list.size(); j++) {
        Entity entity1 = (Entity) list.get(j);
        if (!entity1.canBeCollidedWith() || entity1.isEntityEqual(throwingEntity) && ticksExisted < 25) {
            continue;
        }
        float f2 = 0.3F;
        AxisAlignedBB axisalignedbb = entity1.boundingBox.expand(f2, f2, f2);
        MovingObjectPosition movingobjectposition1 = axisalignedbb.calculateIntercept(vec3d, vec3d1);
        if (movingobjectposition1 == null) {
            continue;
        }
        double d1 = vec3d.distanceTo(movingobjectposition1.hitVec);
        if (d1 < d || d == 0.0D) {
            entity = entity1;
            d = d1;
        }
    }
    if (entity != null) {
        movingobjectposition = new MovingObjectPosition(entity);
    }
    if (movingobjectposition != null) {
        HitObject(movingobjectposition);
    }
    posX += motionX;
    posY += motionY;
    posZ += motionZ;
    float f = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);
    rotationYaw = (float) ((Math.atan2(motionX, motionZ) * 180D) / 3.1415927410125732D);
    for (rotationPitch = (float) ((Math.atan2(motionY, f) * 180D) / 3.1415927410125732D); rotationPitch - prevRotationPitch < -180F; prevRotationPitch -= 360F) {
    }
    for (; rotationPitch - prevRotationPitch >= 180F; prevRotationPitch += 360F) {
    }
    for (; rotationYaw - prevRotationYaw < -180F; prevRotationYaw -= 360F) {
    }
    for (; rotationYaw - prevRotationYaw >= 180F; prevRotationYaw += 360F) {
    }
    rotationPitch = prevRotationPitch + (rotationPitch - prevRotationPitch) * 0.2F;
    rotationYaw = prevRotationYaw + (rotationYaw - prevRotationYaw) * 0.2F;
    float f1 = 0.95F;
    setPosition(posX, posY, posZ);
}
Also used : Entity(net.minecraft.entity.Entity) AMParticle(am2.particles.AMParticle) ParticleColorShift(am2.particles.ParticleColorShift) ISpellModifier(am2.api.spell.component.interfaces.ISpellModifier) ParticleHoldPosition(am2.particles.ParticleHoldPosition) Colour(am2.spell.modifiers.Colour) ParticleChangeSize(am2.particles.ParticleChangeSize) List(java.util.List)

Aggregations

ISpellModifier (am2.api.spell.component.interfaces.ISpellModifier)17 Colour (am2.spell.modifiers.Colour)13 EntityPlayer (net.minecraft.entity.player.EntityPlayer)8 ModifierCalculatedEvent (am2.api.events.ModifierCalculatedEvent)6 Entity (net.minecraft.entity.Entity)6 EntityLivingBase (net.minecraft.entity.EntityLivingBase)5 EntityDragonPart (net.minecraft.entity.boss.EntityDragonPart)5 ISpellComponent (am2.api.spell.component.interfaces.ISpellComponent)4 ISpellShape (am2.api.spell.component.interfaces.ISpellShape)4 ItemStack (net.minecraft.item.ItemStack)4 AMVector3 (am2.api.math.AMVector3)2 Affinity (am2.api.spell.enums.Affinity)2 AMDataWriter (am2.network.AMDataWriter)2 AMParticle (am2.particles.AMParticle)2 Summon (am2.spell.components.Summon)2 DummyEntityPlayer (am2.utility.DummyEntityPlayer)2 KeyValuePair (am2.utility.KeyValuePair)2 SkillLearnedEvent (am2.api.events.SkillLearnedEvent)1 AMLineSegment (am2.api.math.AMLineSegment)1 ISkillTreeEntry (am2.api.spell.component.interfaces.ISkillTreeEntry)1