Search in sources :

Example 16 with ISpellModifier

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

the class EntitySpellEffect method zoneUpdate.

private void zoneUpdate() {
    if (this.worldObj.isRemote) {
        if (!AMCore.config.NoGFX()) {
            this.rotation += this.rotationSpeed;
            this.rotation %= 360;
            double dist = this.dataWatcher.getWatchableObjectFloat(WATCHER_RADIUS);
            double _rotation = rotation;
            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);
                    }
                }
            }
            if ((AMCore.config.FullGFX() && this.ticksExisted % 2 == 0) || this.ticksExisted % 8 == 0) {
                for (int i = 0; i < 4; ++i) {
                    _rotation = (rotation + (90 * i)) % 360;
                    double x = this.posX - Math.cos(3.141 / 180 * (_rotation)) * dist;
                    double z = this.posZ - Math.sin(3.141 / 180 * (_rotation)) * dist;
                    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.setParticleScale(0.15f);
                        effect.setRGBColorI(color);
                        effect.AddParticleController(new ParticleFloatUpward(effect, 0, 0.07f, 1, false));
                        if (AMCore.config.LowGFX()) {
                            effect.AddParticleController(new ParticleOrbitPoint(effect, posX, posY, posZ, 2, false).setIgnoreYCoordinate(true).SetOrbitSpeed(0.05f).SetTargetDistance(dist).setRotateDirection(true));
                        }
                    }
                }
            }
        }
    }
    this.moveEntity(0, this.dataWatcher.getWatchableObjectInt(WATCHER_GRAVITY) / 100.0f, 0);
    ticksToEffect--;
    if (spellStack == null) {
        if (!worldObj.isRemote) {
            this.setDead();
        }
        return;
    }
    if (dummycaster == null) {
        dummycaster = DummyEntityPlayer.fromEntityLiving(new EntityDummyCaster(worldObj));
    }
    if (ticksToEffect <= 0) {
        ticksToEffect = maxTicksToEffect;
        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));
        for (Entity e : possibleTargets) {
            if (e instanceof EntityDragonPart && ((EntityDragonPart) e).entityDragonObj instanceof EntityLivingBase)
                e = (EntityLivingBase) ((EntityDragonPart) e).entityDragonObj;
            if (e instanceof EntityLivingBase)
                SpellHelper.instance.applyStageToEntity(spellStack, dummycaster, worldObj, e, 0, false);
        }
        if (this.dataWatcher.getWatchableObjectInt(WATCHER_GRAVITY) < 0 && !firstApply)
            SpellHelper.instance.applyStackStage(spellStack, dummycaster, null, posX, posY - 1, posZ, 0, worldObj, false, false, this.ticksExisted);
        else
            SpellHelper.instance.applyStackStage(spellStack, dummycaster, null, posX, posY, posZ, 0, worldObj, false, false, this.ticksExisted);
        firstApply = false;
    }
}
Also used : Entity(net.minecraft.entity.Entity) ISpellModifier(am2.api.spell.component.interfaces.ISpellModifier) Colour(am2.spell.modifiers.Colour) EntityDragonPart(net.minecraft.entity.boss.EntityDragonPart) EntityLivingBase(net.minecraft.entity.EntityLivingBase)

Example 17 with ISpellModifier

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

the class EntitySpellEffect method rainOfFireUpdate.

private void rainOfFireUpdate() {
    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 < 10; ++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, "explosion_2", x, y, z);
            if (particle != null) {
                particle.setMaxAge(20);
                particle.addVelocity(rand.nextDouble() * 0.2f, 0, rand.nextDouble() * 0.2f);
                particle.setAffectedByGravity();
                particle.setDontRequireControllers();
                particle.setRGBColorI(color);
                particle.noClip = false;
            }
        }
    //TODO: SoundHelper.instance.loopSound(worldObj, (float)posX, (float)posY, (float)posZ, "arsmagica2:spell.loop.fire", 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;
                double lastVelX = e.motionX;
                double lastVelY = e.motionY;
                double lastVelZ = e.motionZ;
                float damage = 0.75f * this.dataWatcher.getWatchableObjectFloat(WATCHER_DAMAGEBONUS);
                if (SpellHelper.instance.attackTargetSpecial(null, e, DamageSources.causeEntityFireDamage(dummycaster), damage) && !(e instanceof EntityPlayer))
                    e.hurtResistantTime = 10;
                e.addVelocity(-(e.motionX - lastVelX), -(e.motionY - lastVelY), -(e.motionZ - lastVelZ));
            }
        }
        if (this.dataWatcher.getWatchableObjectByte(WATCHER_ROF_IGNITE) == 1 && rand.nextInt(10) < 2) {
            int pX = (int) (posX - radius + rand.nextInt((int) Math.ceil(radius) * 2));
            int pY = (int) posY;
            int pZ = (int) (posZ - radius + rand.nextInt((int) Math.ceil(radius) * 2));
            if (worldObj.isAirBlock(pX, pY, pZ))
                worldObj.setBlock(pX, pY, pZ, Blocks.fire);
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) ISpellModifier(am2.api.spell.component.interfaces.ISpellModifier) Colour(am2.spell.modifiers.Colour) EntityDragonPart(net.minecraft.entity.boss.EntityDragonPart) EntityLivingBase(net.minecraft.entity.EntityLivingBase) DummyEntityPlayer(am2.utility.DummyEntityPlayer) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 18 with ISpellModifier

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

the class EntitySpellProjectile method setEffectStack.

