v0.8.2c: bags now try to grab new items when an item leaves them

This commit is contained in:
Evan Debenham 2020-08-22 20:20:39 -04:00
parent 0608a5447d
commit 39c5da6061
2 changed files with 23 additions and 12 deletions

View File

@ -270,6 +270,7 @@ public class Item implements Bundlable {
if (item == this) { if (item == this) {
container.items.remove(this); container.items.remove(this);
item.onDetach(); item.onDetach();
container.grabItems(); //try to put more items into the bag as it now has free space
return this; return this;
} else if (item instanceof Bag) { } else if (item instanceof Bag) {
Bag bag = (Bag)item; Bag bag = (Bag)item;

View File

@ -69,18 +69,7 @@ public class Bag extends Item implements Iterable<Item> {
@Override @Override
public boolean collect( Bag container ) { public boolean collect( Bag container ) {
for (Item item : container.items.toArray( new Item[0] )) { grabItems(container);
if (canHold( item )) {
int slot = Dungeon.quickslot.getSlot(item);
item.detachAll(container);
if (!item.collect(this)) {
item.collect(container);
}
if (slot != -1) {
Dungeon.quickslot.setSlot(slot, item);
}
}
}
if (super.collect( container )) { if (super.collect( container )) {
@ -102,6 +91,27 @@ public class Bag extends Item implements Iterable<Item> {
updateQuickslot(); updateQuickslot();
} }
public void grabItems(){
if (this != Dungeon.hero.belongings.backpack) {
grabItems(Dungeon.hero.belongings.backpack);
}
}
public void grabItems( Bag container ){
for (Item item : container.items.toArray( new Item[0] )) {
if (canHold( item )) {
int slot = Dungeon.quickslot.getSlot(item);
item.detachAll(container);
if (!item.collect(this)) {
item.collect(container);
}
if (slot != -1) {
Dungeon.quickslot.setSlot(slot, item);
}
}
}
}
@Override @Override
public boolean isUpgradable() { public boolean isUpgradable() {
return false; return false;