v2.5.0: fixed adjusted trap targeting logic ignoring invis characters

This commit is contained in:
Evan Debenham
2024-08-27 14:29:39 -04:00
parent f03af516c0
commit f4aa26bef7
4 changed files with 32 additions and 17 deletions

View File

@@ -50,22 +50,25 @@ public class DisintegrationTrap extends Trap {
@Override
public void activate() {
Char target = Actor.findChar(pos);
//find the closest char that can be aimed at
//can't target beyond view distance, with a min of 6 (torch range)
int range = Math.max(6, Dungeon.level.viewDistance);
if (target == null){
float closestDist = Float.MAX_VALUE;
for (Char ch : Actor.chars()){
if (!ch.isAlive()) continue;
float curDist = Dungeon.level.trueDistance(pos, ch.pos);
if (ch.invisible > 0) curDist += 1000;
//invis targets are considered to be at max range
if (ch.invisible > 0) curDist = Math.max(curDist, range);
Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE);
if (bolt.collisionPos == ch.pos && curDist < closestDist){
if (bolt.collisionPos == ch.pos
&& ( curDist < closestDist || (curDist == closestDist && target instanceof Hero))){
target = ch;
closestDist = curDist;
}
}
//can't target beyond view distance, with a min of 6 (torch range)
if (closestDist > Math.max(6, Dungeon.level.viewDistance)){
if (closestDist > range){
target = null;
}
}

View File

@@ -26,6 +26,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Badges;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.effects.CellEmitter;
import com.shatteredpixel.shatteredpixeldungeon.effects.MagicMissile;
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.ShadowParticle;
@@ -62,20 +63,23 @@ public class GrimTrap extends Trap {
Char target = Actor.findChar(pos);
//find the closest char that can be aimed at
//can't target beyond view distance, with a min of 6 (torch range)
int range = Math.max(6, Dungeon.level.viewDistance);
if (target == null){
float closestDist = Float.MAX_VALUE;
for (Char ch : Actor.chars()){
if (!ch.isAlive()) continue;
float curDist = Dungeon.level.trueDistance(pos, ch.pos);
if (ch.invisible > 0) curDist += 1000;
//invis targets are considered to be at max range
if (ch.invisible > 0) curDist = Math.max(curDist, range);
Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE);
if (bolt.collisionPos == ch.pos && curDist < closestDist){
if (bolt.collisionPos == ch.pos
&& ( curDist < closestDist || (curDist == closestDist && target instanceof Hero))){
target = ch;
closestDist = curDist;
}
}
//can't target beyond view distance, with a min of 6 (torch range)
if (closestDist > Math.max(6, Dungeon.level.viewDistance)){
if (closestDist > range){
target = null;
}
}

View File

@@ -29,6 +29,7 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Poison;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.darts.PoisonDart;
import com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
@@ -76,20 +77,23 @@ public class PoisonDartTrap extends Trap {
}
//find the closest char that can be aimed at
//can't target beyond view distance, with a min of 6 (torch range)
int range = Math.max(6, Dungeon.level.viewDistance);
if (target == null){
float closestDist = Float.MAX_VALUE;
for (Char ch : Actor.chars()){
if (!ch.isAlive()) continue;
float curDist = Dungeon.level.trueDistance(pos, ch.pos);
if (ch.invisible > 0) curDist += 1000;
//invis targets are considered to be at max range
if (ch.invisible > 0) curDist = Math.max(curDist, range);
Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE);
if (canTarget(ch) && bolt.collisionPos == ch.pos && curDist < closestDist){
if (canTarget(ch) && bolt.collisionPos == ch.pos
&& ( curDist < closestDist || (curDist == closestDist && target instanceof Hero))){
target = ch;
closestDist = curDist;
}
}
//can't target beyond view distance, with a min of 6 (torch range)
if (closestDist > Math.max(6, Dungeon.level.viewDistance)){
if (closestDist > range){
target = null;
}
}

View File

@@ -26,6 +26,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.darts.Dart;
import com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
@@ -61,20 +62,23 @@ public class WornDartTrap extends Trap {
Char target = Actor.findChar(pos);
//find the closest char that can be aimed at
//can't target beyond view distance, with a min of 6 (torch range)
int range = Math.max(6, Dungeon.level.viewDistance);
if (target == null){
float closestDist = Float.MAX_VALUE;
for (Char ch : Actor.chars()){
if (!ch.isAlive()) continue;
float curDist = Dungeon.level.trueDistance(pos, ch.pos);
if (ch.invisible > 0) curDist += 1000;
//invis targets are considered to be at max range
if (ch.invisible > 0) curDist = Math.max(curDist, range);
Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE);
if (bolt.collisionPos == ch.pos && curDist < closestDist){
if (bolt.collisionPos == ch.pos
&& ( curDist < closestDist || (curDist == closestDist && target instanceof Hero))){
target = ch;
closestDist = curDist;
}
}
//can't target beyond view distance, with a min of 6 (torch range)
if (closestDist > Math.max(6, Dungeon.level.viewDistance)){
if (closestDist > range){
target = null;
}
}