diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Char.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Char.java index 956ce49b8..0f4f95460 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Char.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Char.java @@ -132,6 +132,39 @@ public abstract class Char extends Actor { return false; } + //swaps places by default + public boolean interact(){ + + if (!Dungeon.level.passable[pos] && !Dungeon.hero.flying){ + return true; + } + + int curPos = pos; + + moveSprite( pos, Dungeon.hero.pos ); + move( Dungeon.hero.pos ); + + Dungeon.hero.sprite.move( Dungeon.hero.pos, curPos ); + Dungeon.hero.move( curPos ); + + Dungeon.hero.spend( 1 / Dungeon.hero.speed() ); + Dungeon.hero.busy(); + + return true; + } + + protected boolean moveSprite( int from, int to ) { + + if (sprite.isVisible() && (Dungeon.level.heroFOV[from] || Dungeon.level.heroFOV[to])) { + sprite.move( from, to ); + return true; + } else { + sprite.turnTo(from, to); + sprite.place( to ); + return true; + } + } + protected static final String POS = "pos"; protected static final String TAG_HP = "HP"; protected static final String TAG_HT = "HT"; 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 bb19b09e5..b4dedf3b2 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 @@ -628,17 +628,17 @@ public class Hero extends Char { private boolean actInteract( HeroAction.Interact action ) { - NPC npc = action.npc; + Char ch = action.ch; - if (Dungeon.level.adjacent( pos, npc.pos )) { + if (Dungeon.level.adjacent( pos, ch.pos )) { ready(); - sprite.turnTo( pos, npc.pos ); - return npc.interact(); + sprite.turnTo( pos, ch.pos ); + return ch.interact(); } else { - if (fieldOfView[npc.pos] && getCloser( npc.pos )) { + if (fieldOfView[ch.pos] && getCloser( ch.pos )) { return true; @@ -1192,8 +1192,8 @@ public class Hero extends Char { } else if (fieldOfView[cell] && (ch = Actor.findChar( cell )) instanceof Mob) { - if (ch instanceof NPC) { - curAction = new HeroAction.Interact( (NPC)ch ); + if (ch.alignment != Alignment.ENEMY) { + curAction = new HeroAction.Interact( ch ); } else { curAction = new HeroAction.Attack( ch ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/HeroAction.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/HeroAction.java index 21944a88b..3896209a1 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/HeroAction.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/HeroAction.java @@ -53,9 +53,9 @@ public class HeroAction { } public static class Interact extends HeroAction { - public NPC npc; - public Interact( NPC npc ) { - this.npc = npc; + public Char ch; + public Interact( Char ch ) { + this.ch = ch; } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java index a1399d062..fc578223e 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java @@ -307,18 +307,6 @@ public abstract class Mob extends Char { } else return enemy; } - - protected boolean moveSprite( int from, int to ) { - - if (sprite.isVisible() && (Dungeon.level.heroFOV[from] || Dungeon.level.heroFOV[to])) { - sprite.move( from, to ); - return true; - } else { - sprite.turnTo(from, to); - sprite.place( to ); - return true; - } - } @Override public void add( Buff buff ) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/MirrorImage.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/MirrorImage.java index 47292a7ae..ca400fc49 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/MirrorImage.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/MirrorImage.java @@ -179,27 +179,6 @@ public class MirrorImage extends NPC { ((MirrorSprite)s).updateArmor( armTier ); return s; } - - @Override - public boolean interact() { - - if (!Dungeon.level.passable[pos]){ - return true; - } - - int curPos = pos; - - moveSprite( pos, Dungeon.hero.pos ); - move( Dungeon.hero.pos ); - - Dungeon.hero.sprite.move( Dungeon.hero.pos, curPos ); - Dungeon.hero.move( curPos ); - - Dungeon.hero.spend( 1 / Dungeon.hero.speed() ); - Dungeon.hero.busy(); - - return true; - } { immunities.add( ToxicGas.class ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/NPC.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/NPC.java index e8cd2354a..8678e2e1e 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/NPC.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/NPC.java @@ -51,6 +51,5 @@ public abstract class NPC extends Mob { @Override public void beckon( int cell ) { } - - abstract public boolean interact(); + } \ No newline at end of file diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/PrismaticImage.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/PrismaticImage.java index 424dba985..232efe9bd 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/PrismaticImage.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/PrismaticImage.java @@ -213,27 +213,6 @@ public class PrismaticImage extends NPC { return s; } - @Override - public boolean interact() { - - if (!Dungeon.level.passable[pos]){ - return true; - } - - int curPos = pos; - - moveSprite( pos, Dungeon.hero.pos ); - move( Dungeon.hero.pos ); - - Dungeon.hero.sprite.move( Dungeon.hero.pos, curPos ); - Dungeon.hero.move( curPos ); - - Dungeon.hero.spend( 1 / Dungeon.hero.speed() ); - Dungeon.hero.busy(); - - return true; - } - { immunities.add( ToxicGas.class ); immunities.add( CorrosiveGas.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 cdae29c0a..0a10e97c7 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 @@ -650,20 +650,8 @@ public class DriedRose extends Artifact { rose.talkedTo = true; GameScene.show(new WndQuest(this, Messages.get(this, "introduce") )); return false; - } else if (Dungeon.level.passable[pos] || Dungeon.hero.flying) { - int curPos = pos; - - moveSprite( pos, Dungeon.hero.pos ); - move( Dungeon.hero.pos ); - - Dungeon.hero.sprite.move( Dungeon.hero.pos, curPos ); - Dungeon.hero.move( curPos ); - - Dungeon.hero.spend( 1 / Dungeon.hero.speed() ); - Dungeon.hero.busy(); - return true; } else { - return false; + return super.interact(); } }