Search in sources :

Example 36 with Callback

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

the class CursedWand method rareEffect.

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

                public void call() {
                    Char ch = Actor.findChar(bolt.collisionPos);
                    if (ch != null && ch != user && !ch.properties().contains(Char.Property.BOSS) && !ch.properties().contains(Char.Property.MINIBOSS)) {
                        Sheep sheep = new Sheep();
                        sheep.lifespan = 10;
                        sheep.pos = ch.pos;
                        ch.destroy();
                        ch.sprite.killAndErase();
                        Dungeon.level.mobs.remove(ch);
                        TargetHealthIndicator.instance.target(null);
                        GameScene.add(sheep);
                        CellEmitter.get(sheep.pos).burst(Speck.factory(Speck.WOOL), 4);
                    } else {
                        GLog.i(Messages.get(CursedWand.class, "nothing"));
                    }
                    wand.wandUsed();
                }
            });
            break;
        // curses!
        case 1:
            CursingTrap.curse(user);
            wand.wandUsed();
            break;
        // inter-level teleportation
        case 2:
            if (Dungeon.depth > 1 && !Dungeon.bossLevel()) {
                // each depth has 1 more weight than the previous depth.
                float[] depths = new float[Dungeon.depth - 1];
                for (int i = 1; i < Dungeon.depth; i++) depths[i - 1] = i;
                int depth = 1 + Random.chances(depths);
                Buff buff = Dungeon.hero.buff(TimekeepersHourglass.timeFreeze.class);
                if (buff != null)
                    buff.detach();
                InterlevelScene.mode = InterlevelScene.Mode.RETURN;
                InterlevelScene.returnDepth = depth;
                InterlevelScene.returnPos = -1;
                Game.switchScene(InterlevelScene.class);
            } else {
                ScrollOfTeleportation.teleportHero(user);
                wand.wandUsed();
            }
            break;
        // summon monsters
        case 3:
            new SummoningTrap().set(user.pos).activate();
            wand.wandUsed();
            break;
    }
}
Also used : Callback(com.watabou.utils.Callback) TimekeepersHourglass(com.shatteredpixel.shatteredpixeldungeon.items.artifacts.TimekeepersHourglass) Char(com.shatteredpixel.shatteredpixeldungeon.actors.Char) Sheep(com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.Sheep) SummoningTrap(com.shatteredpixel.shatteredpixeldungeon.levels.traps.SummoningTrap) Buff(com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff)

Example 37 with Callback

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

the class WandOfBlastWave method throwChar.

public static void throwChar(final Char ch, final Ballistica trajectory, int power) {
    int dist = Math.min(trajectory.dist, power);
    if (ch.properties().contains(Char.Property.BOSS))
        dist /= 2;
    if (dist == 0 || ch.properties().contains(Char.Property.IMMOVABLE))
        return;
    if (Actor.findChar(trajectory.path.get(dist)) != null) {
        dist--;
    }
    final int newPos = trajectory.path.get(dist);
    if (newPos == ch.pos)
        return;
    final int finalDist = dist;
    final int initialpos = ch.pos;
    Actor.addDelayed(new Pushing(ch, ch.pos, newPos, new Callback() {

        public void call() {
            if (initialpos != ch.pos) {
                // something cased movement before pushing resolved, cancel to be safe.
                ch.sprite.place(ch.pos);
                return;
            }
            ch.pos = newPos;
            if (ch.pos == trajectory.collisionPos) {
                ch.damage(Random.NormalIntRange((finalDist + 1) / 2, finalDist), this);
                Paralysis.prolong(ch, Paralysis.class, Random.NormalIntRange((finalDist + 1) / 2, finalDist));
            }
            Dungeon.level.press(ch.pos, ch, true);
            if (ch == Dungeon.hero) {
                Dungeon.observe();
            }
        }
    }), -1);
}
Also used : Callback(com.watabou.utils.Callback) Pushing(com.shatteredpixel.shatteredpixeldungeon.effects.Pushing)

Example 38 with Callback

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

the class MobSpriteDef method selectKind.

@Override
public void selectKind(int kind) {
    EventCollector.collectSessionData("selectKind", name);
    this.kind = kind;
    JSONObject json = defMap.get(name);
    try {
        texture(json.getString("texture"));
        if (json.has("layers")) {
            JSONArray layers = json.getJSONArray("layers");
            for (int i = 0; i < layers.length(); ++i) {
                JSONObject layer = layers.getJSONObject(i);
                addLayer(layer.getString("id"), TextureCache.get(layer.get("texture")));
            }
        }
        int width = json.getInt("width");
        TextureFilm film = new TextureFilm(texture, width, json.getInt("height"));
        bloodColor = 0xFFBB0000;
        Object _bloodColor = json.opt("bloodColor");
        if (_bloodColor instanceof Number) {
            bloodColor = (int) _bloodColor;
        }
        if (_bloodColor instanceof String) {
            bloodColor = Long.decode((String) _bloodColor).intValue();
        }
        levitating = json.optBoolean("levitating", false);
        framesInRow = texture.width / width;
        idle = readAnimation(json, "idle", film);
        run = readAnimation(json, "run", film);
        attack = readAnimation(json, "attack", film);
        die = readAnimation(json, "die", film);
        if (json.has("zap")) {
            zap = readAnimation(json, "zap", film);
        } else {
            zap = attack.clone();
        }
        if (json.has("zapEffect")) {
            zapEffect = json.getString("zapEffect");
            zapCallback = new Callback() {

                @Override
                public void call() {
                // ch.onZapComplete();
                }
            };
        }
        loadAdditionalData(json, film, kind);
    } catch (Exception e) {
        Game.toast(Utils.format("Something bad happens when loading %s", name), e);
        throw new TrackedRuntimeException(Utils.format("Something bad happens when loading %s", name), e);
    }
    play(idle);
}
Also used : Callback(com.watabou.utils.Callback) TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONObject(org.json.JSONObject) TextureFilm(com.watabou.noosa.TextureFilm) JSONException(org.json.JSONException) TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException)

Example 39 with Callback

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

the class PortalGate method playStartUpAnim.

protected void playStartUpAnim() {
    animationRunning = true;
    sprite.playAnim(8, false, new Callback() {

        @Override
        public void call() {
            playActiveLoop();
            activated = true;
            animationRunning = false;
            GLog.w(TXT_ACTIVATED);
        }
    }, image() + 0, image() + 1, image() + 2, image() + 3, image() + 4, image() + 5, image() + 6, image() + 7, image() + 8, image() + 9, image() + 10, image() + 11, image() + 12, image() + 13, image() + 14, image() + 15, image() + 16);
}
Also used : Callback(com.watabou.utils.Callback)

Example 40 with Callback

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

the class Wand method wandEffect.

protected void wandEffect(final int cell) {
    setKnown();
    QuickSlot.target(curItem, Actor.findChar(cell));
    if (curCharges() > 0) {
        getCurUser().busy();
        fx(cell, new Callback() {

            @Override
            public void call() {
                onZap(cell);
                wandUsed();
            }
        });
        Invisibility.dispel(getCurUser());
    } else {
        getCurUser().spendAndNext(TIME_TO_ZAP);
        GLog.w(TXT_FIZZLES);
        levelKnown = true;
        if (Random.Int(5) == 0) {
            identify();
        }
        updateQuickslot();
    }
}
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