From 614dbcfc4c1f0d756902a8b851e7bb695ea2a17c Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Thu, 16 Aug 2018 15:29:52 -0400 Subject: [PATCH] v0.7.0: implemented use of alchemy water into the alchemy scene --- .../actors/blobs/Alchemy.java | 17 ++- .../actors/hero/Hero.java | 8 ++ .../shatteredpixeldungeon/items/Recipe.java | 1 - .../rooms/secret/SecretLaboratoryRoom.java | 2 +- .../levels/rooms/special/LaboratoryRoom.java | 2 +- .../scenes/AlchemyScene.java | 116 +++++++++++++----- 6 files changed, 109 insertions(+), 37 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Alchemy.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Alchemy.java index a6898e2e4..eef2ae059 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Alchemy.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Alchemy.java @@ -25,10 +25,11 @@ import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.effects.BlobEmitter; import com.shatteredpixel.shatteredpixeldungeon.effects.Speck; import com.shatteredpixel.shatteredpixeldungeon.journal.Notes; +import com.shatteredpixel.shatteredpixeldungeon.scenes.AlchemyScene; import com.watabou.utils.PathFinder; import com.watabou.utils.Random; -public class Alchemy extends Blob { +public class Alchemy extends Blob implements AlchemyScene.AlchemyProvider { protected int pos; @@ -64,4 +65,18 @@ public class Alchemy extends Blob { super.use( emitter ); emitter.start( Speck.factory( Speck.BUBBLE ), 0.33f, 0 ); } + + public static int alchPos; + + //1 volume is kept in reserve + + @Override + public int getWater() { + return Math.max(0, cur[alchPos] - 1); + } + + @Override + public void spendWater(int reduction) { + cur[alchPos] = Math.max(1, cur[alchPos] - reduction); + } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java index a79c18883..9a4c2a448 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java @@ -30,6 +30,7 @@ import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.Statistics; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; +import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Alchemy; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.AdrenalineSurge; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Awareness; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Barkskin; @@ -672,6 +673,13 @@ public class Hero extends Char { if (Dungeon.level.distance(dst, pos) <= 1) { ready(); + + Alchemy alch = (Alchemy) Dungeon.level.blobs.get(Alchemy.class); + //TODO logic for a well having dried up? + if (alch != null) { + alch.alchPos = dst; + AlchemyScene.setProvider( alch ); + } ShatteredPixelDungeon.switchScene(AlchemyScene.class); return false; 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 5ca386d33..ffd2f33f6 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Recipe.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Recipe.java @@ -38,7 +38,6 @@ public abstract class Recipe { public abstract boolean testIngredients(ArrayList ingredients); - //not currently used public abstract int cost(ArrayList ingredients); public abstract Item brew(ArrayList ingredients); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/secret/SecretLaboratoryRoom.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/secret/SecretLaboratoryRoom.java index ea7f6bbfd..c2e57e9ca 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/secret/SecretLaboratoryRoom.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/secret/SecretLaboratoryRoom.java @@ -71,7 +71,7 @@ public class SecretLaboratoryRoom extends SecretRoom { Painter.set( level, pot, Terrain.ALCHEMY ); Alchemy alchemy = new Alchemy(); - alchemy.seed( level, pot.x + level.width() * pot.y, Random.IntRange(20, 30) ); + alchemy.seed( level, pot.x + level.width() * pot.y, 1+Random.NormalIntRange(20, 30) ); level.blobs.put( Alchemy.class, alchemy ); int n = Random.IntRange( 2, 3 ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/special/LaboratoryRoom.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/special/LaboratoryRoom.java index 2e3a83984..8f1a9eca9 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/special/LaboratoryRoom.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/special/LaboratoryRoom.java @@ -62,7 +62,7 @@ public class LaboratoryRoom extends SpecialRoom { Alchemy alchemy = new Alchemy(); int chapter = 1 + Dungeon.depth/5; - alchemy.seed( level, pot.x + level.width() * pot.y, chapter*10 + Random.IntRange(0, 20) ); + alchemy.seed( level, pot.x + level.width() * pot.y, 1 + chapter*10 + Random.NormalIntRange(0, 10) ); level.blobs.put( Alchemy.class, alchemy ); int n = Random.NormalIntRange( 2, 3 ); 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 966b03c93..2560cd5dc 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/AlchemyScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/AlchemyScene.java @@ -33,12 +33,15 @@ import com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.darts.Dart import com.shatteredpixel.shatteredpixeldungeon.journal.Document; import com.shatteredpixel.shatteredpixeldungeon.journal.Journal; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; +import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; +import com.shatteredpixel.shatteredpixeldungeon.ui.ExitButton; +import com.shatteredpixel.shatteredpixeldungeon.ui.IconButton; import com.shatteredpixel.shatteredpixeldungeon.ui.Icons; import com.shatteredpixel.shatteredpixeldungeon.ui.ItemSlot; import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton; import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline; -import com.shatteredpixel.shatteredpixeldungeon.windows.IconTitle; +import com.shatteredpixel.shatteredpixeldungeon.ui.Window; import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag; import com.shatteredpixel.shatteredpixeldungeon.windows.WndDocument; import com.shatteredpixel.shatteredpixeldungeon.windows.WndInfoItem; @@ -51,6 +54,7 @@ import com.watabou.noosa.Image; import com.watabou.noosa.NinePatch; import com.watabou.noosa.NoosaScript; import com.watabou.noosa.NoosaScriptNoLighting; +import com.watabou.noosa.RenderedText; import com.watabou.noosa.SkinnedBlock; import com.watabou.noosa.audio.Sample; import com.watabou.noosa.particles.Emitter; @@ -70,6 +74,9 @@ public class AlchemyScene extends PixelScene { private Emitter lowerBubbles; private SkinnedBlock water; + private RenderedText waterLeft; + private RenderedText waterCost; + private RedButton btnCombine; private static final int BTN_SIZE = 28; @@ -104,18 +111,18 @@ public class AlchemyScene extends PixelScene { im.scale.y = Camera.main.width; add(im); + + RenderedText title = PixelScene.renderText( "Alchemy", 9 ); + title.hardlight(Window.TITLE_COLOR); + title.x = (Camera.main.width - title.width()) / 2f; + title.y = (16 - title.baseLine()) / 2f; + align(title); + add(title); + int w = 50 + Camera.main.width/2; int left = (Camera.main.width - w)/2; - int pos = (Camera.main.height - 160)/2; - - IconTitle titlebar = new IconTitle(); - //titlebar.icon(DungeonTerrainTilemap.tile(0, Terrain.ALCHEMY)); - titlebar.label( Messages.get(AlchemyScene.class, "title") ); - titlebar.setRect( 0, 0, w, 0 ); - //add( titlebar ); - - pos += titlebar.height() + 2; + int pos = (Camera.main.height - 120)/2; RenderedTextMultiline desc = PixelScene.renderMultiline(6); desc.text( Messages.get(AlchemyScene.class, "text") ); @@ -219,38 +226,39 @@ public class AlchemyScene extends PixelScene { add(bubbleEmitter); add(smokeEmitter); - pos += 4; + pos += 10; - float btnWidth = (w-14)/2f; + lowerBubbles = new Emitter(); + lowerBubbles.pos(0, pos, Camera.main.width, Math.max(0, Camera.main.height-pos)); + add(lowerBubbles); + lowerBubbles.pour(Speck.factory( Speck.BUBBLE ), 0.1f ); - RedButton btnRecipes = new RedButton(Messages.get(AlchemyScene.class, "recipes_title")){ + ExitButton btnExit = new ExitButton(){ + @Override + protected void onClick() { + Game.switchScene(GameScene.class); + } + }; + btnExit.setPos( Camera.main.width - btnExit.width(), 0 ); + add( btnExit ); + + IconButton btnGuide = new IconButton( new ItemSprite(ItemSpriteSheet.ALCH_PAGE, null)){ @Override protected void onClick() { super.onClick(); AlchemyScene.this.addToFront(new WndDocument(Document.ALCHEMY_GUIDE)); } }; - btnRecipes.setRect(left + 5, pos, btnWidth, 18); - PixelScene.align(btnRecipes); - add(btnRecipes); + btnGuide.setRect(0, 0, 16, 16); + add(btnGuide); - RedButton btnClose = new RedButton(Messages.get(AlchemyScene.class, "close")){ - @Override - protected void onClick() { - super.onClick(); - Game.switchScene(GameScene.class); - } - }; - btnClose.setRect(left + w - 5 - btnWidth, pos, btnWidth, 18); - PixelScene.align(btnClose); - add(btnClose); + waterLeft = PixelScene.renderText("Alchemy Water: " + availableWater(), 9); + waterLeft.y = Camera.main.height - waterLeft.baseLine(); + waterLeft.x = (Camera.main.width - waterLeft.width())/2; + add(waterLeft); - pos = (int)btnClose.bottom() + 20; - - lowerBubbles = new Emitter(); - lowerBubbles.pos(0, pos, Camera.main.width, Math.max(0, Camera.main.height-pos)); - add(lowerBubbles); - lowerBubbles.pour(Speck.factory( Speck.BUBBLE ), 0.1f ); + waterCost = PixelScene.renderText(6); + add(waterCost); fadeIn(); } @@ -306,11 +314,27 @@ public class AlchemyScene extends PixelScene { if (recipe != null){ output.item(recipe.sampleOutput(ingredients)); output.visible = true; - btnCombine.enable(true); + + int cost = recipe.cost(ingredients); + + waterCost.text("Water: " + cost); + waterCost.y = btnCombine.top() - waterCost.baseLine(); + waterCost.x = btnCombine.left() + (btnCombine.width() - waterCost.width())/2; + + waterCost.visible = (cost > 0); + + if (cost <= availableWater()) { + btnCombine.enable(true); + waterCost.resetColor(); + } else { + btnCombine.enable(false); + waterCost.hardlight(1, 0, 0); + } } else { btnCombine.enable(false); output.visible = false; + waterCost.visible = false; } } @@ -323,6 +347,11 @@ public class AlchemyScene extends PixelScene { Item result = null; if (recipe != null){ + provider.spendWater(recipe.cost(ingredients)); + waterLeft.text("Alchemy Water: " + availableWater()); + waterLeft.y = Camera.main.height - waterLeft.baseLine(); + waterLeft.x = (Camera.main.width - waterLeft.width())/2; + result = recipe.brew(ingredients); } @@ -372,6 +401,9 @@ public class AlchemyScene extends PixelScene { inputs[i] = null; } } + + provider = null; + try { Dungeon.saveAll(); Badges.saveGlobal(); @@ -432,4 +464,22 @@ public class AlchemyScene extends PixelScene { slot.item( this.item = item ); } } + + private static AlchemyProvider provider; + + public static void setProvider( AlchemyProvider p ){ + provider = p; + } + + private static int availableWater(){ + return provider == null ? 0 : provider.getWater(); + } + + public interface AlchemyProvider { + + int getWater(); + + void spendWater(int reduction); + + } }