forked from Upstream/mmocore
Boosters with the same multiplier now stack
This commit is contained in:
parent
c0141e2972
commit
fa0d13efa8
@ -4,11 +4,15 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public class Booster {
|
public class Booster {
|
||||||
private final UUID uuid = UUID.randomUUID();
|
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 Profession profession;
|
||||||
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
|
||||||
|
private long length;
|
||||||
|
|
||||||
public Booster(double extra, long length) {
|
public Booster(double extra, long length) {
|
||||||
this(null, null, extra, length);
|
this(null, null, extra, length);
|
||||||
}
|
}
|
||||||
@ -40,6 +44,10 @@ public class Booster {
|
|||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addLength(long length) {
|
||||||
|
this.length += length;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasProfession() {
|
public boolean hasProfession() {
|
||||||
return profession != null;
|
return profession != null;
|
||||||
}
|
}
|
||||||
@ -67,4 +75,8 @@ public class Booster {
|
|||||||
public String getAuthor() {
|
public String getAuthor() {
|
||||||
return author;
|
return author;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean canStackWith(Booster booster) {
|
||||||
|
return extra == booster.extra && (profession != null ? profession.equals(booster.getProfession()) : booster.getProfession() == null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,16 @@ public class BoosterManager {
|
|||||||
private List<Booster> map = new ArrayList<>();
|
private List<Booster> map = new ArrayList<>();
|
||||||
|
|
||||||
public void register(Booster booster) {
|
public void register(Booster booster) {
|
||||||
|
|
||||||
|
// always flush booster list to reduce future calculations
|
||||||
flush();
|
flush();
|
||||||
|
|
||||||
|
for (Booster active : map)
|
||||||
|
if (active.canStackWith(booster)) {
|
||||||
|
active.addLength(booster.getLength());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
map.add(booster);
|
map.add(booster);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,14 +34,17 @@ public class BoosterManager {
|
|||||||
|
|
||||||
public int calculateExp(Profession profession, double exp) {
|
public int calculateExp(Profession profession, double exp) {
|
||||||
flush();
|
flush();
|
||||||
|
|
||||||
for (Booster booster : map)
|
for (Booster booster : map)
|
||||||
if (booster.getProfession() == profession)
|
if (booster.getProfession() == profession)
|
||||||
exp = booster.calculateExp(exp);
|
exp = booster.calculateExp(exp);
|
||||||
|
|
||||||
return (int) exp;
|
return (int) exp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Booster> getBoosters() {
|
public List<Booster> getBoosters() {
|
||||||
flush();
|
flush();
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user