Search in sources :

Example 6 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 7 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 8 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)

Example 9 with ISpellModifier

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

the class AMPacketProcessorClient method handleStarFall.

private void handleStarFall(byte[] data) {
    AMDataReader rdr = new AMDataReader(data, false);
    double x = rdr.getDouble();
    double y = rdr.getDouble();
    double z = rdr.getDouble();
    ItemStack spellStack = null;
    if (rdr.getBoolean())
        spellStack = rdr.getItemStack();
    int color = -1;
    if (spellStack != null) {
        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 < 360; i += AMCore.config.FullGFX() ? 5 : AMCore.config.LowGFX() ? 10 : 20) {
        AMParticle effect = (AMParticle) AMCore.instance.proxy.particleManager.spawn(Minecraft.getMinecraft().theWorld, "sparkle2", x, y + 1.5, z);
        if (effect != null) {
            effect.setIgnoreMaxAge(true);
            effect.AddParticleController(new ParticleMoveOnHeading(effect, i, 0, 0.7f, 1, false));
            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]);
            }
            effect.setParticleScale(1.2f);
            effect.noClip = false;
            effect.setRGBColorI(finalColor);
            effect.AddParticleController(new ParticleFadeOut(effect, 1, false).setFadeSpeed(0.05f).setKillParticleOnFinish(true));
            effect.AddParticleController(new ParticleLeaveParticleTrail(effect, "sparkle2", false, 15, 1, false).addControllerToParticleList(new ParticleChangeSize(effect, 1.2f, 0.01f, 15, 1, false)).setParticleRGB_I(finalColor).setChildAffectedByGravity().addRandomOffset(0.2f, 0.2f, 0.2f));
        }
    }
    Minecraft.getMinecraft().theWorld.playSound(x, y, z, "arsmagica2:spell.special.starfall", 2.0f, 1.0f, false);
}
Also used : ISpellModifier(am2.api.spell.component.interfaces.ISpellModifier) Colour(am2.spell.modifiers.Colour) ItemStack(net.minecraft.item.ItemStack)

Example 10 with ISpellModifier

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

the class SpellUtils method getModifiedDouble_Add.

public double getModifiedDouble_Add(double defaultValue, ItemStack stack, EntityLivingBase caster, Entity target, World world, int stage, SpellModifiers check) {
    int ordinalCount = 0;
    double modifiedValue = defaultValue;
    for (ISpellModifier modifier : getModifiersForStage(stack, stage)) {
        if (modifier.getAspectsModified().contains(check)) {
            byte[] meta = getModifierMetadataFromStack(stack, modifier, stage, ordinalCount++);
            modifiedValue += modifier.getModifier(check, caster, target, world, meta);
        }
    }
    if (caster instanceof EntityPlayer) {
        if (SkillData.For((EntityPlayer) caster).isEntryKnown(SkillTreeManager.instance.getSkillTreeEntry(SkillManager.instance.getSkill("AugmentedCasting")))) {
            modifiedValue *= 1.1f;
        }
    }
    ModifierCalculatedEvent event = new ModifierCalculatedEvent(stack, caster, check, defaultValue, modifiedValue, OperationType.ADD);
    MinecraftForge.EVENT_BUS.post(event);
    return event.modifiedValue;
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) ModifierCalculatedEvent(am2.api.events.ModifierCalculatedEvent)

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