96 lines
4.1 KiB
Java
96 lines
4.1 KiB
Java
package games.dmg.spigottyrant;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
|
|
|
import java.time.Duration;
|
|
import java.time.Instant;
|
|
import java.util.Map;
|
|
import java.util.Optional;
|
|
import java.util.Set;
|
|
import java.util.UUID;
|
|
import java.util.random.RandomGenerator;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
final class TyrantSuccessionServiceTest {
|
|
private static final UUID OLD_TYRANT = UUID.fromString("11111111-1111-1111-1111-111111111111");
|
|
private static final UUID OLD_VIGILANTE = UUID.fromString("22222222-2222-2222-2222-222222222222");
|
|
private static final UUID KILLER = UUID.fromString("33333333-3333-3333-3333-333333333333");
|
|
private static final UUID OTHER = UUID.fromString("44444444-4444-4444-4444-444444444444");
|
|
private static final Instant NOW = Instant.parse("2026-08-14T12:00:00Z");
|
|
private final TyrantSuccessionService service = new TyrantSuccessionService(
|
|
new RoleCandidateSelector(),
|
|
Duration.ofHours(24),
|
|
Duration.ofHours(24),
|
|
RandomGenerator.of("L64X128MixRandom")
|
|
);
|
|
|
|
@Test
|
|
void playerKillerBecomesTyrantAndEntireReignIsReset() {
|
|
PersistentState before = progressedState();
|
|
|
|
LifecycleState after = service.succeed(
|
|
before, Optional.of(KILLER), Set.of(KILLER, OTHER), NOW
|
|
);
|
|
|
|
assertEquals(Optional.of(KILLER), after.game().tyrantId());
|
|
assertEquals(0, after.game().tyrantLevel());
|
|
assertEquals(1, after.game().unspentChoices());
|
|
assertEquals(Set.of(), after.game().purchases());
|
|
assertNotEquals(after.game().tyrantId(), after.game().vigilanteId());
|
|
for (PlayerState player : after.players().values()) {
|
|
assertEquals(TyrantClass.NONE, player.tyrantClass());
|
|
assertEquals(Optional.empty(), player.followerOf());
|
|
assertEquals(Map.of(), player.cooldownEnds());
|
|
}
|
|
}
|
|
|
|
@Test
|
|
void environmentalDeathRandomlySelectsRecentPlayerInsteadOfFormerTyrant() {
|
|
PersistentState before = progressedState();
|
|
|
|
LifecycleState after = service.succeed(before, Optional.empty(), Set.of(OTHER), NOW);
|
|
|
|
UUID selected = after.game().tyrantId().orElseGet(() ->
|
|
after.game().pendingTyrant().orElseThrow().candidateId()
|
|
);
|
|
assertNotEquals(OLD_TYRANT, selected);
|
|
}
|
|
|
|
private static PersistentState progressedState() {
|
|
GameState game = new GameState(
|
|
GameLifecycle.RUNNING, Optional.of(OLD_TYRANT), Optional.of(OLD_VIGILANTE),
|
|
Optional.empty(), Optional.empty(), Optional.empty(), Duration.ZERO,
|
|
5, 2, Set.of(TyrantUnlock.ASSASSIN, TyrantUnlock.STRENGTH)
|
|
);
|
|
Map<UUID, PlayerState> players = Map.of(
|
|
OLD_TYRANT, active(new PlayerState(
|
|
OLD_TYRANT, "OldTyrant", Optional.empty(), Optional.empty(),
|
|
TyrantClass.NONE, Optional.empty(),
|
|
Map.of(Ability.ROSTER_INTELLIGENCE, NOW.plusSeconds(20)),
|
|
Set.of(), java.util.List.of()
|
|
)),
|
|
OLD_VIGILANTE, active(new PlayerState(
|
|
OLD_VIGILANTE, "OldVigilante", Optional.empty(), Optional.empty(),
|
|
TyrantClass.ASSASSIN, Optional.empty(),
|
|
Map.of(Ability.ASSASSIN_INVISIBILITY, NOW.plusSeconds(20)),
|
|
Set.of(Ability.ASSASSIN_INVISIBILITY), java.util.List.of()
|
|
)),
|
|
KILLER, active(PlayerState.newPlayer(KILLER, "Killer")),
|
|
OTHER, active(new PlayerState(
|
|
OTHER, "Other", Optional.empty(), Optional.empty(), TyrantClass.FIXER,
|
|
Optional.of(OLD_VIGILANTE), Map.of(), Set.of(), java.util.List.of()
|
|
))
|
|
);
|
|
return new PersistentState(game, players);
|
|
}
|
|
|
|
private static PlayerState active(PlayerState player) {
|
|
return new PlayerState(
|
|
player.playerId(), player.latestName(), Optional.of(NOW.minusSeconds(60)),
|
|
player.optedOutUntil(), player.tyrantClass(), player.followerOf(),
|
|
player.cooldownEnds(), player.readyAbilityItems(), player.capturedMobs()
|
|
);
|
|
}
|
|
}
|