Boosters with the same multiplier now stack

This commit is contained in:
Indyuce 2020-07-02 19:51:29 +02:00
parent c0141e2972
commit fa0d13efa8
2 changed files with 26 additions and 2 deletions

View File

@ -4,11 +4,15 @@ import java.util.UUID;
public class Booster {
private final UUID uuid = UUID.randomUUID();
private final long date = System.currentTimeMillis(), length;
private final long date = System.currentTimeMillis();
private final Profession profession;
private final double extra;
private final String author;
// length not final because boosters can stack, this allows to reduce the
// amount of boosters
private long length;
public Booster(double extra, long length) {
this(null, null, extra, length);
}
@ -40,6 +44,10 @@ public class Booster {
return length;
}
public void addLength(long length) {
this.length += length;
}
public boolean hasProfession() {
return profession != null;
}
@ -67,4 +75,8 @@ public class Booster {
public String getAuthor() {
return author;
}
public boolean canStackWith(Booster booster) {
return extra == booster.extra && (profession != null ? profession.equals(booster.getProfession()) : booster.getProfession() == null);
}
}

View File

@ -11,7 +11,16 @@ public class BoosterManager {
private List<Booster> map = new ArrayList<>();
public void register(Booster booster) {
// always flush booster list to reduce future calculations
flush();
for (Booster active : map)
if (active.canStackWith(booster)) {
active.addLength(booster.getLength());
return;
}
map.add(booster);
}
@ -25,17 +34,20 @@ public class BoosterManager {
public int calculateExp(Profession profession, double exp) {
flush();
for (Booster booster : map)
if (booster.getProfession() == profession)
exp = booster.calculateExp(exp);
return (int) exp;
}
public List<Booster> getBoosters() {
flush();
return map;
}
public Booster get(int index) {
return map.get(index);
}