Search in sources :

Example 1 with Terror

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

the class ScrollOfTerror method empoweredRead.

@Override
public void empoweredRead() {
    doRead();
    for (Mob mob : Dungeon.level.mobs.toArray(new Mob[0])) {
        if (Dungeon.level.heroFOV[mob.pos]) {
            Terror t = mob.buff(Terror.class);
            if (t != null) {
                Buff.prolong(mob, Terror.class, Terror.DURATION * 1.5f);
                Buff.affect(mob, Paralysis.class, Terror.DURATION * .5f);
            }
        }
    }
}
Also used : Mob(com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob) Terror(com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Terror)

Example 2 with Terror

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

the class Mob method chooseEnemy.

protected Char chooseEnemy() {
    Terror terror = buff(Terror.class);
    if (terror != null) {
        Char source = (Char) Actor.findById(terror.object);
        if (source != null) {
            return source;
        }
    }
    // find a new enemy if..
    boolean newEnemy = false;
    // we have no enemy, or the current one is dead
    if (enemy == null || !enemy.isAlive() || state == WANDERING)
        newEnemy = true;
    else // We are an ally, and current enemy is another ally.
    if (alignment == Alignment.ALLY && enemy.alignment == Alignment.ALLY)
        newEnemy = true;
    else // We are amoked and current enemy is the hero
    if (buff(Amok.class) != null && enemy == Dungeon.hero)
        newEnemy = true;
    if (newEnemy) {
        HashSet<Char> enemies = new HashSet<>();
        // if the mob is amoked...
        if (buff(Amok.class) != null) {
            // try to find an enemy mob to attack first.
            for (Mob mob : Dungeon.level.mobs) if (mob.alignment == Alignment.ENEMY && mob != this && fieldOfView[mob.pos])
                enemies.add(mob);
            if (enemies.isEmpty()) {
                // try to find ally mobs to attack second.
                for (Mob mob : Dungeon.level.mobs) if (mob.alignment == Alignment.ALLY && mob != this && fieldOfView[mob.pos])
                    enemies.add(mob);
                if (enemies.isEmpty()) {
                    // try to find the hero third
                    if (fieldOfView[Dungeon.hero.pos]) {
                        enemies.add(Dungeon.hero);
                    }
                }
            }
        // if the mob is an ally...
        } else if (alignment == Alignment.ALLY) {
            // look for hostile mobs that are not passive to attack
            for (Mob mob : Dungeon.level.mobs) if (mob.alignment == Alignment.ENEMY && fieldOfView[mob.pos] && mob.state != mob.PASSIVE)
                enemies.add(mob);
        // if the mob is an enemy...
        } else if (alignment == Alignment.ENEMY) {
            // look for ally mobs to attack
            for (Mob mob : Dungeon.level.mobs) if (mob.alignment == Alignment.ALLY && fieldOfView[mob.pos])
                enemies.add(mob);
            // and look for the hero
            if (fieldOfView[Dungeon.hero.pos]) {
                enemies.add(Dungeon.hero);
            }
        }
        // neutral character in particular do not choose enemies.
        if (enemies.isEmpty()) {
            return null;
        } else {
            // go after the closest potential enemy, preferring the hero if two are equidistant
            Char closest = null;
            for (Char curr : enemies) {
                if (closest == null || Dungeon.level.distance(pos, curr.pos) < Dungeon.level.distance(pos, closest.pos) || Dungeon.level.distance(pos, curr.pos) == Dungeon.level.distance(pos, closest.pos) && curr == Dungeon.hero) {
                    closest = curr;
                }
            }
            return closest;
        }
    } else
        return enemy;
}
Also used : Char(com.shatteredpixel.shatteredpixeldungeon.actors.Char) Amok(com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Amok) Terror(com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Terror) HashSet(java.util.HashSet)

Aggregations

Terror (com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Terror)2 Char (com.shatteredpixel.shatteredpixeldungeon.actors.Char)1 Amok (com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Amok)1 Mob (com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob)1 HashSet (java.util.HashSet)1