v0.8.0: slightly refactored interacting with characters, and fixed swapping places with rooted allies

This commit is contained in:
Evan Debenham 2020-03-21 21:42:42 -04:00
parent b697ad1cae
commit 0b77c20ca7
14 changed files with 75 additions and 35 deletions

View File

@ -140,18 +140,27 @@ public abstract class Char extends Actor {
return Messages.get(this, "name");
}
public boolean canInteract( Hero h ){
return Dungeon.level.adjacent( pos, h.pos ) && h.buff(Vertigo.class) == null;
public boolean canInteract(Char c){
return Dungeon.level.adjacent( pos, c.pos );
}
//swaps places by default
public boolean interact(){
if (!Dungeon.level.passable[pos] && !Dungeon.hero.flying){
public boolean interact(Char c){
//can't spawn places if one char has restricted movement
if (rooted || c.rooted || buff(Vertigo.class) != null || c.buff(Vertigo.class) != null){
return true;
}
if (properties.contains(Property.LARGE) && !Dungeon.level.openSpace[Dungeon.hero.pos]){
//don't allow char to swap onto hazard unless they're flying
//you can swap onto a hazard though, as you're not the one instigating the swap
if (!Dungeon.level.passable[pos] && !c.flying){
return true;
}
//can't swap into a space without room
if (properties.contains(Property.LARGE) && !Dungeon.level.openSpace[c.pos]
|| c.properties.contains(Property.LARGE) && !Dungeon.level.openSpace[pos]){
return true;
}

View File

@ -633,7 +633,7 @@ public class Hero extends Char {
ready();
sprite.turnTo( pos, ch.pos );
return ch.interact();
return ch.interact(this);
} else {

View File

@ -77,6 +77,7 @@ public class GoldenMimic extends Mimic {
@Override
public void adjustStats(int level) {
//FIXME this causes level to keep increasing over save/load
super.adjustStats(Math.round(level*1.33f));
}

View File

@ -27,6 +27,7 @@ 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.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.effects.CellEmitter;
import com.shatteredpixel.shatteredpixeldungeon.effects.Pushing;
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
@ -138,9 +139,9 @@ public class Mimic extends Mob {
}
@Override
public boolean interact() {
if (alignment != Alignment.NEUTRAL){
return super.interact();
public boolean interact(Char c) {
if (alignment != Alignment.NEUTRAL || c != Dungeon.hero){
return super.interact(c);
}
stopHiding();

View File

@ -139,7 +139,7 @@ public class Pylon extends Mob {
}
@Override
public boolean interact() {
public boolean interact(Char c) {
return true;
}

View File

@ -68,9 +68,13 @@ public class Blacksmith extends NPC {
}
@Override
public boolean interact() {
public boolean interact(Char c) {
sprite.turnTo( pos, Dungeon.hero.pos );
sprite.turnTo( pos, c.pos );
if (c != Dungeon.hero){
return true;
}
if (!Quest.given) {
@ -155,7 +159,7 @@ public class Blacksmith extends NPC {
}
return false;
return true;
}
private void tell( String text ) {

View File

@ -108,10 +108,14 @@ public class Ghost extends NPC {
}
@Override
public boolean interact() {
sprite.turnTo( pos, Dungeon.hero.pos );
public boolean interact(Char c) {
sprite.turnTo( pos, c.pos );
Sample.INSTANCE.play( Assets.SND_GHOST );
if (c != Dungeon.hero){
return super.interact(c);
}
if (Quest.given) {
if (Quest.weapon != null) {
@ -189,7 +193,7 @@ public class Ghost extends NPC {
}
return false;
return true;
}
public static class Quest {

View File

@ -89,9 +89,14 @@ public class Imp extends NPC {
}
@Override
public boolean interact() {
public boolean interact(Char c) {
sprite.turnTo( pos, Dungeon.hero.pos );
if (c != Dungeon.hero){
return true;
}
if (Quest.given) {
DwarfToken tokens = Dungeon.hero.belongings.getItem( DwarfToken.class );
@ -116,7 +121,7 @@ public class Imp extends NPC {
Notes.add( Notes.Landmark.IMP );
}
return false;
return true;
}
private void tell( String text ) {

View File

@ -96,8 +96,13 @@ public class RatKing extends NPC {
//***
@Override
public boolean interact() {
sprite.turnTo( pos, Dungeon.hero.pos );
public boolean interact(Char c) {
sprite.turnTo( pos, c.pos );
if (c != Dungeon.hero){
return super.interact(c);
}
if (state == SLEEPING) {
notice();
yell( Messages.get(this, "not_sleeping") );

View File

@ -70,9 +70,9 @@ public class Sheep extends NPC {
}
@Override
public boolean interact() {
public boolean interact(Char c) {
sprite.showStatus( CharSprite.NEUTRAL, Messages.get(this, Random.element( LINE_KEYS )) );
Dungeon.hero.spendAndNext(1f);
return false;
if (c == Dungeon.hero) Dungeon.hero.spendAndNext(1f);
return true;
}
}

View File

@ -22,6 +22,7 @@
package com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.effects.CellEmitter;
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.ElmoParticle;
@ -101,13 +102,16 @@ public class Shopkeeper extends NPC {
};
@Override
public boolean interact() {
public boolean interact(Char c) {
if (c != Dungeon.hero) {
return true;
}
Game.runOnRenderThread(new Callback() {
@Override
public void call() {
sell();
}
});
return false;
return true;
}
}

View File

@ -83,9 +83,13 @@ public class Wandmaker extends NPC {
}
@Override
public boolean interact() {
public boolean interact(Char c) {
sprite.turnTo( pos, Dungeon.hero.pos );
if (c != Dungeon.hero){
return true;
}
if (Quest.given) {
Item item;
@ -184,7 +188,7 @@ public class Wandmaker extends NPC {
Quest.given = true;
}
return false;
return true;
}
public static class Quest {

View File

@ -714,9 +714,9 @@ public class DriedRose extends Artifact {
}
@Override
public boolean interact() {
public boolean interact(Char c) {
updateRose();
if (rose != null && !rose.talkedTo){
if (c == Dungeon.hero && rose != null && !rose.talkedTo){
rose.talkedTo = true;
Game.runOnRenderThread(new Callback() {
@Override
@ -724,9 +724,9 @@ public class DriedRose extends Artifact {
GameScene.show(new WndQuest(GhostHero.this, Messages.get(GhostHero.this, "introduce") ));
}
});
return false;
return true;
} else {
return super.interact();
return super.interact(c);
}
}

View File

@ -372,12 +372,15 @@ public class WandOfWarding extends Wand {
}
@Override
public boolean canInteract(Hero h) {
public boolean canInteract(Char c) {
return true;
}
@Override
public boolean interact() {
public boolean interact( Char c ) {
if (c != Dungeon.hero){
return true;
}
Game.runOnRenderThread(new Callback() {
@Override
public void call() {