diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java index 35d54fb59..093acb217 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java @@ -64,6 +64,7 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.StartScene; import com.shatteredpixel.shatteredpixeldungeon.ui.QuickSlotButton; import com.shatteredpixel.shatteredpixeldungeon.utils.BArray; import com.shatteredpixel.shatteredpixeldungeon.utils.DungeonSeed; +import com.shatteredpixel.shatteredpixeldungeon.windows.WndAlchemy; import com.shatteredpixel.shatteredpixeldungeon.windows.WndResurrect; import com.watabou.noosa.Game; import com.watabou.utils.Bundlable; @@ -480,6 +481,8 @@ public class Dungeon { SpecialRoom.storeRoomsInBundle( bundle ); SecretRoom.storeRoomsInBundle( bundle ); + + WndAlchemy.storeInBundle( bundle ); Statistics.storeInBundle( bundle ); Notes.storeInBundle( bundle ); @@ -601,6 +604,8 @@ public class Dungeon { hero = null; hero = (Hero)bundle.get( HERO ); + + WndAlchemy.restoreFromBundle( bundle, hero ); gold = bundle.getInt( GOLD ); depth = bundle.getInt( DEPTH ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndAlchemy.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndAlchemy.java index 9c26c0270..2fc7253db 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndAlchemy.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndAlchemy.java @@ -24,6 +24,7 @@ package com.shatteredpixel.shatteredpixeldungeon.windows; import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; +import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.effects.Speck; import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.Recipe; @@ -43,12 +44,14 @@ import com.watabou.noosa.ColorBlock; import com.watabou.noosa.Image; import com.watabou.noosa.audio.Sample; import com.watabou.noosa.particles.Emitter; +import com.watabou.utils.Bundlable; +import com.watabou.utils.Bundle; import java.util.ArrayList; public class WndAlchemy extends Window { - private WndBlacksmith.ItemButton[] inputs = new WndBlacksmith.ItemButton[3]; + private static WndBlacksmith.ItemButton[] inputs = new WndBlacksmith.ItemButton[3]; private ItemSlot output; private Emitter smokeEmitter; @@ -291,13 +294,46 @@ public class WndAlchemy extends Window { @Override public void destroy() { - for (int i = 0; i < inputs.length; i++) { - if (inputs[i].item != null){ - if (!inputs[i].item.collect()){ - Dungeon.level.drop(inputs[i].item, Dungeon.hero.pos); + synchronized ( inputs ) { + for (int i = 0; i < inputs.length; i++) { + if (inputs[i].item != null) { + if (!inputs[i].item.collect()) { + Dungeon.level.drop(inputs[i].item, Dungeon.hero.pos); + } } + inputs[i] = null; } } super.destroy(); } + + private static final String ALCHEMY_INPUTS = "alchemy_inputs"; + + public static void storeInBundle( Bundle b ){ + synchronized ( inputs ){ + ArrayList items = new ArrayList<>(); + for (WndBlacksmith.ItemButton i : inputs){ + if (i != null && i.item != null){ + items.add(i.item); + } + } + if (!items.isEmpty()){ + b.put( ALCHEMY_INPUTS, items ); + } + } + } + + public static void restoreFromBundle( Bundle b, Hero h ){ + + if (b.contains(ALCHEMY_INPUTS)){ + for (Bundlable item : b.getCollection(ALCHEMY_INPUTS)){ + + //try to add normally, force-add otherwise. + if (!((Item)item).collect(h.belongings.backpack)){ + h.belongings.backpack.items.add((Item)item); + } + } + } + + } }