From 72975a49ccc2a057c9b83eaa37dc8e791ecabe1d Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Tue, 10 Feb 2015 02:09:57 -0500 Subject: [PATCH] v0.2.4: made potions susceptible to cold, refactored a bit of buff logic. --- .../actors/buffs/Burning.java | 18 +++++++------- .../actors/buffs/Frost.java | 24 ++++++++++++++++++- .../items/potions/Potion.java | 10 ++++---- .../items/potions/PotionOfFrost.java | 19 ++++++++------- .../items/potions/PotionOfLevitation.java | 13 ++++++---- .../items/potions/PotionOfLiquidFlame.java | 20 +++++++++------- .../items/potions/PotionOfParalyticGas.java | 17 +++++++------ .../items/potions/PotionOfPurity.java | 20 +++++++++------- .../items/potions/PotionOfToxicGas.java | 21 ++++++++-------- 9 files changed, 101 insertions(+), 61 deletions(-) diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Burning.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Burning.java index fc58f33be..45f4815dc 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Burning.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Burning.java @@ -36,7 +36,6 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; -import com.shatteredpixel.shatteredpixeldungeon.utils.Utils; import com.watabou.utils.Bundle; import com.watabou.utils.Random; @@ -75,25 +74,26 @@ public class Burning extends Buff implements Hero.Doom { target.damage( Random.Int( 1, 5 ), this ); if (target instanceof Hero) { - - Item item = ((Hero)target).belongings.randomUnequipped(); + + Hero hero = (Hero)target; + Item item = hero.belongings.randomUnequipped(); if (item instanceof Scroll) { - item = item.detach( ((Hero)target).belongings.backpack ); + item = item.detach( hero.belongings.backpack ); GLog.w( TXT_BURNS_UP, item.toString() ); - Heap.burnFX( target.pos ); + Heap.burnFX( hero.pos ); } else if (item instanceof MysteryMeat) { - item = item.detach( ((Hero)target).belongings.backpack ); + item = item.detach( hero.belongings.backpack ); ChargrilledMeat steak = new ChargrilledMeat(); - if (!steak.collect( ((Hero)target).belongings.backpack )) { - Dungeon.level.drop( steak, target.pos ).sprite.drop(); + if (!steak.collect( hero.belongings.backpack )) { + Dungeon.level.drop( steak, hero.pos ).sprite.drop(); } GLog.w( TXT_BURNS_UP, item.toString() ); - Heap.burnFX( target.pos ); + Heap.burnFX( hero.pos ); } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Frost.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Frost.java index 46032de9a..58b85d5e2 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Frost.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Frost.java @@ -20,14 +20,19 @@ package com.shatteredpixel.shatteredpixeldungeon.actors.buffs; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; +import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Thief; import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.food.FrozenCarpaccio; import com.shatteredpixel.shatteredpixeldungeon.items.food.MysteryMeat; +import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion; import com.shatteredpixel.shatteredpixeldungeon.items.rings.RingOfElements.Resistance; import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator; +import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; public class Frost extends FlavourBuff { + private static final String TXT_FREEZES = "%s freezes!"; + private static final float DURATION = 5f; @Override @@ -36,18 +41,35 @@ public class Frost extends FlavourBuff { target.paralysed = true; Burning.detach( target, Burning.class ); + if (target instanceof Hero) { + Hero hero = (Hero)target; Item item = hero.belongings.randomUnequipped(); - if (item instanceof MysteryMeat) { + if (item instanceof Potion) { + + item = item.detach( hero.belongings.backpack ); + GLog.w(TXT_FREEZES, item.toString()); + ((Potion) item).shatter(hero.pos); + + } else if (item instanceof MysteryMeat) { + item = item.detach( hero.belongings.backpack ); FrozenCarpaccio carpaccio = new FrozenCarpaccio(); if (!carpaccio.collect( hero.belongings.backpack )) { Dungeon.level.drop( carpaccio, target.pos ).sprite.drop(); } + GLog.w(TXT_FREEZES, item.toString()); + } + } else if (target instanceof Thief && ((Thief)target).item instanceof Potion) { + + ((Potion) ((Thief)target).item).shatter( target.pos ); + ((Thief) target).item = null; + } + return true; } else { return false; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/potions/Potion.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/potions/Potion.java index fbe376347..2cdeddb35 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/potions/Potion.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/potions/Potion.java @@ -218,10 +218,12 @@ public class Potion extends Item { shatter( hero.pos ); } - protected void shatter( int cell ) { - GLog.i( "The flask shatters and " + color() + " liquid splashes harmlessly" ); - Sample.INSTANCE.play( Assets.SND_SHATTER ); - splash( cell ); + public void shatter( int cell ) { + if (Dungeon.visible[cell]) { + GLog.i( "The flask shatters and " + color() + " liquid splashes harmlessly" ); + Sample.INSTANCE.play( Assets.SND_SHATTER ); + splash( cell ); + } } @Override diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfFrost.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfFrost.java index b203c80ef..aeaf9f61a 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfFrost.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfFrost.java @@ -35,22 +35,25 @@ public class PotionOfFrost extends Potion { } @Override - protected void shatter( int cell ) { + public void shatter( int cell ) { PathFinder.buildDistanceMap( cell, BArray.not( Level.losBlocking, null ), DISTANCE ); Fire fire = (Fire)Dungeon.level.blobs.get( Fire.class ); - + + boolean visible = false; for (int i=0; i < Level.LENGTH; i++) { if (PathFinder.distance[i] < Integer.MAX_VALUE) { - Freezing.affect( i, fire ); + visible = Freezing.affect( i, fire ) || visible; } } - - splash( cell ); - Sample.INSTANCE.play( Assets.SND_SHATTER ); - - setKnown(); + + if (visible) { + splash( cell ); + Sample.INSTANCE.play( Assets.SND_SHATTER ); + + setKnown(); + } } @Override diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfLevitation.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfLevitation.java index cffa49836..0012ec63e 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfLevitation.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfLevitation.java @@ -18,6 +18,7 @@ package com.shatteredpixel.shatteredpixeldungeon.items.potions; import com.shatteredpixel.shatteredpixeldungeon.Assets; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob; import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.ConfusionGas; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; @@ -34,14 +35,16 @@ public class PotionOfLevitation extends Potion { } @Override - protected void shatter( int cell ) { + public void shatter( int cell ) { - setKnown(); + if (Dungeon.visible[cell]) { + setKnown(); - splash( cell ); - Sample.INSTANCE.play( Assets.SND_SHATTER ); + splash( cell ); + Sample.INSTANCE.play( Assets.SND_SHATTER ); + } - GameScene.add( Blob.seed( cell, 1000, ConfusionGas.class ) ); + GameScene.add( Blob.seed( cell, 1000, ConfusionGas.class ) ); } @Override diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfLiquidFlame.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfLiquidFlame.java index fb2a526f2..cdc449eaa 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfLiquidFlame.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfLiquidFlame.java @@ -17,6 +17,7 @@ */ package com.shatteredpixel.shatteredpixeldungeon.items.potions; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.watabou.noosa.audio.Sample; import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob; @@ -30,15 +31,16 @@ public class PotionOfLiquidFlame extends Potion { } @Override - protected void shatter( int cell ) { - - setKnown(); - - splash( cell ); - Sample.INSTANCE.play( Assets.SND_SHATTER ); - - Fire fire = Blob.seed( cell, 2, Fire.class ); - GameScene.add( fire ); + public void shatter( int cell ) { + + if (Dungeon.visible[cell]) { + setKnown(); + + splash( cell ); + Sample.INSTANCE.play( Assets.SND_SHATTER ); + } + + GameScene.add( Blob.seed( cell, 2, Fire.class ) ); } @Override diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfParalyticGas.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfParalyticGas.java index 3d3a5aadd..5f07d8e96 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfParalyticGas.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfParalyticGas.java @@ -17,6 +17,7 @@ */ package com.shatteredpixel.shatteredpixeldungeon.items.potions; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.watabou.noosa.audio.Sample; import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob; @@ -30,13 +31,15 @@ public class PotionOfParalyticGas extends Potion { } @Override - protected void shatter( int cell ) { - - setKnown(); - - splash( cell ); - Sample.INSTANCE.play( Assets.SND_SHATTER ); - + public void shatter( int cell ) { + + if (Dungeon.visible[cell]) { + setKnown(); + + splash( cell ); + Sample.INSTANCE.play( Assets.SND_SHATTER ); + } + GameScene.add( Blob.seed( cell, 1000, ParalyticGas.class ) ); } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfPurity.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfPurity.java index fd0d9c72d..77e17befd 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfPurity.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfPurity.java @@ -47,7 +47,7 @@ public class PotionOfPurity extends Potion { } @Override - protected void shatter( int cell ) { + public void shatter( int cell ) { PathFinder.buildDistanceMap( cell, BArray.not( Level.losBlocking, null ), DISTANCE ); @@ -76,8 +76,10 @@ public class PotionOfPurity extends Potion { blob.cur[i] = 0; blob.volume -= value; procd = true; - - CellEmitter.get( i ).burst( Speck.factory( Speck.DISCOVER ), 1 ); + + if (Dungeon.visible[i]) { + CellEmitter.get( i ).burst( Speck.factory( Speck.DISCOVER ), 1 ); + } } } @@ -87,12 +89,14 @@ public class PotionOfPurity extends Potion { boolean heroAffected = PathFinder.distance[Dungeon.hero.pos] < Integer.MAX_VALUE; if (procd) { - - splash( cell ); - Sample.INSTANCE.play( Assets.SND_SHATTER ); - + + if (Dungeon.visible[cell]) { + splash( cell ); + Sample.INSTANCE.play( Assets.SND_SHATTER ); + } + setKnown(); - + if (heroAffected) { GLog.p( TXT_FRESHNESS ); } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfToxicGas.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfToxicGas.java index dd3ef2ab9..44a6c13c0 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfToxicGas.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfToxicGas.java @@ -17,6 +17,7 @@ */ package com.shatteredpixel.shatteredpixeldungeon.items.potions; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.watabou.noosa.audio.Sample; import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; @@ -31,16 +32,16 @@ public class PotionOfToxicGas extends Potion { } @Override - protected void shatter( int cell ) { - - setKnown(); - - splash( cell ); - Sample.INSTANCE.play( Assets.SND_SHATTER ); - - ToxicGas gas = Blob.seed( cell, 1000, ToxicGas.class ); - Actor.add( gas ); - GameScene.add( gas ); + public void shatter( int cell ) { + + if (Dungeon.visible[cell]) { + setKnown(); + + splash( cell ); + Sample.INSTANCE.play( Assets.SND_SHATTER ); + } + + GameScene.add( Blob.seed( cell, 1000, ToxicGas.class ) ); } @Override