From 08b552e68934dba7847fde4cc6141d5c1a787b40 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Tue, 12 Feb 2019 22:35:44 -0500 Subject: [PATCH] v0.7.2: buffed scroll of teleportation --- .../items/scrolls/ScrollOfTeleportation.java | 25 ++++++++++++++++ .../levels/rooms/Room.java | 19 +++++++++++- .../levels/rooms/special/SpecialRoom.java | 29 ++++++++++++++++++- .../messages/items/items.properties | 2 +- 4 files changed, 72 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 2f841fab7..10a7e13b0 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 @@ -31,6 +31,7 @@ import com.shatteredpixel.shatteredpixeldungeon.effects.Speck; import com.shatteredpixel.shatteredpixeldungeon.levels.RegularLevel; import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain; import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room; +import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.secret.SecretRoom; import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.SpecialRoom; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.scenes.CellSelector; @@ -172,9 +173,33 @@ public class ScrollOfTeleportation extends Scroll { teleportHero( hero ); } else { int pos = Random.element(candidates); + boolean secretDoor = false; + int doorPos = -1; + if (level.room(pos) instanceof SpecialRoom){ + SpecialRoom room = (SpecialRoom) level.room(pos); + if (room.entrance() != null){ + doorPos = level.pointToCell(room.entrance()); + for (int i : PathFinder.NEIGHBOURS8){ + if (!room.inside(level.cellToPoint(doorPos + i)) + && level.passable[doorPos + i] + && Actor.findChar(doorPos + i) == null){ + secretDoor = room instanceof SecretRoom; + pos = doorPos + i; + break; + } + } + } + } GLog.i( Messages.get(ScrollOfTeleportation.class, "tele") ); appear( hero, pos ); if (!hero.flying) Dungeon.level.press( pos, hero ); + if (secretDoor && level.map[doorPos] == Terrain.SECRET_DOOR){ + Sample.INSTANCE.play( Assets.SND_SECRET ); + int oldValue = Dungeon.level.map[doorPos]; + GameScene.discoverTile( doorPos, oldValue ); + Dungeon.level.discover( doorPos ); + ScrollOfMagicMapping.discover( doorPos ); + } Dungeon.observe(); GameScene.updateFog(); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/Room.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/Room.java index 856fdaf82..5cc36ed6c 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/Room.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/Room.java @@ -381,13 +381,16 @@ public abstract class Room extends Rect implements Graph.Node, Bundlable { //does nothing by default } - public static class Door extends Point { + public static class Door extends Point implements Bundlable { public enum Type { EMPTY, TUNNEL, REGULAR, UNLOCKED, HIDDEN, BARRICADE, LOCKED } public Type type = Type.EMPTY; + public Door(){ + } + public Door( Point p ){ super(p); } @@ -401,5 +404,19 @@ public abstract class Room extends Rect implements Graph.Node, Bundlable { this.type = type; } } + + @Override + public void storeInBundle(Bundle bundle) { + bundle.put("x", x); + bundle.put("y", y); + bundle.put("type", type); + } + + @Override + public void restoreFromBundle(Bundle bundle) { + x = bundle.getInt("x"); + y = bundle.getInt("y"); + type = bundle.getEnum("type", Type.class); + } } } \ No newline at end of file diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/special/SpecialRoom.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/special/SpecialRoom.java index f0b9c195f..056891b1b 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/special/SpecialRoom.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/special/SpecialRoom.java @@ -53,8 +53,35 @@ public class SpecialRoom extends Room { return 1; } + private Door entrance; + public Door entrance() { - return connected.values().iterator().next(); + if (entrance == null){ + if (connected.isEmpty()){ + return null; + } else { + entrance = connected.values().iterator().next(); + } + } + return entrance; + } + + private static final String ENTRANCE = "entrance"; + + @Override + public void storeInBundle(Bundle bundle) { + super.storeInBundle(bundle); + if (entrance() != null){ + bundle.put(ENTRANCE, entrance()); + } + } + + @Override + public void restoreFromBundle(Bundle bundle) { + super.restoreFromBundle(bundle); + if (bundle.contains(ENTRANCE)){ + entrance = (Door)bundle.get(ENTRANCE); + } } private static final ArrayList> ALL_SPEC = new ArrayList<>( Arrays.asList( 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 1707aa23e..10200f273 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 @@ -853,7 +853,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 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.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. It can, however, reveal hidden doors that lead to new areas. items.scrolls.scrollofterror.name=scroll of terror items.scrolls.scrollofterror.none=The scroll emits a brilliant flash of red light.