diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java b/src/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java index 3058f067f..a5b305771 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java @@ -717,12 +717,9 @@ public class Dungeon { System.arraycopy( pass, 0, passable, 0, Level.LENGTH ); } - for (Actor actor : Actor.all()) { - if (actor instanceof Char) { - int pos = ((Char)actor).pos; - if (visible[pos]) { - passable[pos] = false; - } + for (Char c : Actor.chars()) { + if (visible[c.pos]) { + passable[c.pos] = false; } } @@ -738,12 +735,9 @@ public class Dungeon { System.arraycopy( pass, 0, passable, 0, Level.LENGTH ); } - for (Actor actor : Actor.all()) { - if (actor instanceof Char) { - int pos = ((Char)actor).pos; - if (visible[pos]) { - passable[pos] = false; - } + for (Char c : Actor.chars()) { + if (visible[c.pos]) { + passable[c.pos] = false; } } passable[cur] = true; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java index ae5730941..7f0d00b79 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java @@ -98,7 +98,8 @@ public abstract class Actor implements Bundlable { // ********************** // *** Static members *** - private static HashSet all = new HashSet(); + private static HashSet all = new HashSet<>(); + private static HashSet chars = new HashSet<>(); private static Actor current; private static SparseArray ids = new SparseArray(); @@ -110,6 +111,7 @@ public abstract class Actor implements Bundlable { now = 0; all.clear(); + chars.clear(); ids.clear(); } @@ -234,6 +236,7 @@ public abstract class Actor implements Bundlable { if (actor instanceof Char) { Char ch = (Char)actor; + chars.add( ch ); for (Buff buff : ch.buffs()) { all.add( buff ); buff.onAdd(); @@ -245,6 +248,7 @@ public abstract class Actor implements Bundlable { if (actor != null) { all.remove( actor ); + chars.remove( actor ); actor.onRemove(); if (actor.id > 0) { @@ -254,9 +258,9 @@ public abstract class Actor implements Bundlable { } public static Char findChar( int pos ) { - for (Actor actor : all){ - if (actor instanceof Char && ((Char)actor).pos == pos) - return (Char)actor; + for (Char ch : chars){ + if (ch.pos == pos) + return ch; } return null; } @@ -268,4 +272,6 @@ public abstract class Actor implements Bundlable { public static HashSet all() { return all; } + + public static HashSet chars() { return chars; } } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/King.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/King.java index 2ef1d7968..709abf746 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/King.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/King.java @@ -170,10 +170,8 @@ public class King extends Mob { Sample.INSTANCE.play( Assets.SND_CHALLENGE ); boolean[] passable = Level.passable.clone(); - for (Actor actor : Actor.all()) { - if (actor instanceof Char) { - passable[((Char)actor).pos] = false; - } + for (Char c : Actor.chars()) { + passable[c.pos] = false; } int undeadsToSummon = maxArmySize() - Undead.count; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java b/src/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java index 2ee67e9bb..030e84462 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java @@ -164,7 +164,7 @@ public class QuickSlotButton extends Button implements WndBag.Listener { targeting = lastTarget != null && lastTarget.isAlive() && Dungeon.visible[lastTarget.pos]; if (targeting) { - if (Actor.all().contains( lastTarget )) { + if (Actor.chars().contains( lastTarget )) { lastTarget.sprite.parent.add( crossM ); crossM.point( DungeonTilemap.tileToWorld( lastTarget.pos ) ); crossB.x = PixelScene.align( x + (width - crossB.width) / 2 );