v0.7.0: added logic to alchemy scene and recipes in prep for UI changes

This commit is contained in:
Evan Debenham 2018-09-30 18:02:50 -04:00
parent 44c3a99c57
commit e855617fe8
2 changed files with 57 additions and 7 deletions

View File

@ -85,6 +85,22 @@ public abstract class Recipe {
protected int outQuantity;
//***
//gets a simple list of items based on inputs
public ArrayList<Item> getIngredients() {
ArrayList<Item> 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<Item> ingredients) {

View File

@ -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<Item> toFind, Belongings inventory){
clearSlots();
int curslot = 0;
for (Item finding : toFind){
int needed = finding.quantity();
ArrayList<Item> 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;