Search in sources :

Example 6 with Level

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;
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Bundle(com.watabou.utils.Bundle) IceCavesLevel(com.nyrds.pixeldungeon.levels.IceCavesLevel) NecroLevel(com.nyrds.pixeldungeon.levels.NecroLevel) DeadEndLevel(com.watabou.pixeldungeon.levels.DeadEndLevel) Level(com.watabou.pixeldungeon.levels.Level) FileInputStream(java.io.FileInputStream)

Example 7 with 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);
}
Also used : Mob(com.watabou.pixeldungeon.actors.mobs.Mob) Level(com.watabou.pixeldungeon.levels.Level)

Example 8 with Level

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);
    }
}
Also used : TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) RandomLevel(com.nyrds.pixeldungeon.levels.RandomLevel) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) PredesignedLevel(com.nyrds.pixeldungeon.levels.PredesignedLevel) JSONObject(org.json.JSONObject) GutsLevel(com.nyrds.pixeldungeon.levels.GutsLevel) PrisonLevel(com.watabou.pixeldungeon.levels.PrisonLevel) IceCavesLevel(com.nyrds.pixeldungeon.levels.IceCavesLevel) CavesLevel(com.watabou.pixeldungeon.levels.CavesLevel) TownShopLevel(com.nyrds.pixeldungeon.levels.TownShopLevel) HallsBossLevel(com.watabou.pixeldungeon.levels.HallsBossLevel) CavesBossLevel(com.watabou.pixeldungeon.levels.CavesBossLevel) NecroLevel(com.nyrds.pixeldungeon.levels.NecroLevel) ShadowLordLevel(com.nyrds.pixeldungeon.levels.ShadowLordLevel) DeadEndLevel(com.watabou.pixeldungeon.levels.DeadEndLevel) SewerBossLevel(com.watabou.pixeldungeon.levels.SewerBossLevel) LastLevel(com.watabou.pixeldungeon.levels.LastLevel) PrisonBossLevel(com.watabou.pixeldungeon.levels.PrisonBossLevel) CityLevel(com.watabou.pixeldungeon.levels.CityLevel) LastShopLevel(com.watabou.pixeldungeon.levels.LastShopLevel) Level(com.watabou.pixeldungeon.levels.Level) PredesignedLevel(com.nyrds.pixeldungeon.levels.PredesignedLevel) RandomLevel(com.nyrds.pixeldungeon.levels.RandomLevel) SewerLevel(com.watabou.pixeldungeon.levels.SewerLevel) SpiderLevel(com.nyrds.pixeldungeon.spiders.levels.SpiderLevel) CityBossLevel(com.watabou.pixeldungeon.levels.CityBossLevel) HallsLevel(com.watabou.pixeldungeon.levels.HallsLevel) FakeLastLevel(com.nyrds.pixeldungeon.levels.FakeLastLevel) IceCavesBossLevel(com.nyrds.pixeldungeon.levels.IceCavesBossLevel) NecroBossLevel(com.nyrds.pixeldungeon.levels.NecroBossLevel)

Example 9 with Level

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);
    }
}
Also used : Level(com.watabou.pixeldungeon.levels.Level)

Example 10 with Level

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;
}
Also used : Mob(com.watabou.pixeldungeon.actors.mobs.Mob) Hero(com.watabou.pixeldungeon.actors.hero.Hero) Level(com.watabou.pixeldungeon.levels.Level) Sungrass(com.watabou.pixeldungeon.plants.Sungrass)

Aggregations

Level (com.watabou.pixeldungeon.levels.Level)37 Mob (com.watabou.pixeldungeon.actors.mobs.Mob)7 Char (com.watabou.pixeldungeon.actors.Char)5 DeadEndLevel (com.watabou.pixeldungeon.levels.DeadEndLevel)5 LevelObject (com.nyrds.pixeldungeon.levels.objects.LevelObject)4 Pushing (com.watabou.pixeldungeon.effects.Pushing)4 IceCavesLevel (com.nyrds.pixeldungeon.levels.IceCavesLevel)3 NecroLevel (com.nyrds.pixeldungeon.levels.NecroLevel)3 Position (com.nyrds.pixeldungeon.utils.Position)3 Heap (com.watabou.pixeldungeon.items.Heap)3 CavesBossLevel (com.watabou.pixeldungeon.levels.CavesBossLevel)3 CavesLevel (com.watabou.pixeldungeon.levels.CavesLevel)3 CityBossLevel (com.watabou.pixeldungeon.levels.CityBossLevel)3 CityLevel (com.watabou.pixeldungeon.levels.CityLevel)3 HallsBossLevel (com.watabou.pixeldungeon.levels.HallsBossLevel)3 HallsLevel (com.watabou.pixeldungeon.levels.HallsLevel)3 LastLevel (com.watabou.pixeldungeon.levels.LastLevel)3 LastShopLevel (com.watabou.pixeldungeon.levels.LastShopLevel)3 PrisonBossLevel (com.watabou.pixeldungeon.levels.PrisonBossLevel)3 PrisonLevel (com.watabou.pixeldungeon.levels.PrisonLevel)3