32 lines
939 B
Java
32 lines
939 B
Java
package games.dmg.spigottyrant;
|
|
|
|
import java.util.Optional;
|
|
|
|
public final class RoleArenaPolicy {
|
|
private RoleArenaPolicy() {
|
|
}
|
|
|
|
public static Optional<ArenaRole> openRole(GameState game) {
|
|
if (game.lifecycle() != GameLifecycle.RUNNING) {
|
|
return Optional.empty();
|
|
}
|
|
if (game.tyrantId().isEmpty()) {
|
|
return game.pendingTyrant().isEmpty()
|
|
? Optional.of(ArenaRole.TYRANT) : Optional.empty();
|
|
}
|
|
return game.vigilanteId().isEmpty()
|
|
? Optional.of(ArenaRole.VIGILANTE) : Optional.empty();
|
|
}
|
|
|
|
public static boolean isEligible(
|
|
GameState game,
|
|
ArenaRole role,
|
|
PlayerState player
|
|
) {
|
|
return player != null
|
|
&& openRole(game).filter(role::equals).isPresent()
|
|
&& player.optedOutUntil().isEmpty()
|
|
&& game.tyrantId().filter(player.playerId()::equals).isEmpty();
|
|
}
|
|
}
|