Search in sources :

Example 6 with ISpellComponent

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

the class SpellUtils method doAffinityShift.

public void doAffinityShift(EntityLivingBase caster, ISpellComponent component, ISpellShape governingShape) {
    if (!(caster instanceof EntityPlayer))
        return;
    AffinityData aff = AffinityData.For(caster);
    EnumSet<Affinity> affList = component.getAffinity();
    for (Affinity affinity : affList) {
        float shift = component.getAffinityShift(affinity) * aff.getDiminishingReturnsFactor() * 5;
        float xp = 0.05f * aff.getDiminishingReturnsFactor();
        if (governingShape.isChanneled()) {
            shift /= 4;
            xp /= 4;
        }
        if (caster instanceof EntityPlayer) {
            if (SkillData.For((EntityPlayer) caster).isEntryKnown(SkillTreeManager.instance.getSkillTreeEntry(SkillManager.instance.getSkill("AffinityGains")))) {
                shift *= 1.1f;
                xp *= 0.9f;
            }
            ItemStack chestArmor = ((EntityPlayer) caster).getCurrentArmor(2);
            if (chestArmor != null && ArmorHelper.isInfusionPreset(chestArmor, GenericImbuement.magicXP))
                xp *= 1.25f;
        }
        if (shift > 0) {
            AffinityChangingEvent event = new AffinityChangingEvent((EntityPlayer) caster, affinity, shift);
            MinecraftForge.EVENT_BUS.post(event);
            if (!event.isCanceled())
                aff.incrementAffinity(affinity, event.amount);
        }
        if (xp > 0) {
            xp *= caster.getAttributeMap().getAttributeInstance(ArsMagicaApi.xpGainModifier).getAttributeValue();
            ExtendedProperties.For(caster).addMagicXP(xp);
        }
    }
    aff.addDiminishingReturns(governingShape.isChanneled());
}
Also used : AffinityChangingEvent(am2.api.events.AffinityChangingEvent) AffinityData(am2.playerextensions.AffinityData) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Affinity(am2.api.spell.enums.Affinity) ItemStack(net.minecraft.item.ItemStack)

Example 7 with ISpellComponent

use of am2.api.spell.component.interfaces.ISpellComponent 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)

Example 8 with ISpellComponent

use of am2.api.spell.component.interfaces.ISpellComponent 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 9 with ISpellComponent

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

the class GuiSkillTrees method drawScreen.

