diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Recipe.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Recipe.java index f78fcbd06..2e167416d 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Recipe.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Recipe.java @@ -85,6 +85,22 @@ public abstract class Recipe { protected int outQuantity; //*** + //gets a simple list of items based on inputs + public ArrayList getIngredients() { + ArrayList result = new ArrayList<>(); + try { + for (int i = 0; i < inputs.length; i++) { + Item ingredient = inputs[i].newInstance(); + ingredient.quantity(inQuantity[i]); + result.add(ingredient); + } + } catch (Exception e){ + ShatteredPixelDungeon.reportException( e ); + return null; + } + return result; + } + @Override public final boolean testIngredients(ArrayList ingredients) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/AlchemyScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/AlchemyScene.java index 05f99932c..b0abe422c 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/AlchemyScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/AlchemyScene.java @@ -26,6 +26,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Badges; import com.shatteredpixel.shatteredpixeldungeon.Chrome; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; +import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Belongings; import com.shatteredpixel.shatteredpixeldungeon.effects.Speck; import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.Recipe; @@ -396,17 +397,36 @@ public class AlchemyScene extends PixelScene { } + public void populate(ArrayList toFind, Belongings inventory){ + clearSlots(); + + int curslot = 0; + for (Item finding : toFind){ + int needed = finding.quantity(); + ArrayList found = inventory.getAllSimilar(finding); + while (!found.isEmpty() && needed > 0){ + Item detached; + if (finding instanceof Dart) { + detached = found.get(0).detachAll(inventory.backpack); + } else { + detached = found.get(0).detach(inventory.backpack); + } + inputs[curslot].item(detached); + curslot++; + needed -= detached.quantity(); + if (detached == found.get(0)) { + found.remove(0); + } + } + } + updateState(); + } + @Override public void destroy() { synchronized ( inputs ) { + clearSlots(); for (int i = 0; i < inputs.length; i++) { - if (inputs[i] != null && inputs[i].item != null) { - if (!(inputs[i].item instanceof AlchemistsToolkit)) { - if (!inputs[i].item.collect()) { - Dungeon.level.drop(inputs[i].item, Dungeon.hero.pos); - } - } - } inputs[i] = null; } } @@ -421,6 +441,20 @@ public class AlchemyScene extends PixelScene { super.destroy(); } + public void clearSlots(){ + synchronized ( inputs ) { + for (int i = 0; i < inputs.length; i++) { + if (inputs[i] != null && inputs[i].item != null) { + if (!(inputs[i].item instanceof AlchemistsToolkit)) { + if (!inputs[i].item.collect()) { + Dungeon.level.drop(inputs[i].item, Dungeon.hero.pos); + } + } + } + } + } + } + public static class ItemButton extends Component { protected NinePatch bg;