From ba8d158ba73919f313cff7711e6429dee2a0cf3d Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Fri, 3 Oct 2014 14:55:47 -0400 Subject: [PATCH] V0.2.1: Updated generator exception handling to always be internal. --- .../items/Generator.java | 50 +++++++++++-------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/Generator.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/Generator.java index f4cfb2251..19c59c771 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/Generator.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/Generator.java @@ -243,41 +243,49 @@ public class Generator { } } - public static Armor randomArmor() throws Exception { + public static Armor randomArmor(){ int curStr = Hero.STARTING_STR + Dungeon.potionOfStrength; return randomArmor(curStr); } - public static Armor randomArmor(int targetStr) throws Exception { + public static Armor randomArmor(int targetStr) { Category cat = Category.ARMOR; - - Armor a1 = (Armor)cat.classes[Random.chances( cat.probs )].newInstance(); - Armor a2 = (Armor)cat.classes[Random.chances( cat.probs )].newInstance(); - - a1.random(); - a2.random(); - - return Math.abs( targetStr - a1.STR ) < Math.abs( targetStr - a2.STR ) ? a1 : a2; + + try { + Armor a1 = (Armor) cat.classes[Random.chances(cat.probs)].newInstance(); + Armor a2 = (Armor) cat.classes[Random.chances(cat.probs)].newInstance(); + + a1.random(); + a2.random(); + + return Math.abs(targetStr - a1.STR) < Math.abs(targetStr - a2.STR) ? a1 : a2; + } catch (Exception e) { + return null; + } } - public static Weapon randomWeapon() throws Exception { + public static Weapon randomWeapon(){ int curStr = Hero.STARTING_STR + Dungeon.potionOfStrength; return randomWeapon(curStr); } - public static Weapon randomWeapon(int targetStr) throws Exception { + public static Weapon randomWeapon(int targetStr) { - Category cat = Category.WEAPON; - - Weapon w1 = (Weapon)cat.classes[Random.chances( cat.probs )].newInstance(); - Weapon w2 = (Weapon)cat.classes[Random.chances( cat.probs )].newInstance(); - - w1.random(); - w2.random(); - - return Math.abs( targetStr - w1.STR ) < Math.abs( targetStr - w2.STR ) ? w1 : w2; + try { + Category cat = Category.WEAPON; + + Weapon w1 = (Weapon)cat.classes[Random.chances( cat.probs )].newInstance(); + Weapon w2 = (Weapon)cat.classes[Random.chances( cat.probs )].newInstance(); + + w1.random(); + w2.random(); + + return Math.abs( targetStr - w1.STR ) < Math.abs( targetStr - w2.STR ) ? w1 : w2; + } catch (Exception e) { + return null; + } } }