@Override
public void drawScreen(int par1, int par2, float par3) {
    SkillData sk = SkillData.For(Minecraft.getMinecraft().thePlayer);
    int l = (width - xSize) / 2;
    int i1 = (height - ySize) / 2;
    if (AMCore.config.getSkillTreeSecondaryTierCap() < SkillTreeManager.instance.getHighestTier() && (sk.getPrimaryTree() == null || sk.getPrimaryTree() == SkillTrees.None) && sk.getSpellPoints(SkillPointTypes.BLUE) > 0) {
        String s = StatCollector.translateToLocal("am2.gui.lockWarning");
        fontRendererObj.drawSplitString(s, l - 120, i1 + 20, 110, 0xbf6325);
    }
    if (isDragging) {
        int dx = lastMouseX - par1;
        int dy = lastMouseY - par2;
        this.offsetX += dx;
        this.offsetY += dy;
        if (this.offsetX < 0)
            this.offsetX = 0;
        if (this.offsetX > 180)
            this.offsetX = 180;
        if (this.offsetY < 0)
            this.offsetY = 0;
        if (this.offsetY > 180)
            this.offsetY = 180;
    }
    lastMouseX = par1;
    lastMouseY = par2;
    GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
    if (activeTree == SkillTrees.Offense)
        Minecraft.getMinecraft().renderEngine.bindTexture(rl_offense);
    else if (activeTree == SkillTrees.Defense)
        Minecraft.getMinecraft().renderEngine.bindTexture(rl_defense);
    else if (activeTree == SkillTrees.Utility)
        Minecraft.getMinecraft().renderEngine.bindTexture(rl_utility);
    else if (activeTree == SkillTrees.Talents || activeTree == SkillTrees.Affinity)
        Minecraft.getMinecraft().renderEngine.bindTexture(rl_talents);
    else
        return;
    drawTexturedModalRect_Classic(l + 5, i1 + GuiButtonSkillTreeTab.buttonHeight + 5, offsetX, offsetY, 200, 200, 75, 75);
    if (activeTree == SkillTrees.Affinity) {
        drawAffinity();
    } else {
        drawSkillTree();
    }
    GL11.glColor3f(1.0f, 1.0f, 1.0f);
    Minecraft.getMinecraft().renderEngine.bindTexture(rl_background);
    drawTexturedModalRect(l, i1 + GuiButtonSkillTreeTab.buttonHeight, 0, 0, 210, 210);
    drawTexturedModalRect(l + xSize - 29, i1, 210, 0, 37, 37);
    String quantity = String.format("%d", sk.getSpellPoints(SkillPointTypes.BLUE));
    Minecraft.getMinecraft().fontRenderer.drawString(quantity, l + xSize - 24 - (Minecraft.getMinecraft().fontRenderer.getStringWidth(quantity) / 2), i1 + 5, 0x0000FF);
    quantity = String.format("%d", sk.getSpellPoints(SkillPointTypes.GREEN));
    Minecraft.getMinecraft().fontRenderer.drawString(quantity, l + xSize - 12 - (Minecraft.getMinecraft().fontRenderer.getStringWidth(quantity) / 2), i1 + 5, 0x00FF00);
    quantity = String.format("%d", sk.getSpellPoints(SkillPointTypes.RED));
    Minecraft.getMinecraft().fontRenderer.drawString(quantity, l + xSize - 18 - (Minecraft.getMinecraft().fontRenderer.getStringWidth(quantity) / 2), i1 + 15, 0xFF0000);
    super.drawScreen(par1, par2, par3);
    if (hoveredItem != null) {
        ArrayList<String> text = new ArrayList<String>();
        FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
        String s = SkillManager.instance.getDisplayName(hoveredItem.registeredItem);
        LearnStates state = sk.getLearnState(hoveredItem, Minecraft.getMinecraft().thePlayer);
        if (state == LearnStates.LEARNED)
            s += " (" + StatCollector.translateToLocal("am2.gui.known") + ")";
        else if (state == LearnStates.CAN_LEARN)
            s += " (" + StatCollector.translateToLocal("am2.gui.notLearned") + ")";
        else if (state == LearnStates.DISABLED)
            s = StatCollector.translateToLocal("am2.gui.cfgDisabled");
        //else fr = Minecraft.getMinecraft().standardGalacticFontRenderer;
        text.add(s);
        SkillPointTypes type = SkillTreeManager.instance.getSkillPointTypeForPart(hoveredItem.registeredItem);
        if (hoveredItem.registeredItem instanceof ISpellComponent) {
            EnumSet<Affinity> aff = ((ISpellComponent) hoveredItem.registeredItem).getAffinity();
            int affX = lastMouseX + 14;
            int affY = lastMouseY - 34;
            drawGradientAround(affX - 2, affY - 2, 18 * aff.size() + 2, 18);
            for (Affinity a : aff) {
                if (a == Affinity.NONE)
                    continue;
                DrawIconAtXY(a.representItem.getIconFromDamage(a.representMeta), "item", affX, affY, 16, 16, false);
                affX += 18;
            }
        }
        if (!AMCore.config.colourblindMode()) {
            drawHoveringText(text, lastMouseX, lastMouseY, fr, state == LearnStates.LEARNED ? 0xFFFFFF : type == SkillPointTypes.SILVER ? 0x888888 : type == SkillPointTypes.BLUE ? 0x4444FF : type == SkillPointTypes.GREEN ? 0x44FF44 : 0xFF4444);
        } else {
            text.add(StatCollector.translateToLocal("am2.gui." + type.toString().toLowerCase() + "Point"));
            drawHoveringText(text, lastMouseX, lastMouseY, fr, 0xFFFFFF);
        }
    }
    if (hoveredAffinity != null) {
        List list = AffinityData.For(Minecraft.getMinecraft().thePlayer).getColoredAffinityEffects(hoveredAffinity);
        //list.add(0, "\247f" + hoveredAffinity.name());
        drawHoveringText(list, lastMouseX, lastMouseY, fontRendererObj, 0xFFFFFF);
    }
}
Also used : SkillData(am2.playerextensions.SkillData) LearnStates(am2.api.spell.enums.LearnStates) ISpellComponent(am2.api.spell.component.interfaces.ISpellComponent) ArrayList(java.util.ArrayList) Affinity(am2.api.spell.enums.Affinity) ArrayList(java.util.ArrayList) List(java.util.List) FontRenderer(net.minecraft.client.gui.FontRenderer) SkillPointTypes(am2.api.spell.enums.SkillPointTypes)

