v0.9.1: improved code for stone of intuition and item handlers, stone now also works on rings!
This commit is contained in:
parent
2496dc0d1c
commit
38497c6343
|
@ -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
|
||||
|
|
|
@ -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<T extends Item> {
|
||||
|
||||
private Class<? extends T>[] items;
|
||||
private HashMap<Class<? extends T>, String> itemLabels;
|
||||
private HashMap<String, Integer> labelImages;
|
||||
private HashSet<Class<? extends T>> known;
|
||||
private LinkedHashMap<Class<? extends T>, String> itemLabels;
|
||||
private LinkedHashMap<String, Integer> labelImages;
|
||||
private LinkedHashSet<Class<? extends T>> known;
|
||||
|
||||
public ItemStatusHandler( Class<? extends T>[] items, HashMap<String, Integer> 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<String> labelsLeft = new ArrayList<>(labelImages.keySet());
|
||||
|
||||
|
@ -63,9 +65,9 @@ public class ItemStatusHandler<T extends Item> {
|
|||
|
||||
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<String> allLabels = new ArrayList<>(labelImages.keySet());
|
||||
|
||||
|
@ -203,7 +205,7 @@ public class ItemStatusHandler<T extends Item> {
|
|||
}
|
||||
|
||||
public HashSet<Class<? extends T>> unknown() {
|
||||
HashSet<Class<? extends T>> result = new HashSet<>();
|
||||
LinkedHashSet<Class<? extends T>> result = new LinkedHashSet<>();
|
||||
for (Class<? extends T> i : items) {
|
||||
if (!known.contains( i )) {
|
||||
result.add( i );
|
||||
|
|
|
@ -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<String, Integer> colors = new HashMap<String, Integer>() {
|
||||
{
|
||||
put("crimson",ItemSpriteSheet.POTION_CRIMSON);
|
||||
|
@ -163,7 +148,7 @@ public class Potion extends Item {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void initColors() {
|
||||
handler = new ItemStatusHandler<>( (Class<? extends Potion>[])potions, colors );
|
||||
handler = new ItemStatusHandler<>( (Class<? extends Potion>[])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<? extends Potion>[])potions, colors, bundle );
|
||||
handler = new ItemStatusHandler<>( (Class<? extends Potion>[])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(){
|
||||
|
|
|
@ -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<String, Integer> gems = new HashMap<String, Integer>() {
|
||||
{
|
||||
|
@ -85,7 +72,7 @@ public class Ring extends KindofMisc {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void initGems() {
|
||||
handler = new ItemStatusHandler<>( (Class<? extends Ring>[])rings, gems );
|
||||
handler = new ItemStatusHandler<>( (Class<? extends Ring>[])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<? extends Ring>[])rings, gems, bundle );
|
||||
handler = new ItemStatusHandler<>( (Class<? extends Ring>[])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
|
||||
|
|
|
@ -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<String, Integer> runes = new HashMap<String, Integer>() {
|
||||
{
|
||||
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<? extends Scroll>[])scrolls, runes );
|
||||
handler = new ItemStatusHandler<>( (Class<? extends Scroll>[])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<? extends Scroll>[])scrolls, runes, bundle );
|
||||
handler = new ItemStatusHandler<>( (Class<? extends Scroll>[])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
|
||||
|
|
|
@ -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<Class<?extends Item>> unIDed = new HashSet<>();
|
||||
final Class<?extends Item>[] all;
|
||||
|
||||
final ArrayList<Class<?extends Item>> unIDed = new ArrayList<>();
|
||||
if (item.isIdentified()){
|
||||
hide();
|
||||
return;
|
||||
} else if (item instanceof Potion){
|
||||
unIDed.addAll(Potion.getUnknown());
|
||||
all = (Class<? extends Item>[]) 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<?extends Item> i : Potion.getUnknown()){
|
||||
unIDed.add(ExoticPotion.regToExo.get(i));
|
||||
}
|
||||
HashSet<Class<?extends Item>> exoUID = new HashSet<>();
|
||||
for (Class<?extends Item> 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<? extends Item>[]) 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<?extends Item> i : Scroll.getUnknown()){
|
||||
unIDed.add(ExoticScroll.regToExo.get(i));
|
||||
}
|
||||
HashSet<Class<? extends Item>> exoUID = new HashSet<>();
|
||||
for (Class<? extends Item> 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<?extends Item> 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);
|
||||
|
|
|
@ -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) ||
|
||||
|
|
Loading…
Reference in New Issue
Block a user