Search in sources :

Example 1 with Bundlable

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

the class Dungeon method loadGame.

public static void loadGame(String fileName, boolean fullLoad) throws IOException {
    Bundle bundle = gameBundle(fileName);
    Dungeon.challenges = bundle.getInt(CHALLENGES);
    Dungeon.level = null;
    Dungeon.depth = -1;
    if (fullLoad) {
        PathFinder.setMapSize(Level.WIDTH, Level.HEIGHT);
    }
    Scroll.restore(bundle);
    Potion.restore(bundle);
    Wand.restore(bundle);
    Ring.restore(bundle);
    potionOfStrength = bundle.getInt(POS);
    scrollsOfUpgrade = bundle.getInt(SOU);
    scrollsOfEnchantment = bundle.getInt(SOE);
    dewVial = bundle.getBoolean(DV);
    if (fullLoad) {
        chapters = new HashSet<Integer>();
        int[] ids = bundle.getIntArray(CHAPTERS);
        if (ids != null) {
            for (int id : ids) {
                chapters.add(id);
            }
        }
        Bundle quests = bundle.getBundle(QUESTS);
        if (!quests.isNull()) {
            Ghost.Quest.restoreFromBundle(quests);
            Wandmaker.Quest.restoreFromBundle(quests);
            Blacksmith.Quest.restoreFromBundle(quests);
            Imp.Quest.restoreFromBundle(quests);
        } else {
            Ghost.Quest.reset();
            Wandmaker.Quest.reset();
            Blacksmith.Quest.reset();
            Imp.Quest.reset();
        }
        Room.restoreRoomsFromBundle(bundle);
    }
    Bundle badges = bundle.getBundle(BADGES);
    if (!badges.isNull()) {
        Badges.loadLocal(badges);
    } else {
        Badges.reset();
    }
    QuickSlot.restore(bundle);
    @SuppressWarnings("unused") String version = bundle.getString(VERSION);
    hero = null;
    hero = (Hero) bundle.get(HERO);
    QuickSlot.compress();
    gold = bundle.getInt(GOLD);
    depth = bundle.getInt(DEPTH);
    Statistics.restoreFromBundle(bundle);
    Journal.restoreFromBundle(bundle);
    droppedItems = new SparseArray<ArrayList<Item>>();
    for (int i = 2; i <= Statistics.deepestFloor + 1; i++) {
        ArrayList<Item> dropped = new ArrayList<Item>();
        for (Bundlable b : bundle.getCollection(String.format(DROPPED, i))) {
            dropped.add((Item) b);
        }
        if (!dropped.isEmpty()) {
            droppedItems.put(i, dropped);
        }
    }
}
Also used : Item(com.watabou.pixeldungeon.items.Item) Bundlable(com.watabou.utils.Bundlable) Bundle(com.watabou.utils.Bundle) ArrayList(java.util.ArrayList)

Example 2 with Bundlable

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

the class Char method restoreFromBundle.

@Override
public void restoreFromBundle(Bundle bundle) {
    super.restoreFromBundle(bundle);
    pos = bundle.getInt(POS);
    HP = bundle.getInt(TAG_HP);
    HT = bundle.getInt(TAG_HT);
    for (Bundlable b : bundle.getCollection(BUFFS)) {
        if (b != null) {
            ((Buff) b).attachTo(this);
        }
    }
}
Also used : Bundlable(com.watabou.utils.Bundlable) Buff(com.watabou.pixeldungeon.actors.buffs.Buff)

Example 3 with Bundlable

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

the class Level method restoreFromBundle.

@Override
public void restoreFromBundle(Bundle bundle) {
    mobs = new HashSet<Mob>();
    heaps = new SparseArray<Heap>();
    blobs = new HashMap<Class<? extends Blob>, Blob>();
    plants = new SparseArray<Plant>();
    map = bundle.getIntArray(MAP);
    visited = bundle.getBooleanArray(VISITED);
    mapped = bundle.getBooleanArray(MAPPED);
    entrance = bundle.getInt(ENTRANCE);
    exit = bundle.getInt(EXIT);
    weakFloorCreated = false;
    adjustMapSize();
    Collection<Bundlable> collection = bundle.getCollection(HEAPS);
    for (Bundlable h : collection) {
        Heap heap = (Heap) h;
        if (resizingNeeded) {
            heap.pos = adjustPos(heap.pos);
        }
        heaps.put(heap.pos, heap);
    }
    collection = bundle.getCollection(PLANTS);
    for (Bundlable p : collection) {
        Plant plant = (Plant) p;
        if (resizingNeeded) {
            plant.pos = adjustPos(plant.pos);
        }
        plants.put(plant.pos, plant);
    }
    collection = bundle.getCollection(MOBS);
    for (Bundlable m : collection) {
        Mob mob = (Mob) m;
        if (mob != null) {
            if (resizingNeeded) {
                mob.pos = adjustPos(mob.pos);
            }
            mobs.add(mob);
        }
    }
    collection = bundle.getCollection(BLOBS);
    for (Bundlable b : collection) {
        Blob blob = (Blob) b;
        blobs.put(blob.getClass(), blob);
    }
    buildFlagMaps();
    cleanWalls();
}
Also used : Mob(com.watabou.pixeldungeon.actors.mobs.Mob) Blob(com.watabou.pixeldungeon.actors.blobs.Blob) Plant(com.watabou.pixeldungeon.plants.Plant) Bundlable(com.watabou.utils.Bundlable) HeroClass(com.watabou.pixeldungeon.actors.hero.HeroClass) Heap(com.watabou.pixeldungeon.items.Heap)

Aggregations

Bundlable (com.watabou.utils.Bundlable)3 Blob (com.watabou.pixeldungeon.actors.blobs.Blob)1 Buff (com.watabou.pixeldungeon.actors.buffs.Buff)1 HeroClass (com.watabou.pixeldungeon.actors.hero.HeroClass)1 Mob (com.watabou.pixeldungeon.actors.mobs.Mob)1 Heap (com.watabou.pixeldungeon.items.Heap)1 Item (com.watabou.pixeldungeon.items.Item)1 Plant (com.watabou.pixeldungeon.plants.Plant)1 Bundle (com.watabou.utils.Bundle)1 ArrayList (java.util.ArrayList)1