From 3f1043e4b98f67267f8b64783145917a76af399e Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Sat, 25 Apr 2015 01:33:50 -0400 Subject: [PATCH] v0.3.0: added chilled debuff --- .../shatteredpixeldungeon/actors/Char.java | 17 +++- .../actors/buffs/Burning.java | 3 +- .../actors/buffs/Chill.java | 78 +++++++++++++++++++ .../actors/buffs/Frost.java | 7 +- .../actors/mobs/Elemental.java | 3 +- .../effects/IceBlock.java | 3 +- .../items/weapon/Weapon.java | 3 +- .../items/weapon/enchantments/Slow.java | 5 +- .../sprites/CharSprite.java | 16 +++- 9 files changed, 121 insertions(+), 14 deletions(-) create mode 100644 src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Chill.java diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/Char.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/Char.java index 20c783f46..fe7949119 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/Char.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/Char.java @@ -244,9 +244,6 @@ public abstract class Char extends Actor { } if (this.buff(Frost.class) != null){ Buff.detach( this, Frost.class ); - if (Level.water[this.pos]) { - Buff.prolong(this, Paralysis.class, 1f); - } } if (this.buff(MagicalSleep.class) != null){ Buff.detach(this, MagicalSleep.class); @@ -301,6 +298,9 @@ public abstract class Char extends Actor { float timeScale = 1f; if (buff( Slow.class ) != null) { timeScale *= 0.5f; + //slowed and chilled do not stack + } else if (buff( Chill.class ) != null) { + timeScale *= buff( Chill.class ).speedFactor(); } if (buff( Speed.class ) != null) { timeScale *= 2.0f; @@ -363,6 +363,11 @@ public abstract class Char extends Actor { sprite.showStatus( CharSprite.NEGATIVE, "slowed" ); + } else if (buff instanceof Chill) { + + sprite.showStatus( CharSprite.NEGATIVE, "chilled" ); + sprite.add( CharSprite.State.CHILLED ); + } else if (buff instanceof MindVision) { sprite.showStatus( CharSprite.POSITIVE, "mind" ); @@ -427,7 +432,9 @@ public abstract class Char extends Actor { sprite.remove( CharSprite.State.PARALYSED ); } else if (buff instanceof Frost) { sprite.remove( CharSprite.State.FROZEN ); - } + } else if (buff instanceof Chill) { + sprite.remove( CharSprite.State.CHILLED ); + } } public void remove( Class buffClass ) { @@ -457,6 +464,8 @@ public abstract class Char extends Actor { sprite.add( CharSprite.State.FROZEN ); } else if (buff instanceof Light) { sprite.add( CharSprite.State.ILLUMINATED ); + } else if (buff instanceof Chill) { + sprite.add( CharSprite.State.CHILLED ); } } } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Burning.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Burning.java index 45f4815dc..5dac722c9 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Burning.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Burning.java @@ -61,7 +61,7 @@ public class Burning extends Buff implements Hero.Doom { super.restoreFromBundle(bundle); left = bundle.getFloat( LEFT ); } - + @Override public boolean act() { @@ -72,6 +72,7 @@ public class Burning extends Buff implements Hero.Doom { } target.damage( Random.Int( 1, 5 ), this ); + Buff.detach( target, Chill.class); if (target instanceof Hero) { diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Chill.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Chill.java new file mode 100644 index 000000000..0a3a983c3 --- /dev/null +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Chill.java @@ -0,0 +1,78 @@ +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.ui.BuffIndicator; +import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; +import com.watabou.utils.Random; + +/** + * Created by debenhame on 23/04/2015. + */ +public class Chill extends FlavourBuff { + + private static final String TXT_FREEZES = "%s freezes!"; + + @Override + public boolean attachTo(Char target) { + //can't chill what's frozen! + if (target.buff(Frost.class) != null) return false; + + if (super.attachTo(target)){ + Burning.detach( target, Burning.class ); + + //chance of potion breaking is the same as speed factor. + if (Random.Float(1f) > speedFactor() && target instanceof Hero) { + + Hero hero = (Hero)target; + Item item = hero.belongings.randomUnequipped(); + 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; + } + } + + //reduces speed by 10% for every turn remaining, capping at 50% + public float speedFactor(){ + return Math.max(0.5f, 1 - cooldown()*0.1f); + } + + @Override + public int icon() { + return BuffIndicator.FROST; + } + + @Override + public String toString() { + return "Chilled"; + } + +} diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Frost.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Frost.java index 58b85d5e2..dfce26838 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Frost.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Frost.java @@ -26,6 +26,7 @@ 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.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; @@ -40,7 +41,8 @@ public class Frost extends FlavourBuff { if (super.attachTo( target )) { target.paralysed = true; - Burning.detach( target, Burning.class ); + Buff.detach( target, Burning.class ); + Buff.detach( target, Chill.class ); if (target instanceof Hero) { @@ -80,6 +82,9 @@ public class Frost extends FlavourBuff { public void detach() { super.detach(); Paralysis.unfreeze( target ); + if (Level.water[target.pos]){ + Buff.prolong(target, Chill.class, 6f); + } } @Override diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Elemental.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Elemental.java index 168f5b4fd..befec4c1d 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Elemental.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Elemental.java @@ -22,6 +22,7 @@ import java.util.HashSet; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Burning; +import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Chill; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Frost; import com.shatteredpixel.shatteredpixeldungeon.effects.Speck; import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfLiquidFlame; @@ -80,7 +81,7 @@ public class Elemental extends Mob { HP++; sprite.emitter().burst( Speck.factory( Speck.HEALING ), 1 ); } - } else if (buff instanceof Frost) { + } else if (buff instanceof Frost || buff instanceof Chill) { if (Level.water[this.pos]) damage( Random.NormalIntRange( HT / 2, HT ), buff ); else diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/effects/IceBlock.java b/src/com/shatteredpixel/shatteredpixeldungeon/effects/IceBlock.java index 6134b2e7f..99fb2cc76 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/effects/IceBlock.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/effects/IceBlock.java @@ -61,7 +61,8 @@ public class IceBlock extends Gizmo { public static IceBlock freeze( CharSprite sprite ) { IceBlock iceBlock = new IceBlock( sprite ); - sprite.parent.add( iceBlock ); + if (sprite.parent != null) + sprite.parent.add( iceBlock ); return iceBlock; } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/Weapon.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/Weapon.java index a0af6a253..3f38fdfbe 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/Weapon.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/Weapon.java @@ -229,7 +229,8 @@ public class Weapon extends KindOfWeapon { public ItemSprite.Glowing glowing() { return enchantment != null ? enchantment.glowing() : null; } - + + //FIXME: most enchantment names are pretty broken, should refactor public static abstract class Enchantment implements Bundlable { private static final Class[] enchants = new Class[]{ diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/enchantments/Slow.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/enchantments/Slow.java index bab024e4d..a6ec3c432 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/enchantments/Slow.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/enchantments/Slow.java @@ -19,6 +19,7 @@ package com.shatteredpixel.shatteredpixeldungeon.items.weapon.enchantments; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; +import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Chill; import com.shatteredpixel.shatteredpixeldungeon.items.weapon.Weapon; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite.Glowing; @@ -39,8 +40,8 @@ public class Slow extends Weapon.Enchantment { if (Random.Int( level + 4 ) >= 3) { - Buff.prolong( defender, com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Slow.class, - Random.Float( 1, 1.5f + level ) ); + Buff.affect( defender, Chill.class, + Random.Float( 1, 3f ) ); return true; } else { diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/sprites/CharSprite.java b/src/com/shatteredpixel/shatteredpixeldungeon/sprites/CharSprite.java index 83d6d6b4a..a693d2584 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/sprites/CharSprite.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/sprites/CharSprite.java @@ -17,6 +17,7 @@ */ package com.shatteredpixel.shatteredpixeldungeon.sprites; +import com.shatteredpixel.shatteredpixeldungeon.effects.particles.SnowParticle; import com.watabou.noosa.Game; import com.watabou.noosa.MovieClip; import com.watabou.noosa.Visual; @@ -55,7 +56,7 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip private static final float FLASH_INTERVAL = 0.05f; public enum State { - BURNING, LEVITATING, INVISIBLE, PARALYSED, FROZEN, ILLUMINATED + BURNING, LEVITATING, INVISIBLE, PARALYSED, FROZEN, ILLUMINATED, CHILLED } protected Animation idle; @@ -70,6 +71,7 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip protected Tweener motion; protected Emitter burning; + protected Emitter chilled; protected Emitter levitation; protected IceBlock iceBlock; @@ -100,8 +102,7 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip place( ch.pos ); turnTo( ch.pos, Random.Int( Level.LENGTH ) ); - if (parent != null) - ch.updateSpriteState(); + ch.updateSpriteState(); } public PointF worldToCamera( int cell ) { @@ -277,6 +278,10 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip case ILLUMINATED: GameScene.effect( halo = new TorchHalo( this ) ); break; + case CHILLED: + chilled = emitter(); + chilled.pour(SnowParticle.FACTORY, 0.1f); + break; } } @@ -312,6 +317,11 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip halo.putOut(); } break; + case CHILLED: + if (chilled != null){ + chilled.on = false; + chilled = null; + } } }