From d62cb4aa95a2ad12e1d89cce9b38b310f6cff227 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Fri, 31 Jul 2020 19:27:46 -0400 Subject: [PATCH] v0.8.2: targeting traps now prefer visible targets over invisible ones --- .../levels/traps/DisintegrationTrap.java | 6 ++++-- .../shatteredpixeldungeon/levels/traps/GrimTrap.java | 6 ++++-- .../levels/traps/PoisonDartTrap.java | 6 ++++-- .../shatteredpixeldungeon/levels/traps/WornDartTrap.java | 9 +++++---- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/DisintegrationTrap.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/DisintegrationTrap.java index a532c0251..04bc395ae 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/DisintegrationTrap.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/DisintegrationTrap.java @@ -51,10 +51,12 @@ public class DisintegrationTrap extends Trap { //find the closest char that can be aimed at if (target == null){ + float closestDist = Float.MAX_VALUE; for (Char ch : Actor.chars()){ + float curDist = Dungeon.level.trueDistance(pos, target.pos); + if (target.invisible > 0) curDist += 1000; Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE); - if (bolt.collisionPos == ch.pos && - (target == null || Dungeon.level.trueDistance(pos, ch.pos) < Dungeon.level.trueDistance(pos, target.pos))){ + if (bolt.collisionPos == ch.pos && curDist < closestDist){ target = ch; } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/GrimTrap.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/GrimTrap.java index d75a688cb..30fdf81ca 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/GrimTrap.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/GrimTrap.java @@ -50,10 +50,12 @@ public class GrimTrap extends Trap { //find the closest char that can be aimed at if (target == null){ + float closestDist = Float.MAX_VALUE; for (Char ch : Actor.chars()){ + float curDist = Dungeon.level.trueDistance(pos, target.pos); + if (target.invisible > 0) curDist += 1000; Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE); - if (bolt.collisionPos == ch.pos && - (target == null || Dungeon.level.trueDistance(pos, ch.pos) < Dungeon.level.trueDistance(pos, target.pos))){ + if (bolt.collisionPos == ch.pos && curDist < closestDist){ target = ch; } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/PoisonDartTrap.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/PoisonDartTrap.java index 71acd0a2a..8d399dde5 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/PoisonDartTrap.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/PoisonDartTrap.java @@ -62,10 +62,12 @@ public class PoisonDartTrap extends Trap { //find the closest char that can be aimed at if (target == null){ + float closestDist = Float.MAX_VALUE; for (Char ch : Actor.chars()){ + float curDist = Dungeon.level.trueDistance(pos, target.pos); + if (target.invisible > 0) curDist += 1000; Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE); - if (canTarget(ch) && bolt.collisionPos == ch.pos && - (target == null || Dungeon.level.trueDistance(pos, ch.pos) < Dungeon.level.trueDistance(pos, target.pos))){ + if (canTarget(ch) && bolt.collisionPos == ch.pos && curDist < closestDist){ target = ch; } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/WornDartTrap.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/WornDartTrap.java index 84ede08a1..4ca3a252b 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/WornDartTrap.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/WornDartTrap.java @@ -45,13 +45,14 @@ public class WornDartTrap extends Trap { @Override public void activate() { Char target = Actor.findChar(pos); - - //find the closest char that can be aimed at + if (target == null){ + float closestDist = Float.MAX_VALUE; for (Char ch : Actor.chars()){ + float curDist = Dungeon.level.trueDistance(pos, target.pos); + if (target.invisible > 0) curDist += 1000; Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE); - if (bolt.collisionPos == ch.pos && - (target == null || Dungeon.level.trueDistance(pos, ch.pos) < Dungeon.level.trueDistance(pos, target.pos))){ + if (bolt.collisionPos == ch.pos && curDist < closestDist){ target = ch; } }