Fix level displays

This commit is contained in:
Sam 2017-07-25 20:13:50 +01:00
parent 4f221cabba
commit ddf0666ba6
3 changed files with 85 additions and 65 deletions

View File

@ -0,0 +1,48 @@
package nautilus.game.arcade.game.games.moba.progression;
public class MobaLevelData
{
private final int _exp;
private final int _level;
private final int _thisLevel;
private final int _nextLevel;
public MobaLevelData(long exp)
{
_exp = (int) exp;
_level = MobaProgression.getLevel(exp);
_thisLevel = MobaProgression.getExpFor(_level);
_nextLevel = MobaProgression.getExpFor(_level + 1);
}
public int getExp()
{
return _exp;
}
public int getLevel()
{
return _level;
}
public int getExpThisLevel()
{
return _thisLevel;
}
public int getExpJustThisLevel()
{
return _nextLevel - _thisLevel;
}
public int getExpReminder()
{
return _nextLevel - _exp;
}
public double getPercentageComplete()
{
return (double) (_exp - _thisLevel) / (double) (getExpJustThisLevel());
}
}

View File

@ -40,20 +40,18 @@ import java.util.concurrent.atomic.AtomicInteger;
public class MobaProgression implements Listener
{
private static final int[] EXP_LEVELS;
private static final int EXP_PER_LEVEL = 500;
private static final int EXP_PER_LEVEL = 1000;
private static final int EXP_FACTOR = 3;
public static final DecimalFormat FORMAT = new DecimalFormat("0.0");
static
public static int getExpFor(int level)
{
EXP_LEVELS = new int[100];
int expRequired = EXP_PER_LEVEL;
return EXP_PER_LEVEL * (level - 1);
}
for (int level = 0; level < 100; level++)
{
EXP_LEVELS[level] = expRequired += EXP_PER_LEVEL;
}
public static int getLevel(long exp)
{
return (int) Math.floor(exp / EXP_PER_LEVEL);
}
private final Moba _host;
@ -84,7 +82,7 @@ public class MobaProgression implements Listener
public void Execute(Player caller, String[] args)
{
MobaRole role = MobaRole.valueOf(args[0].toUpperCase());
int exp = getExperience(Integer.parseInt(args[1])) - 1;
int exp = getExpFor(Integer.parseInt(args[1])) - 1;
_host.getArcadeManager().GetStatsManager().setStat(caller, _host.GetName() + "." + role.getName() + ".ExpEarned", exp);
caller.sendMessage(F.main("Debug", "Set your " + role.getChatColor() + role.getName() + C.cGray + " level to " + F.elem(getLevel(exp)) + "."));
}
@ -176,32 +174,12 @@ public class MobaProgression implements Listener
_host.GetPlayers(true).forEach(this::rewardPlayer);
}
public int getExperience(int level)
{
if (level > EXP_LEVELS.length)
{
return Integer.MAX_VALUE;
}
else if (level < 1)
{
return 0;
}
return EXP_LEVELS[level - 1];
}
public long getExperience(Player player, MobaRole role)
{
String stat = _host.GetName() + "." + role.getName() + ".ExpEarned";
return _host.getArcadeManager().GetStatsManager().Get(player).getStat(stat);
}
public long getExperienceCurrentLevel(Player player, MobaRole role)
{
int level = getLevel(player, role);
return getExperience(level) - getExperience(level - 1);
}
public int getLevel(Player player, HeroKit kit)
{
return getLevel(player, kit.getRole());
@ -212,28 +190,25 @@ public class MobaProgression implements Listener
return getLevel(getExperience(player, role));
}
private int getLevel(long exp)
{
int i = 0;
for (int expRequired : EXP_LEVELS)
{
i++;
if (expRequired > exp)
{
return i;
}
}
return 1;
}
private void rewardPlayer(Player player)
{
MobaPlayer mobaPlayer = _host.getMobaData(player);
if (mobaPlayer == null)
{
return;
}
MobaRole role = mobaPlayer.getRole();
String stat = _host.GetName() + "." + role.getName() + ".ExpEarned";
long currentExp = _host.getArcadeManager().GetStatsManager().Get(player).getStat(stat);
// EXP before earning
long currentExp = getExperience(player, role);
// Level before earning
int currentLevel = getLevel(currentExp);
player.sendMessage("currentExp = " + currentExp);
player.sendMessage("currentLevel = " + currentLevel);
AtomicInteger earnedExp = new AtomicInteger();
for (GemData data : _host.GetGems(player).values())
@ -242,16 +217,16 @@ public class MobaProgression implements Listener
}
earnedExp.getAndAdd(earnedExp.get() * EXP_FACTOR);
MobaLevelData levelData = new MobaLevelData(currentExp + earnedExp.get());
int level = getLevel(currentExp);
int newLevel = getLevel(currentExp + earnedExp.get());
long expForThisLevel = getExperienceCurrentLevel(player, role);
AtomicBoolean levelUp = new AtomicBoolean();
player.sendMessage("exp = " + levelData.getExp());
player.sendMessage("level = " + levelData.getLevel());
player.sendMessage("thisLevel = " + levelData.getExpThisLevel());
player.sendMessage("justThisLevel = " + levelData.getExpJustThisLevel());
player.sendMessage("reminder = " + levelData.getExpReminder());
player.sendMessage("percentage = " + levelData.getPercentageComplete());
if (newLevel > level)
{
levelUp.set(true);
}
AtomicBoolean levelUp = new AtomicBoolean(levelData.getLevel() > currentLevel);
_host.getArcadeManager().GetStatsManager().incrementStat(player, stat, earnedExp.get());
@ -262,8 +237,8 @@ public class MobaProgression implements Listener
player.sendMessage(" " + role.getChatColor() + C.Bold + role.getName() + " Progression" + (levelUp.get() ? C.cGreenB + " LEVEL UP" : ""));
player.sendMessage("");
player.sendMessage(MobaUtil.getProgressBar(currentExp, currentExp + earnedExp.get(), expForThisLevel, 100) + " " + C.cGray + "+" + C.cGreen + earnedExp + C.cGray + "/" + C.cAqua + expForThisLevel);
player.sendMessage(C.cGreen + FORMAT.format((currentExp + earnedExp.get()) / (double) expForThisLevel * 100D) + C.cWhite + "% complete for Level " + level);
player.sendMessage(MobaUtil.getProgressBar(currentExp, levelData.getExp(), levelData.getExpThisLevel(), 100) + " " + C.cGray + "+" + C.cGreen + earnedExp + C.cGray + "/" + C.cAqua + levelData.getExpJustThisLevel());
player.sendMessage(C.cGreen + FORMAT.format((levelData.getPercentageComplete() * 100D) + C.cWhite + "% complete for Level " + currentLevel));
player.sendMessage("");
player.sendMessage(ArcadeFormat.Line);
@ -272,7 +247,7 @@ public class MobaProgression implements Listener
{
for (HeroKit kit : _host.getKits())
{
if (!kit.getRole().equals(role) || kit.getUnlockLevel() != newLevel)
if (!kit.getRole().equals(role) || kit.getUnlockLevel() != levelData.getLevel())
{
continue;
}

View File

@ -14,6 +14,7 @@ import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.games.moba.Moba;
import nautilus.game.arcade.game.games.moba.MobaRole;
import nautilus.game.arcade.game.games.moba.kit.HeroKit;
import nautilus.game.arcade.game.games.moba.progression.MobaLevelData;
import nautilus.game.arcade.game.games.moba.progression.MobaProgression;
import nautilus.game.arcade.game.games.moba.progression.MobaUnlockAnimation;
import org.bukkit.Material;
@ -49,11 +50,7 @@ public class MobaRolePage extends ShopPageBase<ArcadeManager, MobaRoleShop>
@Override
protected void buildPage()
{
int level = _host.getProgression().getLevel(_player, _role);
long currentExp = _host.getProgression().getExperience(_player, _role);
long thisLevel = _host.getProgression().getExperienceCurrentLevel(_player, _role);
long toNextLevel = _host.getProgression().getExperience(level) - currentExp;
long levelExp = _host.getProgression().getExperience(level);
MobaLevelData levelData = new MobaLevelData(_host.getProgression().getExperience(_player, _role));
addButtonNoAction(13, new ItemBuilder(_role.getSkin().getSkull())
.setTitle(_role.getChatColor() + _role.getName())
@ -62,8 +59,8 @@ public class MobaRolePage extends ShopPageBase<ArcadeManager, MobaRoleShop>
"Every " + F.elem(10) + " levels you unlock a new",
"hero within the " + F.name(_role.getName()) + " category.",
"",
"Your Level: " + C.cGreen + level,
"Next Level: " + C.cGreen + toNextLevel + C.cGray + "/" + C.cGreen + thisLevel + C.cGray + " (" + C.cAqua + MobaProgression.FORMAT.format(100 - ((double) currentExp / (double) levelExp) * 100D) + C.cGray + "%)"
"Your Level: " + C.cGreen + levelData.getLevel(),
"Next Level: " + C.cGreen + levelData.getExpReminder() + C.cGray + "/" + C.cGreen + levelData.getExpJustThisLevel() + C.cGray + " (" + C.cAqua + MobaProgression.FORMAT.format(levelData.getPercentageComplete() * 100D) + C.cGray + "%)"
)
.build());