package uulm.teamname.marvelous.gamelibrary.messages; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import uulm.teamname.marvelous.gamelibrary.config.CharacterConfig; import uulm.teamname.marvelous.gamelibrary.config.CharacterProperties; import uulm.teamname.marvelous.gamelibrary.config.PartyConfig; import uulm.teamname.marvelous.gamelibrary.config.ScenarioConfig; import java.util.Arrays; import java.util.Objects; import java.util.stream.Stream; @JsonPropertyOrder({ "messageType", "assignment", "playerOneName", "playerTwoName", "playerOneCharacters", "playerTwoCharacters", "scenarioconfig", "matchconfig"}) public class GameStructureMessage extends BasicMessage { public final MessageType messageType = MessageType.GAME_STRUCTURE; /** The role the client has been assigned to */ public Assignment assignment; /** The name of the first player */ public String playerOneName; /** The name of the second player */ public String playerTwoName; /** The characters that the first player has chosen (and is therefore playing with in this match) */ public CharacterProperties[] playerOneCharacters; /** The characters that the second player has chosen (and is therefore playing with in this match) */ public CharacterProperties[] playerTwoCharacters; /** The {@link PartyConfig Party Configuration} of the current match */ public PartyConfig matchconfig; /** The {@link ScenarioConfig Scenario Configuration} of the current scenario */ public ScenarioConfig scenarioconfig; @JsonIgnore public CharacterConfig getCharacterConfig() { CharacterConfig characterConfig = new CharacterConfig(); characterConfig.characters = Stream .concat(Arrays.stream(playerOneCharacters), Arrays.stream(playerTwoCharacters)) .toArray(CharacterProperties[]::new); return characterConfig; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; if (!super.equals(o)) return false; GameStructureMessage that = (GameStructureMessage) o; return Objects.equals(assignment, that.assignment) && Objects.equals(playerOneName, that.playerOneName) && Objects.equals(playerTwoName, that.playerTwoName) && Arrays.equals(playerOneCharacters, that.playerOneCharacters) && Arrays.equals(playerTwoCharacters, that.playerTwoCharacters) && Objects.equals(matchconfig, that.matchconfig) && Objects.equals(scenarioconfig, that.scenarioconfig); } @Override public int hashCode() { int result = Objects.hash(super.hashCode(), assignment, playerOneName, playerTwoName, matchconfig, scenarioconfig); result = 31 * result + Arrays.hashCode(playerOneCharacters); result = 31 * result + Arrays.hashCode(playerTwoCharacters); return result; } @Override public String toString() { return "GameStructureMessage{" + "messageType=" + messageType + ", optionals='" + optionals + '\'' + ", assignment='" + assignment + '\'' + ", playerOneName='" + playerOneName + '\'' + ", playerTwoName='" + playerTwoName + '\'' + ", playerOneCharacters=" + Arrays.toString(playerOneCharacters) + ", playerTwoCharacters=" + Arrays.toString(playerTwoCharacters) + ", matchconfig=" + matchconfig + ", scenarioconfig=" + scenarioconfig + '}'; } }