diff --git a/src/main/java/com/leekwars/generator/attack/Attack.java b/src/main/java/com/leekwars/generator/attack/Attack.java index eb1c3a1..cc6a2d8 100644 --- a/src/main/java/com/leekwars/generator/attack/Attack.java +++ b/src/main/java/com/leekwars/generator/attack/Attack.java @@ -182,7 +182,8 @@ public List applyOnCell(Fight fight, Entity caster, Cell target, boolean if (parameters.getId() == Effect.TYPE_ATTRACT) { for (Entity entity : targetEntities) { // Attract directly to target cell - fight.slideEntity(entity, target, caster); + Cell destination = Pathfinding.getAttractLastAvailableCell(entity.getCell(), target, caster.getCell()); + fight.slideEntity(entity, destination, caster); } } else if (parameters.getId() == Effect.TYPE_PUSH) { for (Entity entity : targetEntities) { diff --git a/src/main/java/com/leekwars/generator/fight/entity/Entity.java b/src/main/java/com/leekwars/generator/fight/entity/Entity.java index df864cb..7d6031e 100644 --- a/src/main/java/com/leekwars/generator/fight/entity/Entity.java +++ b/src/main/java/com/leekwars/generator/fight/entity/Entity.java @@ -40,6 +40,7 @@ public abstract class Entity { public static final int TYPE_BULB = 1; public static final int TYPE_TURRET = 2; public static final int TYPE_CHEST = 3; + public static final int TYPE_MOB = 4; // Characteristics constants public final static int CHARAC_LIFE = 0; diff --git a/src/main/java/com/leekwars/generator/maps/Pathfinding.java b/src/main/java/com/leekwars/generator/maps/Pathfinding.java index 6cefb38..8eca724 100644 --- a/src/main/java/com/leekwars/generator/maps/Pathfinding.java +++ b/src/main/java/com/leekwars/generator/maps/Pathfinding.java @@ -746,4 +746,24 @@ public static Cell getPushLastAvailableCell(Cell entity, Cell target, Cell caste } return current; } + + public static Cell getAttractLastAvailableCell(Cell entity, Cell target, Cell caster) { + // Delta caster --> entity + int cdx = (int) Math.signum(entity.x - caster.x); + int cdy = (int) Math.signum(entity.y - caster.y); + // Delta entity --> target + int dx = (int) Math.signum(target.x - entity.x); + int dy = (int) Math.signum(target.y - entity.y); + // Check deltas (must be attracted in the correct direction) + if (cdx != -dx || cdy != -dy) return entity; // no change + Cell current = entity; + while (current != target) { + Cell next = current.next(dx, dy); + if (!next.available()) { + return current; + } + current = next; + } + return current; + } }