Search in sources :

Example 6 with TrackedRuntimeException

use of com.nyrds.android.util.TrackedRuntimeException in project pixel-dungeon-remix by NYRDS.

the class ChaosStaff method onZap.

@Override
protected void onZap(int cell) {
    ChaosCommon.doChaosMark(cell, 10 + level() * 10 + charge);
    charge = 0;
    if (Math.random() < 0.1f) {
        Char ch = Actor.findChar(cell);
        if (ch instanceof Mob) {
            Mob mob = (Mob) ch;
            if ((mob instanceof Boss) || (mob instanceof NPC)) {
                return;
            }
            switch(Random.Int(0, 4)) {
                case 0:
                    mob.die(getCurUser());
                    break;
                case 1:
                    Mob.makePet(mob, getCurUser());
                    break;
                case 2:
                    int nextCell = Dungeon.level.getEmptyCellNextTo(cell);
                    if (Dungeon.level.cellValid(nextCell)) {
                        try {
                            Mob newMob = mob.getClass().newInstance();
                            Dungeon.level.spawnMob(newMob);
                        } catch (Exception e) {
                            throw new TrackedRuntimeException(e);
                        }
                    }
                    break;
                case 3:
                    WandOfTeleportation.teleport(mob);
                    break;
                case 4:
                    PotionOfHealing.heal(ch, 1);
                    break;
            }
        }
    }
}
Also used : NPC(com.watabou.pixeldungeon.actors.mobs.npcs.NPC) Mob(com.watabou.pixeldungeon.actors.mobs.Mob) Boss(com.watabou.pixeldungeon.actors.mobs.Boss) TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) Char(com.watabou.pixeldungeon.actors.Char) TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException)

Example 7 with TrackedRuntimeException

use of com.nyrds.android.util.TrackedRuntimeException in project pixel-dungeon-remix by NYRDS.

the class Level method fillAreaWith.

public void fillAreaWith(Class<? extends Blob> blobClass, int x, int y, int xs, int ys, int amount) {
    Blob blob = Dungeon.level.blobs.get(blobClass);
    if (blob == null) {
        try {
            blob = blobClass.newInstance();
        } catch (Exception e) {
            throw new TrackedRuntimeException(e);
        }
        GameScene.add(blob);
    }
    for (int i = x; i <= x + xs; i++) {
        for (int j = y; j <= y + ys; j++) {
            if (cellValid(i, j)) {
                blob.seed(i, j, amount);
            }
        }
    }
    blobs.put(blobClass, blob);
}
Also used : Blob(com.watabou.pixeldungeon.actors.blobs.Blob) TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException)

Example 8 with TrackedRuntimeException

use of com.nyrds.android.util.TrackedRuntimeException in project pixel-dungeon-remix by NYRDS.

the class MagicWellPainter method paint.

public static void paint(Level level, Room room) {
    fill(level, room, Terrain.WALL);
    fill(level, room, 1, Terrain.EMPTY);
    Point c = room.center();
    set(level, c.x, c.y, Terrain.WELL);
    @SuppressWarnings("unchecked") Class<? extends WellWater> waterClass = Dungeon.depth >= Dungeon.transmutation ? WaterOfTransmutation.class : (Class<? extends WellWater>) Random.element(WATERS);
    if (waterClass == WaterOfTransmutation.class) {
        Dungeon.transmutation = Integer.MAX_VALUE;
    }
    WellWater water = (WellWater) level.blobs.get(waterClass);
    if (water == null) {
        try {
            water = waterClass.newInstance();
        } catch (Exception e) {
            throw new TrackedRuntimeException(e);
        }
    }
    water.seed(c.x + level.getWidth() * c.y, 1);
    level.blobs.put(waterClass, water);
    room.entrance().set(Room.Door.Type.REGULAR);
}
Also used : TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) WellWater(com.watabou.pixeldungeon.actors.blobs.WellWater) Point(com.watabou.utils.Point) TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException)

Example 9 with TrackedRuntimeException

use of com.nyrds.android.util.TrackedRuntimeException 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 10 with TrackedRuntimeException

use of com.nyrds.android.util.TrackedRuntimeException in project pixel-dungeon-remix by NYRDS.

the class DungeonGenerator method descendOrAscend.

private static Position descendOrAscend(Position current, boolean descend) {
    try {
        if (current.levelId.equals("unknown")) {
            current.levelId = "1";
        }
        JSONArray currentLevel = mGraph.getJSONArray(current.levelId);
        JSONArray nextLevelSet = currentLevel.getJSONArray(descend ? 0 : 1);
        Position next = new Position();
        int index = 0;
        next.cellId = -1;
        if (descend && !current.levelId.equals(getEntryLevel())) {
            if (Dungeon.level != null) {
                // not first descend
                if (Dungeon.level.isExit(current.cellId)) {
                    index = Dungeon.level.exitIndex(current.cellId);
                    next.cellId = -(index + 1);
                }
            }
        }
        if (!descend) {
            if (currentLevel.length() > 2) {
                int exitIndex = currentLevel.getJSONArray(2).getInt(0);
                next.cellId = -exitIndex;
            }
        }
        if (index >= nextLevelSet.length()) {
            index = 0;
            EventCollector.logEvent("DungeonGenerator", "wrong next level index");
        }
        mCurrentLevelId = nextLevelSet.optString(index, "0");
        JSONObject nextLevelDesc = mLevels.getJSONObject(mCurrentLevelId);
        next.levelId = mCurrentLevelId;
        mCurrentLevelDepth = nextLevelDesc.optInt("depth", 0);
        mCurrentLevelKind = getLevelKind(next.levelId);
        return next;
    } catch (JSONException e) {
        throw new TrackedRuntimeException(e);
    }
}
Also used : TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException)

Aggregations

TrackedRuntimeException (com.nyrds.android.util.TrackedRuntimeException)41 JSONException (org.json.JSONException)24 JSONArray (org.json.JSONArray)15 JSONObject (org.json.JSONObject)10 IOException (java.io.IOException)5 Mob (com.watabou.pixeldungeon.actors.mobs.Mob)4 Item (com.watabou.pixeldungeon.items.Item)3 SuppressLint (android.annotation.SuppressLint)2 Pushing (com.watabou.pixeldungeon.effects.Pushing)2 Bitmap (android.graphics.Bitmap)1 Nullable (android.support.annotation.Nullable)1 FakeLastLevel (com.nyrds.pixeldungeon.levels.FakeLastLevel)1 GutsLevel (com.nyrds.pixeldungeon.levels.GutsLevel)1 IceCavesBossLevel (com.nyrds.pixeldungeon.levels.IceCavesBossLevel)1 IceCavesLevel (com.nyrds.pixeldungeon.levels.IceCavesLevel)1 NecroBossLevel (com.nyrds.pixeldungeon.levels.NecroBossLevel)1 NecroLevel (com.nyrds.pixeldungeon.levels.NecroLevel)1 PredesignedLevel (com.nyrds.pixeldungeon.levels.PredesignedLevel)1 RandomLevel (com.nyrds.pixeldungeon.levels.RandomLevel)1 ShadowLordLevel (com.nyrds.pixeldungeon.levels.ShadowLordLevel)1