From 5f615bb178b7c9988a5ca55dad23060cc2c32549 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Sun, 24 Jun 2018 21:20:30 -0400 Subject: [PATCH] v0.7.0: made reset functionality less brittle for potions/scrolls/rings --- .../shatteredpixeldungeon/items/ItemStatusHandler.java | 9 +++++++++ .../shatteredpixeldungeon/items/potions/Potion.java | 2 +- .../shatteredpixeldungeon/items/rings/Ring.java | 2 +- .../shatteredpixeldungeon/items/scrolls/Scroll.java | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) 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 6ef5464dc..412ea92ad 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/ItemStatusHandler.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/ItemStatusHandler.java @@ -136,6 +136,15 @@ public class ItemStatusHandler { } } + public boolean contains( T item ){ + for (Class i : items){ + if (item.getClass().equals(i)){ + return true; + } + } + return false; + } + public int image( T item ) { return labelImages.get(label(item)); } 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 1e55dad08..db39ef5b5 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 @@ -146,7 +146,7 @@ public class Potion extends Item { @Override public void reset(){ super.reset(); - if (handler != null) { + if (handler != null && handler.contains(this)) { image = handler.image(this); color = handler.label(this); } 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 ccbd8c892..e77b10372 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 @@ -108,7 +108,7 @@ public class Ring extends KindofMisc { public void reset() { super.reset(); - if (handler != null){ + if (handler != null && handler.contains(this)){ image = handler.image(this); gem = handler.label(this); } 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 d7c7d8ece..2f750cfbc 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 @@ -130,7 +130,7 @@ public abstract class Scroll extends Item { @Override public void reset(){ super.reset(); - if (handler != null) { + if (handler != null && handler.contains(this)) { image = handler.image(this); rune = handler.label(this); }