Fixed page count not being computed correctly when first joining a world

This commit is contained in:
Sollace 2021-02-13 19:24:25 +02:00
parent 88279b18b6
commit 209ddbb972

View file

@ -30,7 +30,7 @@ public class AbilityDispatcher implements Tickable, NbtSerialisable {
@Nullable @Nullable
private Race prevRace; private Race prevRace;
private long maxPage; private long maxPage = -1;
public AbilityDispatcher(Pony player) { public AbilityDispatcher(Pony player) {
this.player = player; this.player = player;
@ -39,6 +39,7 @@ public class AbilityDispatcher implements Tickable, NbtSerialisable {
public void clear(AbilitySlot slot) { public void clear(AbilitySlot slot) {
Stat stat = getStat(slot); Stat stat = getStat(slot);
if (stat.canSwitchStates()) { if (stat.canSwitchStates()) {
stat.setActiveAbility(null); stat.setActiveAbility(null);
} }
@ -61,9 +62,12 @@ public class AbilityDispatcher implements Tickable, NbtSerialisable {
} }
public long getMaxPage() { public long getMaxPage() {
if (prevRace != player.getSpecies()) { if (maxPage < 0 || prevRace != player.getSpecies()) {
prevRace = player.getSpecies(); prevRace = player.getSpecies();
maxPage = Math.max(0, stats.values().stream().mapToLong(Stat::getMaxPage).reduce(0, Math::max) - 1); maxPage = 0;
for (AbilitySlot slot : AbilitySlot.values()) {
maxPage = Math.max(maxPage, getStat(slot).getMaxPage() - 1);
}
} }
return maxPage; return maxPage;
} }