v0.6.1: ghost hero now follows the player between floors

This commit is contained in:
Evan Debenham 2017-06-25 20:19:49 -04:00
parent 80414bd6fd
commit 6a0a7ae450
9 changed files with 47 additions and 33 deletions

View File

@ -36,6 +36,7 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.Wandmaker;
import com.shatteredpixel.shatteredpixeldungeon.items.Ankh; import com.shatteredpixel.shatteredpixeldungeon.items.Ankh;
import com.shatteredpixel.shatteredpixeldungeon.items.Generator; import com.shatteredpixel.shatteredpixeldungeon.items.Generator;
import com.shatteredpixel.shatteredpixeldungeon.items.Item; 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.potions.Potion;
import com.shatteredpixel.shatteredpixeldungeon.items.rings.Ring; import com.shatteredpixel.shatteredpixeldungeon.items.rings.Ring;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.Scroll; import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.Scroll;
@ -309,10 +310,16 @@ public class Dungeon {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static void switchLevel( final Level level, int pos ) { public static void switchLevel( final Level level, int pos ) {
Dungeon.level = level; if (pos < 0 || pos >= level.length()){
Actor.init(); pos = level.exit;
}
PathFinder.setMapSize(level.width(), level.height()); 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()]; visible = new boolean[level.length()];
Actor respawner = level.respawner(); Actor respawner = level.respawner();
@ -320,7 +327,7 @@ public class Dungeon {
Actor.add( level.respawner() ); Actor.add( level.respawner() );
} }
hero.pos = pos != -1 ? pos : level.exit; hero.pos = pos;
Light light = hero.buff( Light.class ); Light light = hero.buff( Light.class );
hero.viewDistance = light == null ? level.viewDistance : Math.max( Light.DISTANCE, level.viewDistance ); hero.viewDistance = light == null ? level.viewDistance : Math.max( Light.DISTANCE, level.viewDistance );

View File

@ -806,9 +806,6 @@ public class Hero extends Char {
Buff buff = buff(TimekeepersHourglass.timeFreeze.class); Buff buff = buff(TimekeepersHourglass.timeFreeze.class);
if (buff != null) buff.detach(); 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; InterlevelScene.mode = InterlevelScene.Mode.DESCEND;
Game.switchScene( InterlevelScene.class ); Game.switchScene( InterlevelScene.class );
@ -852,9 +849,6 @@ public class Hero extends Char {
Buff buff = buff(TimekeepersHourglass.timeFreeze.class); Buff buff = buff(TimekeepersHourglass.timeFreeze.class);
if (buff != null) buff.detach(); 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; InterlevelScene.mode = InterlevelScene.Mode.ASCEND;
Game.switchScene( InterlevelScene.class ); Game.switchScene( InterlevelScene.class );
} }

View File

@ -200,6 +200,30 @@ public class DriedRose extends Artifact {
spawned = bundle.getBoolean( SPAWNED ); spawned = bundle.getBoolean( SPAWNED );
droppedPetals = bundle.getInt( PETALS ); 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 { public class roseRecharge extends ArtifactBuff {

View File

@ -29,7 +29,6 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Invisibility; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Invisibility;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.LockedFloor; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.LockedFloor;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
import com.shatteredpixel.shatteredpixeldungeon.effects.MagicMissile; import com.shatteredpixel.shatteredpixeldungeon.effects.MagicMissile;
import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfTeleportation; import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfTeleportation;
@ -166,9 +165,6 @@ public class LloydsBeacon extends Artifact {
Buff buff = Dungeon.hero.buff(TimekeepersHourglass.timeFreeze.class); Buff buff = Dungeon.hero.buff(TimekeepersHourglass.timeFreeze.class);
if (buff != null) buff.detach(); 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.mode = InterlevelScene.Mode.RETURN;
InterlevelScene.returnDepth = returnDepth; InterlevelScene.returnDepth = returnDepth;
InterlevelScene.returnPos = returnPos; InterlevelScene.returnPos = returnPos;

View File

@ -38,7 +38,6 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Frost;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Recharging; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Recharging;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mimic; 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.actors.mobs.npcs.Sheep;
import com.shatteredpixel.shatteredpixeldungeon.effects.CellEmitter; import com.shatteredpixel.shatteredpixeldungeon.effects.CellEmitter;
import com.shatteredpixel.shatteredpixeldungeon.effects.Flare; 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.Bomb;
import com.shatteredpixel.shatteredpixeldungeon.items.Generator; import com.shatteredpixel.shatteredpixeldungeon.items.Generator;
import com.shatteredpixel.shatteredpixeldungeon.items.Item; 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.artifacts.TimekeepersHourglass;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfRecharging; import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfRecharging;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfTeleportation; import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfTeleportation;
@ -330,9 +328,6 @@ public class CursedWand {
Buff buff = Dungeon.hero.buff(TimekeepersHourglass.timeFreeze.class); Buff buff = Dungeon.hero.buff(TimekeepersHourglass.timeFreeze.class);
if (buff != null) buff.detach(); 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.mode = InterlevelScene.Mode.RETURN;
InterlevelScene.returnDepth = depth; InterlevelScene.returnDepth = depth;
InterlevelScene.returnPos = -1; InterlevelScene.returnPos = -1;

View File

@ -29,7 +29,6 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Cripple; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Cripple;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob; 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.items.artifacts.TimekeepersHourglass;
import com.shatteredpixel.shatteredpixeldungeon.levels.RegularLevel; import com.shatteredpixel.shatteredpixeldungeon.levels.RegularLevel;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room; import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room;
@ -74,9 +73,6 @@ public class Chasm {
Buff buff = Dungeon.hero.buff(TimekeepersHourglass.timeFreeze.class); Buff buff = Dungeon.hero.buff(TimekeepersHourglass.timeFreeze.class);
if (buff != null) buff.detach(); 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()) { if (Dungeon.hero.isAlive()) {
Dungeon.hero.interrupt(); Dungeon.hero.interrupt();

View File

@ -23,9 +23,7 @@ package com.shatteredpixel.shatteredpixeldungeon.levels.traps;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Belongings; 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.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.DriedRose;
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.LloydsBeacon; import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.LloydsBeacon;
import com.shatteredpixel.shatteredpixeldungeon.scenes.InterlevelScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.InterlevelScene;
import com.watabou.noosa.Game; import com.watabou.noosa.Game;
@ -48,9 +46,6 @@ public class DistortionTrap extends Trap{
((LloydsBeacon) i).returnDepth = -1; ((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; InterlevelScene.mode = InterlevelScene.Mode.RESET;
Game.switchScene(InterlevelScene.class); Game.switchScene(InterlevelScene.class);
} }

View File

@ -26,12 +26,10 @@ import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; 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.CellEmitter;
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck; import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
import com.shatteredpixel.shatteredpixeldungeon.items.Heap; import com.shatteredpixel.shatteredpixeldungeon.items.Heap;
import com.shatteredpixel.shatteredpixeldungeon.items.Item; 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.artifacts.TimekeepersHourglass;
import com.shatteredpixel.shatteredpixeldungeon.scenes.InterlevelScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.InterlevelScene;
import com.watabou.noosa.Game; import com.watabou.noosa.Game;
@ -76,9 +74,6 @@ public class WarpingTrap extends Trap {
Buff buff = Dungeon.hero.buff(TimekeepersHourglass.timeFreeze.class); Buff buff = Dungeon.hero.buff(TimekeepersHourglass.timeFreeze.class);
if (buff != null) buff.detach(); 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.mode = InterlevelScene.Mode.RETURN;
InterlevelScene.returnDepth = depth; InterlevelScene.returnDepth = depth;
InterlevelScene.returnPos = -1; InterlevelScene.returnPos = -1;

View File

@ -26,6 +26,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.shatteredpixel.shatteredpixeldungeon.Statistics; import com.shatteredpixel.shatteredpixeldungeon.Statistics;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.DriedRose;
import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.SpecialRoom; import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.SpecialRoom;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
@ -197,7 +198,9 @@ public class InterlevelScene extends PixelScene {
private void descend() throws IOException { private void descend() throws IOException {
Actor.fixTime(); Actor.fixTime();
if (Dungeon.hero == null) { if (Dungeon.hero == null) {
DriedRose.clearHeldGhostHero();
Dungeon.init(); Dungeon.init();
if (noStory) { if (noStory) {
Dungeon.chapters.add( WndStory.ID_SEWERS ); Dungeon.chapters.add( WndStory.ID_SEWERS );
@ -205,6 +208,7 @@ public class InterlevelScene extends PixelScene {
} }
GameLog.wipe(); GameLog.wipe();
} else { } else {
DriedRose.holdGhostHero( Dungeon.level );
Dungeon.saveAll(); Dungeon.saveAll();
} }
@ -221,6 +225,8 @@ public class InterlevelScene extends PixelScene {
private void fall() throws IOException { private void fall() throws IOException {
Actor.fixTime(); Actor.fixTime();
DriedRose.holdGhostHero( Dungeon.level );
Dungeon.saveAll(); Dungeon.saveAll();
Level level; Level level;
@ -234,7 +240,9 @@ public class InterlevelScene extends PixelScene {
} }
private void ascend() throws IOException { private void ascend() throws IOException {
Actor.fixTime(); Actor.fixTime();
DriedRose.holdGhostHero( Dungeon.level );
Dungeon.saveAll(); Dungeon.saveAll();
Dungeon.depth--; Dungeon.depth--;
@ -245,6 +253,7 @@ public class InterlevelScene extends PixelScene {
private void returnTo() throws IOException { private void returnTo() throws IOException {
Actor.fixTime(); Actor.fixTime();
DriedRose.holdGhostHero( Dungeon.level );
Dungeon.saveAll(); Dungeon.saveAll();
Dungeon.depth = returnDepth; Dungeon.depth = returnDepth;
@ -255,6 +264,7 @@ public class InterlevelScene extends PixelScene {
private void restore() throws IOException { private void restore() throws IOException {
Actor.fixTime(); Actor.fixTime();
DriedRose.clearHeldGhostHero();
GameLog.wipe(); GameLog.wipe();
@ -271,6 +281,7 @@ public class InterlevelScene extends PixelScene {
private void resurrect() throws IOException { private void resurrect() throws IOException {
Actor.fixTime(); Actor.fixTime();
DriedRose.holdGhostHero( Dungeon.level );
if (Dungeon.level.locked) { if (Dungeon.level.locked) {
Dungeon.hero.resurrect( Dungeon.depth ); Dungeon.hero.resurrect( Dungeon.depth );
@ -286,6 +297,7 @@ public class InterlevelScene extends PixelScene {
private void reset() throws IOException { private void reset() throws IOException {
Actor.fixTime(); Actor.fixTime();
DriedRose.holdGhostHero( Dungeon.level );
SpecialRoom.resetPitRoom(Dungeon.depth+1); SpecialRoom.resetPitRoom(Dungeon.depth+1);