Search in sources :

Example 1 with Actor

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

the class GrimTrap method activate.

@Override
public void activate() {
    Char target = Actor.findChar(pos);
    // find the closest char that can be aimed at
    if (target == null) {
        for (Char ch : Actor.chars()) {
            Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE);
            if (bolt.collisionPos == ch.pos && (target == null || Dungeon.level.trueDistance(pos, ch.pos) < Dungeon.level.trueDistance(pos, target.pos))) {
                target = ch;
            }
        }
    }
    if (target != null) {
        final Char finalTarget = target;
        final GrimTrap trap = this;
        int damage;
        // almost kill the player
        if (finalTarget == Dungeon.hero && ((float) finalTarget.HP / finalTarget.HT) >= 0.9f) {
            damage = finalTarget.HP - 1;
        // kill 'em
        } else {
            damage = finalTarget.HP;
        }
        final int finalDmg = damage;
        Actor.add(new Actor() {

            {
                // it's a visual effect, gets priority no matter what
                actPriority = VFX_PRIO;
            }

            @Override
            protected boolean act() {
                final Actor toRemove = this;
                ((MagicMissile) finalTarget.sprite.parent.recycle(MagicMissile.class)).reset(MagicMissile.SHADOW, DungeonTilemap.tileCenterToWorld(pos), finalTarget.sprite.center(), new Callback() {

                    @Override
                    public void call() {
                        finalTarget.damage(finalDmg, trap);
                        if (finalTarget == Dungeon.hero) {
                            Sample.INSTANCE.play(Assets.SND_CURSED);
                            if (!finalTarget.isAlive()) {
                                Dungeon.fail(GrimTrap.class);
                                GLog.n(Messages.get(GrimTrap.class, "ondeath"));
                            }
                        } else {
                            Sample.INSTANCE.play(Assets.SND_BURNING);
                        }
                        finalTarget.sprite.emitter().burst(ShadowParticle.UP, 10);
                        Actor.remove(toRemove);
                        next();
                    }
                });
                return false;
            }
        });
    } else {
        CellEmitter.get(pos).burst(ShadowParticle.UP, 10);
        Sample.INSTANCE.play(Assets.SND_BURNING);
    }
}
Also used : Callback(com.watabou.utils.Callback) Char(com.shatteredpixel.shatteredpixeldungeon.actors.Char) Actor(com.shatteredpixel.shatteredpixeldungeon.actors.Actor) Ballistica(com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica)

Example 2 with Actor

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

the class WornDartTrap method activate.

@Override
public void activate() {
    Char target = Actor.findChar(pos);
    // find the closest char that can be aimed at
    if (target == null) {
        for (Char ch : Actor.chars()) {
            Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE);
            if (bolt.collisionPos == ch.pos && (target == null || Dungeon.level.trueDistance(pos, ch.pos) < Dungeon.level.trueDistance(pos, target.pos))) {
                target = ch;
            }
        }
    }
    if (target != null) {
        final Char finalTarget = target;
        final WornDartTrap trap = this;
        if (Dungeon.level.heroFOV[pos] || Dungeon.level.heroFOV[target.pos]) {
            Actor.add(new Actor() {

                {
                    // it's a visual effect, gets priority no matter what
                    actPriority = VFX_PRIO;
                }

                @Override
                protected boolean act() {
                    final Actor toRemove = this;
                    ((MissileSprite) ShatteredPixelDungeon.scene().recycle(MissileSprite.class)).reset(pos, finalTarget.sprite, new Dart(), new Callback() {

                        @Override
                        public void call() {
                            int dmg = Random.NormalIntRange(1, 4) - finalTarget.drRoll();
                            finalTarget.damage(dmg, trap);
                            if (finalTarget == Dungeon.hero && !finalTarget.isAlive()) {
                                Dungeon.fail(trap.getClass());
                            }
                            Sample.INSTANCE.play(Assets.SND_HIT, 1, 1, Random.Float(0.8f, 1.25f));
                            finalTarget.sprite.bloodBurstA(finalTarget.sprite.center(), dmg);
                            finalTarget.sprite.flash();
                            Actor.remove(toRemove);
                            next();
                        }
                    });
                    return false;
                }
            });
        } else {
            finalTarget.damage(Random.NormalIntRange(1, 4) - finalTarget.drRoll(), trap);
        }
    }
}
Also used : Callback(com.watabou.utils.Callback) Char(com.shatteredpixel.shatteredpixeldungeon.actors.Char) Actor(com.shatteredpixel.shatteredpixeldungeon.actors.Actor) Ballistica(com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica) Dart(com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.darts.Dart)

Example 3 with Actor

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

the class PoisonDartTrap method activate.

