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