use of com.watabou.pixeldungeon.levels.Level in project pixel-dungeon-remix by NYRDS.
the class Dungeon method loadLevel.
public static Level loadLevel(Position next) throws IOException {
loading = true;
DungeonGenerator.loadingLevel(next);
String loadFrom = SaveUtils.depthFileForLoad(heroClass, DungeonGenerator.getLevelDepth(next.levelId), DungeonGenerator.getLevelKind(next.levelId), next.levelId);
GLog.toFile("loading level: %s", loadFrom);
InputStream input;
if (!DungeonGenerator.isStatic(next.levelId) && FileSystem.getFile(loadFrom).exists()) {
input = new FileInputStream(FileSystem.getFile(loadFrom));
Dungeon.level = null;
} else {
GLog.toFile("File %s not found!", loadFrom);
return newLevel(next);
}
Bundle bundle = Bundle.read(input);
input.close();
if (bundle == null) {
EventCollector.logEvent("Dungeon.loadLevel", "read fail");
return newLevel(next);
}
Level level = Level.fromBundle(bundle, "level");
LuaEngine.getEngine().require(SCRIPTS_LIB_STORAGE).get("deserializeLevelData").call(bundle.getString(SCRIPTS_DATA));
if (level == null) {
level = newLevel(next);
}
level.levelId = next.levelId;
initSizeDependentStuff(level.getWidth(), level.getHeight());
loading = false;
return level;
}
use of com.watabou.pixeldungeon.levels.Level in project pixel-dungeon-remix by NYRDS.
the class ScrollOfSummoning method doRead.
@Override
protected void doRead() {
Level level = Dungeon.level;
if (level.isBossLevel() || !level.cellValid(level.randomRespawnCell())) {
GLog.w(Utils.format(R.string.Using_Failed_Because_Magic, this.name()));
return;
}
int cell = level.getEmptyCellNextTo(getCurUser().getPos());
if (level.cellValid(cell)) {
Mob mob = Bestiary.mob(level);
GLog.i(Game.getVar(R.string.ScrollOfSummoning_Info_2));
if (mob.canBePet()) {
Mob.makePet(mob, getCurUser());
} else {
GLog.w(Utils.format(R.string.Mob_Cannot_Be_Pet, mob.getName()));
}
level.spawnMob(mob);
WandOfBlink.appear(mob, cell);
} else {
GLog.w(Game.getVar(R.string.No_Valid_Cell));
}
setKnown();
SpellSprite.show(getCurUser(), SpellSprite.SUMMON);
Sample.INSTANCE.play(Assets.SND_READ);
Invisibility.dispel(getCurUser());
getCurUser().spendAndNext(TIME_TO_READ);
}
use of com.watabou.pixeldungeon.levels.Level in project pixel-dungeon-remix by NYRDS.
the class DungeonGenerator method createLevel.
public static Level createLevel(Position pos) {
Class<? extends Level> levelClass = mLevelKindList.get(getLevelKind(pos.levelId));
if (levelClass == null) {
GLog.w("Unknown level type: %s", getLevelKind(pos.levelId));
return createLevel(pos);
}
try {
Level ret;
String levelId = pos.levelId;
if (levelClass == PredesignedLevel.class) {
String levelFile = mLevels.getJSONObject(levelId).getString("file");
ret = new PredesignedLevel(levelFile);
} else if (levelClass == RandomLevel.class) {
String levelFile = mLevels.getJSONObject(levelId).getString("file");
ret = new RandomLevel(levelFile);
} else {
ret = levelClass.newInstance();
}
ret.levelId = levelId;
JSONObject levelDesc = mLevels.getJSONObject(pos.levelId);
int xs = 32;
int ys = 32;
if (levelDesc.has("size")) {
JSONArray levelSize = levelDesc.getJSONArray("size");
xs = levelSize.optInt(0, 32);
ys = levelSize.optInt(1, 32);
}
ret.create(xs, ys);
return ret;
} catch (InstantiationException | IllegalAccessException | JSONException e) {
throw new TrackedRuntimeException(e);
}
}
use of com.watabou.pixeldungeon.levels.Level in project pixel-dungeon-remix by NYRDS.
the class Lich method spawnSkulls.
private void spawnSkulls() {
int nSkulls = SKULLS_BY_DEFAULT;
if (Game.getDifficulty() == 0) {
nSkulls = 2;
} else if (Game.getDifficulty() > 2) {
nSkulls = SKULLS_MAX;
}
Level level = Dungeon.level;
ArrayList<Integer> pedestals = level.getAllTerrainCells(Terrain.PEDESTAL);
Collections.shuffle(pedestals);
Sample.INSTANCE.play(Assets.SND_CURSED);
for (int i = 0; i < nSkulls && i < pedestals.size(); ++i) {
RunicSkull skull = RunicSkull.makeNewSkull(i);
level.spawnMob(skull);
CellEmitter.center(pedestals.get(i)).burst(ShadowParticle.CURSE, 8);
WandOfBlink.appear(skull, pedestals.get(i));
skulls.add(skull);
}
}
use of com.watabou.pixeldungeon.levels.Level in project pixel-dungeon-remix by NYRDS.
the class SummoningSpell method cast.
@Override
public boolean cast(@NonNull Char chr) {
if (chr instanceof Hero) {
Hero hero = (Hero) chr;
if (isSummoningLimitReached(hero)) {
GLog.w(getLimitWarning(getSummonLimit()));
return false;
}
hero.spend(castTime);
hero.busy();
hero.getSprite().zap(hero.getPos());
}
if (!super.cast(chr)) {
return false;
}
Level level = Dungeon.level;
int spawnPos = level.getEmptyCellNextTo(chr.getPos());
Wound.hit(chr);
Buff.detach(chr, Sungrass.Health.class);
if (level.cellValid(spawnPos)) {
Mob pet = getSummonMob();
if (chr instanceof Hero) {
Hero hero = (Hero) chr;
pet = Mob.makePet(pet, hero);
} else if (chr instanceof Mob) {
Mob mob = (Mob) chr;
pet.setFraction(mob.fraction());
} else {
pet.setFraction(Fraction.DUNGEON);
}
pet.setPos(spawnPos);
level.spawnMob(pet);
}
castCallback(chr);
return true;
}
Aggregations