From 8c1f4aed38ad18e4854cb665350f26d6da60d592 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Mon, 27 Apr 2015 02:00:52 -0400 Subject: [PATCH] v0.3.0: wand of firebolt rework mostly implemented. --- .../items/wands/WandOfFirebolt.java | 108 +++++++++++++----- 1 file changed, 80 insertions(+), 28 deletions(-) diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfFirebolt.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfFirebolt.java index a6fc0610c..4692c21af 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfFirebolt.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfFirebolt.java @@ -17,67 +17,110 @@ */ package com.shatteredpixel.shatteredpixeldungeon.items.wands; +import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Cripple; +import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Paralysis; import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.MagesStaff; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.watabou.noosa.audio.Sample; import com.shatteredpixel.shatteredpixeldungeon.Assets; -import com.shatteredpixel.shatteredpixeldungeon.Dungeon; -import com.shatteredpixel.shatteredpixeldungeon.ResultDescriptions; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob; import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Fire; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Burning; -import com.shatteredpixel.shatteredpixeldungeon.effects.MagicMissile; -import com.shatteredpixel.shatteredpixeldungeon.effects.particles.FlameParticle; -import com.shatteredpixel.shatteredpixeldungeon.items.weapon.Weapon; import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; -import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; -import com.shatteredpixel.shatteredpixeldungeon.utils.Utils; -import com.watabou.noosa.audio.Sample; import com.watabou.utils.Callback; import com.watabou.utils.Random; +import java.util.HashSet; + +//TODO: rename to fireblast public class WandOfFirebolt extends Wand { { name = "Wand of Firebolt"; image = ItemSpriteSheet.WAND_FIREBOLT; + + collisionProperties = Ballistica.STOP_TERRAIN; } + + private HashSet affectedCells; + private int direction = 0; @Override protected void onZap( Ballistica bolt ) { int level = level(); - - for (int c : bolt.subPath(0, bolt.dist)) { - if (Level.flamable[c]) { - GameScene.add( Blob.seed( c, 1, Fire.class ) ); + + affectedCells = new HashSet<>(); + + int maxDist = 1 + chargesPerCast()*2; + int dist = Math.min(bolt.dist, maxDist); + + for (int i = 0; i < Level.NEIGHBOURS8.length; i++){ + if (bolt.sourcePos+Level.NEIGHBOURS8[i] == bolt.path.get(1)){ + direction = i; + break; } } - int cell = bolt.collisionPos; + float strength = maxDist; + for (int c : bolt.subPath(1, dist)) { + strength--; //as we start at dist 1, not 0. + affectedCells.add(c); + spreadFlames(c + Level.NEIGHBOURS8[left(direction)], strength - 1); + spreadFlames(c + Level.NEIGHBOURS8[direction], strength - 1); + spreadFlames(c + Level.NEIGHBOURS8[right(direction)], strength - 1); + } - GameScene.add( Blob.seed( cell, 1, Fire.class ) ); - - Char ch = Actor.findChar( cell ); - if (ch != null) { - - ch.damage( Random.Int( 1, 8 + level * level ), this ); - Buff.affect( ch, Burning.class ).reignite( ch ); - - ch.sprite.emitter().burst( FlameParticle.FACTORY, 5 ); - - if (ch == curUser && !ch.isAlive()) { - Dungeon.fail( Utils.format( ResultDescriptions.ITEM, name ) ); - GLog.n( "You killed yourself with your own Wand of Firebolt..." ); + if (Level.flamable[bolt.sourcePos]){ + GameScene.add( Blob.seed( bolt.sourcePos, 2, Fire.class ) ); + } + + for( int cell : affectedCells){ + GameScene.add( Blob.seed( cell, 1+chargesPerCast(), Fire.class ) ); + Char ch = Actor.findChar( cell ); + if (ch != null) { + + ch.damage(Random.NormalIntRange(1, (int) (8 + (level * level * (1 + chargesPerCast()) / 6f))), this); + Buff.affect( ch, Burning.class ).reignite( ch ); + switch(chargesPerCast()){ + case 1: + Buff.affect(ch, Cripple.class, 3f); break; + case 2: + Buff.affect(ch, Cripple.class, 6f); break; + case 3: + Buff.affect(ch, Paralysis.class, 3f); break; + case 4: + Buff.affect(ch, Paralysis.class, 6f); break; + } } } } + //burn... BURNNNNN!..... + private void spreadFlames(int cell, float strength){ + if (strength >= 0 && Level.passable[cell]){ + affectedCells.add(cell); + if (strength >= 1.5f) { + spreadFlames(cell + Level.NEIGHBOURS8[left(direction)], strength-1.5f); + spreadFlames(cell + Level.NEIGHBOURS8[direction], strength-1.5f); + spreadFlames(cell + Level.NEIGHBOURS8[right(direction)], strength-1.5f); + } + } + } + + private int left(int direction){ + return direction == 0 ? 7 : direction-1; + } + + private int right(int direction){ + return direction == 7 ? 0 : direction+1; + } + @Override public void onHit(MagesStaff staff, Char attacker, Char defender, int damage) { //acts like blazing enchantment, package conflict..... @@ -87,12 +130,21 @@ public class WandOfFirebolt extends Wand { @Override protected void fx( Ballistica bolt, Callback callback ) { - MagicMissile.fire( curUser.sprite.parent, bolt.sourcePos, bolt.collisionPos, callback ); + //TODO: add new effects + //MagicMissile.fire( curUser.sprite.parent, bolt.sourcePos, bolt.collisionPos, callback ); Sample.INSTANCE.play( Assets.SND_ZAP ); + callback.call(); } - + + @Override + protected int chargesPerCast() { + //consumes 40% of current charges, rounded up, with a minimum of one. + return Math.max(1, (int)Math.ceil(curCharges*0.4f)); + } + @Override public String desc() { + //TODO add new description return "This wand unleashes bursts of magical fire. It will ignite " + "flammable terrain, and will damage and burn a creature it hits.";