Search in sources :

Example 6 with Bundle

use of com.watabou.utils.Bundle in project pixel-dungeon by watabou.

the class Bones method get.

public static Item get() {
    if (depth == -1) {
        try {
            InputStream input = Game.instance.openFileInput(BONES_FILE);
            Bundle bundle = Bundle.read(input);
            input.close();
            depth = bundle.getInt(LEVEL);
            item = (Item) bundle.get(ITEM);
            return get();
        } catch (IOException e) {
            return null;
        }
    } else {
        if (depth == Dungeon.depth) {
            Game.instance.deleteFile(BONES_FILE);
            depth = 0;
            if (!item.stackable) {
                item.cursed = true;
                item.cursedKnown = true;
                if (item.isUpgradable()) {
                    int lvl = (Dungeon.depth - 1) * 3 / 5 + 1;
                    if (lvl < item.level()) {
                        item.degrade(item.level() - lvl);
                    }
                    item.levelKnown = false;
                }
            }
            if (item instanceof Ring) {
                ((Ring) item).syncGem();
            }
            return item;
        } else {
            return null;
        }
    }
}
Also used : InputStream(java.io.InputStream) Bundle(com.watabou.utils.Bundle) Ring(com.watabou.pixeldungeon.items.rings.Ring) IOException(java.io.IOException)

Example 7 with Bundle

use of com.watabou.utils.Bundle in project pixel-dungeon by watabou.

the class Bones method leave.

public static void leave() {
    item = null;
    switch(Random.Int(4)) {
        case 0:
            item = Dungeon.hero.belongings.weapon;
            break;
        case 1:
            item = Dungeon.hero.belongings.armor;
            break;
        case 2:
            item = Dungeon.hero.belongings.ring1;
            break;
        case 3:
            item = Dungeon.hero.belongings.ring2;
            break;
    }
    if (item == null) {
        if (Dungeon.gold > 0) {
            item = new Gold(Random.IntRange(1, Dungeon.gold));
        } else {
            item = new Gold(1);
        }
    }
    depth = Dungeon.depth;
    Bundle bundle = new Bundle();
    bundle.put(LEVEL, depth);
    bundle.put(ITEM, item);
    try {
        OutputStream output = Game.instance.openFileOutput(BONES_FILE, Game.MODE_PRIVATE);
        Bundle.write(bundle, output);
        output.close();
    } catch (IOException e) {
    }
}
Also used : Gold(com.watabou.pixeldungeon.items.Gold) Bundle(com.watabou.utils.Bundle) OutputStream(java.io.OutputStream) IOException(java.io.IOException)

Example 8 with Bundle

use of com.watabou.utils.Bundle in project pixel-dungeon by watabou.

the class Dungeon method loadLevel.

public static Level loadLevel(HeroClass cl) throws IOException {
    Dungeon.level = null;
    Actor.clear();
    InputStream input = Game.instance.openFileInput(Utils.format(depthFile(cl), depth));
    Bundle bundle = Bundle.read(input);
    input.close();
    return (Level) bundle.get("level");
}
Also used : InputStream(java.io.InputStream) Bundle(com.watabou.utils.Bundle) PrisonLevel(com.watabou.pixeldungeon.levels.PrisonLevel) HallsBossLevel(com.watabou.pixeldungeon.levels.HallsBossLevel) CavesBossLevel(com.watabou.pixeldungeon.levels.CavesBossLevel) DeadEndLevel(com.watabou.pixeldungeon.levels.DeadEndLevel) LastLevel(com.watabou.pixeldungeon.levels.LastLevel) CityLevel(com.watabou.pixeldungeon.levels.CityLevel) LastShopLevel(com.watabou.pixeldungeon.levels.LastShopLevel) CavesLevel(com.watabou.pixeldungeon.levels.CavesLevel) SewerBossLevel(com.watabou.pixeldungeon.levels.SewerBossLevel) PrisonBossLevel(com.watabou.pixeldungeon.levels.PrisonBossLevel) Level(com.watabou.pixeldungeon.levels.Level) SewerLevel(com.watabou.pixeldungeon.levels.SewerLevel) CityBossLevel(com.watabou.pixeldungeon.levels.CityBossLevel) HallsLevel(com.watabou.pixeldungeon.levels.HallsLevel)

Example 9 with Bundle

use of com.watabou.utils.Bundle in project pixel-dungeon by watabou.

the class Dungeon method saveLevel.

public static void saveLevel() throws IOException {
    Bundle bundle = new Bundle();
    bundle.put(LEVEL, level);
    OutputStream output = Game.instance.openFileOutput(Utils.format(depthFile(hero.heroClass), depth), Game.MODE_PRIVATE);
    Bundle.write(bundle, output);
    output.close();
}
Also used : Bundle(com.watabou.utils.Bundle) OutputStream(java.io.OutputStream)

Example 10 with Bundle

use of com.watabou.utils.Bundle in project pixel-dungeon by watabou.

the class GamesInProgress method check.

public static Info check(HeroClass cl) {
    if (state.containsKey(cl)) {
        return state.get(cl);
    } else {
        Info info;
        try {
            Bundle bundle = Dungeon.gameBundle(Dungeon.gameFile(cl));
            info = new Info();
            Dungeon.preview(info, bundle);
        } catch (Exception e) {
            info = null;
        }
        state.put(cl, info);
        return info;
    }
}
Also used : Bundle(com.watabou.utils.Bundle)

Aggregations

Bundle (com.watabou.utils.Bundle)10 IOException (java.io.IOException)5 InputStream (java.io.InputStream)4 OutputStream (java.io.OutputStream)4 Gold (com.watabou.pixeldungeon.items.Gold)1 Item (com.watabou.pixeldungeon.items.Item)1 Ring (com.watabou.pixeldungeon.items.rings.Ring)1 CavesBossLevel (com.watabou.pixeldungeon.levels.CavesBossLevel)1 CavesLevel (com.watabou.pixeldungeon.levels.CavesLevel)1 CityBossLevel (com.watabou.pixeldungeon.levels.CityBossLevel)1 CityLevel (com.watabou.pixeldungeon.levels.CityLevel)1 DeadEndLevel (com.watabou.pixeldungeon.levels.DeadEndLevel)1 HallsBossLevel (com.watabou.pixeldungeon.levels.HallsBossLevel)1 HallsLevel (com.watabou.pixeldungeon.levels.HallsLevel)1 LastLevel (com.watabou.pixeldungeon.levels.LastLevel)1 LastShopLevel (com.watabou.pixeldungeon.levels.LastShopLevel)1 Level (com.watabou.pixeldungeon.levels.Level)1 PrisonBossLevel (com.watabou.pixeldungeon.levels.PrisonBossLevel)1 PrisonLevel (com.watabou.pixeldungeon.levels.PrisonLevel)1 SewerBossLevel (com.watabou.pixeldungeon.levels.SewerBossLevel)1