diff --git a/core/src/main/assets/messages/items/items.properties b/core/src/main/assets/messages/items/items.properties index e66ea16a6..f7e3814ef 100644 --- a/core/src/main/assets/messages/items/items.properties +++ b/core/src/main/assets/messages/items/items.properties @@ -1118,9 +1118,9 @@ items.stones.stoneofflock.desc=This runestone summons magical sheep for a short items.stones.stoneofintuition.name=stone of intuition items.stones.stoneofintuition.inv_title=Select an item -items.stones.stoneofintuition.desc=This runestone holds a weaker version of the magic found in scrolls of identification. Rather than directly identifying an item, it will work on your intuition, allowing you to attempt to identify a potion or scroll by guessing. -items.stones.stoneofintuition$wndguess.text=Guess what the unidentified item is. If you guess correctly, it will be identified! -items.stones.stoneofintuition$wndguess.correct=Correct. The item has been identified! +items.stones.stoneofintuition.desc=This runestone holds a weaker version of the magic found in scrolls of identification. Rather than directly identifying an item, it will work on your intuition, allowing you to attempt to identify the type of a potion, scroll, or ring by guessing. +items.stones.stoneofintuition$wndguess.text=Guess what the type of the unidentified item is. If you guess correctly, the type will be identified! +items.stones.stoneofintuition$wndguess.correct=Correct. The item's type has been identified! items.stones.stoneofintuition$wndguess.incorrect=Your guess was incorrect. items.stones.stoneofshock.name=stone of shock diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/ItemStatusHandler.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/ItemStatusHandler.java index c405af35d..fe1df337c 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/ItemStatusHandler.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/ItemStatusHandler.java @@ -28,22 +28,24 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; public class ItemStatusHandler { private Class[] items; - private HashMap, String> itemLabels; - private HashMap labelImages; - private HashSet> known; + private LinkedHashMap, String> itemLabels; + private LinkedHashMap labelImages; + private LinkedHashSet> known; public ItemStatusHandler( Class[] items, HashMap labelImages ) { this.items = items; - this.itemLabels = new HashMap<>(); - this.labelImages = new HashMap<>(labelImages); - known = new HashSet<>(); + this.itemLabels = new LinkedHashMap<>(); + this.labelImages = new LinkedHashMap<>(labelImages); + known = new LinkedHashSet<>(); ArrayList labelsLeft = new ArrayList<>(labelImages.keySet()); @@ -63,9 +65,9 @@ public class ItemStatusHandler { this.items = items; - this.itemLabels = new HashMap<>(); - this.labelImages = new HashMap<>(labelImages); - known = new HashSet<>(); + this.itemLabels = new LinkedHashMap<>(); + this.labelImages = new LinkedHashMap<>(labelImages); + known = new LinkedHashSet<>(); ArrayList allLabels = new ArrayList<>(labelImages.keySet()); @@ -203,7 +205,7 @@ public class ItemStatusHandler { } public HashSet> unknown() { - HashSet> result = new HashSet<>(); + LinkedHashSet> result = new LinkedHashSet<>(); for (Class i : items) { if (!known.contains( i )) { result.add( i ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/Potion.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/Potion.java index 8b8266b6d..3b321f5bd 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/Potion.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/Potion.java @@ -90,21 +90,6 @@ public class Potion extends Item { private static final float TIME_TO_DRINK = 1f; - private static final Class[] potions = { - PotionOfHealing.class, - PotionOfExperience.class, - PotionOfToxicGas.class, - PotionOfLiquidFlame.class, - PotionOfStrength.class, - PotionOfParalyticGas.class, - PotionOfLevitation.class, - PotionOfMindVision.class, - PotionOfPurity.class, - PotionOfInvisibility.class, - PotionOfHaste.class, - PotionOfFrost.class - }; - private static final HashMap colors = new HashMap() { { put("crimson",ItemSpriteSheet.POTION_CRIMSON); @@ -163,7 +148,7 @@ public class Potion extends Item { @SuppressWarnings("unchecked") public static void initColors() { - handler = new ItemStatusHandler<>( (Class[])potions, colors ); + handler = new ItemStatusHandler<>( (Class[])Generator.Category.POTION.classes, colors ); } public static void save( Bundle bundle ) { @@ -188,7 +173,7 @@ public class Potion extends Item { @SuppressWarnings("unchecked") public static void restore( Bundle bundle ) { - handler = new ItemStatusHandler<>( (Class[])potions, colors, bundle ); + handler = new ItemStatusHandler<>( (Class[])Generator.Category.POTION.classes, colors, bundle ); } public Potion() { @@ -412,7 +397,7 @@ public class Potion extends Item { } public static boolean allKnown() { - return handler.known().size() == potions.length; + return handler.known().size() == Generator.Category.POTION.classes.length; } protected int splashColor(){ diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java index da0c3bef5..23d3d4177 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java @@ -27,6 +27,7 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Talent; +import com.shatteredpixel.shatteredpixeldungeon.items.Generator; import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.ItemStatusHandler; import com.shatteredpixel.shatteredpixeldungeon.items.KindofMisc; @@ -44,20 +45,6 @@ import java.util.HashSet; public class Ring extends KindofMisc { protected Buff buff; - - private static final Class[] rings = { - RingOfAccuracy.class, - RingOfEvasion.class, - RingOfElements.class, - RingOfForce.class, - RingOfFuror.class, - RingOfHaste.class, - RingOfEnergy.class, - RingOfMight.class, - RingOfSharpshooting.class, - RingOfTenacity.class, - RingOfWealth.class, - }; private static final HashMap gems = new HashMap() { { @@ -85,7 +72,7 @@ public class Ring extends KindofMisc { @SuppressWarnings("unchecked") public static void initGems() { - handler = new ItemStatusHandler<>( (Class[])rings, gems ); + handler = new ItemStatusHandler<>( (Class[])Generator.Category.RING.classes, gems ); } public static void save( Bundle bundle ) { @@ -98,7 +85,7 @@ public class Ring extends KindofMisc { @SuppressWarnings("unchecked") public static void restore( Bundle bundle ) { - handler = new ItemStatusHandler<>( (Class[])rings, gems, bundle ); + handler = new ItemStatusHandler<>( (Class[])Generator.Category.RING.classes, gems, bundle ); } public Ring() { @@ -247,7 +234,7 @@ public class Ring extends KindofMisc { } public static boolean allKnown() { - return handler.known().size() == rings.length - 2; + return handler.known().size() == Generator.Category.RING.classes.length; } @Override diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/Scroll.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/Scroll.java index 1381e60af..94b17c8e2 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/Scroll.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/Scroll.java @@ -29,6 +29,7 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Invisibility; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.MagicImmune; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Talent; +import com.shatteredpixel.shatteredpixeldungeon.items.Generator; import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.ItemStatusHandler; import com.shatteredpixel.shatteredpixeldungeon.items.Recipe; @@ -66,21 +67,6 @@ public abstract class Scroll extends Item { protected static final float TIME_TO_READ = 1f; - private static final Class[] scrolls = { - ScrollOfIdentify.class, - ScrollOfMagicMapping.class, - ScrollOfRecharging.class, - ScrollOfRemoveCurse.class, - ScrollOfTeleportation.class, - ScrollOfUpgrade.class, - ScrollOfRage.class, - ScrollOfTerror.class, - ScrollOfLullaby.class, - ScrollOfTransmutation.class, - ScrollOfRetribution.class, - ScrollOfMirrorImage.class - }; - private static final HashMap runes = new HashMap() { { put("KAUNAN",ItemSpriteSheet.SCROLL_KAUNAN); @@ -109,7 +95,7 @@ public abstract class Scroll extends Item { @SuppressWarnings("unchecked") public static void initLabels() { - handler = new ItemStatusHandler<>( (Class[])scrolls, runes ); + handler = new ItemStatusHandler<>( (Class[])Generator.Category.SCROLL.classes, runes ); } public static void save( Bundle bundle ) { @@ -134,7 +120,7 @@ public abstract class Scroll extends Item { @SuppressWarnings("unchecked") public static void restore( Bundle bundle ) { - handler = new ItemStatusHandler<>( (Class[])scrolls, runes, bundle ); + handler = new ItemStatusHandler<>( (Class[])Generator.Category.SCROLL.classes, runes, bundle ); } public Scroll() { @@ -264,7 +250,7 @@ public abstract class Scroll extends Item { } public static boolean allKnown() { - return handler.known().size() == scrolls.length; + return handler.known().size() == Generator.Category.SCROLL.classes.length; } @Override diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/stones/StoneOfIntuition.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/stones/StoneOfIntuition.java index 87b18a765..baa224f74 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/stones/StoneOfIntuition.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/stones/StoneOfIntuition.java @@ -23,10 +23,10 @@ package com.shatteredpixel.shatteredpixeldungeon.items.stones; import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.effects.Identification; -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.exotic.ExoticPotion; +import com.shatteredpixel.shatteredpixeldungeon.items.rings.Ring; import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.Scroll; import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.exotic.ExoticScroll; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; @@ -44,7 +44,7 @@ import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag; import com.watabou.noosa.Image; import com.watabou.utils.Reflection; -import java.util.HashSet; +import java.util.ArrayList; public class StoneOfIntuition extends InventoryStone { @@ -88,7 +88,11 @@ public class StoneOfIntuition extends InventoryStone { super.onClick(); useAnimation(); if (item.getClass() == curGuess){ - item.identify(); + if (item instanceof Ring){ + ((Ring) item).setKnown(); + } else { + item.identify(); + } GLog.p( Messages.get(WndGuess.class, "correct") ); curUser.sprite.parent.add( new Identification( curUser.sprite.center().offset( 0, -16 ) ) ); } else { @@ -109,44 +113,34 @@ public class StoneOfIntuition extends InventoryStone { int rows; int placed = 0; - HashSet> unIDed = new HashSet<>(); - final Class[] all; - + final ArrayList> unIDed = new ArrayList<>(); if (item.isIdentified()){ hide(); return; } else if (item instanceof Potion){ - unIDed.addAll(Potion.getUnknown()); - all = (Class[]) Generator.Category.POTION.classes.clone(); - if (item instanceof ExoticPotion){ - for (int i = 0; i < all.length; i++){ - all[i] = ExoticPotion.regToExo.get(all[i]); + if (item instanceof ExoticPotion) { + for (Class i : Potion.getUnknown()){ + unIDed.add(ExoticPotion.regToExo.get(i)); } - HashSet> exoUID = new HashSet<>(); - for (Class i : unIDed){ - exoUID.add(ExoticPotion.regToExo.get(i)); - } - unIDed = exoUID; + } else { + unIDed.addAll(Potion.getUnknown()); } } else if (item instanceof Scroll){ - unIDed.addAll(Scroll.getUnknown()); - all = (Class[]) Generator.Category.SCROLL.classes.clone(); if (item instanceof ExoticScroll) { - for (int i = 0; i < all.length; i++) { - all[i] = ExoticScroll.regToExo.get(all[i]); + for (Class i : Scroll.getUnknown()){ + unIDed.add(ExoticScroll.regToExo.get(i)); } - HashSet> exoUID = new HashSet<>(); - for (Class i : unIDed) { - exoUID.add(ExoticScroll.regToExo.get(i)); - } - unIDed = exoUID; + } else { + unIDed.addAll(Scroll.getUnknown()); } + } else if (item instanceof Ring) { + unIDed.addAll(Ring.getUnknown()); } else { hide(); return; } - if (unIDed.size() < 6){ + if (unIDed.size() <= 5){ rows = 1; top += BTN_SIZE/2f; left = (WIDTH - BTN_SIZE*unIDed.size())/2f; @@ -155,16 +149,12 @@ public class StoneOfIntuition extends InventoryStone { left = (WIDTH - BTN_SIZE*((unIDed.size()+1)/2))/2f; } - for (int i = 0; i < all.length; i++){ - if (!unIDed.contains(all[i])) { - continue; - } - - final int j = i; + for (final Class i : unIDed){ + IconButton btn = new IconButton(){ @Override protected void onClick() { - curGuess = all[j]; + curGuess = i; guess.visible = true; guess.text( Messages.titleCase(Messages.get(curGuess, "name")) ); guess.enable(true); @@ -172,7 +162,7 @@ public class StoneOfIntuition extends InventoryStone { } }; Image im = new Image(Assets.Sprites.ITEM_ICONS); - im.frame(ItemSpriteSheet.Icons.film.get(Reflection.newInstance(all[i]).icon)); + im.frame(ItemSpriteSheet.Icons.film.get(Reflection.newInstance(i).icon)); im.scale.set(2f); btn.icon(im); btn.setRect(left + placed*BTN_SIZE, top, BTN_SIZE, BTN_SIZE); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java index b3d25ea93..42a8091d3 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java @@ -40,6 +40,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.bags.ScrollHolder; import com.shatteredpixel.shatteredpixeldungeon.items.bags.VelvetPouch; import com.shatteredpixel.shatteredpixeldungeon.items.food.Food; import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion; +import com.shatteredpixel.shatteredpixeldungeon.items.rings.Ring; import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.Scroll; import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfRemoveCurse; import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfTransmutation; @@ -443,7 +444,7 @@ public class WndBag extends WndTabbed { mode == Mode.FOOD && (item instanceof Food) || mode == Mode.POTION && (item instanceof Potion) || mode == Mode.SCROLL && (item instanceof Scroll) || - mode == Mode.UNIDED_POTION_OR_SCROLL && (!item.isIdentified() && (item instanceof Scroll || item instanceof Potion)) || + mode == Mode.UNIDED_POTION_OR_SCROLL && (!item.isIdentified() && (item instanceof Scroll || item instanceof Potion || item instanceof Ring)) || mode == Mode.EQUIPMENT && (item instanceof EquipableItem || item instanceof Wand) || mode == Mode.ALCHEMY && Recipe.usableInRecipe(item) || mode == Mode.TRANMSUTABLE && ScrollOfTransmutation.canTransmute(item) ||