Search in sources :

Example 1 with SpellRequirements

use of am2.spell.SpellUtils.SpellRequirements in project ArsMagica2 by Mithion.

the class SpellUtils method modifySpellRequirementsByAffinity.

public SpellRequirements modifySpellRequirementsByAffinity(ItemStack stack, EntityLivingBase caster, SpellRequirements reqs) {
    HashMap<Affinity, Float> affinities = this.AffinityFor(stack);
    AffinityData affData = AffinityData.For(caster);
    if (affData == null)
        return reqs;
    float manaCost = reqs.manaCost;
    for (Affinity aff : affinities.keySet()) {
        float depth = affData.getAffinityDepth(aff);
        // calculate the modifier based on the player's affinity depth as well as how much of the spell is that affinity
        // how much does this affinity affect the overall mana cost?
        float effectiveness = affinities.get(aff);
        // how much will the player's affinity reduce the mana cost? (max 50%)
        float multiplier = 0.5f * depth;
        float manaMod = manaCost * effectiveness;
        manaCost -= manaMod * multiplier;
    }
    return new SpellRequirements(manaCost, reqs.burnout, reqs.reagents);
}
Also used : AffinityData(am2.playerextensions.AffinityData) Affinity(am2.api.spell.enums.Affinity)

Example 2 with SpellRequirements

use of am2.spell.SpellUtils.SpellRequirements in project ArsMagica2 by Mithion.

the class SpellBase method addInformation.

@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4) {
    if (!stack.hasTagCompound())
        return;
    ItemStack legacySpell = SpellUtils.instance.constructSpellStack(stack);
    SpellRequirements reqs = SpellUtils.instance.getSpellRequirements(legacySpell, player);
    float manaCost = reqs.manaCost;
    float burnout = reqs.burnout;
    ArrayList<ItemStack> reagents = reqs.reagents;
    ManaCostEvent mce = new ManaCostEvent(legacySpell, player, manaCost, 0);
    MinecraftForge.EVENT_BUS.post(mce);
    manaCost = mce.manaCost;
    list.add(String.format("\2477Mana Cost: %.2f", manaCost));
    if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
        HashMap<Affinity, Float> affinityData = SpellUtils.instance.AffinityFor(legacySpell);
        for (Affinity aff : affinityData.keySet()) {
            list.add(String.format("%s (%.2f%%)", aff.toString(), affinityData.get(aff) * 100));
        }
        if (stack.stackTagCompound.hasKey("Lore")) {
            NBTTagList nbttaglist1 = stack.stackTagCompound.getTagList("Lore", Constants.NBT.TAG_COMPOUND);
            if (nbttaglist1.tagCount() > 0) {
                for (int j = 0; j < nbttaglist1.tagCount(); ++j) {
                    list.add(EnumChatFormatting.DARK_PURPLE + "" + EnumChatFormatting.ITALIC + nbttaglist1.getStringTagAt(j));
                }
            }
        }
    } else {
        list.add(StatCollector.translateToLocal("am2.tooltip.shiftForAffinity"));
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) SpellRequirements(am2.spell.SpellUtils.SpellRequirements) ManaCostEvent(am2.api.events.ManaCostEvent) Affinity(am2.api.spell.enums.Affinity) ItemStack(net.minecraft.item.ItemStack) SideOnly(cpw.mods.fml.relauncher.SideOnly)

Example 3 with SpellRequirements

use of am2.spell.SpellUtils.SpellRequirements in project ArsMagica2 by Mithion.

the class SpellHelper method preSpellCast.

private SpellCastingEvent.Pre preSpellCast(ItemStack stack, EntityLivingBase caster, boolean isChanneled) {
    SpellRequirements reqs = SpellUtils.instance.getSpellRequirements(stack, caster);
    float manaCost = reqs.manaCost;
    float burnout = reqs.burnout;
    ArrayList<ItemStack> reagents = reqs.reagents;
    ManaCostEvent mce = new ManaCostEvent(stack, caster, manaCost, burnout);
    MinecraftForge.EVENT_BUS.post(mce);
    manaCost = mce.manaCost;
    burnout = mce.burnout;
    SpellCastingEvent.Pre event = new SpellCastingEvent().new Pre(stack, (ItemSpellBase) stack.getItem(), caster, manaCost, burnout, isChanneled);
    if (MinecraftForge.EVENT_BUS.post(event)) {
        event.castResult = SpellCastResult.EFFECT_FAILED;
        return event;
    }
    event.castResult = SpellCastResult.SUCCESS;
    if (!SpellUtils.instance.casterHasAllReagents(caster, reagents))
        event.castResult = SpellCastResult.REAGENTS_MISSING;
    if (!SpellUtils.instance.casterHasMana(caster, manaCost))
        event.castResult = SpellCastResult.NOT_ENOUGH_MANA;
    return event;
}
Also used : SpellRequirements(am2.spell.SpellUtils.SpellRequirements) ManaCostEvent(am2.api.events.ManaCostEvent) ItemStack(net.minecraft.item.ItemStack) SpellCastingEvent(am2.api.events.SpellCastingEvent)

Aggregations

ManaCostEvent (am2.api.events.ManaCostEvent)2 Affinity (am2.api.spell.enums.Affinity)2 SpellRequirements (am2.spell.SpellUtils.SpellRequirements)2 ItemStack (net.minecraft.item.ItemStack)2 SpellCastingEvent (am2.api.events.SpellCastingEvent)1 AffinityData (am2.playerextensions.AffinityData)1 SideOnly (cpw.mods.fml.relauncher.SideOnly)1 NBTTagList (net.minecraft.nbt.NBTTagList)1