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

60 lines
2.1 KiB
Java
Raw Normal View History

package uulm.teamname.marvelous.gamelibrary.events;
import uulm.teamname.marvelous.gamelibrary.IntVector2;
import uulm.teamname.marvelous.gamelibrary.entities.Entity;
import uulm.teamname.marvelous.gamelibrary.entities.EntityID;
import java.util.Arrays;
import java.util.Objects;
/** Represents the game state event ({@link EventType#GamestateEvent}). */
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;
}
}