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;
|
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 POS = "pos";
|
||||||
protected static final String TAG_HP = "HP";
|
protected static final String TAG_HP = "HP";
|
||||||
protected static final String TAG_HT = "HT";
|
protected static final String TAG_HT = "HT";
|
||||||
|
|
|
@ -628,17 +628,17 @@ public class Hero extends Char {
|
||||||
|
|
||||||
private boolean actInteract( HeroAction.Interact action ) {
|
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();
|
ready();
|
||||||
sprite.turnTo( pos, npc.pos );
|
sprite.turnTo( pos, ch.pos );
|
||||||
return npc.interact();
|
return ch.interact();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (fieldOfView[npc.pos] && getCloser( npc.pos )) {
|
if (fieldOfView[ch.pos] && getCloser( ch.pos )) {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -1192,8 +1192,8 @@ public class Hero extends Char {
|
||||||
|
|
||||||
} else if (fieldOfView[cell] && (ch = Actor.findChar( cell )) instanceof Mob) {
|
} else if (fieldOfView[cell] && (ch = Actor.findChar( cell )) instanceof Mob) {
|
||||||
|
|
||||||
if (ch instanceof NPC) {
|
if (ch.alignment != Alignment.ENEMY) {
|
||||||
curAction = new HeroAction.Interact( (NPC)ch );
|
curAction = new HeroAction.Interact( ch );
|
||||||
} else {
|
} else {
|
||||||
curAction = new HeroAction.Attack( ch );
|
curAction = new HeroAction.Attack( ch );
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,9 +53,9 @@ public class HeroAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Interact extends HeroAction {
|
public static class Interact extends HeroAction {
|
||||||
public NPC npc;
|
public Char ch;
|
||||||
public Interact( NPC npc ) {
|
public Interact( Char ch ) {
|
||||||
this.npc = npc;
|
this.ch = ch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -308,18 +308,6 @@ public abstract class Mob extends Char {
|
||||||
return enemy;
|
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
|
@Override
|
||||||
public void add( Buff buff ) {
|
public void add( Buff buff ) {
|
||||||
super.add( buff );
|
super.add( buff );
|
||||||
|
|
|
@ -180,27 +180,6 @@ public class MirrorImage extends NPC {
|
||||||
return s;
|
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( ToxicGas.class );
|
||||||
immunities.add( CorrosiveGas.class );
|
immunities.add( CorrosiveGas.class );
|
||||||
|
|
|
@ -52,5 +52,4 @@ public abstract class NPC extends Mob {
|
||||||
public void beckon( int cell ) {
|
public void beckon( int cell ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract public boolean interact();
|
|
||||||
}
|
}
|
|
@ -213,27 +213,6 @@ public class PrismaticImage extends NPC {
|
||||||
return s;
|
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( ToxicGas.class );
|
||||||
immunities.add( CorrosiveGas.class );
|
immunities.add( CorrosiveGas.class );
|
||||||
|
|
|
@ -650,20 +650,8 @@ public class DriedRose extends Artifact {
|
||||||
rose.talkedTo = true;
|
rose.talkedTo = true;
|
||||||
GameScene.show(new WndQuest(this, Messages.get(this, "introduce") ));
|
GameScene.show(new WndQuest(this, Messages.get(this, "introduce") ));
|
||||||
return false;
|
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 {
|
} else {
|
||||||
return false;
|
return super.interact();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user