From caf6f5ca50ab39846e8f41b1972ec3e83f8677b8 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Sat, 5 Aug 2017 02:52:08 -0400 Subject: [PATCH] v0.6.1: improved quickslot interactions with thieves and monks --- .../shatteredpixeldungeon/QuickSlot.java | 4 ++-- .../shatteredpixeldungeon/actors/hero/Belongings.java | 11 +++++++++++ .../shatteredpixeldungeon/actors/mobs/Monk.java | 2 +- .../shatteredpixeldungeon/actors/mobs/Thief.java | 4 +++- .../shatteredpixeldungeon/items/Item.java | 2 +- .../items/weapon/missiles/Boomerang.java | 2 +- 6 files changed, 19 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/QuickSlot.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/QuickSlot.java index d754dd0a3..c3c13a992 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/QuickSlot.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/QuickSlot.java @@ -85,9 +85,9 @@ public class QuickSlot { return getSlot(item) != -1; } - public void replaceSimilar(Item item){ + public void replacePlaceholder(Item item){ for (int i = 0; i < SIZE; i++) - if (getItem(i) != null && item.isSimilar(getItem(i))) + if (isPlaceholder(i) && item.isSimilar(getItem(i))) setSlot( i , item ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java index 760345e43..e67602ddf 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java @@ -139,6 +139,17 @@ public class Belongings implements Iterable { return null; } + public Item getSimilar( Item similar ){ + + for (Item item : this) { + if (item.isSimilar(similar)) { + return item; + } + } + + return null; + } + public void identify() { for (Item item : this) { item.identify(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Monk.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Monk.java index 5b2dc6b5a..2a64708f8 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Monk.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Monk.java @@ -97,7 +97,7 @@ public class Monk extends Mob { if (--hitsToDisarm == 0) { hero.belongings.weapon = null; - Dungeon.quickslot.clearItem(weapon); + Dungeon.quickslot.convertToPlaceholder(weapon); weapon.updateQuickslot(); Dungeon.level.drop(weapon, hero.pos).sprite.drop(); GLog.w(Messages.get(this, "disarm", weapon.name())); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Thief.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Thief.java index 9c51feaba..b9a423d04 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Thief.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Thief.java @@ -147,7 +147,9 @@ public class Thief extends Mob { if (item != null && !item.unique && item.level() < 1 ) { GLog.w( Messages.get(Thief.class, "stole", item.name()) ); - Dungeon.quickslot.clearItem( item ); + if (!item.stackable || hero.belongings.getSimilar(item) == null) { + Dungeon.quickslot.convertToPlaceholder(item); + } item.updateQuickslot(); if (item instanceof Honeypot){ diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Item.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Item.java index 88de3954e..a669146a2 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Item.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Item.java @@ -190,7 +190,7 @@ public class Item implements Bundlable { } items.add( this ); - if (stackable || this instanceof Boomerang) Dungeon.quickslot.replaceSimilar(this); + Dungeon.quickslot.replacePlaceholder(this); updateQuickslot(); Collections.sort( items, itemComparator ); return true; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/Boomerang.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/Boomerang.java index a11bd6b90..e0cbacc8c 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/Boomerang.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/Boomerang.java @@ -114,7 +114,7 @@ public class Boomerang extends MissileWeapon { if (throwEquiped) { owner.belongings.weapon = this; owner.spend( -TIME_TO_EQUIP ); - Dungeon.quickslot.replaceSimilar(this); + Dungeon.quickslot.replacePlaceholder(this); updateQuickslot(); } else if (!collect( curUser.belongings.backpack )) {