Search in sources :

Example 31 with Callback

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

the class CharSprite method onComplete.

@Override
public void onComplete(Animation anim) {
    if (animCallback != null) {
        Callback executing = animCallback;
        animCallback = null;
        executing.call();
    } else {
        if (anim == attack) {
            idle();
            ch.onAttackComplete();
        } else if (anim == operate) {
            idle();
            ch.onOperateComplete();
        }
    }
}
Also used : Callback(com.watabou.utils.Callback)

Example 32 with Callback

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

the class BurningFistSprite method onComplete.

@Override
public void onComplete(Animation anim) {
    if (anim == attack) {
        Sample.INSTANCE.play(Assets.SND_ZAP);
        MagicMissile.boltFromChar(parent, MagicMissile.SHADOW, this, posToShoot, new Callback() {

            @Override
            public void call() {
                ch.onAttackComplete();
            }
        });
        idle();
    } else {
        super.onComplete(anim);
    }
}
Also used : Callback(com.watabou.utils.Callback)

Example 33 with Callback

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

the class CursedWand method veryRareEffect.

private static void veryRareEffect(final Wand wand, final Hero user, final Ballistica bolt) {
    switch(Random.Int(4)) {
        // great forest fire!
        case 0:
            for (int i = 0; i < Dungeon.level.length(); i++) {
                int c = Dungeon.level.map[i];
                if (c == Terrain.EMPTY || c == Terrain.EMBERS || c == Terrain.EMPTY_DECO || c == Terrain.GRASS || c == Terrain.HIGH_GRASS) {
                    GameScene.add(Blob.seed(i, 15, Regrowth.class));
                }
            }
            do {
                GameScene.add(Blob.seed(Dungeon.level.randomDestination(), 10, Fire.class));
            } while (Random.Int(5) != 0);
            new Flare(8, 32).color(0xFFFF66, true).show(user.sprite, 2f);
            Sample.INSTANCE.play(Assets.SND_TELEPORT);
            GLog.p(Messages.get(CursedWand.class, "grass"));
            GLog.w(Messages.get(CursedWand.class, "fire"));
            wand.wandUsed();
            break;
        // superpowered mimic
        case 1:
            cursedFX(user, bolt, new Callback() {

                public void call() {
                    Mimic mimic = Mimic.spawnAt(bolt.collisionPos, new ArrayList<Item>());
                    if (mimic != null) {
                        mimic.adjustStats(Dungeon.depth + 10);
                        mimic.HP = mimic.HT;
                        Item reward;
                        do {
                            reward = Generator.random(Random.oneOf(Generator.Category.WEAPON, Generator.Category.ARMOR, Generator.Category.RING, Generator.Category.WAND));
                        } while (reward.level() < 1);
                        Sample.INSTANCE.play(Assets.SND_MIMIC, 1, 1, 0.5f);
                        mimic.items.clear();
                        mimic.items.add(reward);
                    } else {
                        GLog.i(Messages.get(CursedWand.class, "nothing"));
                    }
                    wand.wandUsed();
                }
            });
            break;
        // crashes the game, yes, really.
        case 2:
            try {
                Dungeon.saveAll();
                if (Messages.lang() != Languages.ENGLISH) {
                    // Don't bother doing this joke to none-english speakers, I doubt it would translate.
                    GLog.i(Messages.get(CursedWand.class, "nothing"));
                    wand.wandUsed();
                } else {
                    GameScene.show(new WndOptions("CURSED WAND ERROR", "this application will now self-destruct", "abort", "retry", "fail") {

                        @Override
                        protected void onSelect(int index) {
                            Game.instance.finish();
                        }

                        @Override
                        public void onBackPressed() {
                        // do nothing
                        }
                    });
                }
            } catch (IOException e) {
                ShatteredPixelDungeon.reportException(e);
                // oookay maybe don't kill the game if the save failed.
                GLog.i(Messages.get(CursedWand.class, "nothing"));
                wand.wandUsed();
            }
            break;
        // random transmogrification
        case 3:
            wand.wandUsed();
            wand.detach(user.belongings.backpack);
            Item result;
            do {
                result = Generator.random(Random.oneOf(Generator.Category.WEAPON, Generator.Category.ARMOR, Generator.Category.RING, Generator.Category.ARTIFACT));
            } while (result.cursed);
            if (result.isUpgradable())
                result.upgrade();
            result.cursed = result.cursedKnown = true;
            GLog.w(Messages.get(CursedWand.class, "transmogrify"));
            Dungeon.level.drop(result, user.pos).sprite.drop();
            wand.wandUsed();
            break;
    }
}
Also used : WndOptions(com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions) Item(com.shatteredpixel.shatteredpixeldungeon.items.Item) Flare(com.shatteredpixel.shatteredpixeldungeon.effects.Flare) Callback(com.watabou.utils.Callback) Mimic(com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mimic) Fire(com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Fire) ArrayList(java.util.ArrayList) Regrowth(com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Regrowth) IOException(java.io.IOException)

