feat: reworked GamestateEvent according to new standard

This commit is contained in:
Yannik Bretschneider 2021-05-05 17:32:18 +02:00
parent 9405b89fb3
commit 3038368ad8

View File

@ -1,5 +1,6 @@
package uulm.teamname.marvelous.gamelibrary.events; 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.Entity;
import uulm.teamname.marvelous.gamelibrary.entities.EntityID; import uulm.teamname.marvelous.gamelibrary.entities.EntityID;
@ -10,7 +11,9 @@ import java.util.Objects;
public class GameStateEvent extends Event { public class GameStateEvent extends Event {
public Entity[] entities; public Entity[] entities;
public EntityID[] turnOrder; public EntityID[] turnOrder;
public IntVector2 mapSize; // Stores the map size, for example for a 10x15 map [9,14] (starting from 0)
public EntityID activeCharacter; public EntityID activeCharacter;
public Integer[] stoneCooldowns; // Int[6]
public Boolean winCondition; public Boolean winCondition;
@Override @Override
@ -24,7 +27,9 @@ public class GameStateEvent extends Event {
case GameStateEvent: case GameStateEvent:
if (this.entities == null || if (this.entities == null ||
this.turnOrder == null || this.turnOrder == null ||
this.mapSize == null ||
this.activeCharacter == null || this.activeCharacter == null ||
this.stoneCooldowns == null ||
this.winCondition == null) { this.winCondition == null) {
return false; return false;
} }
@ -40,14 +45,15 @@ public class GameStateEvent extends Event {
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false; if (!super.equals(o)) return false;
GameStateEvent that = (GameStateEvent) o; GameStateEvent that = (GameStateEvent) o;
return winCondition == that.winCondition && Arrays.equals(entities, that.entities) && Arrays.equals(turnOrder, that.turnOrder) && Objects.equals(activeCharacter, that.activeCharacter); 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 @Override
public int hashCode() { public int hashCode() {
int result = Objects.hash(super.hashCode(), activeCharacter, winCondition); int result = Objects.hash(super.hashCode(), mapSize, activeCharacter, winCondition);
result = 31 * result + Arrays.hashCode(entities); result = 31 * result + Arrays.hashCode(entities);
result = 31 * result + Arrays.hashCode(turnOrder); result = 31 * result + Arrays.hashCode(turnOrder);
result = 31 * result + Arrays.hashCode(stoneCooldowns);
return result; return result;
} }
} }