Gamelib/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/GameStructureMessage.java

79 lines
3.3 KiB
Java
Raw Normal View History

2021-06-03 14:12:21 +00:00
package uulm.teamname.marvelous.gamelibrary.messages;
import com.fasterxml.jackson.annotation.JsonIgnore;
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;
2021-06-03 14:12:21 +00:00
import java.util.stream.Stream;
public class GameStructureMessage extends BasicMessage {
public final MessageType messageType = MessageType.GAME_STRUCTURE;
/** The role the client has been assigned to */
public Assignment assignment;
2021-06-03 14:12:21 +00:00
/** The name of the first player */
public String playerOneName;
2021-06-03 14:12:21 +00:00
/** The name of the second player */
public String playerTwoName;
2021-06-03 14:12:21 +00:00
/** The characters that the first player has chosen (and is therefore playing with in this match) */
public CharacterProperties[] playerOneCharacters;
2021-06-03 14:12:21 +00:00
/** The characters that the second player has chosen (and is therefore playing with in this match) */
public CharacterProperties[] playerTwoCharacters;
2021-06-03 14:12:21 +00:00
/** The {@link PartyConfig Party Configuration} of the current match */
public PartyConfig matchconfig;
2021-06-03 14:12:21 +00:00
/** The {@link ScenarioConfig Scenario Configuration} of the current scenario */
public ScenarioConfig scenarioconfig;
2021-06-03 14:12:21 +00:00
@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 +
'}';
}
2021-06-03 14:12:21 +00:00
}