v0.8.2: targeting traps now prefer visible targets over invisible ones

This commit is contained in:
Evan Debenham 2020-07-31 19:27:46 -04:00
parent 55f3fba7e1
commit d62cb4aa95
4 changed files with 17 additions and 10 deletions

View File

@ -51,10 +51,12 @@ public class DisintegrationTrap extends Trap {
//find the closest char that can be aimed at //find the closest char that can be aimed at
if (target == null){ if (target == null){
float closestDist = Float.MAX_VALUE;
for (Char ch : Actor.chars()){ 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); Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE);
if (bolt.collisionPos == ch.pos && if (bolt.collisionPos == ch.pos && curDist < closestDist){
(target == null || Dungeon.level.trueDistance(pos, ch.pos) < Dungeon.level.trueDistance(pos, target.pos))){
target = ch; target = ch;
} }
} }

View File

@ -50,10 +50,12 @@ public class GrimTrap extends Trap {
//find the closest char that can be aimed at //find the closest char that can be aimed at
if (target == null){ if (target == null){
float closestDist = Float.MAX_VALUE;
for (Char ch : Actor.chars()){ 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); Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE);
if (bolt.collisionPos == ch.pos && if (bolt.collisionPos == ch.pos && curDist < closestDist){
(target == null || Dungeon.level.trueDistance(pos, ch.pos) < Dungeon.level.trueDistance(pos, target.pos))){
target = ch; target = ch;
} }
} }

View File

@ -62,10 +62,12 @@ public class PoisonDartTrap extends Trap {
//find the closest char that can be aimed at //find the closest char that can be aimed at
if (target == null){ if (target == null){
float closestDist = Float.MAX_VALUE;
for (Char ch : Actor.chars()){ 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); Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE);
if (canTarget(ch) && bolt.collisionPos == ch.pos && if (canTarget(ch) && bolt.collisionPos == ch.pos && curDist < closestDist){
(target == null || Dungeon.level.trueDistance(pos, ch.pos) < Dungeon.level.trueDistance(pos, target.pos))){
target = ch; target = ch;
} }
} }

View File

@ -45,13 +45,14 @@ public class WornDartTrap extends Trap {
@Override @Override
public void activate() { public void activate() {
Char target = Actor.findChar(pos); Char target = Actor.findChar(pos);
//find the closest char that can be aimed at
if (target == null){ if (target == null){
float closestDist = Float.MAX_VALUE;
for (Char ch : Actor.chars()){ 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); Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE);
if (bolt.collisionPos == ch.pos && if (bolt.collisionPos == ch.pos && curDist < closestDist){
(target == null || Dungeon.level.trueDistance(pos, ch.pos) < Dungeon.level.trueDistance(pos, target.pos))){
target = ch; target = ch;
} }
} }