From 0b77c20ca746f16a54347104ee2e7421cfcd5388 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Sat, 21 Mar 2020 21:42:42 -0400 Subject: [PATCH] v0.8.0: slightly refactored interacting with characters, and fixed swapping places with rooted allies --- .../shatteredpixeldungeon/actors/Char.java | 21 +++++++++++++------ .../actors/hero/Hero.java | 2 +- .../actors/mobs/GoldenMimic.java | 1 + .../actors/mobs/Mimic.java | 7 ++++--- .../actors/mobs/Pylon.java | 2 +- .../actors/mobs/npcs/Blacksmith.java | 10 ++++++--- .../actors/mobs/npcs/Ghost.java | 10 ++++++--- .../actors/mobs/npcs/Imp.java | 9 ++++++-- .../actors/mobs/npcs/RatKing.java | 9 ++++++-- .../actors/mobs/npcs/Sheep.java | 6 +++--- .../actors/mobs/npcs/Shopkeeper.java | 8 +++++-- .../actors/mobs/npcs/Wandmaker.java | 10 ++++++--- .../items/artifacts/DriedRose.java | 8 +++---- .../items/wands/WandOfWarding.java | 7 +++++-- 14 files changed, 75 insertions(+), 35 deletions(-) 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 c41f59997..7854e9cc8 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Char.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Char.java @@ -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; } 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 9f7aac5fa..20f8f1c88 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 @@ -633,7 +633,7 @@ public class Hero extends Char { ready(); sprite.turnTo( pos, ch.pos ); - return ch.interact(); + return ch.interact(this); } else { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/GoldenMimic.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/GoldenMimic.java index 5ebfc3671..84aeb2b00 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/GoldenMimic.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/GoldenMimic.java @@ -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)); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mimic.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mimic.java index 6ff3d1023..01add218e 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mimic.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mimic.java @@ -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(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Pylon.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Pylon.java index d180b0794..aaaf6ec75 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Pylon.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Pylon.java @@ -139,7 +139,7 @@ public class Pylon extends Mob { } @Override - public boolean interact() { + public boolean interact(Char c) { return true; } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Blacksmith.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Blacksmith.java index 5f0be8403..d5ebed50f 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Blacksmith.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Blacksmith.java @@ -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 ) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Ghost.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Ghost.java index 565933d09..30f30d7b8 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Ghost.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Ghost.java @@ -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 { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Imp.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Imp.java index e5e45f25f..ab337a11a 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Imp.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Imp.java @@ -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 ) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/RatKing.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/RatKing.java index 6722a1197..5f248c393 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/RatKing.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/RatKing.java @@ -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") ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Sheep.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Sheep.java index 47731f07e..1c7e68f1d 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Sheep.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Sheep.java @@ -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; } } \ No newline at end of file diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Shopkeeper.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Shopkeeper.java index 60e301c06..83de5d9ff 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Shopkeeper.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Shopkeeper.java @@ -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; } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Wandmaker.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Wandmaker.java index ab261e2be..4a4cf0a33 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Wandmaker.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Wandmaker.java @@ -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 { 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 f8a079157..43c8cd1b1 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 @@ -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); } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfWarding.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfWarding.java index 105aab5af..bae278c4e 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfWarding.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfWarding.java @@ -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() {