Search in sources :

Example 16 with TrackedRuntimeException

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

the class CustomMob method fillMobStats.

private void fillMobStats(boolean restoring) {
    try {
        JSONObject classDesc = getClassDef();
        defenseSkill = classDesc.optInt("defenseSkill", defenseSkill);
        attackSkill = classDesc.optInt("attackSkill", attackSkill);
        exp = classDesc.optInt("exp", exp);
        maxLvl = classDesc.optInt("maxLvl", maxLvl);
        dmgMin = classDesc.optInt("dmgMin", dmgMin);
        dmgMax = classDesc.optInt("dmgMax", dmgMax);
        dr = classDesc.optInt("dr", dr);
        baseSpeed = (float) classDesc.optDouble("baseSpeed", baseSpeed);
        attackDelay = (float) classDesc.optDouble("attackDelay", attackDelay);
        name = StringsManager.maybeId(classDesc.optString("name", mobClass + "_Name"));
        name_objective = StringsManager.maybeId(classDesc.optString("name_objective", mobClass + "_Name_Objective"));
        description = StringsManager.maybeId(classDesc.optString("description", mobClass + "_Desc"));
        gender = Utils.genderFromString(classDesc.optString("gender", mobClass + "_Gender"));
        spriteClass = classDesc.optString("spriteDesc", "spritesDesc/Rat.json");
        flying = classDesc.optBoolean("flying", flying);
        lootChance = (float) classDesc.optDouble("lootChance", lootChance);
        if (classDesc.has("loot")) {
            loot = ItemFactory.createItemFromDesc(classDesc.getJSONObject("loot"));
        }
        viewDistance = classDesc.optInt("viewDistance", viewDistance);
        viewDistance = Math.min(viewDistance, ShadowCaster.MAX_DISTANCE);
        walkingType = Enum.valueOf(WalkingType.class, classDesc.optString("walkingType", "NORMAL"));
        defenceVerb = StringsManager.maybeId(classDesc.optString("defenceVerb", Game.getVars(R.array.Char_StaDodged)[gender]));
        canBePet = classDesc.optBoolean("canBePet", canBePet);
        attackRange = classDesc.optInt("attackRange", attackRange);
        scriptFile = classDesc.optString("scriptFile", scriptFile);
        if (!restoring) {
            setFraction(Enum.valueOf(Fraction.class, classDesc.optString("fraction", "DUNGEON")));
            friendly = classDesc.optBoolean("friendly", friendly);
            hp(ht(classDesc.optInt("ht", 1)));
            fromJson(classDesc);
        }
        runMobScript("fillStats");
    } catch (Exception e) {
        throw new TrackedRuntimeException(e);
    }
}
Also used : WalkingType(com.watabou.pixeldungeon.actors.mobs.WalkingType) TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) JSONObject(org.json.JSONObject) Fraction(com.watabou.pixeldungeon.actors.mobs.Fraction) TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException)

Example 17 with TrackedRuntimeException

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

the class Dialog method getFromJson.

