forked from Upstream/mmocore
add max level mechanic to profession
This commit is contained in:
parent
7da69adb42
commit
5ffbb37acd
@ -113,7 +113,16 @@ public class PlayerProfessions {
|
||||
giveExperience(profession, value, null);
|
||||
}
|
||||
|
||||
public boolean hasReachedMaxLevel(Profession profession) {
|
||||
return profession.getMaxLevel() > 0 && getLevel(profession) >= profession.getMaxLevel();
|
||||
}
|
||||
|
||||
public void giveExperience(Profession profession, int value, Location loc) {
|
||||
if(hasReachedMaxLevel(profession)) {
|
||||
setExperience(profession, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
value = MMOCore.plugin.boosterManager.calculateExp(profession, value);
|
||||
exp.put(profession.getId(), exp.containsKey(profession.getId()) ? exp.get(profession.getId()) + value : value);
|
||||
|
||||
@ -124,8 +133,19 @@ public class PlayerProfessions {
|
||||
MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message(), playerData.getPlayer());
|
||||
|
||||
int needed, exp, level, oldLevel = getLevel(profession);
|
||||
|
||||
/*
|
||||
* loop for exp overload when leveling up,
|
||||
* will continue looping until exp is 0 or max level has been reached
|
||||
*/
|
||||
boolean check = false;
|
||||
while ((exp = this.exp.get(profession.getId())) >= (needed = profession.getExpCurve().getExperience((level = getLevel(profession)) + 1))) {
|
||||
if (hasReachedMaxLevel(profession)) {
|
||||
setExperience(profession, 0);
|
||||
check = true;
|
||||
break;
|
||||
}
|
||||
|
||||
this.exp.put(profession.getId(), exp - needed);
|
||||
this.level.put(profession.getId(), level + 1);
|
||||
check = true;
|
||||
@ -135,7 +155,7 @@ public class PlayerProfessions {
|
||||
if (check) {
|
||||
Bukkit.getPluginManager().callEvent(new PlayerLevelUpEvent(playerData, profession, oldLevel, level));
|
||||
new SmallParticleEffect(playerData.getPlayer(), Particle.SPELL_INSTANT);
|
||||
new ConfigMessage("profession-level-up").addPlaceholders("level", "" + (level + 1), "profession", profession.getName())
|
||||
new ConfigMessage("profession-level-up").addPlaceholders("level", "" + (level), "profession", profession.getName())
|
||||
.send(playerData.getPlayer());
|
||||
playerData.getPlayer().playSound(playerData.getPlayer().getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2);
|
||||
playerData.getStats().updateStats();
|
||||
|
@ -19,6 +19,7 @@ import net.mmogroup.mmolib.api.MMOLineConfig;
|
||||
public class Profession extends PostLoadObject {
|
||||
private final String id, name;
|
||||
private final ExpCurve expCurve;
|
||||
private final int maxLevel;
|
||||
|
||||
/*
|
||||
* experience given to the main player level whenever he levels up this
|
||||
@ -38,6 +39,10 @@ public class Profession extends PostLoadObject {
|
||||
: ExpCurve.DEFAULT;
|
||||
experience = new LinearValue(config.getConfigurationSection("experience"));
|
||||
|
||||
maxLevel = config.contains("max-level")
|
||||
? config.getInt("max-level")
|
||||
: -1;
|
||||
|
||||
if (config.contains("exp-sources"))
|
||||
for (String key : config.getStringList("exp-sources"))
|
||||
try {
|
||||
@ -119,6 +124,10 @@ public class Profession extends PostLoadObject {
|
||||
return expCurve;
|
||||
}
|
||||
|
||||
public int getMaxLevel() {
|
||||
return maxLevel;
|
||||
}
|
||||
|
||||
public int calculateExperience(int x) {
|
||||
return (int) experience.calculate(x);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user