Search in sources :

Example 16 with Callback

use of com.watabou.utils.Callback 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 17 with Callback

use of com.watabou.utils.Callback in project shattered-pixel-dungeon-gdx by 00-Evan.

the class Item method cast.

public void cast(final Hero user, final int dst) {
    final int cell = throwPos(user, dst);
    user.sprite.zap(cell);
    user.busy();
    Sample.INSTANCE.play(Assets.SND_MISS, 0.6f, 0.6f, 1.5f);
    Char enemy = Actor.findChar(cell);
    QuickSlotButton.target(enemy);
    final float delay = castDelay(user, dst);
    if (enemy != null) {
        ((MissileSprite) user.sprite.parent.recycle(MissileSprite.class)).reset(user.sprite, enemy.sprite, this, new Callback() {

            @Override
            public void call() {
                Item.this.detach(user.belongings.backpack).onThrow(cell);
                user.spendAndNext(delay);
            }
        });
    } else {
        ((MissileSprite) user.sprite.parent.recycle(MissileSprite.class)).reset(user.sprite, cell, this, new Callback() {

            @Override
            public void call() {
                Item.this.detach(user.belongings.backpack).onThrow(cell);
                user.spendAndNext(delay);
            }
        });
    }
}
Also used : Callback(com.watabou.utils.Callback) Char(com.shatteredpixel.shatteredpixeldungeon.actors.Char) MissileSprite(com.shatteredpixel.shatteredpixeldungeon.sprites.MissileSprite)

Example 18 with Callback

use of com.watabou.utils.Callback in project shattered-pixel-dungeon-gdx by 00-Evan.

the class HuntressArmor method doSpecial.

@Override
public void doSpecial() {
    Item proto = new Shuriken();
    for (Mob mob : Dungeon.level.mobs) {
        if (Dungeon.level.heroFOV[mob.pos]) {
            Callback callback = new Callback() {

                @Override
                public void call() {
                    curUser.attack(targets.get(this));
                    targets.remove(this);
                    if (targets.isEmpty()) {
                        curUser.spendAndNext(curUser.attackDelay());
                    }
                }
            };
            ((MissileSprite) curUser.sprite.parent.recycle(MissileSprite.class)).reset(curUser.pos, mob.pos, proto, callback);
            targets.put(callback, mob);
        }
    }
    if (targets.size() == 0) {
        GLog.w(Messages.get(this, "no_enemies"));
        return;
    }
    curUser.HP -= (curUser.HP / 3);
    curUser.sprite.zap(curUser.pos);
    curUser.busy();
}
Also used : Item(com.shatteredpixel.shatteredpixeldungeon.items.Item) Mob(com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob) Callback(com.watabou.utils.Callback) Shuriken(com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.Shuriken) MissileSprite(com.shatteredpixel.shatteredpixeldungeon.sprites.MissileSprite)

Example 19 with Callback

use of com.watabou.utils.Callback in project shattered-pixel-dungeon-gdx by 00-Evan.

the class EtherealChains method chainEnemy.

// pulls an enemy to a position along the chain's path, as close to the hero as possible
private void chainEnemy(Ballistica chain, final Hero hero, final Char enemy) {
    if (enemy.properties().contains(Char.Property.IMMOVABLE)) {
        GLog.w(Messages.get(this, "cant_pull"));
        return;
    }
    int bestPos = -1;
    for (int i : chain.subPath(1, chain.dist)) {
        // prefer to the earliest point on the path
        if (!Dungeon.level.solid[i] && Actor.findChar(i) == null) {
            bestPos = i;
            break;
        }
    }
    if (bestPos == -1) {
        GLog.i(Messages.get(this, "does_nothing"));
        return;
    }
    final int pulledPos = bestPos;
    int chargeUse = Dungeon.level.distance(enemy.pos, pulledPos);
    if (chargeUse > charge) {
        GLog.w(Messages.get(this, "no_charge"));
        return;
    } else {
        charge -= chargeUse;
        updateQuickslot();
    }
    hero.busy();
    hero.sprite.parent.add(new Chains(hero.sprite.center(), enemy.sprite.center(), new Callback() {

        public void call() {
            Actor.add(new Pushing(enemy, enemy.pos, pulledPos, new Callback() {

                public void call() {
                    Dungeon.level.press(pulledPos, enemy, true);
                }
            }));
            enemy.pos = pulledPos;
            Dungeon.observe();
            GameScene.updateFog();
            hero.spendAndNext(1f);
        }
    }));
}
Also used : Callback(com.watabou.utils.Callback) Pushing(com.shatteredpixel.shatteredpixeldungeon.effects.Pushing) Chains(com.shatteredpixel.shatteredpixeldungeon.effects.Chains)

Example 20 with Callback

use of com.watabou.utils.Callback in project pixel-dungeon-remix by NYRDS.

the class Wand method mobWandUse.

public void mobWandUse(Char user, final int tgt) {
    wandUser = user;
    fx(tgt, new Callback() {

        @Override
        public void call() {
            onZap(tgt);
        }
    });
}
Also used : Callback(com.watabou.utils.Callback)

Aggregations

Callback (com.watabou.utils.Callback)43 Char (com.shatteredpixel.shatteredpixeldungeon.actors.Char)8 Pushing (com.shatteredpixel.shatteredpixeldungeon.effects.Pushing)4 Ballistica (com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica)4 Char (com.watabou.pixeldungeon.actors.Char)4 MissileSprite (com.watabou.pixeldungeon.sprites.MissileSprite)4 Actor (com.shatteredpixel.shatteredpixeldungeon.actors.Actor)3 Chains (com.shatteredpixel.shatteredpixeldungeon.effects.Chains)3 Shuriken (com.watabou.pixeldungeon.items.weapon.missiles.Shuriken)3 Mob (com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob)2 Item (com.shatteredpixel.shatteredpixeldungeon.items.Item)2 Shuriken (com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.Shuriken)2 Dart (com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.darts.Dart)2 MissileSprite (com.shatteredpixel.shatteredpixeldungeon.sprites.MissileSprite)2 BitmapText (com.watabou.noosa.BitmapText)2 Hunger (com.watabou.pixeldungeon.actors.buffs.Hunger)2 SnipersMark (com.watabou.pixeldungeon.actors.buffs.SnipersMark)2 Mob (com.watabou.pixeldungeon.actors.mobs.Mob)2 Item (com.watabou.pixeldungeon.items.Item)2 MissileWeapon (com.watabou.pixeldungeon.items.weapon.missiles.MissileWeapon)2