Example 10 with ISpellComponent

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

the class SpellUtils method AffinityFor.

public HashMap<Affinity, Float> AffinityFor(ItemStack stack) {
    HashMap<Affinity, Integer> affinityFrequency = new HashMap<Affinity, Integer>();
    HashMap<Affinity, Float> affinities = new HashMap<Affinity, Float>();
    float totalAffinityEntries = 0;
    if (stack.stackTagCompound.hasKey(ForcedAffinity)) {
        int aff = stack.stackTagCompound.getInteger(ForcedAffinity);
        affinities.put(Affinity.values()[aff], 100f);
        return affinities;
    }
    for (int i = 0; i < numStages(stack); ++i) {
        for (ISpellComponent comp : getComponentsForStage(stack, i)) {
            if (comp == SkillManager.instance.missingComponent)
                continue;
            EnumSet<Affinity> affList = comp.getAffinity();
            for (Affinity affinity : affList) {
                totalAffinityEntries++;
                if (!affinityFrequency.containsKey(affinity)) {
                    affinityFrequency.put(affinity, 1);
                } else {
                    int old = affinityFrequency.get(affinity);
                    affinityFrequency.put(affinity, old + 1);
                }
            }
        }
    }
    for (Affinity key : affinityFrequency.keySet()) {
        int count = affinityFrequency.get(key);
        float percent = (totalAffinityEntries > 0) ? count / totalAffinityEntries : 0;
        affinities.put(key, percent);
    }
    return affinities;
}
Also used : HashMap(java.util.HashMap) Affinity(am2.api.spell.enums.Affinity)

Aggregations

ISpellComponent (am2.api.spell.component.interfaces.ISpellComponent)7 ISpellShape (am2.api.spell.component.interfaces.ISpellShape)5 Affinity (am2.api.spell.enums.Affinity)5 ISpellModifier (am2.api.spell.component.interfaces.ISpellModifier)4 ItemStack (net.minecraft.item.ItemStack)4 AMDataWriter (am2.network.AMDataWriter)2 Summon (am2.spell.components.Summon)2 Colour (am2.spell.modifiers.Colour)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 AffinityChangingEvent (am2.api.events.AffinityChangingEvent)1 SkillLearnedEvent (am2.api.events.SkillLearnedEvent)1 SpellRecipeItemsEvent (am2.api.events.SpellRecipeItemsEvent)1 PowerTypes (am2.api.power.PowerTypes)1 ISkillTreeEntry (am2.api.spell.component.interfaces.ISkillTreeEntry)1 ISpellPart (am2.api.spell.component.interfaces.ISpellPart)1 LearnStates (am2.api.spell.enums.LearnStates)1 SkillPointTypes (am2.api.spell.enums.SkillPointTypes)1 TileEntitySpellSealedDoor (am2.blocks.tileentities.TileEntitySpellSealedDoor)1 AffinityData (am2.playerextensions.AffinityData)1