@Override
    public void restoreFromBundle(Bundle bundle) {

      info = bundle.getString(REASON);
      win = bundle.getBoolean(WIN);
      score = bundle.getInt(SCORE);

      heroClass = HeroClass.restoreInBundle(bundle);
      armorTier = bundle.getInt(TIER);

      gameFile = bundle.getString(GAME);

      // Here lies a collection of messy logic, some to account for transferring pre-0.2.3 rankings
      // to the new
      // system, some to account for errors in that process which were patched.
      // commented here is info about what was added when, and why, eventually after almost everyone
      // has
      // dropped 0.2.2 this can be phased out.

      // 0.2.3, adds depth and parses info, works almost perfectly, except for the edge case in the
      // next comment.
      if (!bundle.contains(DEPTH)) {
        try {
          depth = Integer.parseInt(info.replaceAll("[\\D]", ""));
        } catch (Exception e) {
          depth = 0;
        }
        info = info.split("on level")[0].trim();
      } else depth = bundle.getInt(DEPTH);

      // 0.2.3d, fixes a case where a player who died to dm-300 would have a recorded depth of
      // 30015.
      if (depth == 30015) depth = 15;

      // basically every patch until 0.2.3d, extracts the hero's level from the bundle structure.
      // the second condition in the if is important, helps account for bugged rankings from pre
      // 0.2.3d
      if (!bundle.contains(LEVEL)
          || bundle.getInt(LEVEL) == 0 && ShatteredPixelDungeon.version() < 30) {
        try {

          InputStream input = Game.instance.openFileInput(gameFile);
          Bundle gameBundle = Bundle.read(input);
          input.close();

          herolevel = gameBundle.getBundle("hero").getInt("lvl");
        } catch (Exception e) {
          herolevel = 0;
        }
      } else herolevel = bundle.getInt(LEVEL);
    }
 public static HeroSubClass restoreInBundle(Bundle bundle) {
   String value = bundle.getString(SUBCLASS);
   try {
     return valueOf(value);
   } catch (Exception e) {
     return NONE;
   }
 }
  private void restore(Bundle bundle, String[] allLabels, Integer[] allImages) {

    ArrayList<String> labelsLeft = new ArrayList<String>(Arrays.asList(allLabels));
    ArrayList<Integer> imagesLeft = new ArrayList<Integer>(Arrays.asList(allImages));

    for (int i = 0; i < items.length; i++) {

      Class<? extends T> item = (Class<? extends T>) (items[i]);
      String itemName = item.toString();

      if (bundle.contains(itemName + PFX_LABEL)) {

        String label = bundle.getString(itemName + PFX_LABEL);
        labels.put(item, label);
        labelsLeft.remove(label);

        Integer image = bundle.getInt(itemName + PFX_IMAGE);
        images.put(item, image);
        imagesLeft.remove(image);

        if (bundle.getBoolean(itemName + PFX_KNOWN)) {
          known.add(item);
        }

      } else {

        int index = Random.Int(labelsLeft.size());

        labels.put(item, labelsLeft.get(index));
        labelsLeft.remove(index);

        images.put(item, imagesLeft.get(index));
        imagesLeft.remove(index);
      }
    }
  }
예제 #4
0
  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);
    arcaneStyli = bundle.getInt(AS);
    dewVial = bundle.getBoolean(DV);
    transmutation = bundle.getInt(WT);

    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();
    }

    String qsClass = bundle.getString(QUICKSLOT);
    if (qsClass != null) {
      try {
        quickslot = Class.forName(qsClass);
      } catch (ClassNotFoundException e) {
      }
    } else {
      quickslot = null;
    }

    @SuppressWarnings("unused")
    String version = bundle.getString(VERSION);

    hero = null;
    hero = (Hero) bundle.get(HERO);

    gold = bundle.getInt(GOLD);
    depth = bundle.getInt(DEPTH);

    Statistics.restoreFromBundle(bundle);
    Journal.restoreFromBundle(bundle);
  }
예제 #5
0
 @Override
 public void restoreFromBundle(Bundle bundle) {
   feature = Feature.valueOf(bundle.getString(FEATURE));
   depth = bundle.getInt(DEPTH);
 }