forked from Upstream/mmocore
Added %mmocore_exp_<boost/multiplier>_<main/profession>%
This commit is contained in:
parent
9a37ed70e3
commit
6f749e2684
@ -9,18 +9,44 @@ public class Booster {
|
|||||||
private final double extra;
|
private final double extra;
|
||||||
private final String author;
|
private final String author;
|
||||||
|
|
||||||
// length not final because boosters can stack, this allows to reduce the
|
/**
|
||||||
// amount of boosters
|
* Length is not final because boosters can stacks. This allows to reduce
|
||||||
|
* the amount of boosters displayed in the main player menu
|
||||||
|
*/
|
||||||
private long length;
|
private long length;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param extra
|
||||||
|
* 1 for +100% experience, 3 for 300% etc.
|
||||||
|
* @param length
|
||||||
|
* Booster length in milliseconds
|
||||||
|
*/
|
||||||
public Booster(double extra, long length) {
|
public Booster(double extra, long length) {
|
||||||
this(null, null, extra, length);
|
this(null, null, extra, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param author
|
||||||
|
* The booster creator
|
||||||
|
* @param extra
|
||||||
|
* 1 for +100% experience, 3 for 300% etc.
|
||||||
|
* @param length
|
||||||
|
* Booster length in milliseconds
|
||||||
|
*/
|
||||||
public Booster(String author, double extra, long length) {
|
public Booster(String author, double extra, long length) {
|
||||||
this(author, null, extra, length);
|
this(author, null, extra, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param author
|
||||||
|
* The booster creator
|
||||||
|
* @param profession
|
||||||
|
* Either null for main level boosters or a specific profession
|
||||||
|
* @param extra
|
||||||
|
* 1 for +100% experience, 3 for 300% etc.
|
||||||
|
* @param length
|
||||||
|
* Booster length in milliseconds
|
||||||
|
*/
|
||||||
public Booster(String author, Profession profession, double extra, long length) {
|
public Booster(String author, Profession profession, double extra, long length) {
|
||||||
this.author = author;
|
this.author = author;
|
||||||
this.length = length * 1000;
|
this.length = length * 1000;
|
||||||
@ -28,42 +54,10 @@ public class Booster {
|
|||||||
this.extra = extra;
|
this.extra = extra;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTimedOut() {
|
|
||||||
return date + length < System.currentTimeMillis();
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getLeft() {
|
|
||||||
return Math.max(0, date + length - System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getCreationDate() {
|
|
||||||
return date;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getLength() {
|
|
||||||
return length;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addLength(long length) {
|
|
||||||
this.length += length;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasProfession() {
|
|
||||||
return profession != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Profession getProfession() {
|
|
||||||
return profession;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getUniqueId() {
|
public UUID getUniqueId() {
|
||||||
return uuid;
|
return uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double calculateExp(double exp) {
|
|
||||||
return exp * (1 + extra);
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getExtra() {
|
public double getExtra() {
|
||||||
return extra;
|
return extra;
|
||||||
}
|
}
|
||||||
@ -76,6 +70,34 @@ public class Booster {
|
|||||||
return author;
|
return author;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getCreationDate() {
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasProfession() {
|
||||||
|
return profession != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Profession getProfession() {
|
||||||
|
return profession;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isTimedOut() {
|
||||||
|
return date + length < System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getLeft() {
|
||||||
|
return Math.max(0, date + length - System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getLength() {
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addLength(long length) {
|
||||||
|
this.length += length;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean canStackWith(Booster booster) {
|
public boolean canStackWith(Booster booster) {
|
||||||
return extra == booster.extra && (profession != null ? profession.equals(booster.getProfession()) : booster.getProfession() == null);
|
return extra == booster.extra && (profession != null ? profession.equals(booster.getProfession()) : booster.getProfession() == null);
|
||||||
}
|
}
|
||||||
|
@ -100,16 +100,27 @@ public class RPGPlaceholders extends PlaceholderExpansion {
|
|||||||
return "" + PlayerData.get(player).getAttributeReallocationPoints();
|
return "" + PlayerData.get(player).getAttributeReallocationPoints();
|
||||||
|
|
||||||
else if (identifier.startsWith("attribute_"))
|
else if (identifier.startsWith("attribute_"))
|
||||||
return String.valueOf(PlayerData.get(player).getAttributes().getAttribute(
|
return String.valueOf(PlayerData.get(player).getAttributes()
|
||||||
MMOCore.plugin.attributeManager.get(identifier.substring(10).toLowerCase().replace("_", "-"))));
|
.getAttribute(MMOCore.plugin.attributeManager.get(identifier.substring(10).toLowerCase().replace("_", "-"))));
|
||||||
|
|
||||||
else if (identifier.equals("mana"))
|
else if (identifier.equals("mana"))
|
||||||
return MMOCore.plugin.configManager.decimal.format(PlayerData.get(player).getMana());
|
return MMOCore.plugin.configManager.decimal.format(PlayerData.get(player).getMana());
|
||||||
|
|
||||||
else if (identifier.equals("mana_bar")) {
|
else if (identifier.equals("mana_bar")) {
|
||||||
PlayerData data = PlayerData.get(player);
|
PlayerData data = PlayerData.get(player);
|
||||||
return data.getProfess().getManaDisplay().generateBar(data.getMana(),
|
return data.getProfess().getManaDisplay().generateBar(data.getMana(), data.getStats().getStat(StatType.MAX_MANA));
|
||||||
data.getStats().getStat(StatType.MAX_MANA));
|
}
|
||||||
|
|
||||||
|
else if (identifier.startsWith("exp_multiplier_")) {
|
||||||
|
String format = identifier.substring(15).toLowerCase().replace("_", "-").replace(" ", "-");
|
||||||
|
Profession profession = format.equals("main") ? null : MMOCore.plugin.professionManager.get(format);
|
||||||
|
return MMOCore.plugin.configManager.decimal.format(MMOCore.plugin.boosterManager.getMultiplier(profession) * 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (identifier.startsWith("exp_boost_")) {
|
||||||
|
String format = identifier.substring(10).toLowerCase().replace("_", "-").replace(" ", "-");
|
||||||
|
Profession profession = format.equals("main") ? null : MMOCore.plugin.professionManager.get(format);
|
||||||
|
return MMOCore.plugin.configManager.decimal.format((MMOCore.plugin.boosterManager.getMultiplier(profession) - 1) * 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (identifier.equals("stamina"))
|
else if (identifier.equals("stamina"))
|
||||||
@ -121,8 +132,7 @@ public class RPGPlaceholders extends PlaceholderExpansion {
|
|||||||
double ratio = 20 * data.getStamina() / data.getStats().getStat(StatType.MAX_STAMINA);
|
double ratio = 20 * data.getStamina() / data.getStats().getStat(StatType.MAX_STAMINA);
|
||||||
for (double j = 1; j < 20; j++)
|
for (double j = 1; j < 20; j++)
|
||||||
format += (ratio >= j ? MMOCore.plugin.configManager.staminaFull
|
format += (ratio >= j ? MMOCore.plugin.configManager.staminaFull
|
||||||
: ratio >= j - .5 ? MMOCore.plugin.configManager.staminaHalf
|
: ratio >= j - .5 ? MMOCore.plugin.configManager.staminaHalf : MMOCore.plugin.configManager.staminaEmpty)
|
||||||
: MMOCore.plugin.configManager.staminaEmpty)
|
|
||||||
+ AltChar.listSquare;
|
+ AltChar.listSquare;
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
@ -140,8 +150,7 @@ public class RPGPlaceholders extends PlaceholderExpansion {
|
|||||||
PlayerData data = PlayerData.get(player);
|
PlayerData data = PlayerData.get(player);
|
||||||
double ratio = 20 * data.getStellium() / data.getStats().getStat(StatType.MAX_STELLIUM);
|
double ratio = 20 * data.getStellium() / data.getStats().getStat(StatType.MAX_STELLIUM);
|
||||||
for (double j = 1; j < 20; j++)
|
for (double j = 1; j < 20; j++)
|
||||||
format += (ratio >= j ? ChatColor.BLUE : ratio >= j - .5 ? ChatColor.AQUA : ChatColor.WHITE)
|
format += (ratio >= j ? ChatColor.BLUE : ratio >= j - .5 ? ChatColor.AQUA : ChatColor.WHITE) + AltChar.listSquare;
|
||||||
+ AltChar.listSquare;
|
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,8 +162,8 @@ public class RPGPlaceholders extends PlaceholderExpansion {
|
|||||||
else if (identifier.equals("quest_progress")) {
|
else if (identifier.equals("quest_progress")) {
|
||||||
PlayerQuests data = PlayerData.get(player).getQuestData();
|
PlayerQuests data = PlayerData.get(player).getQuestData();
|
||||||
return data.hasCurrent()
|
return data.hasCurrent()
|
||||||
? MMOCore.plugin.configManager.decimal.format((int) (double) data.getCurrent().getObjectiveNumber()
|
? MMOCore.plugin.configManager.decimal
|
||||||
/ data.getCurrent().getQuest().getObjectives().size() * 100)
|
.format((int) (double) data.getCurrent().getObjectiveNumber() / data.getCurrent().getQuest().getObjectives().size() * 100)
|
||||||
: "0";
|
: "0";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,11 +8,19 @@ import net.Indyuce.mmocore.api.experience.Booster;
|
|||||||
import net.Indyuce.mmocore.api.experience.Profession;
|
import net.Indyuce.mmocore.api.experience.Profession;
|
||||||
|
|
||||||
public class BoosterManager {
|
public class BoosterManager {
|
||||||
private List<Booster> map = new ArrayList<>();
|
private final List<Booster> map = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If MMOCore can find a booster with the same profession and value, the two
|
||||||
|
* boosters will stack to reduce the amount of boosters displayed at the
|
||||||
|
* same time. Otherwise, booster is registered
|
||||||
|
*
|
||||||
|
* @param booster
|
||||||
|
* Booster to register
|
||||||
|
*/
|
||||||
public void register(Booster booster) {
|
public void register(Booster booster) {
|
||||||
|
|
||||||
// always flush booster list to reduce future calculations
|
// flushes booster list to reduce future calculations
|
||||||
flush();
|
flush();
|
||||||
|
|
||||||
for (Booster active : map)
|
for (Booster active : map)
|
||||||
@ -24,6 +32,13 @@ public class BoosterManager {
|
|||||||
map.add(booster);
|
map.add(booster);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Booster get(int index) {
|
||||||
|
return map.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cleans timed out boosters from the MMOCore registry
|
||||||
|
*/
|
||||||
public void flush() {
|
public void flush() {
|
||||||
for (Iterator<Booster> iterator = map.iterator(); iterator.hasNext();) {
|
for (Iterator<Booster> iterator = map.iterator(); iterator.hasNext();) {
|
||||||
Booster next = iterator.next();
|
Booster next = iterator.next();
|
||||||
@ -32,23 +47,28 @@ public class BoosterManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int calculateExp(Profession profession, double exp) {
|
/**
|
||||||
flush();
|
* @return Sums all current experience boosters values
|
||||||
|
*/
|
||||||
|
public double getMultiplier(Profession profession) {
|
||||||
|
double d = 1;
|
||||||
|
|
||||||
for (Booster booster : map)
|
for (Booster booster : map)
|
||||||
if (booster.getProfession() == profession)
|
if (booster.getProfession() == profession && !booster.isTimedOut())
|
||||||
exp = booster.calculateExp(exp);
|
d += booster.getExtra();
|
||||||
|
|
||||||
return (int) exp;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Booster> getBoosters() {
|
public int calculateExp(Profession profession, double exp) {
|
||||||
flush();
|
return (int) (exp * getMultiplier(profession));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection of currently registered boosters. Some of them can be
|
||||||
|
* expired but are not unregistered yet!
|
||||||
|
*/
|
||||||
|
public List<Booster> getBoosters() {
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Booster get(int index) {
|
|
||||||
return map.get(index);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user