diff --git a/.idea/misc.xml b/.idea/misc.xml
index 9a2ce5e..d683bfb 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,5 +1,5 @@
-
+
\ No newline at end of file
diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/EntityID.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/EntityID.java
index e1b38ca..a855563 100644
--- a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/EntityID.java
+++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/EntityID.java
@@ -29,17 +29,6 @@ public class EntityID {
return type == other;
}
- @Override
- public boolean equals(Object obj){
- if(this == obj) return true;
-
- if(!(obj instanceof EntityID)) return false;
-
- EntityID other = (EntityID)obj;
-
- return this.id == other.id && this.type == other.type;
- }
-
/**
* Clones this entity id.
* @return The cloned {@link EntityID}
diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/events/EventBuilder.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/events/EventBuilder.java
index fff5c60..564abaf 100644
--- a/src/main/java/uulm/teamname/marvelous/gamelibrary/events/EventBuilder.java
+++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/events/EventBuilder.java
@@ -21,6 +21,7 @@ public class EventBuilder {
private EntityID targetEntity;
private IntVector2 targetField;
private Integer amount;
+ private Entity entity;
// Keys used primarily in CharacterEvents
private EntityID originEntity;
@@ -28,21 +29,21 @@ public class EventBuilder {
private StoneType stoneType;
// Keys used primarily in GameEvents
- private int roundCount;
- private int turnCount;
+ private Integer roundCount = null;
+ private Integer turnCount = null;
private EntityID[] characterOrder;
private EntityID nextCharacter;
- private int playerWon;
+ private Integer playerWon;
private String message;
- private int timeLeft;
+ private Integer timeLeft;
// Keys used primarily in GamestateEvents
private Entity[] entities;
private EntityID[] turnOrder;
private EntityID activeCharacter;
- private boolean winCondition;
+ private Boolean winCondition;
// Keys used in CustomEvents
private String teamIdentifier;
@@ -78,6 +79,12 @@ public class EventBuilder {
return this;
}
+
+ public EventBuilder withEntity(Entity entity) {
+ this.entity = entity;
+ return this;
+ }
+
public EventBuilder withOriginEntity(EntityID originEntity) {
this.originEntity = originEntity;
return this;
@@ -159,7 +166,7 @@ public class EventBuilder {
}
/**
- * Builds a {@link GameEvent} from the values given to the builder
+ * Builds a generic {@link GameEvent} from the values given to the builder
*
* - type is the {@link EventType} of the {@link GameEvent}.
* - roundCount describes the count of rounds in the RoundSetupEvent
@@ -172,7 +179,7 @@ public class EventBuilder {
*
* @return a {@link GameEvent} based on the builder. Caution: non-given fields are null!
*/
- public GameEvent buildGameEvent() {
+ public GameEvent buildGenericGameEvent() {
var gameEvent = new GameEvent();
gameEvent.type = this.type;
gameEvent.roundCount = this.roundCount;
@@ -188,7 +195,7 @@ public class EventBuilder {
}
/**
- * Builds an {@link EntityEvent} from the values given to the builder.
+ * Builds a generic {@link EntityEvent} from the values given to the builder.
*
* - type is the {@link EventType} of the EntityEvent
* - targetEntity is the target {@link Entity}
@@ -197,17 +204,18 @@ public class EventBuilder {
*
* @return a {@link EntityEvent} based on the builder. Caution: non-given fields are null!
*/
- public EntityEvent buildEntityEvent() {
+ public EntityEvent buildGenericEntityEvent() {
var entityEvent = new EntityEvent();
entityEvent.type = this.type;
entityEvent.targetEntity = this.targetEntity;
entityEvent.targetField = this.targetField;
entityEvent.amount = this.amount;
+ entityEvent.entity = this.entity;
return entityEvent;
}
/**
- * Builds a {@link CharacterEvent} from the values given to the builder.
+ * Builds a generic {@link CharacterEvent} from the values given to the builder.
*
* - type is the {@link EventType} of the EntityEvent
* - originEntity is the origin {@link Entity}
@@ -217,7 +225,7 @@ public class EventBuilder {
*
* @return a {@link CharacterEvent} based on the builder. Caution: non-given fields are null!
*/
- public CharacterEvent buildCharacterEvent() {
+ public CharacterEvent buildGenericCharacterEvent() {
var characterEvent = new CharacterEvent();
characterEvent.type = this.type;
characterEvent.originEntity = this.originEntity;
@@ -230,7 +238,7 @@ public class EventBuilder {
}
/**
- * Builds a {@link GameStateEvent} from the values given to the builder.
+ * Builds a generic {@link GameStateEvent} from the values given to the builder.
*
* - type is the {@link EventType} of the {@link GameStateEvent}
* - entities is an array of {@link Entity Entities}
@@ -240,7 +248,7 @@ public class EventBuilder {
*
* @return a {@link GameStateEvent} based on the builder. Caution: non-given fields are null!
*/
- public GameStateEvent buildGamestateEvent() {
+ public GameStateEvent buildGenericGameStateEvent() {
var gamestateEvent = new GameStateEvent();
gamestateEvent.type = this.type;
gamestateEvent.entities = this.entities;
@@ -258,12 +266,351 @@ public class EventBuilder {
*
* @return a {@link CustomEvent} based on the builder. Caution: non-given fields are null!
*/
- public CustomEvent buildCustomEvent() {
+ public CustomEvent buildGenericCustomEvent() {
var customEvent = new CustomEvent();
customEvent.type = this.type;
customEvent.teamIdentifier = this.teamIdentifier;
customEvent.customContent = this.customContent;
return customEvent;
}
+
+ /** Builds a new Ack {@link GameStateEvent}. Can have a no declared type. */
+ public GameStateEvent buildAckEvent() throws IllegalStateException {
+ if (this.type == null || this.type != EventType.Ack) throw new IllegalStateException("EventType was not Ack");
+ var ackEvent = new GameStateEvent();
+ ackEvent.type = EventType.Ack;
+ return ackEvent;
+ }
+
+ /** Builds a new Nack {@link GameStateEvent}. Can have no declared type. */
+ public GameStateEvent buildNackEvent() throws IllegalStateException {
+ if (this.type == null || this.type != EventType.Nack) throw new IllegalStateException("EventType was not Ack");
+ var nackEvent = new GameStateEvent();
+ nackEvent.type = EventType.Nack;
+ return nackEvent;
+ }
+
+ /** Builds a new Req {@link GameStateEvent}. Can have no declared type. */
+ public GameStateEvent buildReqEvent() throws IllegalStateException {
+ if (this.type == null || this.type != EventType.Req) throw new IllegalStateException("EventType was not Req");
+ var reqEvent = new GameStateEvent();
+ reqEvent.type = EventType.Req;
+ return reqEvent;
+ }
+
+ /**
+ * Builds a new {@link GameStateEvent}.
+ * This event needs the fields entities, turnOrder, activeCharacter and winCondition.
+ */
+ public GameStateEvent buildGameStateEvent() throws IllegalStateException {
+ if (this.type == null || this.type != EventType.GameStateEvent ||
+ this.entities == null ||
+ this.turnOrder == null ||
+ this.activeCharacter == null ||
+ this.winCondition == null
+ ) {
+ throw new IllegalStateException("Properties malformed for GameStateEvent");
+ }
+ var gameStateEvent = new GameStateEvent();
+ gameStateEvent.type = EventType.GameStateEvent;
+ gameStateEvent.entities = this.entities;
+ gameStateEvent.turnOrder = this.turnOrder;
+ gameStateEvent.activeCharacter = this.activeCharacter;
+ gameStateEvent.winCondition = this.winCondition;
+
+ return gameStateEvent;
+ }
+
+
+ /**
+ * Builds a new {@link CustomEvent}.
+ * This event needs the field customContent.
+ */
+ public CustomEvent buildCustomEvent() throws IllegalStateException {
+ if (this.type == null || this.type != EventType.CustomEvent ||
+ this.customContent == null
+ ) {
+ throw new IllegalStateException("Properties malformed for CustomEvent");
+ }
+ var customEvent = new CustomEvent();
+ customEvent.type = EventType.CustomEvent;
+ customEvent.customContent = this.customContent;
+
+ return customEvent;
+ }
+
+ /**
+ * Builds a new {@link EntityEvent}.
+ * This event needs the fields targetField and targetEntity.
+ */
+ public EntityEvent buildDestroyedEntityEvent() throws IllegalStateException {
+ if (this.type == null || this.type != EventType.DestroyedEntityEvent ||
+ this.targetField == null ||
+ this.targetEntity == null
+ ) {
+ throw new IllegalStateException("Properties malformed for DestroyedEntityEvent");
+ }
+ var destroyedEntityEvent = new EntityEvent();
+ destroyedEntityEvent.type = EventType.DestroyedEntityEvent;
+ destroyedEntityEvent.targetField = this.targetField;
+ destroyedEntityEvent.targetEntity = this.targetEntity;
+
+ return destroyedEntityEvent;
+ }
+
+ /**
+ * Builds a new {@link EntityEvent}.
+ * This event needs the fields targetField, targetEntity and amount.
+ */
+ public EntityEvent buildTakenDamageEvent() throws IllegalStateException {
+ if (this.type == null || this.type != EventType.TakenDamageEvent ||
+ this.targetField == null ||
+ this.targetEntity == null ||
+ this.amount == null
+ ) {
+ throw new IllegalStateException("Properties malformed for TakenDamageEvent");
+ }
+ var takenDamageEvent = new EntityEvent();
+ takenDamageEvent.type = EventType.TakenDamageEvent;
+ takenDamageEvent.targetField = this.targetField;
+ takenDamageEvent.targetEntity = this.targetEntity;
+ takenDamageEvent.amount = this.amount;
+
+ return takenDamageEvent;
+ }
+
+ /**
+ * Builds a new {@link EntityEvent}.
+ * This event needs the fields targetField, targetEntity and amount.
+ */
+ public EntityEvent buildConsumedAPEvent() throws IllegalStateException {
+ if (this.type == null || this.type != EventType.ConsumedAPEvent ||
+ this.targetField == null ||
+ this.targetEntity == null ||
+ this.amount == null
+ ) {
+ throw new IllegalStateException("Properties malformed for ConsumedAPEvent");
+ }
+ var consumedAPEvent = new EntityEvent();
+ consumedAPEvent.type = EventType.ConsumedAPEvent;
+ consumedAPEvent.targetField = this.targetField;
+ consumedAPEvent.targetEntity = this.targetEntity;
+ consumedAPEvent.amount = this.amount;
+
+ return consumedAPEvent;
+ }
+
+ /**
+ * Builds a new {@link EntityEvent}.
+ * This event needs the fields targetField, targetEntity and amount.
+ */
+ public EntityEvent buildConsumedMPEvent() throws IllegalStateException {
+ if (this.type == null || this.type != EventType.ConsumedMPEvent ||
+ this.targetField == null ||
+ this.targetEntity == null ||
+ this.amount == null
+ ) {
+ throw new IllegalStateException("Properties malformed for ConsumedMPEvent");
+ }
+ var consumedAPEvent = new EntityEvent();
+ consumedAPEvent.type = EventType.ConsumedMPEvent;
+ consumedAPEvent.targetField = this.targetField;
+ consumedAPEvent.targetEntity = this.targetEntity;
+ consumedAPEvent.amount = this.amount;
+
+ return consumedAPEvent;
+ }
+
+
+ /**
+ * Builds a new {@link EntityEvent}.
+ * This event needs the field entity.
+ */
+ public EntityEvent buildSpawnEntityEvent() throws IllegalStateException {
+ if (this.type == null || this.type != EventType.SpawnEntityEvent ||
+ this.targetField == null ||
+ this.targetEntity == null ||
+ this.amount == null
+ ) {
+ throw new IllegalStateException("Properties malformed for SpawnEntityEvent");
+ }
+ var spawnEntityEvent = new EntityEvent();
+ spawnEntityEvent.type = EventType.SpawnEntityEvent;
+ spawnEntityEvent.entity = this.entity;
+
+ return spawnEntityEvent;
+ }
+
+ /**
+ * Builds a new {@link EntityEvent}.
+ * This event needs the fields targetField, targetEntity and amount.
+ */
+ public EntityEvent buildHealedEvent() throws IllegalStateException {
+ if (this.type == null || this.type != EventType.HealedEvent ||
+ this.targetField == null ||
+ this.targetEntity == null ||
+ this.amount == null
+ ) {
+ throw new IllegalStateException("Properties malformed for HealedEvent");
+ }
+ var healedEvent = new EntityEvent();
+ healedEvent.type = EventType.HealedEvent;
+ healedEvent.targetField = this.targetField;
+ healedEvent.targetEntity = this.targetEntity;
+ healedEvent.amount = this.amount;
+
+ return healedEvent;
+ }
+
+
+
+
+ /**
+ * Builds a new {@link CharacterEvent}.
+ * This event needs the fields originField, targetField, originEntity and targetEntity.
+ */
+ public CharacterEvent buildMeleeAttackEvent() throws IllegalStateException {
+ if (this.type == null || this.type != EventType.MeleeAttackEvent ||
+ this.originField == null ||
+ this.targetField == null ||
+ this.originEntity == null ||
+ this.targetEntity == null
+ ) {
+ throw new IllegalStateException("Properties malformed for MeleeAttackEvent");
+ }
+ var meleeAttackEvent = new CharacterEvent();
+ meleeAttackEvent.type = EventType.MeleeAttackEvent;
+ meleeAttackEvent.originField = this.originField;
+ meleeAttackEvent.targetField = this.targetField;
+ meleeAttackEvent.originEntity = this.originEntity;
+ meleeAttackEvent.targetEntity = this.targetEntity;
+
+ return meleeAttackEvent;
+ }
+
+
+ /**
+ * Builds a new {@link CharacterEvent}.
+ * This event needs the fields originField, targetField, originEntity and targetEntity.
+ */
+ public CharacterEvent buildRangedAttackEvent() throws IllegalStateException {
+ if (this.type == null || this.type != EventType.RangedAttackEvent ||
+ this.originField == null ||
+ this.targetField == null ||
+ this.originEntity == null ||
+ this.targetEntity == null
+ ) {
+ throw new IllegalStateException("Properties malformed for RangedAttackEvent");
+ }
+ var rangedAttackEvent = new CharacterEvent();
+ rangedAttackEvent.type = EventType.RangedAttackEvent;
+ rangedAttackEvent.originField = this.originField;
+ rangedAttackEvent.targetField = this.targetField;
+ rangedAttackEvent.originEntity = this.originEntity;
+ rangedAttackEvent.targetEntity = this.targetEntity;
+
+ return rangedAttackEvent;
+ }
+
+
+ /**
+ * Builds a new {@link CharacterEvent}.
+ * This event needs the fields stoneType, originField, targetField, originEntity and targetEntity.
+ */
+ public CharacterEvent buildExchangeInfinityStoneEvent() throws IllegalStateException {
+ if (this.type == null || this.type != EventType.ExchangeInfinityStoneEvent ||
+ this.originField == null ||
+ this.targetField == null ||
+ this.originEntity == null ||
+ this.targetEntity == null ||
+ this.stoneType == null
+ ) {
+ throw new IllegalStateException("Properties malformed for ExchangeInfinityStoneEvent");
+ }
+ var exchangeInfinityStoneEvent = new CharacterEvent();
+ exchangeInfinityStoneEvent.type = EventType.ExchangeInfinityStoneEvent;
+ exchangeInfinityStoneEvent.originField = this.originField;
+ exchangeInfinityStoneEvent.targetField = this.targetField;
+ exchangeInfinityStoneEvent.originEntity = this.originEntity;
+ exchangeInfinityStoneEvent.targetEntity = this.targetEntity;
+
+ return exchangeInfinityStoneEvent;
+ }
+
+
+
+ /**
+ * Builds a new {@link CharacterEvent}.
+ * This event needs the fields originField, targetField and originEntity.
+ */
+ public CharacterEvent buildMoveEvent() throws IllegalStateException {
+ if (this.type == null || this.type != EventType.MoveEvent ||
+ this.originField == null ||
+ this.targetField == null ||
+ this.originEntity == null
+ ) {
+ throw new IllegalStateException("Properties malformed for MoveEvent");
+ }
+ var moveEvent = new CharacterEvent();
+ moveEvent.type = EventType.ExchangeInfinityStoneEvent;
+ moveEvent.originField = this.originField;
+ moveEvent.targetField = this.targetField;
+ moveEvent.originEntity = this.originEntity;
+
+ return moveEvent;
+ }
+
+
+ /**
+ * Builds a new {@link CharacterEvent}.
+ * This event needs the fields stoneType, originField, targetField, originEntity and targetEntity.
+ */
+ public CharacterEvent buildUseInfinityStoneEvent() throws IllegalStateException {
+ if (this.type == null || this.type != EventType.UseInfinityStoneEvent ||
+ this.originField == null ||
+ this.targetField == null ||
+ this.originEntity == null ||
+ this.targetEntity == null ||
+ this.stoneType == null
+ ) {
+ throw new IllegalStateException("Properties malformed for UseInfinityStoneEvent");
+ }
+ var useInfinityStoneEvent = new CharacterEvent();
+ useInfinityStoneEvent.type = EventType.UseInfinityStoneEvent;
+ useInfinityStoneEvent.originField = this.originField;
+ useInfinityStoneEvent.targetField = this.targetField;
+ useInfinityStoneEvent.originEntity = this.originEntity;
+ useInfinityStoneEvent.targetEntity = this.targetEntity;
+
+ return useInfinityStoneEvent;
+ }
+
+
+
+ /**
+ * Builds a new {@link GameEvent}.
+ * This event needs the fields roundCount and characterOrder.
+ */
+ public GameEvent buildRoundSetupEvent() throws IllegalStateException {
+ if (this.type == null || this.type != EventType.RoundSetupEvent ||
+ this.roundCount == null ||
+ this.characterOrder == null
+ ) {
+ throw new IllegalStateException("Properties malformed for RoundSetupEvent");
+ }
+ var roundSetupEvent = new GameEvent();
+ roundSetupEvent.type = EventType.UseInfinityStoneEvent;
+ roundSetupEvent.roundCount = this.roundCount;
+ roundSetupEvent.characterOrder = this.characterOrder;
+
+ return roundSetupEvent;
+ }
+
+
+
+
+
+
+
}
diff --git a/src/test/java/uulm/teamname/marvelous/gamelibrary/events/EventBuilderTest.java b/src/test/java/uulm/teamname/marvelous/gamelibrary/events/EventBuilderTest.java
new file mode 100644
index 0000000..f138822
--- /dev/null
+++ b/src/test/java/uulm/teamname/marvelous/gamelibrary/events/EventBuilderTest.java
@@ -0,0 +1,77 @@
+package uulm.teamname.marvelous.gamelibrary.events;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import static org.assertj.core.api.Assertions.*;
+import uulm.teamname.marvelous.gamelibrary.IntVector2;
+import uulm.teamname.marvelous.gamelibrary.entities.*;
+
+import java.util.HashMap;
+
+import static org.mockito.Mockito.*;
+import static org.junit.jupiter.api.Assertions.*;
+
+class EventBuilderTest {
+
+ @BeforeEach
+ void setUp() {
+ EventBuilder builder = new EventBuilder()
+ .withType(EventType.CustomEvent)
+ .withTargetEntity(new EntityID(EntityType.P1, 1))
+ .withTargetField(new IntVector2(11, 13))
+ .withAmount(15)
+ .withOriginEntity(new EntityID(EntityType.P2, 4))
+ .withOriginField(new IntVector2(15, 3))
+ .withStoneType(StoneType.MindStone)
+ .withRoundCount(3)
+ .withTurnCount(4)
+ .withCharacterOrder(new EntityID[] {
+ new EntityID(EntityType.P1, 4),
+ new EntityID(EntityType.P1, 1),
+ new EntityID(EntityType.P2, 2),
+ new EntityID(EntityType.P2, 4),
+ new EntityID(EntityType.P1, 3),
+ new EntityID(EntityType.P2, 5),})
+ .withNextCharacter(new EntityID(EntityType.P2, 2))
+ .withPlayerWon(2)
+ .withMessage("Some message")
+ .withTimeLeft(11)
+ .withEntities(new Entity[] {})
+ .withTurnOrder(new EntityID[] {
+ new EntityID(EntityType.P1, 4),
+ new EntityID(EntityType.P1, 1),
+ new EntityID(EntityType.P2, 2),
+ new EntityID(EntityType.P2, 4),
+ new EntityID(EntityType.P1, 3),
+ new EntityID(EntityType.P2, 5),})
+ .withActiveCharacter(new EntityID(EntityType.P1, 1))
+ .withWinCondition(false)
+ .withTeamIdentifier("Team25")
+ .withCustomContent(new HashMap<>());
+ }
+
+ @Test
+ void buildGameEvent() {
+ var gameEvent = new EventBuilder()
+ .withType(EventType.DisconnectEvent)
+ .buildEntityEvent();
+
+ assertThat(gameEvent).isEqualTo()
+ }
+
+ @Test
+ void buildEntityEvent() {
+ }
+
+ @Test
+ void buildCharacterEvent() {
+ }
+
+ @Test
+ void buildGamestateEvent() {
+ }
+
+ @Test
+ void buildCustomEvent() {
+ }
+}
\ No newline at end of file