From e4cfe7586a53e8e1a8773c72f91869238d6f0665 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Thu, 12 Feb 2015 15:28:10 -0500 Subject: [PATCH] v0.2.4: refactored handling the quickslot when equipping. --- .../shatteredpixeldungeon/items/EquipableItem.java | 9 ++++++++- .../shatteredpixeldungeon/items/KindOfWeapon.java | 4 ---- .../shatteredpixeldungeon/items/armor/Armor.java | 4 ---- .../shatteredpixeldungeon/items/artifacts/Artifact.java | 4 ---- .../shatteredpixeldungeon/items/rings/Ring.java | 4 ---- 5 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/EquipableItem.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/EquipableItem.java index ac45591d9..2bd8fc9c9 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/EquipableItem.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/EquipableItem.java @@ -38,7 +38,14 @@ public abstract class EquipableItem extends Item { @Override public void execute( Hero hero, String action ) { if (action.equals( AC_EQUIP )) { - doEquip( hero ); + //In addition to equipping itself, item reassigns itself to the quickslot + //This is a special case as the item is being removed from inventory, but is staying with the hero. + int slot = Dungeon.quickslot.getSlot( this ); + doEquip(hero); + if (slot != -1) { + Dungeon.quickslot.setSlot( slot, this ); + updateQuickslot(); + } } else if (action.equals( AC_UNEQUIP )) { doUnequip( hero, true ); } else { diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/KindOfWeapon.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/KindOfWeapon.java index 3ecd558dc..aac9265bb 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/KindOfWeapon.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/KindOfWeapon.java @@ -49,11 +49,7 @@ public class KindOfWeapon extends EquipableItem { @Override public boolean doEquip( Hero hero ) { - int slot = Dungeon.quickslot.getSlot( this ); - detachAll( hero.belongings.backpack ); - - if (slot != -1) Dungeon.quickslot.setSlot( slot, this ); if (hero.belongings.weapon == null || hero.belongings.weapon.doUnequip( hero, true )) { diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/armor/Armor.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/armor/Armor.java index 02f9a9b3d..aa980e1aa 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/armor/Armor.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/armor/Armor.java @@ -92,13 +92,9 @@ public class Armor extends EquipableItem { @Override public boolean doEquip( Hero hero ) { - - int slot = Dungeon.quickslot.getSlot( this ); detach( hero.belongings.backpack ); - if (slot != -1) Dungeon.quickslot.setSlot( slot, this ); - if (hero.belongings.armor == null || hero.belongings.armor.doUnequip( hero, true, false )) { hero.belongings.armor = this; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/Artifact.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/Artifact.java index e26190037..d82de0c74 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/Artifact.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/Artifact.java @@ -80,12 +80,8 @@ public class Artifact extends KindofMisc { hero.belongings.misc2 = this; } - int slot = Dungeon.quickslot.getSlot( this ); - detach( hero.belongings.backpack ); - if (slot != -1) Dungeon.quickslot.setSlot( slot, this ); - activate( hero ); cursedKnown = true; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java index b1b5ff799..a3a9c973a 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java @@ -126,11 +126,7 @@ public class Ring extends KindofMisc { hero.belongings.misc2 = this; } - int slot = Dungeon.quickslot.getSlot( this ); - detach( hero.belongings.backpack ); - - if (slot != -1) Dungeon.quickslot.setSlot( slot, this ); activate( hero );