From 3d47e9a9e81f92da27f796612e083cffb288ca13 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Mon, 18 Jun 2018 21:58:02 -0400 Subject: [PATCH] v0.7.0: buffed scroll of teleportation --- .../items/scrolls/ScrollOfTeleportation.java | 53 ++++++++++++++++++- .../messages/items/items.properties | 2 +- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfTeleportation.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfTeleportation.java index 7f1bd69e3..143c87d7f 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfTeleportation.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfTeleportation.java @@ -28,6 +28,8 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Invisibility; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.effects.Speck; +import com.shatteredpixel.shatteredpixeldungeon.levels.RegularLevel; +import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.scenes.CellSelector; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; @@ -37,6 +39,9 @@ import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; import com.watabou.noosa.audio.Sample; import com.watabou.noosa.tweeners.AlphaTweener; import com.watabou.utils.PathFinder; +import com.watabou.utils.Random; + +import java.util.ArrayList; public class ScrollOfTeleportation extends Scroll { @@ -50,7 +55,7 @@ public class ScrollOfTeleportation extends Scroll { Sample.INSTANCE.play( Assets.SND_READ ); Invisibility.dispel(); - teleportHero( curUser ); + teleportPreferringUnseen( curUser ); setKnown(); readAnimation(); @@ -98,7 +103,7 @@ public class ScrollOfTeleportation extends Scroll { } - public static void teleportHero(Hero hero ) { + public static void teleportHero( Hero hero ) { int count = 10; int pos; @@ -124,6 +129,50 @@ public class ScrollOfTeleportation extends Scroll { } } + + public static void teleportPreferringUnseen( Hero hero ){ + + if (!(Dungeon.level instanceof RegularLevel)){ + teleportHero( hero ); + } + + RegularLevel level = (RegularLevel) Dungeon.level; + ArrayList candidates = new ArrayList<>(); + + Room r; + for (int i = 0; i < level.length(); i++){ + if (!level.passable[i] || level.visited[i]){ + continue; + } + r = level.room(i); + if (r == null || Actor.findChar(i) != null){ + continue; + } + boolean locked = false; + for (Room.Door d : r.connected.values()){ + if (d.type == Room.Door.Type.LOCKED || d.type == Room.Door.Type.BARRICADE) { + locked = true; + break; + } + } + if (locked){ + continue; + } + candidates.add(i); + } + + if (candidates.isEmpty()){ + teleportHero( hero ); + } else { + int pos = Random.element(candidates); + appear( hero, pos ); + Dungeon.level.press( pos, hero ); + Dungeon.observe(); + GameScene.updateFog(); + GLog.i( Messages.get(ScrollOfTeleportation.class, "tele") ); + } + + } public static void appear( Char ch, int pos ) { diff --git a/core/src/main/resources/com/shatteredpixel/shatteredpixeldungeon/messages/items/items.properties b/core/src/main/resources/com/shatteredpixel/shatteredpixeldungeon/messages/items/items.properties index a35331392..6fe74d4ce 100644 --- a/core/src/main/resources/com/shatteredpixel/shatteredpixeldungeon/messages/items/items.properties +++ b/core/src/main/resources/com/shatteredpixel/shatteredpixeldungeon/messages/items/items.properties @@ -656,7 +656,7 @@ items.scrolls.scrollofteleportation.tele=In a blink of an eye you were teleporte items.scrolls.scrollofteleportation.no_tele=Strong magic aura of this place prevents you from teleporting! items.scrolls.scrollofteleportation.cant_reach=You can't teleport there items.scrolls.scrollofteleportation.prompt=Choose a location to teleport -items.scrolls.scrollofteleportation.desc=The spell on this parchment instantly transports the reader to a random location on the dungeon level. It can be used to escape a dangerous situation, but the unlucky reader might find themselves in an even more dangerous place. +items.scrolls.scrollofteleportation.desc=The spell on this parchment instantly transports the reader to a different location on the dungeon level. The scroll prioritizes areas the reader hasn't been to before, through it is not able to teleport past locked doors or barricades. items.scrolls.scrollofterror.name=scroll of terror items.scrolls.scrollofterror.none=The scroll emits a brilliant flash of red light.