Gamelib/src/main/java/uulm/teamname/marvelous/gamelibrary/events/GamestateEvent.java

80 lines
3.0 KiB
Java

package uulm.teamname.marvelous.gamelibrary.events;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import uulm.teamname.marvelous.gamelibrary.IntVector2;
import uulm.teamname.marvelous.gamelibrary.entities.Entity;
import uulm.teamname.marvelous.gamelibrary.entities.EntityID;
import uulm.teamname.marvelous.gamelibrary.json.ingame.deserialize.EventDeserializer;
import uulm.teamname.marvelous.gamelibrary.json.ingame.serialize.EventSerializer;
import java.util.Arrays;
import java.util.Objects;
/** Represents the game state event ({@link EventType#GamestateEvent}). */
@JsonDeserialize(using = EventDeserializer.class)
@JsonSerialize(using = EventSerializer.class)
public class GamestateEvent extends Event {
public Entity[] entities;
public EntityID[] turnOrder;
public IntVector2 mapSize;
public EntityID activeCharacter;
public Integer[] stoneCooldowns;
public Boolean winCondition;
@Override
public boolean check() {
if(!super.check()) {
return false;
}
switch(type) {
// GameState needs very specific properties
case GamestateEvent:
if (this.entities == null ||
this.turnOrder == null ||
this.mapSize == null ||
this.activeCharacter == null ||
this.stoneCooldowns == null ||
this.winCondition == null) {
return false;
}
break;
}
return true;
}
@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;
GamestateEvent that = (GamestateEvent) o;
return Arrays.equals(entities, that.entities) && Arrays.equals(turnOrder, that.turnOrder) && Objects.equals(mapSize, that.mapSize) && Objects.equals(activeCharacter, that.activeCharacter) && Arrays.equals(stoneCooldowns, that.stoneCooldowns) && Objects.equals(winCondition, that.winCondition);
}
@Override
public int hashCode() {
int result = Objects.hash(super.hashCode(), mapSize, activeCharacter, winCondition);
result = 31 * result + Arrays.hashCode(entities);
result = 31 * result + Arrays.hashCode(turnOrder);
result = 31 * result + Arrays.hashCode(stoneCooldowns);
return result;
}
@Override
public String toString() {
return "GamestateEvent{" +
"eventType=" + this.type +
", entities=" + Arrays.toString(entities) +
", turnOrder=" + Arrays.toString(turnOrder) +
", mapSize=" + mapSize +
", activeCharacter=" + activeCharacter +
", stoneCooldowns=" + Arrays.toString(stoneCooldowns) +
", winCondition=" + winCondition +
'}';
}
}