public void setEffectStack(ItemStack stack) {
    this.dataWatcher.updateObject(DW_EFFECT, stack);
    if (!this.worldObj.isRemote) {
        Affinity aff = SpellUtils.instance.mainAffinityFor(stack);
        switch(aff) {
            case AIR:
                setIcon("wind");
                break;
            case ARCANE:
                setIcon("arcane");
                break;
            case EARTH:
                setIcon("rock");
                break;
            case ENDER:
                setIcon("pulse");
                setColor(0x550055);
                break;
            case FIRE:
                setIcon("explosion_2");
                break;
            case ICE:
                setIcon("ember");
                setColor(0x2299FF);
                break;
            case LIFE:
                setIcon("sparkle");
                setColor(0x22FF44);
                break;
            case LIGHTNING:
                setIcon("lightning_hand");
                break;
            case NATURE:
                setIcon("plant");
                break;
            case WATER:
                setIcon("water_ball");
                break;
            case NONE:
            default:
                setIcon("lens_flare");
                break;
        }
    }
    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++);
                setColor((int) mod.getModifier(SpellModifiers.COLOR, null, null, null, meta));
            }
        }
    }
}
Also used : ISpellModifier(am2.api.spell.component.interfaces.ISpellModifier) Affinity(am2.api.spell.enums.Affinity) Colour(am2.spell.modifiers.Colour)

Example 19 with ISpellModifier

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

the class SpellUtils method getModifiedInt_Mul.

public int getModifiedInt_Mul(int defaultValue, ItemStack stack, EntityLivingBase caster, Entity target, World world, int stage, SpellModifiers check) {
    int ordinalCount = 0;
    int 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.MULTIPLY);
    MinecraftForge.EVENT_BUS.post(event);
    return (int) event.modifiedValue;
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) ModifierCalculatedEvent(am2.api.events.ModifierCalculatedEvent)

Example 20 with ISpellModifier

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

the class SpellUtils method createSpellStack.

public ItemStack createSpellStack(ArrayList<ArrayList<KeyValuePair<ISpellPart, byte[]>>> shapeGroups, ArrayList<KeyValuePair<ISpellPart, byte[]>> spell) {
    ArrayList<KeyValuePair<ISpellPart, byte[]>> recipeCopy = (ArrayList<KeyValuePair<ISpellPart, byte[]>>) spell.clone();
    if (recipeCopy.size() > 0 && !(recipeCopy.get(0).getKey() instanceof ISpellShape))
        recipeCopy.add(0, new KeyValuePair<ISpellPart, byte[]>(SkillManager.instance.missingShape, new byte[0]));
    ItemStack stack = new ItemStack(ItemsCommonProxy.spell);
    boolean hasSummon = false;
    while (recipeCopy.size() > 0) {
        ISpellShape shape;
        ArrayList<Integer> components = new ArrayList<Integer>();
        ArrayListMultimap<Integer, byte[]> modifiers = ArrayListMultimap.create();
        KeyValuePair<ISpellPart, byte[]> part = recipeCopy.get(0);
        recipeCopy.remove(0);
        if (part.getKey() instanceof ISpellShape) {
            shape = (ISpellShape) part.getKey();
            part = recipeCopy.size() > 0 ? recipeCopy.get(0) : null;
            while (part != null && !(part.getKey() instanceof ISpellShape)) {
                recipeCopy.remove(0);
                if (part.getKey() instanceof ISpellComponent) {
                    components.add(SkillManager.instance.getShiftedPartID(part.getKey()));
                    if (part.getKey() instanceof Summon) {
                        hasSummon = true;
                    }
                } else if (part.getKey() instanceof ISpellModifier) {
                    modifiers.put(SkillManager.instance.getShiftedPartID(part.getKey()), part.getValue());
                }
                part = recipeCopy.size() > 0 ? recipeCopy.get(0) : null;
            }
            if (hasSummon) {
                ((Summon) SkillManager.instance.getSkill("Summon")).setSummonType(stack, EntitySkeleton.class);
            }
            SpellUtils.instance.addSpellStageToScroll(stack, shape.getID(), ArrayListToIntArray(components), modifiers);
        }
    }
    for (int i = 0; i < shapeGroups.size(); ++i) {
        ArrayList<KeyValuePair<ISpellPart, byte[]>> shapeGroup = shapeGroups.get(i);
        if (shapeGroup.size() == 0)
            continue;
        int[] sgp = new int[shapeGroup.size()];
        byte[][] sgp_m = new byte[shapeGroup.size()][];
        for (int n = 0; n < shapeGroup.size(); ++n) {
            sgp[n] = SkillManager.instance.getShiftedPartID(shapeGroup.get(n).getKey());
            sgp_m[n] = shapeGroup.get(n).getValue();
        }
        SpellUtils.instance.addShapeGroup(sgp, sgp_m, stack);
    }
    SpellUtils.instance.writeModVersionToStack(stack);
    ItemStack checkStack = constructSpellStack(stack);
    int silkTouchLevel = 0;
    int fortuneLevel = 0;
    for (int i = 0; i < numStages(checkStack); ++i) {
        int st = countModifiers(SpellModifiers.SILKTOUCH_LEVEL, checkStack, 0);
        int fn = countModifiers(SpellModifiers.FORTUNE_LEVEL, checkStack, 0);
        if (st > silkTouchLevel)
            silkTouchLevel = st;
        if (fn > fortuneLevel)
            fortuneLevel = fn;
    }
    if (fortuneLevel > 0) {
        AMEnchantmentHelper.fortuneStack(stack, fortuneLevel);
        AMEnchantmentHelper.lootingStack(stack, fortuneLevel);
    }
    if (silkTouchLevel > 0)
        AMEnchantmentHelper.silkTouchStack(stack, silkTouchLevel);
    return stack;
}
Also used : KeyValuePair(am2.utility.KeyValuePair) Summon(am2.spell.components.Summon) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

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