v0.7.4: refactored interaction code. Places can now be swapped with any ally
This commit is contained in:
parent
e047d1aee1
commit
0f3a6c8fa2
|
@ -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";
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 ) {
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -51,6 +51,5 @@ public abstract class NPC extends Mob {
|
|||
@Override
|
||||
public void beckon( int cell ) {
|
||||
}
|
||||
|
||||
abstract public boolean interact();
|
||||
|
||||
}
|
|
@ -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 );
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user