v2.5.0: fixed adjusted trap targeting logic ignoring invis characters
This commit is contained in:
@@ -50,22 +50,25 @@ public class DisintegrationTrap 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
|
//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){
|
if (target == null){
|
||||||
float closestDist = Float.MAX_VALUE;
|
float closestDist = Float.MAX_VALUE;
|
||||||
for (Char ch : Actor.chars()){
|
for (Char ch : Actor.chars()){
|
||||||
if (!ch.isAlive()) continue;
|
if (!ch.isAlive()) continue;
|
||||||
float curDist = Dungeon.level.trueDistance(pos, ch.pos);
|
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);
|
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;
|
target = ch;
|
||||||
closestDist = curDist;
|
closestDist = curDist;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//can't target beyond view distance, with a min of 6 (torch range)
|
if (closestDist > range){
|
||||||
if (closestDist > Math.max(6, Dungeon.level.viewDistance)){
|
|
||||||
target = null;
|
target = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Badges;
|
|||||||
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.effects.CellEmitter;
|
import com.shatteredpixel.shatteredpixeldungeon.effects.CellEmitter;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.effects.MagicMissile;
|
import com.shatteredpixel.shatteredpixeldungeon.effects.MagicMissile;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.ShadowParticle;
|
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.ShadowParticle;
|
||||||
@@ -62,20 +63,23 @@ public class GrimTrap extends Trap {
|
|||||||
Char target = Actor.findChar(pos);
|
Char target = Actor.findChar(pos);
|
||||||
|
|
||||||
//find the closest char that can be aimed at
|
//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){
|
if (target == null){
|
||||||
float closestDist = Float.MAX_VALUE;
|
float closestDist = Float.MAX_VALUE;
|
||||||
for (Char ch : Actor.chars()){
|
for (Char ch : Actor.chars()){
|
||||||
if (!ch.isAlive()) continue;
|
if (!ch.isAlive()) continue;
|
||||||
float curDist = Dungeon.level.trueDistance(pos, ch.pos);
|
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);
|
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;
|
target = ch;
|
||||||
closestDist = curDist;
|
closestDist = curDist;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//can't target beyond view distance, with a min of 6 (torch range)
|
if (closestDist > range){
|
||||||
if (closestDist > Math.max(6, Dungeon.level.viewDistance)){
|
|
||||||
target = null;
|
target = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
|
|||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Poison;
|
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.items.weapon.missiles.darts.PoisonDart;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica;
|
import com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
|
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
|
||||||
@@ -76,20 +77,23 @@ public class PoisonDartTrap extends Trap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//find the closest char that can be aimed at
|
//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){
|
if (target == null){
|
||||||
float closestDist = Float.MAX_VALUE;
|
float closestDist = Float.MAX_VALUE;
|
||||||
for (Char ch : Actor.chars()){
|
for (Char ch : Actor.chars()){
|
||||||
if (!ch.isAlive()) continue;
|
if (!ch.isAlive()) continue;
|
||||||
float curDist = Dungeon.level.trueDistance(pos, ch.pos);
|
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);
|
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;
|
target = ch;
|
||||||
closestDist = curDist;
|
closestDist = curDist;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//can't target beyond view distance, with a min of 6 (torch range)
|
if (closestDist > range){
|
||||||
if (closestDist > Math.max(6, Dungeon.level.viewDistance)){
|
|
||||||
target = null;
|
target = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
|||||||
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
|
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
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.items.weapon.missiles.darts.Dart;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica;
|
import com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
|
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
|
||||||
@@ -61,20 +62,23 @@ public class WornDartTrap extends Trap {
|
|||||||
Char target = Actor.findChar(pos);
|
Char target = Actor.findChar(pos);
|
||||||
|
|
||||||
//find the closest char that can be aimed at
|
//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){
|
if (target == null){
|
||||||
float closestDist = Float.MAX_VALUE;
|
float closestDist = Float.MAX_VALUE;
|
||||||
for (Char ch : Actor.chars()){
|
for (Char ch : Actor.chars()){
|
||||||
if (!ch.isAlive()) continue;
|
if (!ch.isAlive()) continue;
|
||||||
float curDist = Dungeon.level.trueDistance(pos, ch.pos);
|
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);
|
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;
|
target = ch;
|
||||||
closestDist = curDist;
|
closestDist = curDist;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//can't target beyond view distance, with a min of 6 (torch range)
|
if (closestDist > range){
|
||||||
if (closestDist > Math.max(6, Dungeon.level.viewDistance)){
|
|
||||||
target = null;
|
target = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user