// Параметр next - казывает индекс следующей карточки
// Параметр replies - массив указывающий на наличие кнопок, указывающих на индекс следующей карточки
// Если нету ни next ни replies - "следующее" действие это не смена карточки, а завершение диалога
// Все текстовые данные надо вынести в strings
// Сделать по подобию Ice Wind Dale? У игрока портрета не будет. У NPC портрет только для порядка. Текст пишется сверху. Варианты ответа снизу
// Список вариантов, так же как и текст сообщения - лист с прокруткой, так можно уместить ответы любой длины
// После выбора ответа, он показывается снизу, пока NPC чиатет соотвествующую реплику, при условии, что эта реплика не сопровождается своими вариантами ответов
// Изображение и "Заголовок" указываем в начале диалога, и не меняем пока оно явно не казано в карточках. Т.е можно освободить место.
public Dialog getFromJson(String targetID, int cardNum) {
    JSONObject initDialogs = JsonHelper.readJsonFromAsset("dialogDesc/Dialogs.json");
    if (initDialogs.has("dialogs")) {
        Dialog dialog = new Dialog();
        try {
            JSONArray dialogs = initDialogs.getJSONArray("dialogs");
            for (int i = 0; i < dialogs.length(); ++i) {
                JSONObject currentDialog = dialogs.getJSONObject(i);
                if (currentDialog.has("id")) {
                    String tempID = currentDialog.optString("id", "test");
                    if (tempID.equals(targetID)) {
                        dialog.dialogID = tempID;
                    }
                    break;
                }
                if (currentDialog.has("image")) {
                    dialog.imagePath = currentDialog.optString("image", "mobs/dialogAvatars.png");
                }
                if (currentDialog.has("dialogCards")) {
                    JSONArray cards = currentDialog.getJSONArray("dialogCards");
                    for (int j = 0; j < cards.length(); ++j) {
                        if (j == cardNum) {
                            dialog.imageIndex = cards.getJSONObject(j).optInt("imageIndex", 0);
                            dialog.title = cards.getJSONObject(j).optString("title", "N/A");
                            dialog.text = cards.getJSONObject(j).optString("text", "No text found");
                            return dialog;
                        }
                    }
                }
            }
        } catch (JSONException e) {
            throw new TrackedRuntimeException(e);
        }
    }
    return null;
}
Also used : TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException)

Example 18 with TrackedRuntimeException

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

the class SpellFactory method registerSpellClass.

private static void registerSpellClass(Class<? extends Spell> spellClass) {
    mSpellsList.put(spellClass.getSimpleName(), spellClass);
    mNamesList.put(spellClass, spellClass.getSimpleName());
    try {
        Spell spell = spellClass.newInstance();
        String affinity = spell.getMagicAffinity();
        if (!mSpellsByAffinity.containsKey(affinity)) {
            mSpellsByAffinity.put(affinity, new ArrayList<String>());
        }
        mSpellsByAffinity.get(affinity).add(spellClass.getSimpleName());
    } catch (InstantiationException e) {
        throw new TrackedRuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new TrackedRuntimeException(e);
    }
}
Also used : TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException)

Example 19 with TrackedRuntimeException

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

the class Mob method ressurrect.

public void ressurrect(Char parent) {
    int spawnPos = Dungeon.level.getEmptyCellNextTo(parent.getPos());
    Mob new_mob;
    try {
        new_mob = this.getClass().newInstance();
    } catch (Exception e) {
        throw new TrackedRuntimeException("resurrect issue");
    }
    if (Dungeon.level.cellValid(spawnPos)) {
        new_mob.setPos(spawnPos);
        Dungeon.level.spawnMob(new_mob);
        if (parent instanceof Hero) {
            Mob.makePet(new_mob, (Hero) parent);
            Actor.addDelayed(new Pushing(new_mob, parent.getPos(), new_mob.getPos()), -1);
        }
    }
}
Also used : TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) Pushing(com.watabou.pixeldungeon.effects.Pushing) Hero(com.watabou.pixeldungeon.actors.hero.Hero) JSONException(org.json.JSONException) TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException)

Example 20 with TrackedRuntimeException

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

the class Mob method sprite.

public CharSprite sprite() {
    try {
        {
            String descName = "spritesDesc/" + getMobClassName() + ".json";
            if (ModdingMode.isResourceExist(descName) || ModdingMode.isAssetExist(descName)) {
                return new MobSpriteDef(descName, getKind());
            }
        }
        if (spriteClass instanceof Class) {
            CharSprite sprite = (CharSprite) ((Class<?>) spriteClass).newInstance();
            sprite.selectKind(getKind());
            return sprite;
        }
        if (spriteClass instanceof String) {
            return new MobSpriteDef((String) spriteClass, getKind());
        }
        throw new TrackedRuntimeException(String.format("sprite creation failed - mob class %s", getMobClassName()));
    } catch (Exception e) {
        throw new TrackedRuntimeException(e);
    }
}
Also used : TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) HeroClass(com.watabou.pixeldungeon.actors.hero.HeroClass) HeroSubClass(com.watabou.pixeldungeon.actors.hero.HeroSubClass) CharSprite(com.watabou.pixeldungeon.sprites.CharSprite) MobSpriteDef(com.watabou.pixeldungeon.sprites.MobSpriteDef) 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