diff --git a/src/main/java/am2/common/extensions/EntityExtension.java b/src/main/java/am2/common/extensions/EntityExtension.java index c994dfac0..a3d8cc3f5 100644 --- a/src/main/java/am2/common/extensions/EntityExtension.java +++ b/src/main/java/am2/common/extensions/EntityExtension.java @@ -124,6 +124,8 @@ private void addSyncCode(int code) { @Override public boolean hasEnoughtMana(float cost) { + if (this.entity instanceof EntityPlayer && ((EntityPlayer) this.entity).capabilities.isCreativeMode) + return true; return !(this.getCurrentMana() + this.getBonusCurrentMana() < cost); } @@ -499,6 +501,8 @@ public void updateManaLink(EntityLivingBase entity){ @Override public void deductMana(float manaCost){ + if (entity instanceof EntityPlayer && ((EntityPlayer) entity).capabilities.isCreativeMode) + return; float leftOver = manaCost - this.getCurrentMana(); this.setCurrentMana(this.getCurrentMana() - manaCost); if (leftOver > 0){ diff --git a/src/main/java/am2/common/spell/SpellCaster.java b/src/main/java/am2/common/spell/SpellCaster.java index 14d0138d1..72208e1e4 100644 --- a/src/main/java/am2/common/spell/SpellCaster.java +++ b/src/main/java/am2/common/spell/SpellCaster.java @@ -1,11 +1,7 @@ package am2.common.spell; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; -import java.util.UUID; import am2.common.utils.AffinityShiftUtils; import com.google.common.collect.ImmutableList; @@ -117,24 +113,29 @@ public boolean cast(ItemStack source, World world, EntityLivingBase caster) { if (ext.hasEnoughtMana(manaCost)) { SpellCastResult result = data.execute(world, caster); ext.deductMana(manaCost); - float burnout = 0.0F; - float modMult = 1.0F; + if (result == SpellCastResult.SUCCESS) + ext.addMagicXP(AffinityShiftUtils.calculateXPGains(caster, data)); + float cost = 0F; + float multiplier = 1F; + float stageMultiplier = 1.0F; for (List parts : data.getStages()) { - float mult = 1; - float amount = 0; + float _cost = 0F; + float _multiplier = stageMultiplier; + parts.sort(Comparator.naturalOrder()); for (AbstractSpellPart part : parts) { - if (part instanceof SpellShape) - mult *= ((SpellShape) part).manaCostMultiplier(); - else if (part instanceof SpellModifier) - modMult *= ((SpellModifier) part).getManaCostMultiplier(); - else if (part instanceof SpellComponent) - amount += ((SpellComponent) part).burnout(caster); + if (part instanceof SpellModifier) { + multiplier *= ((SpellModifier) part).getManaCostMultiplier(); + } else if (part instanceof SpellShape) { + _multiplier *= ((SpellShape) part).manaCostMultiplier(); + stageMultiplier = 1.0F; + } else if (part instanceof SpellComponent) { + _cost += ((SpellComponent) part).burnout(caster); + } } - burnout += mult * amount; + + cost += _cost * _multiplier; } - ext.setCurrentBurnout(Math.min(ext.getMaxBurnout(), ext.getCurrentBurnout() + (burnout * modMult))); - if (result == SpellCastResult.SUCCESS) - ext.addMagicXP(AffinityShiftUtils.calculateXPGains(caster, data)); + ext.setCurrentBurnout(Math.min(ext.getMaxBurnout(), ext.getCurrentBurnout() + (cost * multiplier))); return result == SpellCastResult.SUCCESS; } return false; @@ -251,7 +252,7 @@ public void gatherBaseManaCosts() { for (List parts : this.spellCommon) { float _cost = 0F; float _multiplier = stageMultiplier; - parts.sort((t, o)-> t.compareTo(o)); + parts.sort(Comparator.naturalOrder()); for (AbstractSpellPart part : parts) { if (part instanceof SpellModifier) { multiplier *= ((SpellModifier) part).getManaCostMultiplier(); diff --git a/src/main/java/am2/common/utils/AffinityShiftUtils.java b/src/main/java/am2/common/utils/AffinityShiftUtils.java index 5f5e5593b..3f876d870 100644 --- a/src/main/java/am2/common/utils/AffinityShiftUtils.java +++ b/src/main/java/am2/common/utils/AffinityShiftUtils.java @@ -18,6 +18,7 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.common.MinecraftForge; +import java.util.Comparator; import java.util.List; import java.util.Set; @@ -71,13 +72,15 @@ public static ItemStack getEssenceForAffinity (Affinity affinity) { public static float calculateXPGains(EntityLivingBase caster, SpellData data) { IEntityExtension extension = EntityExtension.For(caster); - float modMultiplier = 0.1F; - float total = 0F; + float cost = 0F; + float multiplier = 0.1F; + float stageMultiplier = 1.0F; for (List parts : data.getStages()) { - float base = 0F; - float localMultiplier = 1.0F; + float _cost = 0F; + float _multiplier = stageMultiplier; + parts.sort(Comparator.naturalOrder()); for (AbstractSpellPart part : parts) { - float multiplier = 0.1F; + float __multiplier = 0.1F; Skill skill = ArsMagicaAPI.getSkillRegistry().getObject(part.getRegistryName()); if (skill != null) { SkillPoint point = skill.getPoint(); @@ -86,16 +89,18 @@ public static float calculateXPGains(EntityLivingBase caster, SpellData data) { } else multiplier *= 2F; } - if (part instanceof SpellComponent) - base += ((SpellComponent) part).manaCost() * multiplier; - else if (part instanceof SpellModifier) - modMultiplier *= (1+multiplier); - else if (part instanceof SpellShape) - localMultiplier *= 10 * multiplier * (((SpellShape) part).isChanneled() ? 0.1F : 1F); - + if (part instanceof SpellModifier) { + multiplier *= (1+__multiplier); + } else if (part instanceof SpellShape) { + _multiplier *= 10 * __multiplier * (((SpellShape) part).isChanneled() ? 0.1F : 1F); + stageMultiplier = 1.0F; + } else if (part instanceof SpellComponent) { + _cost += 10 * Math.log(((SpellComponent) part).manaCost()) * __multiplier; + } } - total += base * localMultiplier; + + cost += _cost * _multiplier; } - return total * modMultiplier * 0.01F; + return cost * multiplier * 0.05F; } }