Search in sources :

Example 36 with TrackedRuntimeException

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

the class PredesignedLevel method createItems.

@Override
protected void createItems() {
    try {
        if (mLevelDesc.has("items")) {
            JSONArray itemsDesc = mLevelDesc.getJSONArray("items");
            for (int i = 0; i < itemsDesc.length(); ++i) {
                JSONObject itemDesc = itemsDesc.optJSONObject(i);
                int x = itemDesc.getInt("x");
                int y = itemDesc.getInt("y");
                if (cellValid(x, y)) {
                    Item item = ItemFactory.createItemFromDesc(itemDesc);
                    drop(item, cell(x, y));
                }
            }
        }
    } catch (JSONException e) {
        throw new TrackedRuntimeException("bad items description", e);
    } catch (Exception e) {
        throw new TrackedRuntimeException(e);
    }
}
Also used : Item(com.watabou.pixeldungeon.items.Item) TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) JSONException(org.json.JSONException)

Example 37 with TrackedRuntimeException

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

the class SpellFactory method getSpellByName.

@Nullable
public static Spell getSpellByName(String name) {
    try {
        Class<? extends Spell> spellClass = mSpellsList.get(name);
        if (spellClass == null) {
            EventCollector.logEvent("bug", Utils.format("Unknown spell: [%s], getting Magic Torch instead", name));
            spellClass = mSpellsList.get("MagicTorch");
        }
        return spellClass.newInstance();
    } catch (InstantiationException e) {
        throw new TrackedRuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new TrackedRuntimeException(e);
    }
}
Also used : TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) Nullable(android.support.annotation.Nullable)

Example 38 with TrackedRuntimeException

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

the class Item method detach.

public final Item detach(Bag container) {
    if (quantity() <= 0) {
        return null;
    } else {
        if (quantity() == 1) {
            return detachAll(container);
        } else {
            quantity(quantity() - 1);
            updateQuickslot();
            try {
                Item detached = getClass().newInstance();
                detached.level(level());
                detached.onDetach();
                return detached;
            } catch (Exception e) {
                throw new TrackedRuntimeException(e);
            }
        }
    }
}
Also used : TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) JSONException(org.json.JSONException) TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException)

Example 39 with TrackedRuntimeException

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

the class Item method virtual.

public static Item virtual(Class<? extends Item> cl) {
    try {
        Item item = cl.newInstance();
        item.quantity(0);
        return item;
    } catch (Exception e) {
        throw new TrackedRuntimeException("Item.virtual");
    }
}
Also used : TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) JSONException(org.json.JSONException) TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException)

Example 40 with TrackedRuntimeException

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

the class Item method morphTo.

protected Item morphTo(Class<? extends Item> itemClass) {
    try {
        Item result = itemClass.newInstance();
        result.quantity(quantity());
        return result;
    } catch (Exception e) {
        throw new TrackedRuntimeException(e);
    }
}
Also used : TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) JSONException(org.json.JSONException) TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException)

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