From aabd3a4bc6809f67c4d29efd96ba3a598c1b14e1 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Thu, 24 Dec 2015 22:07:56 -0500 Subject: [PATCH] v0.3.3a: fixed newborn elementals spawning inside the hero --- .../items/quest/CeremonialCandle.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/quest/CeremonialCandle.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/quest/CeremonialCandle.java index 7f64edba3..174a96daf 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/quest/CeremonialCandle.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/quest/CeremonialCandle.java @@ -22,6 +22,8 @@ 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.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.NewbornElemental; import com.shatteredpixel.shatteredpixeldungeon.effects.CellEmitter; @@ -32,6 +34,9 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.watabou.noosa.audio.Sample; +import com.watabou.utils.Random; + +import java.util.ArrayList; public class CeremonialCandle extends Item { @@ -93,7 +98,23 @@ public class CeremonialCandle extends Item { heapLeft.pickUp(); NewbornElemental elemental = new NewbornElemental(); - elemental.pos = ritualPos; + Char ch = Actor.findChar( ritualPos ); + if (ch != null) { + ArrayList candidates = new ArrayList<>(); + for (int n : Level.NEIGHBOURS8) { + int cell = ritualPos + n; + if ((Level.passable[cell] || Level.avoid[cell]) && Actor.findChar( cell ) == null) { + candidates.add( cell ); + } + } + if (candidates.size() > 0) { + elemental.pos = Random.element( candidates ); + } else { + elemental.pos = ritualPos; + } + } else { + elemental.pos = ritualPos; + } elemental.state = elemental.HUNTING; GameScene.add(elemental, 1);