From 48409b1e4a3dab5115e5f04b272f40badf73530b Mon Sep 17 00:00:00 2001 From: punchready Date: Fri, 6 Aug 2021 15:57:05 +0200 Subject: [PATCH] fix: mind stone is apparently just a glorified ranged attack --- .../gamelibrary/gamelogic/GameLogic.java | 49 +++++++++++++------ 1 file changed, 35 insertions(+), 14 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 8b1a75f..ffabd7d 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java @@ -136,12 +136,7 @@ public class GameLogic { } } case MindStone -> { - if(data.originField == data.targetField) { - throw new InvalidRequestException("Invalid mind stone target field"); - } - if(data.value != state.partyConfig.mindStoneDMG) { - throw new InvalidRequestException("Invalid mind stone damage"); - } + requireLineOfSight(state, data.originField, data.targetField); } case RealityStone -> { // no check done @@ -454,17 +449,43 @@ public class GameLogic { .buildCharacterEvent()); } case MindStone -> { - EntityType target = data.originEntity.type == EntityType.P1 ? EntityType.P2 : EntityType.P1; - for(IntVector2 pos: rasterizeInfinity(data.originField, data.targetField, state.mapSize, false)) { - for(Entity entity: state.entities.findByPosition(pos)) { - if(entity.id.isSameType(target)) { - result.add(new EventBuilder(EventType.TakenDamageEvent) - .withTargetEntity(entity.id) - .withTargetField(pos) - .withAmount(data.value) + Entity targetEntity = state.entities.findEntity(data.targetEntity); + + result.add(new EventBuilder(EventType.TakenDamageEvent) + .withTargetEntity(targetEntity.id) + .withTargetField(data.targetField) + .withAmount(state.partyConfig.mindStoneDMG) + .buildEntityEvent()); + + if(targetEntity instanceof Character) { + Character target = (Character)targetEntity; + if(target.hp.getValue() <= data.value) { + + List stones = Arrays.asList(target.inventory.getStonesAsArray()); + Collections.shuffle(stones); // required by documents + + ArrayList used = new ArrayList<>(); + for(StoneType stone: stones) { + ArrayList options = getFreeNeighbour(state, target.getPosition(), used); + IntVector2 picked = options.get(rand.nextInt(options.size())); + used.add(picked); + result.add(new EventBuilder(EventType.SpawnEntityEvent) + .withEntity(new InfinityStone( + new EntityID(EntityType.InfinityStones, stone.getID()), + picked, + stone + )) .buildEntityEvent()); } } + }else if(targetEntity instanceof Rock) { + Rock target = (Rock)targetEntity; + if(target.getHp() <= data.value) { + result.add(new EventBuilder(EventType.DestroyedEntityEvent) + .withTargetField(data.targetField) + .withTargetEntity(target.id) + .buildEntityEvent()); + } } } case RealityStone -> {