80 lines
2.9 KiB
Java
80 lines
2.9 KiB
Java
package games.dmg.spigottyrant;
|
|
|
|
import java.time.Duration;
|
|
import java.time.Instant;
|
|
import java.util.EnumMap;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
|
|
public record TyrantControlPanelModel(
|
|
int level,
|
|
int unspentChoices,
|
|
Map<TyrantUnlock, UnlockAvailability> unlocks,
|
|
Set<TyrantArmorPiece> claimedArmor,
|
|
Map<TyrantClass, String> classHolders,
|
|
Duration intelligenceCooldown
|
|
) {
|
|
public TyrantControlPanelModel {
|
|
unlocks = Map.copyOf(unlocks);
|
|
claimedArmor = Set.copyOf(claimedArmor);
|
|
classHolders = Map.copyOf(classHolders);
|
|
}
|
|
|
|
public Set<TyrantUnlock> purchasedUnlocks() {
|
|
return unlocks.entrySet().stream()
|
|
.filter(entry -> entry.getValue() == UnlockAvailability.PURCHASED)
|
|
.map(Map.Entry::getKey)
|
|
.collect(java.util.stream.Collectors.toUnmodifiableSet());
|
|
}
|
|
|
|
public boolean allStandardUnlocksPurchased() {
|
|
return purchasedUnlocks().size() == TyrantUnlock.values().length;
|
|
}
|
|
|
|
public boolean armorAvailable(TyrantArmorPiece piece) {
|
|
return allStandardUnlocksPurchased() && unspentChoices > 0
|
|
&& !claimedArmor.contains(piece);
|
|
}
|
|
|
|
public static TyrantControlPanelModel create(
|
|
GameState game,
|
|
PlayerState tyrant,
|
|
Map<java.util.UUID, PlayerState> players,
|
|
Instant now
|
|
) {
|
|
Map<TyrantUnlock, UnlockAvailability> unlocks = new EnumMap<>(TyrantUnlock.class);
|
|
for (TyrantUnlock unlock : TyrantUnlock.values()) {
|
|
UnlockAvailability availability;
|
|
if (game.purchases().contains(unlock)) {
|
|
availability = UnlockAvailability.PURCHASED;
|
|
} else if (game.lifecycle() == GameLifecycle.RUNNING
|
|
&& game.unspentChoices() > 0) {
|
|
availability = UnlockAvailability.AVAILABLE;
|
|
} else {
|
|
availability = UnlockAvailability.UNAVAILABLE;
|
|
}
|
|
unlocks.put(unlock, availability);
|
|
}
|
|
Map<TyrantClass, String> holders = new EnumMap<>(TyrantClass.class);
|
|
for (TyrantClass tyrantClass : new TyrantClass[] {
|
|
TyrantClass.ASSASSIN, TyrantClass.FIXER, TyrantClass.TAMER
|
|
}) {
|
|
String holder = players.values().stream()
|
|
.filter(player -> player.tyrantClass() == tyrantClass)
|
|
.map(PlayerState::latestName)
|
|
.findFirst()
|
|
.orElse("Unassigned");
|
|
holders.put(tyrantClass, holder);
|
|
}
|
|
Duration cooldown = tyrant.cooldownEnds().getOrDefault(
|
|
Ability.ROSTER_INTELLIGENCE, now
|
|
).isAfter(now)
|
|
? Duration.between(now, tyrant.cooldownEnds().get(Ability.ROSTER_INTELLIGENCE))
|
|
: Duration.ZERO;
|
|
return new TyrantControlPanelModel(
|
|
game.tyrantLevel(), game.unspentChoices(), unlocks, game.claimedArmor(),
|
|
holders, cooldown
|
|
);
|
|
}
|
|
}
|