Search in sources :

Example 21 with Affinity

use of am2.api.spell.enums.Affinity 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 22 with Affinity

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

the class EntityFlicker method getCanSpawnHere.

@Override
public boolean getCanSpawnHere() {
    if (AMCore.proxy.getTotalFlickerCount() > 8 * worldObj.playerEntities.size() || worldObj.rand.nextDouble() > 0.2f) {
        return false;
    }
    // get the biome we're trying to spawn in
    BiomeGenBase biome = worldObj.getBiomeGenForCoords((int) Math.floor(this.posX), (int) Math.floor(this.posZ));
    if (biome != null) {
        // get the tags on this biome
        Type[] biomeTags = BiomeDictionary.getTypesForBiome(biome);
        // pick a random tag to focus on
        Type tagType = biomeTags[worldObj.rand.nextInt(biomeTags.length)];
        // create a list of valid types based on that tag
        ArrayList<Affinity> validAffinities = new ArrayList<Affinity>();
        // DO NOT USE THIS LIST FOR AIR/EARTH/LIFE - they are handled by special cases.
        switch(tagType) {
            case END:
                validAffinities.add(Affinity.ENDER);
                break;
            case FOREST:
            case CONIFEROUS:
            case JUNGLE:
                validAffinities.add(Affinity.NATURE);
                break;
            case COLD:
            case SNOWY:
                validAffinities.add(Affinity.ICE);
                break;
            case MAGICAL:
                validAffinities.add(Affinity.ARCANE);
                break;
            case NETHER:
                validAffinities.add(Affinity.FIRE);
                break;
            case OCEAN:
                validAffinities.add(Affinity.LIGHTNING);
            case SWAMP:
            case WATER:
            case RIVER:
            case WET:
            case BEACH:
                validAffinities.add(Affinity.WATER);
                break;
            case DEAD:
            case DENSE:
            case DRY:
            case HOT:
            case LUSH:
            case MESA:
            case SANDY:
            case SAVANNA:
            case SPARSE:
            case SPOOKY:
            case WASTELAND:
            case PLAINS:
            case HILLS:
            case MOUNTAIN:
            case MUSHROOM:
            default:
                break;
        }
        // special conditions for air/earth flickers based on y coordinate
        if (posY < 55) {
            validAffinities.add(Affinity.EARTH);
        }
        if (worldObj.canBlockSeeTheSky((int) Math.floor(posX), (int) Math.floor(posY), (int) Math.floor(posZ)))
            validAffinities.add(Affinity.AIR);
        if (worldObj.isRaining() && worldObj.rand.nextBoolean()) {
            validAffinities.clear();
            validAffinities.add(Affinity.LIGHTNING);
        }
        if (validAffinities.size() <= 0)
            return false;
        // life flickers always have a chance to spawn?
        if (worldObj.rand.nextDouble() < 0.1f) {
            this.setFlickerType(Affinity.LIFE);
        } else {
            this.setFlickerType(validAffinities.get(worldObj.rand.nextInt(validAffinities.size())));
        }
        if (this.worldObj.checkNoEntityCollision(this.boundingBox) && this.worldObj.getCollidingBoundingBoxes(this, this.boundingBox).isEmpty()) {
            AMCore.proxy.incrementFlickerCount();
            return true;
        }
    }
    return false;
}
Also used : Type(net.minecraftforge.common.BiomeDictionary.Type) ArrayList(java.util.ArrayList) Affinity(am2.api.spell.enums.Affinity) BiomeGenBase(net.minecraft.world.biome.BiomeGenBase)

Example 23 with Affinity

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

the class TileEntityInscriptionTable method writeRecipeAndDataToBook.

