diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/quest/CorpseDust.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/quest/CorpseDust.java index dd1476756..d2ed0b534 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/quest/CorpseDust.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/quest/CorpseDust.java @@ -20,8 +20,22 @@ */ package com.shatteredpixel.shatteredpixeldungeon.items.quest; +import com.shatteredpixel.shatteredpixeldungeon.Assets; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; +import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; +import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; +import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; +import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob; +import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Wraith; import com.shatteredpixel.shatteredpixeldungeon.items.Item; +import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; +import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; +import com.watabou.noosa.audio.Sample; +import com.watabou.utils.Bundle; +import com.watabou.utils.Random; + +import java.util.ArrayList; public class CorpseDust extends Item { @@ -34,7 +48,12 @@ public class CorpseDust extends Item { unique = true; } - + + @Override + public ArrayList actions(Hero hero) { + return new ArrayList<>(); //yup, no dropping this one + } + @Override public boolean isUpgradable() { return false; @@ -44,11 +63,85 @@ public class CorpseDust extends Item { public boolean isIdentified() { return true; } - + + @Override + public boolean doPickUp(Hero hero) { + if (super.doPickUp(hero)){ + GLog.n("You feel a shiver run down your spine."); + Buff.affect(hero, DustGhostSpawner.class); + return true; + } + return false; + } + + @Override + protected void onDetach() { + DustGhostSpawner spawner = Dungeon.hero.buff(DustGhostSpawner.class); + if (spawner != null){ + spawner.dispel(); + } + } + @Override public String info() { return - "The ball of corpse dust doesn't differ outwardly from a regular dust ball. However, " + - "you know somehow that it's better to get rid of it as soon as possible."; + "The ball of corpse dust doesn't differ outwardly from a regular dust ball. But you " + + "can feel a malevolent energy lurking within it.\n\n" + + "Getting rid of it as soon as possible would be a good idea."; } + + public static class DustGhostSpawner extends Buff { + + int spawnPower = 0; + + @Override + public boolean act() { + spawnPower++; + int wraiths = 1; //we include the wraith we're trying to spawn + for (Mob mob : Dungeon.level.mobs){ + if (mob instanceof Wraith){ + wraiths++; + } + } + + int powerNeeded = Math.min(25, wraiths*wraiths); + + if (powerNeeded <= spawnPower){ + spawnPower -= powerNeeded; + int pos = 0; + do{ + pos = Random.Int(Level.LENGTH); + } while (!Dungeon.visible[pos] || !Level.passable[pos] || Actor.findChar( pos ) != null); + Wraith.spawnAt(pos); + Sample.INSTANCE.play(Assets.SND_CURSED); + } + + spend(TICK); + return true; + } + + public void dispel(){ + detach(); + for (Mob mob : Dungeon.level.mobs.toArray(new Mob[0])){ + if (mob instanceof Wraith){ + mob.die(null); + } + } + } + + private static String SPAWNPOWER = "spawnpower"; + + @Override + public void storeInBundle(Bundle bundle) { + super.storeInBundle(bundle); + bundle.put( SPAWNPOWER, spawnPower ); + } + + @Override + public void restoreFromBundle(Bundle bundle) { + super.restoreFromBundle(bundle); + spawnPower = bundle.getInt( SPAWNPOWER ); + } + } + }