feat: handle Req request and remove handling of lobby events
This commit is contained in:
		| @ -120,4 +120,12 @@ public class EntityManager { | |||||||
|     public Iterator<Entity> getEntities() { |     public Iterator<Entity> getEntities() { | ||||||
|         return entities.iterator(); |         return entities.iterator(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Exports all entities as an array. | ||||||
|  |      * @return An array containing every {@link Entity} | ||||||
|  |      */ | ||||||
|  |     public Entity[] export() { | ||||||
|  |         return (Entity[])entities.toArray(); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -88,9 +88,15 @@ class GameLogic { | |||||||
|                         .buildEntityEvent()); |                         .buildEntityEvent()); | ||||||
|                 //TODO: add infinity stone usage effect in GameLogic.executeRequest |                 //TODO: add infinity stone usage effect in GameLogic.executeRequest | ||||||
|             } |             } | ||||||
|             case DisconnectRequest -> { |             case Req -> { | ||||||
|                 result.add(new EventBuilder(EventType.DisconnectEvent) |                 result.add(new EventBuilder(EventType.GameStateEvent) | ||||||
|                         .buildGameEvent()); |                         .withEntities(state.entities.export()) | ||||||
|  |                         .withTurnOrder((EntityID[])state.turnOrder.toArray()) | ||||||
|  |                         .withMapSize(state.mapSize) | ||||||
|  |                         .withActiveCharacter(state.activeCharacter) | ||||||
|  |                         .withStoneCooldowns(state.stoneCooldown.export()) | ||||||
|  |                         .withWinCondition(state.won) | ||||||
|  |                         .buildGameStateEvent()); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @ -182,11 +188,8 @@ class GameLogic { | |||||||
|                     } |                     } | ||||||
|  |  | ||||||
|                     return true; |                     return true; | ||||||
|  |  | ||||||
|                 } |                 } | ||||||
|                 case DisconnectRequest -> { |                 case Req -> { | ||||||
|                     //TODO: add check for DisconnectRequest in GameLogic.checkRequest |  | ||||||
|  |  | ||||||
|                     return true; |                     return true; | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  | |||||||
| @ -1,5 +1,6 @@ | |||||||
| package uulm.teamname.marvelous.gamelibrary.gamelogic; | package uulm.teamname.marvelous.gamelibrary.gamelogic; | ||||||
|  |  | ||||||
|  | import uulm.teamname.marvelous.gamelibrary.entities.Entity; | ||||||
| import uulm.teamname.marvelous.gamelibrary.entities.StoneType; | import uulm.teamname.marvelous.gamelibrary.entities.StoneType; | ||||||
|  |  | ||||||
| import java.util.HashMap; | import java.util.HashMap; | ||||||
| @ -51,4 +52,17 @@ public class StoneCooldownManager { | |||||||
|     public void setCooldown(StoneType stone, int duration) { |     public void setCooldown(StoneType stone, int duration) { | ||||||
|         cooldowns.put(stone, Math.max(0, duration)); |         cooldowns.put(stone, Math.max(0, duration)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Exports the cooldowns as an array ordered according to the enum. | ||||||
|  |      * @return An array containing every cooldown | ||||||
|  |      */ | ||||||
|  |     public Integer[] export() { | ||||||
|  |         Integer[] data = new Integer[6]; | ||||||
|  |         int i = 0; | ||||||
|  |         for (StoneType stone: StoneType.values()) { | ||||||
|  |             data[i++] = cooldowns.getOrDefault(stone, 0); | ||||||
|  |         } | ||||||
|  |         return data; | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user