@Override
public void activate() {
    Char target = Actor.findChar(pos);
    // find the closest char that can be aimed at
    if (target == null) {
        for (Char ch : Actor.chars()) {
            Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE);
            if (bolt.collisionPos == ch.pos && (target == null || Dungeon.level.trueDistance(pos, ch.pos) < Dungeon.level.trueDistance(pos, target.pos))) {
                target = ch;
            }
        }
    }
    if (target != null) {
        final Char finalTarget = target;
        final PoisonDartTrap trap = this;
        if (Dungeon.level.heroFOV[pos] || Dungeon.level.heroFOV[target.pos]) {
            Actor.add(new Actor() {

                {
                    // it's a visual effect, gets priority no matter what
                    actPriority = VFX_PRIO;
                }

                @Override
                protected boolean act() {
                    final Actor toRemove = this;
                    ((MissileSprite) ShatteredPixelDungeon.scene().recycle(MissileSprite.class)).reset(pos, finalTarget.sprite, new PoisonDart(), new Callback() {

                        @Override
                        public void call() {
                            int dmg = Random.NormalIntRange(1, 4) - finalTarget.drRoll();
                            finalTarget.damage(dmg, trap);
                            if (finalTarget == Dungeon.hero && !finalTarget.isAlive()) {
                                Dungeon.fail(trap.getClass());
                            }
                            Buff.affect(finalTarget, Poison.class).set(4 + Dungeon.depth);
                            Sample.INSTANCE.play(Assets.SND_HIT, 1, 1, Random.Float(0.8f, 1.25f));
                            finalTarget.sprite.bloodBurstA(finalTarget.sprite.center(), dmg);
                            finalTarget.sprite.flash();
                            Actor.remove(toRemove);
                            next();
                        }
                    });
                    return false;
                }
            });
        } else {
            finalTarget.damage(Random.NormalIntRange(1, 4) - finalTarget.drRoll(), trap);
            Buff.affect(finalTarget, Poison.class).set(4 + Dungeon.depth);
        }
    }
}
Also used : Callback(com.watabou.utils.Callback) Char(com.shatteredpixel.shatteredpixeldungeon.actors.Char) Actor(com.shatteredpixel.shatteredpixeldungeon.actors.Actor) Ballistica(com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica) PoisonDart(com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.darts.PoisonDart) Poison(com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Poison)

Example 4 with Actor

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

the class Dungeon method switchLevel.

@SuppressWarnings("deprecation")
public static void switchLevel(final Level level, int pos) {
    if (pos < 0 || pos >= level.length()) {
        pos = level.exit;
    }
    PathFinder.setMapSize(level.width(), level.height());
    Dungeon.level = level;
    DriedRose.restoreGhostHero(level, pos);
    Actor.init();
    Actor respawner = level.respawner();
    if (respawner != null) {
        Actor.add(level.respawner());
    }
    hero.pos = pos;
    Light light = hero.buff(Light.class);
    hero.viewDistance = light == null ? level.viewDistance : Math.max(Light.DISTANCE, level.viewDistance);
    hero.curAction = hero.lastAction = null;
    observe();
    try {
        saveAll();
    } catch (IOException e) {
        ShatteredPixelDungeon.reportException(e);
    /*This only catches IO errors. Yes, this means things can go wrong, and they can go wrong catastrophically.
			But when they do the user will get a nice 'report this issue' dialogue, and I can fix the bug.*/
    }
}
Also used : Light(com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Light) Actor(com.shatteredpixel.shatteredpixeldungeon.actors.Actor) IOException(java.io.IOException)

Example 5 with Actor

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

the class Amulet method doPickUp.

@Override
public boolean doPickUp(Hero hero) {
    if (super.doPickUp(hero)) {
        if (!Statistics.amuletObtained) {
            Statistics.amuletObtained = true;
            Badges.validateVictory();
            hero.spend(-TIME_TO_PICK_UP);
            // add a delayed actor here so pickup behaviour can fully process.
            Actor.addDelayed(new Actor() {

                @Override
                protected boolean act() {
                    Actor.remove(this);
                    showAmuletScene(true);
                    return false;
                }
            }, -5);
        }
        return true;
    } else {
        return false;
    }
}
Also used : Actor(com.shatteredpixel.shatteredpixeldungeon.actors.Actor)

Aggregations

Actor (com.shatteredpixel.shatteredpixeldungeon.actors.Actor)6 Char (com.shatteredpixel.shatteredpixeldungeon.actors.Char)3 Ballistica (com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica)3 Callback (com.watabou.utils.Callback)3 Light (com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Light)1 Poison (com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Poison)1 Mob (com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob)1 Dart (com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.darts.Dart)1 PoisonDart (com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.darts.PoisonDart)1 Point (com.watabou.utils.Point)1 IOException (java.io.IOException)1