2021-05-01 20:30:52 +00:00
|
|
|
package uulm.teamname.marvelous.gamelibrary.events;
|
|
|
|
|
2021-06-03 20:58:25 +00:00
|
|
|
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
|
|
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
2021-05-05 15:32:18 +00:00
|
|
|
import uulm.teamname.marvelous.gamelibrary.IntVector2;
|
2021-05-01 20:30:52 +00:00
|
|
|
import uulm.teamname.marvelous.gamelibrary.entities.Entity;
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.entities.EntityID;
|
2021-06-03 20:58:25 +00:00
|
|
|
import uulm.teamname.marvelous.gamelibrary.json.ingame.deserialize.EventDeserializer;
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.json.ingame.serialize.EventSerializer;
|
2021-05-01 20:30:52 +00:00
|
|
|
|
2021-05-01 22:03:09 +00:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Objects;
|
|
|
|
|
2021-05-11 03:06:00 +00:00
|
|
|
/** Represents the game state event ({@link EventType#GamestateEvent}). */
|
2021-06-03 20:58:25 +00:00
|
|
|
@JsonDeserialize(using = EventDeserializer.class)
|
|
|
|
@JsonSerialize(using = EventSerializer.class)
|
2021-05-11 03:06:00 +00:00
|
|
|
public class GamestateEvent extends Event {
|
2021-05-01 21:19:36 +00:00
|
|
|
public Entity[] entities;
|
2021-05-01 20:30:52 +00:00
|
|
|
public EntityID[] turnOrder;
|
2021-05-05 16:58:39 +00:00
|
|
|
public IntVector2 mapSize;
|
2021-05-01 20:30:52 +00:00
|
|
|
public EntityID activeCharacter;
|
2021-05-05 16:58:39 +00:00
|
|
|
public Integer[] stoneCooldowns;
|
2021-05-02 01:15:20 +00:00
|
|
|
public Boolean winCondition;
|
2021-05-01 22:03:09 +00:00
|
|
|
|
2021-05-03 17:25:36 +00:00
|
|
|
@Override
|
|
|
|
public boolean check() {
|
|
|
|
if(!super.check()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(type) {
|
|
|
|
// GameState needs very specific properties
|
2021-05-11 03:06:00 +00:00
|
|
|
case GamestateEvent:
|
2021-05-03 17:25:36 +00:00
|
|
|
if (this.entities == null ||
|
|
|
|
this.turnOrder == null ||
|
2021-05-05 15:32:18 +00:00
|
|
|
this.mapSize == null ||
|
2021-05-03 17:25:36 +00:00
|
|
|
this.activeCharacter == null ||
|
2021-05-05 15:32:18 +00:00
|
|
|
this.stoneCooldowns == null ||
|
2021-05-03 17:25:36 +00:00
|
|
|
this.winCondition == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-05-01 22:03:09 +00:00
|
|
|
@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;
|
2021-05-11 03:06:00 +00:00
|
|
|
GamestateEvent that = (GamestateEvent) o;
|
2021-05-05 15:32:18 +00:00
|
|
|
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);
|
2021-05-01 22:03:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
2021-05-05 15:32:18 +00:00
|
|
|
int result = Objects.hash(super.hashCode(), mapSize, activeCharacter, winCondition);
|
2021-05-01 22:03:09 +00:00
|
|
|
result = 31 * result + Arrays.hashCode(entities);
|
|
|
|
result = 31 * result + Arrays.hashCode(turnOrder);
|
2021-05-05 15:32:18 +00:00
|
|
|
result = 31 * result + Arrays.hashCode(stoneCooldowns);
|
2021-05-01 22:03:09 +00:00
|
|
|
return result;
|
|
|
|
}
|
2021-05-11 04:11:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "GamestateEvent{" +
|
2021-05-13 12:21:32 +00:00
|
|
|
"eventType=" + this.type +
|
|
|
|
", entities=" + Arrays.toString(entities) +
|
2021-05-11 04:11:01 +00:00
|
|
|
", turnOrder=" + Arrays.toString(turnOrder) +
|
|
|
|
", mapSize=" + mapSize +
|
|
|
|
", activeCharacter=" + activeCharacter +
|
|
|
|
", stoneCooldowns=" + Arrays.toString(stoneCooldowns) +
|
|
|
|
", winCondition=" + winCondition +
|
|
|
|
'}';
|
|
|
|
}
|
2021-05-01 20:30:52 +00:00
|
|
|
}
|