feat: implement GameLogic.applyEvent

This commit is contained in:
punchready 2021-05-18 13:55:36 +02:00
parent 729a1d4a71
commit b00ba50f97
2 changed files with 40 additions and 1 deletions

View File

@ -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

View File

@ -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);
}
}
}
/**