Example 34 with Callback

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

the class CursedWand method uncommonEffect.

private static void uncommonEffect(final Wand wand, final Hero user, final Ballistica bolt) {
    switch(Random.Int(4)) {
        // Random plant
        case 0:
            cursedFX(user, bolt, new Callback() {

                public void call() {
                    int pos = bolt.collisionPos;
                    // place the plant infront of an enemy so they walk into it.
                    if (Actor.findChar(pos) != null && bolt.dist > 1) {
                        pos = bolt.path.get(bolt.dist - 1);
                    }
                    if (pos == Terrain.EMPTY || pos == Terrain.EMBERS || pos == Terrain.EMPTY_DECO || pos == Terrain.GRASS || pos == Terrain.HIGH_GRASS) {
                        Dungeon.level.plant((Plant.Seed) Generator.random(Generator.Category.SEED), pos);
                    }
                    wand.wandUsed();
                }
            });
            break;
        // Health transfer
        case 1:
            final Char target = Actor.findChar(bolt.collisionPos);
            if (target != null) {
                cursedFX(user, bolt, new Callback() {

                    public void call() {
                        int damage = user.lvl * 2;
                        switch(Random.Int(2)) {
                            case 0:
                                user.HP = Math.min(user.HT, user.HP + damage);
                                user.sprite.emitter().burst(Speck.factory(Speck.HEALING), 3);
                                target.damage(damage, wand);
                                target.sprite.emitter().start(ShadowParticle.UP, 0.05f, 10);
                                break;
                            case 1:
                                user.damage(damage, this);
                                user.sprite.emitter().start(ShadowParticle.UP, 0.05f, 10);
                                target.HP = Math.min(target.HT, target.HP + damage);
                                target.sprite.emitter().burst(Speck.factory(Speck.HEALING), 3);
                                Sample.INSTANCE.play(Assets.SND_CURSED);
                                if (!user.isAlive()) {
                                    Dungeon.fail(wand.getClass());
                                    GLog.n(Messages.get(CursedWand.class, "ondeath", wand.name()));
                                }
                                break;
                        }
                        wand.wandUsed();
                    }
                });
            } else {
                GLog.i(Messages.get(CursedWand.class, "nothing"));
                wand.wandUsed();
            }
            break;
        // Bomb explosion
        case 2:
            cursedFX(user, bolt, new Callback() {

                public void call() {
                    new Bomb().explode(bolt.collisionPos);
                    wand.wandUsed();
                }
            });
            break;
        // shock and recharge
        case 3:
            new ShockingTrap().set(user.pos).activate();
            Buff.prolong(user, Recharging.class, 20f);
            ScrollOfRecharging.charge(user);
            SpellSprite.show(user, SpellSprite.CHARGE);
            wand.wandUsed();
            break;
    }
}
Also used : Callback(com.watabou.utils.Callback) Char(com.shatteredpixel.shatteredpixeldungeon.actors.Char) ShockingTrap(com.shatteredpixel.shatteredpixeldungeon.levels.traps.ShockingTrap) Bomb(com.shatteredpixel.shatteredpixeldungeon.items.Bomb)

