main
Johannes Hochwart 3 years ago
parent 77c3db0f2d
commit 0e23ddc343

@ -19,8 +19,8 @@ public final class HandMessage extends ObserverMessage {
*/ */
private final @NotNull UUID player; private final @NotNull UUID player;
/** /**
* A list of all the hand cards. May consist only of {@link Card#HIDDEN} if the cars are not visible to the player * A list of all the hand cards. May consist only of {@link Card#HIDDEN} if the cards are not visible to the player
* receiving this message * receiving this message.
*/ */
private final @NotNull List<@NotNull Card> hand; private final @NotNull List<@NotNull Card> hand;

@ -4,9 +4,9 @@ import eu.jonahbauer.wizard.common.messages.data.PlayerData;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public final class PlayerJoinMessage extends PlayerModifiedMessage { public final class PlayerJoinedMessage extends PlayerModifiedMessage {
public PlayerJoinMessage(PlayerData playerData) { public PlayerJoinedMessage(PlayerData playerData) {
super(playerData); super(playerData);
} }
} }

@ -9,7 +9,7 @@ import java.util.UUID;
@Getter @Getter
@RequiredArgsConstructor @RequiredArgsConstructor
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public final class PlayerLeaveMessage extends ServerMessage { public final class PlayerLeftMessage extends ServerMessage {
/** /**
* UUID of player who has left * UUID of player who has left
*/ */

@ -8,9 +8,9 @@ import lombok.RequiredArgsConstructor;
@Getter @Getter
@RequiredArgsConstructor @RequiredArgsConstructor
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public sealed class PlayerModifiedMessage extends ServerMessage permits PlayerJoinMessage { public sealed class PlayerModifiedMessage extends ServerMessage permits PlayerJoinedMessage {
/** /**
* Joining player * Joining player
*/ */
private final PlayerData playerData; private final PlayerData player;
} }

@ -7,7 +7,7 @@ import eu.jonahbauer.wizard.common.util.SealedClassTypeAdapterFactory;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
@EqualsAndHashCode @EqualsAndHashCode
public abstract sealed class ServerMessage permits AckMessage, GameMessage, JoinedSessionMessage, NackMessage, PlayerLeaveMessage, PlayerModifiedMessage, SessionListMessage, SessionModifiedMessage, SessionRemovedMessage, StartingGameMessage { public abstract sealed class ServerMessage permits AckMessage, GameMessage, JoinedSessionMessage, NackMessage, PlayerLeftMessage, PlayerModifiedMessage, SessionListMessage, SessionModifiedMessage, SessionRemovedMessage, StartingGameMessage {
public static final Gson GSON = new GsonBuilder() public static final Gson GSON = new GsonBuilder()
.registerTypeAdapterFactory(SealedClassTypeAdapterFactory.of(ServerMessage.class, "Message")) .registerTypeAdapterFactory(SealedClassTypeAdapterFactory.of(ServerMessage.class, "Message"))
.registerTypeAdapterFactory(SealedClassTypeAdapterFactory.of(ObserverMessage.class, "Message")) .registerTypeAdapterFactory(SealedClassTypeAdapterFactory.of(ObserverMessage.class, "Message"))

@ -57,7 +57,12 @@ public final class DeterminingTrump extends RoundState {
@Override @Override
public void onTimeout(Game game) { public void onTimeout(Game game) {
Card.Suit[] suits = new Card.Suit[]{Card.Suit.BLUE, Card.Suit.GREEN, Card.Suit.RED, Card.Suit.YELLOW}; Card.Suit[] suits;
if (werewolf) {
suits = new Card.Suit[]{Card.Suit.BLUE, Card.Suit.GREEN, Card.Suit.RED, Card.Suit.YELLOW, Card.Suit.NONE};
} else {
suits = new Card.Suit[]{Card.Suit.BLUE, Card.Suit.GREEN, Card.Suit.RED, Card.Suit.YELLOW};
}
transition(game, suits[game.getRandom().nextInt(suits.length)]); transition(game, suits[game.getRandom().nextInt(suits.length)]);
} }
@ -72,8 +77,10 @@ public final class DeterminingTrump extends RoundState {
} }
private void checkTrumpSuit(Card.Suit suit) { private void checkTrumpSuit(Card.Suit suit) {
if (suit == Card.Suit.NONE) { if (!werewolf && suit == Card.Suit.NONE) {
throw new IllegalArgumentException("Trump suit must not be " + Card.Suit.NONE + "."); throw new IllegalArgumentException("Trump suit must not be " + Card.Suit.NONE + ".");
} else if (suit == null) {
throw new IllegalArgumentException("Trump suit must not be null.");
} }
} }

@ -33,6 +33,9 @@ public final class PlayingCard extends TrickState {
@Override @Override
public void onMessage(Game game, UUID player, PlayerMessage message) { public void onMessage(Game game, UUID player, PlayerMessage message) {
if (get(CURRENT_PLAYER).equals(player) && message instanceof PlayCardMessage cardMessage) { if (get(CURRENT_PLAYER).equals(player) && message instanceof PlayCardMessage cardMessage) {
if (cardMessage.getCard() == null) {
throw new IllegalArgumentException("Card must not be null.");
}
transition(game, cardMessage.getCard()); transition(game, cardMessage.getCard());
} else { } else {
super.onMessage(game, player, message); super.onMessage(game, player, message);

@ -57,7 +57,7 @@ public class CardUtils {
} else if (card instanceof ColoredCard coloredCard) { } else if (card instanceof ColoredCard coloredCard) {
if (coloredCard.getSuit() == trumpSuit) { if (coloredCard.getSuit() == trumpSuit) {
return 200 + coloredCard.getValue(); return 200 + coloredCard.getValue();
} else if (coloredCard.getSuit() == suit) { } else if (coloredCard.getSuit() == suit) {
return 100 + coloredCard.getValue(); return 100 + coloredCard.getValue();
} else { } else {
return coloredCard.getValue(); return coloredCard.getValue();

Loading…
Cancel
Save