feat: implement GameLogic.applyEvent
This commit is contained in:
parent
729a1d4a71
commit
b00ba50f97
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user