public ItemStack writeRecipeAndDataToBook(ItemStack bookstack, EntityPlayer player, String title) {
    if (bookstack.getItem() == Items.written_book && this.currentRecipe != null) {
        if (!currentRecipeIsValid().valid)
            return bookstack;
        if (!bookstack.hasTagCompound())
            bookstack.setTagCompound(new NBTTagCompound());
        else if (// don't overwrite a completed spell
        bookstack.getTagCompound().getBoolean("spellFinalized"))
            return bookstack;
        LinkedHashMap<String, Integer> materialsList = new LinkedHashMap<String, Integer>();
        materialsList.put(ItemsCommonProxy.rune.getItemStackDisplayName(new ItemStack(ItemsCommonProxy.rune, 1, ItemsCommonProxy.rune.META_BLANK)), 1);
        ArrayList<ItemStack> componentRecipeList = new ArrayList<ItemStack>();
        int count = 0;
        ArrayList<ISpellPart> allRecipeItems = new ArrayList<ISpellPart>();
        for (ArrayList<ISpellPart> shapeGroup : shapeGroups) {
            if (shapeGroup == null || shapeGroup.size() == 0)
                continue;
            allRecipeItems.addAll(shapeGroup);
        }
        allRecipeItems.addAll(currentRecipe);
        for (ISpellPart part : allRecipeItems) {
            if (part == null) {
                LogHelper.error("Unable to write recipe to book.  Recipe part is null!");
                return bookstack;
            }
            Object[] recipeItems = part.getRecipeItems();
            SpellRecipeItemsEvent event = new SpellRecipeItemsEvent(SkillManager.instance.getSkillName(part), SkillManager.instance.getShiftedPartID(part), recipeItems);
            MinecraftForge.EVENT_BUS.post(event);
            recipeItems = event.recipeItems;
            if (recipeItems == null) {
                LogHelper.error("Unable to write recipe to book.  Recipe items are null for part %d!", part.getID());
                return bookstack;
            }
            for (int i = 0; i < recipeItems.length; ++i) {
                Object o = recipeItems[i];
                String materialkey = "";
                int qty = 1;
                ItemStack recipeStack = null;
                if (o instanceof ItemStack) {
                    materialkey = ((ItemStack) o).getDisplayName();
                    recipeStack = (ItemStack) o;
                } else if (o instanceof Item) {
                    recipeStack = new ItemStack((Item) o);
                    materialkey = ((Item) o).getItemStackDisplayName(new ItemStack((Item) o));
                } else if (o instanceof Block) {
                    recipeStack = new ItemStack((Block) o);
                    materialkey = ((Block) o).getLocalizedName();
                } else if (o instanceof String) {
                    if (((String) o).startsWith("P:")) {
                        String s = ((String) o).substring(2);
                        int pfx = SpellRecipeManager.parsePotionMeta(s);
                        recipeStack = new ItemStack(Items.potionitem, 1, pfx);
                        materialkey = recipeStack.getDisplayName();
                    } else if (((String) o).startsWith("E:")) {
                        int[] ids = SpellRecipeManager.ParseEssenceIDs((String) o);
                        materialkey = "Essence (";
                        for (int powerID : ids) {
                            PowerTypes type = PowerTypes.getByID(powerID);
                            materialkey += type.name() + "/";
                        }
                        if (materialkey.equals("Essence (")) {
                            ++i;
                            continue;
                        }
                        o = recipeItems[++i];
                        if (materialkey.startsWith("Essence (")) {
                            materialkey = materialkey.substring(0, materialkey.lastIndexOf("/")) + ")";
                            qty = (Integer) o;
                            int flag = 0;
                            for (int f : ids) {
                                flag |= f;
                            }
                            recipeStack = new ItemStack(ItemsCommonProxy.essence, qty, ItemsCommonProxy.essence.META_MAX + flag);
                        }
                    } else {
                        ArrayList<ItemStack> ores = OreDictionary.getOres((String) o);
                        recipeStack = ores.size() > 0 ? ores.get(1) : null;
                        materialkey = (String) o;
                    }
                }
                if (materialsList.containsKey(materialkey)) {
                    int old = materialsList.get(materialkey);
                    old += qty;
                    materialsList.put(materialkey, old);
                } else {
                    materialsList.put(materialkey, qty);
                }
                if (recipeStack != null)
                    componentRecipeList.add(recipeStack);
            }
        }
        materialsList.put(ItemsCommonProxy.spellParchment.getItemStackDisplayName(new ItemStack(ItemsCommonProxy.spellParchment)), 1);
        StringBuilder sb = new StringBuilder();
        int sgCount = 0;
        int[][] shapeGroupCombos = new int[shapeGroups.size()][];
        for (ArrayList<ISpellPart> shapeGroup : shapeGroups) {
            sb.append("Shape Group " + ++sgCount + "\n\n");
            Iterator<ISpellPart> it = shapeGroup.iterator();
            shapeGroupCombos[sgCount - 1] = SpellPartListToStringBuilder(it, sb, " -");
            sb.append("\n");
        }
        sb.append("Combination:\n\n");
        Iterator<ISpellPart> it = currentRecipe.iterator();
        ArrayList<Integer> outputCombo = new ArrayList<Integer>();
        int[] outputData = SpellPartListToStringBuilder(it, sb, null);
        ArrayList<NBTTagString> pages = Story.splitStoryPartIntoPages(sb.toString());
        sb = new StringBuilder();
        sb.append("\n\nMaterials List:\n\n");
        for (String s : materialsList.keySet()) {
            sb.append(materialsList.get(s) + " x " + s + "\n");
        }
        pages.addAll(Story.splitStoryPartIntoPages(sb.toString()));
        sb = new StringBuilder();
        sb.append("Affinity Breakdown:\n\n");
        it = currentRecipe.iterator();
        HashMap<Affinity, Integer> affinityData = new HashMap<Affinity, Integer>();
        int cpCount = 0;
        while (it.hasNext()) {
            ISpellPart part = it.next();
            if (part instanceof ISpellComponent) {
                EnumSet<Affinity> aff = ((ISpellComponent) part).getAffinity();
                for (Affinity affinity : aff) {
                    int qty = 1;
                    if (affinityData.containsKey(affinity)) {
                        qty = 1 + affinityData.get(affinity);
                    }
                    affinityData.put(affinity, qty);
                }
                cpCount++;
            }
        }
        ValueComparator vc = new ValueComparator(affinityData);
        TreeMap<Affinity, Integer> sorted = new TreeMap<Affinity, Integer>(vc);
        sorted.putAll(affinityData);
        for (Affinity aff : sorted.keySet()) {
            float pct = (float) sorted.get(aff) / (float) cpCount * 100f;
            sb.append(String.format("%s: %.2f%%", aff.toString(), pct));
            sb.append("\n");
        }
        pages.addAll(Story.splitStoryPartIntoPages(sb.toString()));
        Story.WritePartToNBT(bookstack.stackTagCompound, pages);
        bookstack = Story.finalizeStory(bookstack, title, player.getCommandSenderName());
        int[] recipeData = new int[componentRecipeList.size() * 3];
        int idx = 0;
        for (ItemStack stack : componentRecipeList) {
            recipeData[idx++] = Item.getIdFromItem(stack.getItem());
            recipeData[idx++] = stack.stackSize;
            recipeData[idx++] = stack.getItemDamage();
        }
        bookstack.stackTagCompound.setIntArray("spell_combo", recipeData);
        bookstack.stackTagCompound.setIntArray("output_combo", outputData);
        bookstack.stackTagCompound.setInteger("numShapeGroups", shapeGroupCombos.length);
        int index = 0;
        for (int[] sgArray : shapeGroupCombos) {
            bookstack.stackTagCompound.setIntArray("shapeGroupCombo_" + index++, sgArray);
        }
        bookstack.stackTagCompound.setString("spell_mod_version", AMCore.instance.getVersion());
        if (currentSpellName.equals(""))
            currentSpellName = "Spell Recipe";
        bookstack.setStackDisplayName(currentSpellName);
        this.currentRecipe.clear();
        for (ArrayList<ISpellPart> list : shapeGroups) list.clear();
        currentSpellName = "";
        bookstack.stackTagCompound.setBoolean("spellFinalized", true);
        worldObj.playSound(xCoord, yCoord, zCoord, "arsmagica2:misc.inscriptiontable.takebook", 1.0f, 1.0f, true);
        worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
    }
    return bookstack;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) Item(net.minecraft.item.Item) PowerTypes(am2.api.power.PowerTypes) NBTTagString(net.minecraft.nbt.NBTTagString) SpellRecipeItemsEvent(am2.api.events.SpellRecipeItemsEvent) Block(net.minecraft.block.Block) Affinity(am2.api.spell.enums.Affinity) ItemStack(net.minecraft.item.ItemStack)

