From 6a0a7ae450937fdd9001273a57feb06ada7d758e Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Sun, 25 Jun 2017 20:19:49 -0400 Subject: [PATCH] v0.6.1: ghost hero now follows the player between floors --- .../shatteredpixeldungeon/Dungeon.java | 15 ++++++++---- .../actors/hero/Hero.java | 6 ----- .../items/artifacts/DriedRose.java | 24 +++++++++++++++++++ .../items/artifacts/LloydsBeacon.java | 4 ---- .../items/wands/CursedWand.java | 5 ---- .../levels/features/Chasm.java | 4 ---- .../levels/traps/DistortionTrap.java | 5 ---- .../levels/traps/WarpingTrap.java | 5 ---- .../scenes/InterlevelScene.java | 12 ++++++++++ 9 files changed, 47 insertions(+), 33 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java index 28f0e4903..589bcd600 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java @@ -36,6 +36,7 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.Wandmaker; import com.shatteredpixel.shatteredpixeldungeon.items.Ankh; import com.shatteredpixel.shatteredpixeldungeon.items.Generator; import com.shatteredpixel.shatteredpixeldungeon.items.Item; +import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.DriedRose; import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion; import com.shatteredpixel.shatteredpixeldungeon.items.rings.Ring; import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.Scroll; @@ -309,10 +310,16 @@ public class Dungeon { @SuppressWarnings("deprecation") public static void switchLevel( final Level level, int pos ) { - Dungeon.level = level; - Actor.init(); - + if (pos < 0 || pos >= level.length()){ + pos = level.exit; + } + PathFinder.setMapSize(level.width(), level.height()); + + Dungeon.level = level; + DriedRose.restoreGhostHero( level, pos + PathFinder.NEIGHBOURS8[Random.Int(8)]); + Actor.init(); + visible = new boolean[level.length()]; Actor respawner = level.respawner(); @@ -320,7 +327,7 @@ public class Dungeon { Actor.add( level.respawner() ); } - hero.pos = pos != -1 ? pos : level.exit; + hero.pos = pos; Light light = hero.buff( Light.class ); hero.viewDistance = light == null ? level.viewDistance : Math.max( Light.DISTANCE, level.viewDistance ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java index f5d1ead56..513e2fa13 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java @@ -806,9 +806,6 @@ public class Hero extends Char { Buff buff = buff(TimekeepersHourglass.timeFreeze.class); if (buff != null) buff.detach(); - - for (Mob mob : Dungeon.level.mobs.toArray( new Mob[0] )) - if (mob instanceof DriedRose.GhostHero) mob.destroy(); InterlevelScene.mode = InterlevelScene.Mode.DESCEND; Game.switchScene( InterlevelScene.class ); @@ -852,9 +849,6 @@ public class Hero extends Char { Buff buff = buff(TimekeepersHourglass.timeFreeze.class); if (buff != null) buff.detach(); - for (Mob mob : Dungeon.level.mobs.toArray( new Mob[0] )) - if (mob instanceof DriedRose.GhostHero) mob.destroy(); - InterlevelScene.mode = InterlevelScene.Mode.ASCEND; Game.switchScene( InterlevelScene.class ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/DriedRose.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/DriedRose.java index eea7368f5..dd2e42f84 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/DriedRose.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/DriedRose.java @@ -200,6 +200,30 @@ public class DriedRose extends Artifact { spawned = bundle.getBoolean( SPAWNED ); droppedPetals = bundle.getInt( PETALS ); } + + private static GhostHero heldGhost; + + public static void holdGhostHero( Level level ){ + for (Mob mob : level.mobs.toArray( new Mob[0] )) { + if (mob instanceof DriedRose.GhostHero) { + Dungeon.level.mobs.remove( mob ); + heldGhost = (GhostHero) mob; + break; + } + } + } + + public static void restoreGhostHero( Level level, int pos ){ + if (heldGhost != null){ + Dungeon.level.mobs.add( heldGhost ); + heldGhost.pos = pos; + heldGhost = null; + } + } + + public static void clearHeldGhostHero(){ + heldGhost = null; + } public class roseRecharge extends ArtifactBuff { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/LloydsBeacon.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/LloydsBeacon.java index 750504051..5d398ea16 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/LloydsBeacon.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/LloydsBeacon.java @@ -29,7 +29,6 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Invisibility; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.LockedFloor; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; -import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob; import com.shatteredpixel.shatteredpixeldungeon.effects.MagicMissile; import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfTeleportation; @@ -166,9 +165,6 @@ public class LloydsBeacon extends Artifact { Buff buff = Dungeon.hero.buff(TimekeepersHourglass.timeFreeze.class); if (buff != null) buff.detach(); - for (Mob mob : Dungeon.level.mobs.toArray( new Mob[0] )) - if (mob instanceof DriedRose.GhostHero) mob.destroy(); - InterlevelScene.mode = InterlevelScene.Mode.RETURN; InterlevelScene.returnDepth = returnDepth; InterlevelScene.returnPos = returnPos; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/CursedWand.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/CursedWand.java index d748e5111..4641d387d 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/CursedWand.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/CursedWand.java @@ -38,7 +38,6 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Frost; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Recharging; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mimic; -import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.Sheep; import com.shatteredpixel.shatteredpixeldungeon.effects.CellEmitter; import com.shatteredpixel.shatteredpixeldungeon.effects.Flare; @@ -49,7 +48,6 @@ import com.shatteredpixel.shatteredpixeldungeon.effects.particles.ShadowParticle import com.shatteredpixel.shatteredpixeldungeon.items.Bomb; import com.shatteredpixel.shatteredpixeldungeon.items.Generator; import com.shatteredpixel.shatteredpixeldungeon.items.Item; -import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.DriedRose; import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.TimekeepersHourglass; import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfRecharging; import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfTeleportation; @@ -330,9 +328,6 @@ public class CursedWand { Buff buff = Dungeon.hero.buff(TimekeepersHourglass.timeFreeze.class); if (buff != null) buff.detach(); - for (Mob mob : Dungeon.level.mobs.toArray( new Mob[0] )) - if (mob instanceof DriedRose.GhostHero) mob.destroy(); - InterlevelScene.mode = InterlevelScene.Mode.RETURN; InterlevelScene.returnDepth = depth; InterlevelScene.returnPos = -1; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/features/Chasm.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/features/Chasm.java index 51c2bea55..5823b820b 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/features/Chasm.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/features/Chasm.java @@ -29,7 +29,6 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Cripple; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob; -import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.DriedRose; import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.TimekeepersHourglass; import com.shatteredpixel.shatteredpixeldungeon.levels.RegularLevel; import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room; @@ -74,9 +73,6 @@ public class Chasm { Buff buff = Dungeon.hero.buff(TimekeepersHourglass.timeFreeze.class); if (buff != null) buff.detach(); - - for (Mob mob : Dungeon.level.mobs.toArray( new Mob[0] )) - if (mob instanceof DriedRose.GhostHero) mob.destroy(); if (Dungeon.hero.isAlive()) { Dungeon.hero.interrupt(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/DistortionTrap.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/DistortionTrap.java index 86ce67361..fc9ea7085 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/DistortionTrap.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/DistortionTrap.java @@ -23,9 +23,7 @@ package com.shatteredpixel.shatteredpixeldungeon.levels.traps; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Belongings; -import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob; import com.shatteredpixel.shatteredpixeldungeon.items.Item; -import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.DriedRose; import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.LloydsBeacon; import com.shatteredpixel.shatteredpixeldungeon.scenes.InterlevelScene; import com.watabou.noosa.Game; @@ -48,9 +46,6 @@ public class DistortionTrap extends Trap{ ((LloydsBeacon) i).returnDepth = -1; } - for (Mob mob : Dungeon.level.mobs.toArray( new Mob[0] )) - if (mob instanceof DriedRose.GhostHero) mob.destroy(); - InterlevelScene.mode = InterlevelScene.Mode.RESET; Game.switchScene(InterlevelScene.class); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/WarpingTrap.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/WarpingTrap.java index 5a9e6bd03..b9a5cb842 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/WarpingTrap.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/WarpingTrap.java @@ -26,12 +26,10 @@ import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; -import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob; import com.shatteredpixel.shatteredpixeldungeon.effects.CellEmitter; import com.shatteredpixel.shatteredpixeldungeon.effects.Speck; import com.shatteredpixel.shatteredpixeldungeon.items.Heap; import com.shatteredpixel.shatteredpixeldungeon.items.Item; -import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.DriedRose; import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.TimekeepersHourglass; import com.shatteredpixel.shatteredpixeldungeon.scenes.InterlevelScene; import com.watabou.noosa.Game; @@ -76,9 +74,6 @@ public class WarpingTrap extends Trap { Buff buff = Dungeon.hero.buff(TimekeepersHourglass.timeFreeze.class); if (buff != null) buff.detach(); - for (Mob mob : Dungeon.level.mobs.toArray( new Mob[0] )) - if (mob instanceof DriedRose.GhostHero) mob.destroy(); - InterlevelScene.mode = InterlevelScene.Mode.RETURN; InterlevelScene.returnDepth = depth; InterlevelScene.returnPos = -1; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/InterlevelScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/InterlevelScene.java index 6c95c6b9e..374c92aaa 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/InterlevelScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/InterlevelScene.java @@ -26,6 +26,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.Statistics; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; +import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.DriedRose; import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.SpecialRoom; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; @@ -197,7 +198,9 @@ public class InterlevelScene extends PixelScene { private void descend() throws IOException { Actor.fixTime(); + if (Dungeon.hero == null) { + DriedRose.clearHeldGhostHero(); Dungeon.init(); if (noStory) { Dungeon.chapters.add( WndStory.ID_SEWERS ); @@ -205,6 +208,7 @@ public class InterlevelScene extends PixelScene { } GameLog.wipe(); } else { + DriedRose.holdGhostHero( Dungeon.level ); Dungeon.saveAll(); } @@ -221,6 +225,8 @@ public class InterlevelScene extends PixelScene { private void fall() throws IOException { Actor.fixTime(); + DriedRose.holdGhostHero( Dungeon.level ); + Dungeon.saveAll(); Level level; @@ -234,7 +240,9 @@ public class InterlevelScene extends PixelScene { } private void ascend() throws IOException { + Actor.fixTime(); + DriedRose.holdGhostHero( Dungeon.level ); Dungeon.saveAll(); Dungeon.depth--; @@ -245,6 +253,7 @@ public class InterlevelScene extends PixelScene { private void returnTo() throws IOException { Actor.fixTime(); + DriedRose.holdGhostHero( Dungeon.level ); Dungeon.saveAll(); Dungeon.depth = returnDepth; @@ -255,6 +264,7 @@ public class InterlevelScene extends PixelScene { private void restore() throws IOException { Actor.fixTime(); + DriedRose.clearHeldGhostHero(); GameLog.wipe(); @@ -271,6 +281,7 @@ public class InterlevelScene extends PixelScene { private void resurrect() throws IOException { Actor.fixTime(); + DriedRose.holdGhostHero( Dungeon.level ); if (Dungeon.level.locked) { Dungeon.hero.resurrect( Dungeon.depth ); @@ -286,6 +297,7 @@ public class InterlevelScene extends PixelScene { private void reset() throws IOException { Actor.fixTime(); + DriedRose.holdGhostHero( Dungeon.level ); SpecialRoom.resetPitRoom(Dungeon.depth+1);