From 05f4751a2cf5becb94e46be26b6ef731bdbe7b89 Mon Sep 17 00:00:00 2001 From: punchready Date: Sun, 2 May 2021 14:38:03 +0200 Subject: [PATCH] feat: properly handle movement requests --- .../gamelibrary/gamelogic/GameLogic.java | 19 ++++++++++++++++--- .../gamelogic/GameStateManager.java | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) 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 f8b239b..3ac0ee9 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java @@ -13,12 +13,15 @@ import java.util.ArrayList; /** Contains game logic handling. */ class GameLogic { /** - * Produces resulting {@link Event}s from a given {@link Request} independently of any {@link GameState}. + * Produces resulting {@link Event}s from a given {@link Request}. + * @param state The game state to execute on + * @param request The request to execute * @return The list of resulting events */ - public static ArrayList executeRequest(Request request) { + public static ArrayList executeRequest(GameState state, Request request) { ArrayList result = new ArrayList<>(); + //TODO: refactor for EventBuilder in GameLogic.executeRequest switch(request.type) { case MeleeAttackRequest, RangedAttackRequest -> { CharacterRequest data = (CharacterRequest)request; @@ -52,7 +55,16 @@ class GameLogic { .setTargetField(data.targetField) //when this event gets handled, the character already moved to the target field .setAmount(1) .type(EventType.ConsumedMPEvent)); - //TODO: execute character swap in GameLogic.executeRequest + for(Entity entity: state.entities.findByPosition(data.targetField)) { + if(entity instanceof Character) { + result.add(new CharacterEvent() + .setOriginEntity(entity.id) + .setOriginField(data.targetField) + .setTargetField(data.originField) + .type(EventType.MoveEvent)); + break; //we should only have one character per field anyways + } + } } case ExchangeInfinityStoneRequest, UseInfinityStoneRequest -> { CharacterRequest data = (CharacterRequest)request; @@ -68,6 +80,7 @@ class GameLogic { .setTargetField(data.originField) .setAmount(1) .type(EventType.ConsumedAPEvent)); + //TODO: add infinity stone use effect in GameLogic.executeRequest } case DisconnectRequest -> { diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameStateManager.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameStateManager.java index ec6984b..5738627 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameStateManager.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameStateManager.java @@ -32,7 +32,7 @@ class GameStateManager { for(Request request: requests) { if (GameLogic.checkRequest(snapshot, request)) { - ArrayList result = GameLogic.executeRequest(request); + ArrayList result = GameLogic.executeRequest(snapshot, request); if(apply) { queue.addAll(result); }