prevent direct access of Player->counters ; some cleanup on counter removal effects ; implement [MH3] Izzet Generatorium (#12314)

This commit is contained in:
Susucre 2024-05-29 22:34:54 +02:00 committed by GitHub
parent 8d02ff14ff
commit 20b7a115da
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
110 changed files with 895 additions and 646 deletions

View file

@ -27,35 +27,17 @@ public class Counters extends HashMap<String, Counter> implements Serializable,
return new Counters(this);
}
public Counters addCounter(String name, int amount) {
putIfAbsent(name, new Counter(name));
this.get(name).add(amount);
return this;
}
public Counters addCounter(Counter counter) {
if (!containsKey(counter.name)) {
put(counter.name, counter);
} else {
get(counter.name).add(counter.getCount());
}
return this;
}
public boolean removeCounter(String name) {
return removeCounter(name, 1);
}
public boolean removeCounter(CounterType counterType, int amount) {
if (this.containsKey(counterType.getName())) {
get(counterType.getName()).remove(amount);
if (get(counterType.getName()).count == 0) {
this.remove(counterType.getName());
}
return true;
}
return false;
return removeCounter(counterType.getName(), amount);
}
public boolean removeCounter(String name, int amount) {
@ -69,17 +51,6 @@ public class Counters extends HashMap<String, Counter> implements Serializable,
return false;
}
public void removeAllCounters(CounterType counterType) {
removeAllCounters(counterType.getName());
}
public void removeAllCounters(String name) {
if (this.containsKey(name)) {
this.remove(name);
}
}
public int getCount(String name) {
if (this.containsKey(name)) {
return this.get(name).getCount();
@ -91,6 +62,10 @@ public class Counters extends HashMap<String, Counter> implements Serializable,
return getCount(counterType) > 0;
}
public int getTotalCount() {
return this.values().stream().mapToInt(Counter::getCount).sum();
}
public int getCount(CounterType type) {
if (this.containsKey(type.getName())) {
return this.get(type.getName()).getCount();