Example 24 with Affinity

use of am2.api.spell.enums.Affinity 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 25 with Affinity

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

the class ShiftAffinityCommand method processCommand.

@Override
public void processCommand(ICommandSender var1, String[] var2) {
    if (var2.length != 3 && var2.length != 2) {
        throw new WrongUsageException(this.getCommandUsage(var1), new Object[0]);
    }
    EntityPlayer player = null;
    String affinity = "";
    float amt = 0f;
    if (var2.length == 3) {
        player = getPlayer(var1, var2[0]);
        affinity = var2[1].toUpperCase();
        amt = tryParseFloat(var2[2]);
    } else {
        player = getCommandSenderAsPlayer(var1);
        affinity = var2[0].toUpperCase();
        amt = tryParseFloat(var2[1]);
    }
    if (player == null)
        return;
    Affinity enumAffinity;
    try {
        enumAffinity = Affinity.valueOf(affinity);
    } catch (Throwable t) {
        player.addChatMessage(new ChatComponentText("Unknown affinity name specified."));
        return;
    }
    float affinityDepth = AffinityData.For(player).getAffinityDepth(enumAffinity) * AffinityData.MAX_DEPTH;
    affinityDepth += amt;
    AffinityData.For(player).setAffinityAndDepth(enumAffinity, affinityDepth);
    AffinityData.For(player).forceSync();
    func_152373_a(var1, this, "Shifting " + player.getCommandSenderName() + "'s " + affinity + " affinity level by " + amt, new Object[0]);
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Affinity(am2.api.spell.enums.Affinity) ChatComponentText(net.minecraft.util.ChatComponentText)

Aggregations

Affinity (am2.api.spell.enums.Affinity)27 AffinityData (am2.playerextensions.AffinityData)6 ItemStack (net.minecraft.item.ItemStack)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)4 TileEntity (net.minecraft.tileentity.TileEntity)4 ArrayList (java.util.ArrayList)3 AMVector2 (am2.api.math.AMVector2)2 AMVector3 (am2.api.math.AMVector3)2 ISpellModifier (am2.api.spell.component.interfaces.ISpellModifier)2 AMParticle (am2.particles.AMParticle)2 Colour (am2.spell.modifiers.Colour)2 HashMap (java.util.HashMap)2 Block (net.minecraft.block.Block)2 WrongUsageException (net.minecraft.command.WrongUsageException)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 ChatComponentText (net.minecraft.util.ChatComponentText)2 AffinityChangingEvent (am2.api.events.AffinityChangingEvent)1 ManaCostEvent (am2.api.events.ManaCostEvent)1 SpellRecipeItemsEvent (am2.api.events.SpellRecipeItemsEvent)1