diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/StoneType.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/StoneType.java index 909f4f0..f3c042d 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/StoneType.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/StoneType.java @@ -13,20 +13,19 @@ public enum StoneType { SoulStone(5); private final int id; - private final static HashMap map; + private final static HashMap map = new HashMap<>(); - private StoneType(int id) { + StoneType(int id) { this.id = id; } static { - map = new HashMap<>(); - for (StoneType stoneType : StoneType.values()) { + for (StoneType stoneType: StoneType.values()) { map.put(stoneType.id, stoneType); } } - public static StoneType valueOf (int stoneType) { + public static StoneType valueOf(int stoneType) { return map.get(stoneType); } 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 5e2a525..3ef2a4c 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java @@ -94,7 +94,24 @@ class GameLogic { .buildCharacterEvent()); } case MindStone -> { - //TODO: mind stone effect ??????? + EntityType target = data.originEntity.type == EntityType.P1 ? EntityType.P2 : EntityType.P1; + Line2D line = new Line2D.Float(data.originField.getX(), data.originField.getY(), data.targetField.getX(), data.targetField.getY()); + for(int i = data.originField.getX(); i <= data.targetField.getX(); i++) { + for(int j = data.originField.getY(); j <= data.targetField.getY(); j++) { + var cell = new Rectangle.Float(i - 0.5f, j - 0.5f, 1, 1); + if(line.intersects(cell)) { + for(Entity entity: state.entities.findByPosition(data.targetField)) { + if(entity.id.isSameType(target)) { + result.add(new EventBuilder(EventType.TakenDamageEvent) + .withTargetEntity(entity.id) + .withTargetField(new IntVector2(i, j)) + .withAmount(data.value) + .buildEntityEvent()); + } + } + } + } + } } case RealityStone -> { if(data.originEntity == data.targetEntity) { // => place stone @@ -266,7 +283,10 @@ class GameLogic { } } case MindStone -> { - //TODO: mind stone requirements (config, etc) ??????? + if(data.originField == data.targetField) { + throw new InvalidRequestException(); + } + //TODO: mind stone damage check (config) ??????? } case RealityStone -> { if(data.originEntity == data.targetEntity) { // => place stone