Search in sources :

Example 11 with Char

use of com.shatteredpixel.shatteredpixeldungeon.actors.Char 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)

Example 12 with Char

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

the class Eye method deathGaze.

public void deathGaze() {
    if (!beamCharged || beamCooldown > 0 || beam == null)
        return;
    beamCharged = false;
    beamCooldown = Random.IntRange(3, 6);
    boolean terrainAffected = false;
    for (int pos : beam.subPath(1, beam.dist)) {
        if (Dungeon.level.flamable[pos]) {
            Dungeon.level.destroy(pos);
            GameScene.updateMap(pos);
            terrainAffected = true;
        }
        Char ch = Actor.findChar(pos);
        if (ch == null) {
            continue;
        }
        if (hit(this, ch, true)) {
            ch.damage(Random.NormalIntRange(30, 50), this);
            if (Dungeon.level.heroFOV[pos]) {
                ch.sprite.flash();
                CellEmitter.center(pos).burst(PurpleParticle.BURST, Random.IntRange(1, 2));
            }
            if (!ch.isAlive() && ch == Dungeon.hero) {
                Dungeon.fail(getClass());
                GLog.n(Messages.get(this, "deathgaze_kill"));
            }
        } else {
            ch.sprite.showStatus(CharSprite.NEUTRAL, ch.defenseVerb());
        }
    }
    if (terrainAffected) {
        Dungeon.observe();
    }
    beam = null;
    beamTarget = -1;
}
Also used : Char(com.shatteredpixel.shatteredpixeldungeon.actors.Char)

Example 13 with Char

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

the class Bomb method explode.

public void explode(int cell) {
    // We're blowing up, so no need for a fuse anymore.
    this.fuse = null;
    Sample.INSTANCE.play(Assets.SND_BLAST);
    if (Dungeon.level.heroFOV[cell]) {
        CellEmitter.center(cell).burst(BlastParticle.FACTORY, 30);
    }
    boolean terrainAffected = false;
    for (int n : PathFinder.NEIGHBOURS9) {
        int c = cell + n;
        if (c >= 0 && c < Dungeon.level.length()) {
            if (Dungeon.level.heroFOV[c]) {
                CellEmitter.get(c).burst(SmokeParticle.FACTORY, 4);
            }
            if (Dungeon.level.flamable[c]) {
                Dungeon.level.destroy(c);
                GameScene.updateMap(c);
                terrainAffected = true;
            }
            // destroys items / triggers bombs caught in the blast.
            Heap heap = Dungeon.level.heaps.get(c);
            if (heap != null)
                heap.explode();
            Char ch = Actor.findChar(c);
            if (ch != null) {
                // those not at the center of the blast take damage less consistently.
                int minDamage = c == cell ? Dungeon.depth + 5 : 1;
                int maxDamage = 10 + Dungeon.depth * 2;
                int dmg = Random.NormalIntRange(minDamage, maxDamage) - ch.drRoll();
                if (dmg > 0) {
                    ch.damage(dmg, this);
                }
                if (ch == Dungeon.hero && !ch.isAlive())
                    Dungeon.fail(getClass());
            }
        }
    }
    if (terrainAffected) {
        Dungeon.observe();
    }
}
Also used : Char(com.shatteredpixel.shatteredpixeldungeon.actors.Char)

Example 14 with Char

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

the class TenguSprite method attack.

@Override
public void attack(int cell) {
    if (!Dungeon.level.adjacent(cell, ch.pos)) {
        final Char enemy = Actor.findChar(cell);
        ((MissileSprite) parent.recycle(MissileSprite.class)).reset(ch.pos, cell, new Shuriken(), new Callback() {

            @Override
            public void call() {
                ch.next();
                if (enemy != null)
                    ch.attack(enemy);
            }
        });
        play(cast);
        turnTo(ch.pos, cell);
    } else {
        super.attack(cell);
    }
}
Also used : Callback(com.watabou.utils.Callback) Shuriken(com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.Shuriken) Char(com.shatteredpixel.shatteredpixeldungeon.actors.Char)

Example 15 with Char

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

the class CellSelector method zoom.

private float zoom(float value) {
    value = GameMath.gate(PixelScene.minZoom, value, PixelScene.maxZoom);
    SPDSettings.zoom((int) (value - PixelScene.defaultZoom));
    camera.zoom(value);
    // This can lead to none-whole coordinate, which need to be aligned with the zoom
    for (Char c : Actor.chars()) {
        if (c.sprite != null && !c.sprite.isMoving) {
            c.sprite.point(c.sprite.worldToCamera(c.pos));
        }
    }
    return value;
}
Also used : Char(com.shatteredpixel.shatteredpixeldungeon.actors.Char)

Aggregations

Char (com.shatteredpixel.shatteredpixeldungeon.actors.Char)65 Mob (com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob)13 Heap (com.shatteredpixel.shatteredpixeldungeon.items.Heap)13 Hero (com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero)8 Callback (com.watabou.utils.Callback)8 Item (com.shatteredpixel.shatteredpixeldungeon.items.Item)7 Ballistica (com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica)5 ArrayList (java.util.ArrayList)4 Actor (com.shatteredpixel.shatteredpixeldungeon.actors.Actor)3 Fire (com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Fire)3 Buff (com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff)3 Burning (com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Burning)3 Frost (com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Frost)3 Bleeding (com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Bleeding)2 Chill (com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Chill)2 Paralysis (com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Paralysis)2 Lightning (com.shatteredpixel.shatteredpixeldungeon.effects.Lightning)2 Blob (com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob)1 CorrosiveGas (com.shatteredpixel.shatteredpixeldungeon.actors.blobs.CorrosiveGas)1 Regrowth (com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Regrowth)1