feat(progression): add tyrant unlock choices
This commit is contained in:
@@ -20,6 +20,9 @@ final class PluginMetadataTest {
|
||||
assertEquals("SpigotTyrant", plugin.get("name"));
|
||||
assertEquals("games.dmg.spigottyrant.SpigotTyrantPlugin", plugin.get("main"));
|
||||
assertEquals("1.20", plugin.get("api-version"));
|
||||
Map<?, ?> commands = (Map<?, ?>) plugin.get("commands");
|
||||
assertNotNull(commands);
|
||||
assertNotNull(commands.get("tyrant"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package games.dmg.spigottyrant;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
final class TyrantCommandTest {
|
||||
@Test
|
||||
void choicesClearlyIdentifyPurchasedAvailableAndUnavailableUnlocks() {
|
||||
UUID tyrantId = UUID.fromString("11111111-1111-1111-1111-111111111111");
|
||||
GameState state = new GameState(
|
||||
GameLifecycle.RUNNING,
|
||||
Optional.of(tyrantId),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
Duration.ZERO,
|
||||
1,
|
||||
1,
|
||||
Set.of(TyrantUnlock.STRENGTH)
|
||||
);
|
||||
TyrantStateManager manager = mock(TyrantStateManager.class);
|
||||
when(manager.game()).thenReturn(state);
|
||||
Player player = mock(Player.class);
|
||||
when(player.getUniqueId()).thenReturn(tyrantId);
|
||||
TyrantCommand command = new TyrantCommand(manager, new TyrantProgressionService());
|
||||
|
||||
command.onCommand(player, mock(Command.class), "tyrant", new String[] {"choices"});
|
||||
|
||||
ArgumentCaptor<String> messages = ArgumentCaptor.forClass(String.class);
|
||||
verify(player, org.mockito.Mockito.atLeastOnce()).sendMessage(messages.capture());
|
||||
List<String> all = messages.getAllValues();
|
||||
assertTrue(all.stream().anyMatch(message -> message.contains("PURCHASED")
|
||||
&& message.contains("STRENGTH")));
|
||||
assertTrue(all.stream().anyMatch(message -> message.contains("AVAILABLE")
|
||||
&& message.contains("ASSASSIN")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
package games.dmg.spigottyrant;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
final class TyrantProgressionServiceTest {
|
||||
private static final UUID TYRANT = UUID.fromString("11111111-1111-1111-1111-111111111111");
|
||||
private static final UUID VIGILANTE = UUID.fromString("22222222-2222-2222-2222-222222222222");
|
||||
private static final UUID OTHER = UUID.fromString("33333333-3333-3333-3333-333333333333");
|
||||
private final TyrantProgressionService service = new TyrantProgressionService();
|
||||
|
||||
@Test
|
||||
void tyrantPersonallyKillingCurrentVigilanteEarnsOneLevelAndChoice() {
|
||||
GameState before = runningState(0, 1, Set.of());
|
||||
|
||||
GameState after = service.recordVigilanteDeath(before, Optional.of(TYRANT));
|
||||
|
||||
assertEquals(1, after.tyrantLevel());
|
||||
assertEquals(2, after.unspentChoices());
|
||||
}
|
||||
|
||||
@Test
|
||||
void otherEnvironmentalAndPausedDeathsDoNotEarnProgress() {
|
||||
GameState running = runningState(2, 0, Set.of());
|
||||
GameState paused = new GameState(
|
||||
GameLifecycle.PAUSED,
|
||||
running.tyrantId(),
|
||||
running.vigilanteId(),
|
||||
running.pendingTyrant(),
|
||||
running.pendingVigilante(),
|
||||
Optional.of(java.time.Instant.parse("2026-08-14T12:00:00Z")),
|
||||
Duration.ZERO,
|
||||
2,
|
||||
0,
|
||||
Set.of()
|
||||
);
|
||||
|
||||
assertEquals(running, service.recordVigilanteDeath(running, Optional.of(OTHER)));
|
||||
assertEquals(running, service.recordVigilanteDeath(running, Optional.empty()));
|
||||
assertEquals(paused, service.recordVigilanteDeath(paused, Optional.of(TYRANT)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void purchaseConsumesOneChoiceAndCannotBeBoughtTwice() {
|
||||
GameState before = runningState(1, 2, Set.of());
|
||||
|
||||
PurchaseResult first = service.purchase(before, TYRANT, TyrantUnlock.ASSASSIN);
|
||||
PurchaseResult duplicate = service.purchase(
|
||||
first.state(), TYRANT, TyrantUnlock.ASSASSIN
|
||||
);
|
||||
|
||||
assertEquals(PurchaseStatus.PURCHASED, first.status());
|
||||
assertEquals(1, first.state().unspentChoices());
|
||||
assertTrue(first.state().purchases().contains(TyrantUnlock.ASSASSIN));
|
||||
assertEquals(PurchaseStatus.ALREADY_PURCHASED, duplicate.status());
|
||||
assertEquals(first.state(), duplicate.state());
|
||||
}
|
||||
|
||||
@Test
|
||||
void nonTyrantPausedAndNoChoicePurchasesAreRejected() {
|
||||
GameState noChoices = runningState(0, 0, Set.of());
|
||||
GameState paused = new GameState(
|
||||
GameLifecycle.PAUSED,
|
||||
noChoices.tyrantId(),
|
||||
noChoices.vigilanteId(),
|
||||
noChoices.pendingTyrant(),
|
||||
noChoices.pendingVigilante(),
|
||||
Optional.of(java.time.Instant.parse("2026-08-14T12:00:00Z")),
|
||||
Duration.ZERO,
|
||||
0,
|
||||
1,
|
||||
Set.of()
|
||||
);
|
||||
|
||||
assertEquals(PurchaseStatus.NO_CHOICES,
|
||||
service.purchase(noChoices, TYRANT, TyrantUnlock.FIXER).status());
|
||||
assertEquals(PurchaseStatus.NOT_TYRANT,
|
||||
service.purchase(runningState(0, 1, Set.of()), OTHER, TyrantUnlock.FIXER).status());
|
||||
PurchaseResult pausedResult = service.purchase(paused, TYRANT, TyrantUnlock.FIXER);
|
||||
assertEquals(PurchaseStatus.GAME_NOT_RUNNING, pausedResult.status());
|
||||
assertFalse(pausedResult.state().purchases().contains(TyrantUnlock.FIXER));
|
||||
}
|
||||
|
||||
@Test
|
||||
void endingReignClearsLevelChoicesAndPurchases() {
|
||||
GameState progressed = runningState(
|
||||
4,
|
||||
2,
|
||||
Set.of(TyrantUnlock.ASSASSIN, TyrantUnlock.STRENGTH)
|
||||
);
|
||||
|
||||
GameState reset = service.resetReignProgression(progressed);
|
||||
|
||||
assertEquals(0, reset.tyrantLevel());
|
||||
assertEquals(0, reset.unspentChoices());
|
||||
assertEquals(Set.of(), reset.purchases());
|
||||
}
|
||||
|
||||
private static GameState runningState(
|
||||
int level,
|
||||
int choices,
|
||||
Set<TyrantUnlock> purchases
|
||||
) {
|
||||
return new GameState(
|
||||
GameLifecycle.RUNNING,
|
||||
Optional.of(TYRANT),
|
||||
Optional.of(VIGILANTE),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
Duration.ZERO,
|
||||
level,
|
||||
choices,
|
||||
purchases
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user