Skip to content

Commit

Permalink
Tweaks to the Level Curve, again.
Browse files Browse the repository at this point in the history
Changed mana for XP from linear to logarithmic.
Fixed burnout and XP calculations
  • Loading branch information
EdwinMindcraft committed Mar 20, 2018
1 parent 706fdca commit 50f9442
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 34 deletions.
4 changes: 4 additions & 0 deletions src/main/java/am2/common/extensions/EntityExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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){
Expand Down
41 changes: 21 additions & 20 deletions src/main/java/am2/common/spell/SpellCaster.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<AbstractSpellPart> 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;
Expand Down Expand Up @@ -251,7 +252,7 @@ public void gatherBaseManaCosts() {
for (List<AbstractSpellPart> 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();
Expand Down
33 changes: 19 additions & 14 deletions src/main/java/am2/common/utils/AffinityShiftUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<AbstractSpellPart> 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();
Expand All @@ -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;
}
}

0 comments on commit 50f9442

Please sign in to comment.