From 1104f6473b8bb5f51b5aa9e77ac7ea8c47a2dc97 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Wed, 10 Dec 2014 14:53:05 -0500 Subject: [PATCH] v0.2.3: artifact refactoring, changed how new artifacts deal with collections of items. --- .../items/artifacts/AlchemistsToolkit.java | 15 ++++++++------- .../items/artifacts/Artifact.java | 11 +++++++++++ .../items/artifacts/UnstableSpellbook.java | 6 +++--- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/AlchemistsToolkit.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/AlchemistsToolkit.java index 943b9f116..291399815 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/AlchemistsToolkit.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/AlchemistsToolkit.java @@ -6,7 +6,6 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.items.Generator; import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion; -import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfExperience; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; @@ -51,12 +50,14 @@ public class AlchemistsToolkit extends Artifact { public AlchemistsToolkit() { super(); + Generator.Category cat = Generator.Category.POTION; for (int i = 1; i <= 3; i++){ - Potion potion; + String potion; do{ - potion = (Potion)Generator.random(Generator.Category.POTION); - } while (combination.contains(potion.trueName()) || potion instanceof PotionOfExperience); - combination.add(potion.trueName()); + potion = convertName(cat.classes[Random.chances(cat.probs)].getSimpleName()); + //forcing the player to use experience potions would be completely unfair. + } while (combination.contains(potion) || potion.equals("Experience")); + combination.add(potion); } } @@ -242,7 +243,7 @@ public class AlchemistsToolkit extends Artifact { @Override public void onSelect(Item item) { if (item != null && item instanceof Potion && item.isIdentified()){ - if (!curGuess.contains(item.name())) { + if (!curGuess.contains(convertName(item.getClass().getSimpleName()))) { Hero hero = Dungeon.hero; hero.sprite.operate( hero.pos ); @@ -252,7 +253,7 @@ public class AlchemistsToolkit extends Artifact { item.detach(hero.belongings.backpack); - curGuess.add(item.name()); + curGuess.add(convertName(item.getClass().getSimpleName())); if (curGuess.size() == 3){ guessBrew(); } else { diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/Artifact.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/Artifact.java index bbce27617..726b74298 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/Artifact.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/Artifact.java @@ -205,6 +205,17 @@ public class Artifact extends KindofMisc { return null; } + //converts class names to be more concise and readable. + protected String convertName(String className){ + //removes known redundant parts of names. + className.replaceFirst("ScrollOf|PotionOf", ""); + + //inserts a space infront of every uppercase character + className.replaceAll("(\\p{Ll})(\\p{Lu})", "$1 $2"); + + return className; + }; + @Override public Item random() { if (Random.Float() < 0.3f) { diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/UnstableSpellbook.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/UnstableSpellbook.java index e7bb2c812..d3ab86d0d 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/UnstableSpellbook.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/UnstableSpellbook.java @@ -55,11 +55,11 @@ public class UnstableSpellbook extends Artifact { super(); Class[] scrollClasses = Generator.Category.SCROLL.classes; - float[] probs = Generator.Category.SCROLL.probs.clone(); + float[] probs = Generator.Category.SCROLL.probs.clone(); //array of primitives, clone gives deep copy. int i = Random.chances(probs); while (i != -1){ - scrolls.add(scrollClasses[i].getSimpleName()); + scrolls.add(convertName(scrollClasses[i].getSimpleName())); probs[i] = 0; i = Random.chances(probs); @@ -207,7 +207,7 @@ public class UnstableSpellbook extends Artifact { @Override public void onSelect(Item item) { if (item != null && item instanceof Scroll && item.isIdentified()){ - String scroll = item.getClass().getSimpleName(); + String scroll = convertName(item.getClass().getSimpleName()); Hero hero = Dungeon.hero; for (int i = 0; ( i <= 1 && i < scrolls.size() ); i++){ if (scrolls.get(i).equals(scroll)){