v2.0.1: quickslot contents now auto-swap when equipping items

This commit is contained in:
Evan Debenham
2023-03-22 17:56:47 -04:00
parent a317cf47c2
commit 6f7b1f80b8
3 changed files with 29 additions and 10 deletions
@@ -66,6 +66,8 @@ public abstract class EquipableItem extends Item {
} }
} }
protected static int slotOfUnequipped = -1;
@Override @Override
public void execute( Hero hero, String action ) { public void execute( Hero hero, String action ) {
@@ -75,10 +77,16 @@ public abstract class EquipableItem extends Item {
//In addition to equipping itself, item reassigns itself to the quickslot //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. //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 ); int slot = Dungeon.quickslot.getSlot( this );
slotOfUnequipped = -1;
doEquip(hero); doEquip(hero);
if (slot != -1) { if (slot != -1) {
Dungeon.quickslot.setSlot( slot, this ); Dungeon.quickslot.setSlot( slot, this );
updateQuickslot(); updateQuickslot();
//if this item wasn't quickslotted, but the item it is replacing as equipped was
//then also have the item occupy the unequipped item's quickslot
} else if (slotOfUnequipped != -1 && defaultAction() != null) {
Dungeon.quickslot.setSlot( slotOfUnequipped, this );
updateQuickslot();
} }
} else if (action.equals( AC_UNEQUIP )) { } else if (action.equals( AC_UNEQUIP )) {
doUnequip( hero, true ); doUnequip( hero, true );
@@ -130,6 +138,8 @@ public abstract class EquipableItem extends Item {
hero.spend( time2equip( hero ) ); hero.spend( time2equip( hero ) );
} }
slotOfUnequipped = Dungeon.quickslot.getSlot(this);
//temporarily keep this item so it can be collected //temporarily keep this item so it can be collected
boolean wasKept = keptThoughLostInvent; boolean wasKept = keptThoughLostInvent;
keptThoughLostInvent = true; keptThoughLostInvent = true;
@@ -66,19 +66,23 @@ abstract public class KindOfWeapon extends EquipableItem {
@Override @Override
protected void onSelect(int index) { protected void onSelect(int index) {
super.onSelect(index); super.onSelect(index);
if (index == 0){ if (index == 0 || index == 1){
//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( KindOfWeapon.this ); int slot = Dungeon.quickslot.getSlot( KindOfWeapon.this );
doEquip(hero); slotOfUnequipped = -1;
if (index == 0) {
doEquip(hero);
} else {
equipSecondary(hero);
}
if (slot != -1) { if (slot != -1) {
Dungeon.quickslot.setSlot( slot, KindOfWeapon.this ); Dungeon.quickslot.setSlot( slot, KindOfWeapon.this );
updateQuickslot(); updateQuickslot();
} //if this item wasn't quickslotted, but the item it is replacing as equipped was
} //then also have the item occupy the unequipped item's quickslot
if (index == 1){ } else if (slotOfUnequipped != -1 && defaultAction() != null) {
int slot = Dungeon.quickslot.getSlot( KindOfWeapon.this ); Dungeon.quickslot.setSlot( slotOfUnequipped, KindOfWeapon.this );
equipSecondary(hero);
if (slot != -1) {
Dungeon.quickslot.setSlot( slot, KindOfWeapon.this );
updateQuickslot(); updateQuickslot();
} }
} }
@@ -100,6 +100,7 @@ public abstract class KindofMisc extends EquipableItem {
// to unequip the equipped one, but don't want to trigger any other // to unequip the equipped one, but don't want to trigger any other
// item detaching logic // item detaching logic
int slot = Dungeon.quickslot.getSlot(KindofMisc.this); int slot = Dungeon.quickslot.getSlot(KindofMisc.this);
slotOfUnequipped = -1;
Dungeon.hero.belongings.backpack.items.remove(KindofMisc.this); Dungeon.hero.belongings.backpack.items.remove(KindofMisc.this);
if (equipped.doUnequip(hero, true, false)) { if (equipped.doUnequip(hero, true, false)) {
//swap out equip in misc slot if needed //swap out equip in misc slot if needed
@@ -115,7 +116,11 @@ public abstract class KindofMisc extends EquipableItem {
} else { } else {
Dungeon.hero.belongings.backpack.items.add(KindofMisc.this); Dungeon.hero.belongings.backpack.items.add(KindofMisc.this);
} }
if (slot != -1) Dungeon.quickslot.setSlot(slot, KindofMisc.this); if (slot != -1) {
Dungeon.quickslot.setSlot(slot, KindofMisc.this);
} else if (slotOfUnequipped != -1){
Dungeon.quickslot.setSlot(slotOfUnequipped, KindofMisc.this);
}
updateQuickslot(); updateQuickslot();
} }