Search in sources :

Example 1 with Awareness

use of com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Awareness in project shattered-pixel-dungeon-gdx by 00-Evan.

the class Level method updateFieldOfView.

public void updateFieldOfView(Char c, boolean[] fieldOfView) {
    int cx = c.pos % width();
    int cy = c.pos / width();
    boolean sighted = c.buff(Blindness.class) == null && c.buff(Shadows.class) == null && c.buff(TimekeepersHourglass.timeStasis.class) == null && c.isAlive();
    if (sighted) {
        ShadowCaster.castShadow(cx, cy, fieldOfView, c.viewDistance);
    } else {
        BArray.setFalse(fieldOfView);
    }
    int sense = 1;
    // Currently only the hero can get mind vision
    if (c.isAlive() && c == Dungeon.hero) {
        for (Buff b : c.buffs(MindVision.class)) {
            sense = Math.max(((MindVision) b).distance, sense);
        }
    }
    if ((sighted && sense > 1) || !sighted) {
        int ax = Math.max(0, cx - sense);
        int bx = Math.min(cx + sense, width() - 1);
        int ay = Math.max(0, cy - sense);
        int by = Math.min(cy + sense, height() - 1);
        int len = bx - ax + 1;
        int pos = ax + ay * width();
        for (int y = ay; y <= by; y++, pos += width()) {
            System.arraycopy(discoverable, pos, fieldOfView, pos, len);
        }
    }
    // Currently only the hero can get mind vision or awareness
    if (c.isAlive() && c == Dungeon.hero) {
        Dungeon.hero.mindVisionEnemies.clear();
        if (c.buff(MindVision.class) != null) {
            for (Mob mob : mobs) {
                int p = mob.pos;
                if (!fieldOfView[p]) {
                    Dungeon.hero.mindVisionEnemies.add(mob);
                }
            }
        } else if (((Hero) c).heroClass == HeroClass.HUNTRESS) {
            for (Mob mob : mobs) {
                int p = mob.pos;
                if (distance(c.pos, p) == 2) {
                    if (!fieldOfView[p]) {
                        Dungeon.hero.mindVisionEnemies.add(mob);
                    }
                }
            }
        }
        for (Mob m : Dungeon.hero.mindVisionEnemies) {
            for (int i : PathFinder.NEIGHBOURS9) {
                fieldOfView[m.pos + i] = true;
            }
        }
        if (c.buff(Awareness.class) != null) {
            for (Heap heap : heaps.values()) {
                int p = heap.pos;
                for (int i : PathFinder.NEIGHBOURS9) fieldOfView[p + i] = true;
            }
        }
    }
    if (c == Dungeon.hero) {
        for (Heap heap : heaps.values()) if (!heap.seen && fieldOfView[heap.pos])
            heap.seen = true;
    }
}
Also used : Mob(com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob) Awareness(com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Awareness) Hero(com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero) Buff(com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff) MindVision(com.shatteredpixel.shatteredpixeldungeon.actors.buffs.MindVision) Point(com.watabou.utils.Point) Heap(com.shatteredpixel.shatteredpixeldungeon.items.Heap)

Aggregations

Awareness (com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Awareness)1 Buff (com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff)1 MindVision (com.shatteredpixel.shatteredpixeldungeon.actors.buffs.MindVision)1 Hero (com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero)1 Mob (com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob)1 Heap (com.shatteredpixel.shatteredpixeldungeon.items.Heap)1 Point (com.watabou.utils.Point)1