Example 35 with Callback

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

the class CursedWand method commonEffect.

private static void commonEffect(final Wand wand, final Hero user, final Ballistica bolt) {
    switch(Random.Int(4)) {
        // anti-entropy
        case 0:
            cursedFX(user, bolt, new Callback() {

                public void call() {
                    Char target = Actor.findChar(bolt.collisionPos);
                    switch(Random.Int(2)) {
                        case 0:
                            if (target != null)
                                Buff.affect(target, Burning.class).reignite(target);
                            Buff.affect(user, Frost.class, Frost.duration(user) * Random.Float(3f, 5f));
                            break;
                        case 1:
                            Buff.affect(user, Burning.class).reignite(user);
                            if (target != null)
                                Buff.affect(target, Frost.class, Frost.duration(target) * Random.Float(3f, 5f));
                            break;
                    }
                    wand.wandUsed();
                }
            });
            break;
        // spawns some regrowth
        case 1:
            cursedFX(user, bolt, new Callback() {

                public void call() {
                    int c = Dungeon.level.map[bolt.collisionPos];
                    if (c == Terrain.EMPTY || c == Terrain.EMBERS || c == Terrain.EMPTY_DECO || c == Terrain.GRASS || c == Terrain.HIGH_GRASS) {
                        GameScene.add(Blob.seed(bolt.collisionPos, 30, Regrowth.class));
                    }
                    wand.wandUsed();
                }
            });
            break;
        // random teleportation
        case 2:
            switch(Random.Int(2)) {
                case 0:
                    ScrollOfTeleportation.teleportHero(user);
                    wand.wandUsed();
                    break;
                case 1:
                    cursedFX(user, bolt, new Callback() {

                        public void call() {
                            Char ch = Actor.findChar(bolt.collisionPos);
                            if (ch == user) {
                                ScrollOfTeleportation.teleportHero(user);
                                wand.wandUsed();
                            } else if (ch != null && !ch.properties().contains(Char.Property.IMMOVABLE)) {
                                int count = 10;
                                int pos;
                                do {
                                    pos = Dungeon.level.randomRespawnCell();
                                    if (count-- <= 0) {
                                        break;
                                    }
                                } while (pos == -1);
                                if (pos == -1 || Dungeon.bossLevel()) {
                                    GLog.w(Messages.get(ScrollOfTeleportation.class, "no_tele"));
                                } else {
                                    ch.pos = pos;
                                    if (((Mob) ch).state == ((Mob) ch).HUNTING)
                                        ((Mob) ch).state = ((Mob) ch).WANDERING;
                                    ch.sprite.place(ch.pos);
                                    ch.sprite.visible = Dungeon.level.heroFOV[pos];
                                }
                            }
                            wand.wandUsed();
                        }
                    });
                    break;
            }
            break;
        // random gas at location
        case 3:
            cursedFX(user, bolt, new Callback() {

                public void call() {
                    switch(Random.Int(3)) {
                        case 0:
                            GameScene.add(Blob.seed(bolt.collisionPos, 800, ConfusionGas.class));
                            break;
                        case 1:
                            GameScene.add(Blob.seed(bolt.collisionPos, 500, ToxicGas.class));
                            break;
                        case 2:
                            GameScene.add(Blob.seed(bolt.collisionPos, 200, ParalyticGas.class));
                            break;
                    }
                    wand.wandUsed();
                }
            });
            break;
    }
}
Also used : ScrollOfTeleportation(com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfTeleportation) Mob(com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob) Callback(com.watabou.utils.Callback) Char(com.shatteredpixel.shatteredpixeldungeon.actors.Char) Frost(com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Frost) Burning(com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Burning)

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