diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/EntityManager.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/EntityManager.java index 067a9ce..c4422dc 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/EntityManager.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/EntityManager.java @@ -84,6 +84,19 @@ public class EntityManager { return entities.remove(entity); } + /** + * Removes an entity from the list. + * @param entityid The {@link EntityID} of the {@link Entity} to remove + */ + public boolean removeEntity(EntityID entityid) { + Entity entity = findEntity(entityid); + if(entity != null) { + return entities.remove(entity); + }else { + return false; + } + } + /** * Finds an entity with an {@link EntityID}. * @param id The id to search for diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java index 3ef2a4c..c88a035 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java @@ -431,7 +431,33 @@ class GameLogic { * @param event The event to apply */ public static void applyEvent(GameState state, Event event) { - //TODO: implement GameLogic.applyEvent + switch(event.type) { + case DestroyedEntityEvent -> { + state.entities.removeEntity(((EntityEvent)event).targetEntity); + } + case TakenDamageEvent -> { + ((Character)state.entities.findEntity(((CharacterEvent)event).targetEntity)).hp.decreaseValue(((CharacterEvent)event).amount); + } + case ConsumedAPEvent -> { + ((Character)state.entities.findEntity(((CharacterEvent)event).targetEntity)).ap.decreaseValue(((CharacterEvent)event).amount); + } + case ConsumedMPEvent -> { + ((Character)state.entities.findEntity(((CharacterEvent)event).targetEntity)).mp.decreaseValue(((CharacterEvent)event).amount); + } + case SpawnEntityEvent -> { + state.entities.addEntity(((EntityEvent)event).entity); + } + case HealedEvent -> { + ((Character)state.entities.findEntity(((CharacterEvent)event).targetEntity)).hp.increaseValue(((CharacterEvent)event).amount); + } + case MoveEvent -> { + (state.entities.findEntity(((CharacterEvent)event).originEntity)).setPosition(((CharacterEvent)event).targetField); + } + case ExchangeInfinityStoneEvent -> { + ((Character)state.entities.findEntity(((CharacterEvent)event).originEntity)).inventory.removeStone(((CharacterEvent)event).stoneType); + ((Character)state.entities.findEntity(((CharacterEvent)event).targetEntity)).inventory.addStone(((CharacterEvent)event).stoneType); + } + } } /**