From 42197fdbad9cc778caddf55f28689970dfef2378 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Sun, 21 Aug 2022 13:13:19 -0400 Subject: [PATCH] v1.4.0: fixed various char positioning errors with warp effects --- .../shatteredpixeldungeon/Dungeon.java | 2 +- .../hero/abilities/mage/WarpBeacon.java | 9 +++- .../items/spells/BeaconOfReturning.java | 47 ++++++++++++------- 3 files changed, 37 insertions(+), 21 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java index b93507d87..556334cf0 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java @@ -429,7 +429,7 @@ public class Dungeon { level.addRespawner(); for(Mob m : level.mobs){ - if (m.pos == hero.pos){ + if (m.pos == hero.pos && !Char.hasProp(m, Char.Property.IMMOVABLE)){ //displace mob for(int i : PathFinder.NEIGHBOURS8){ if (Actor.findChar(m.pos+i) == null && level.passable[m.pos + i]){ diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/abilities/mage/WarpBeacon.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/abilities/mage/WarpBeacon.java index b3dcd3fd0..2c46a0f77 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/abilities/mage/WarpBeacon.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/abilities/mage/WarpBeacon.java @@ -119,8 +119,6 @@ public class WarpBeacon extends ArmorAbility { if (tracker.depth == Dungeon.depth && tracker.branch == Dungeon.branch){ Char existing = Actor.findChar(tracker.pos); - ScrollOfTeleportation.appear(hero, tracker.pos); - if (existing != null && existing != hero){ if (hero.hasTalent(Talent.TELEFRAG)){ int heroHP = hero.HP + hero.shielding(); @@ -150,13 +148,20 @@ public class WarpBeacon extends ArmorAbility { Random.shuffle(candidates); if (!candidates.isEmpty()){ + ScrollOfTeleportation.appear(hero, tracker.pos); Actor.addDelayed( new Pushing( toPush, toPush.pos, candidates.get(0) ), -1 ); toPush.pos = candidates.get(0); Dungeon.level.occupyCell(toPush); hero.next(); + } else { + GLog.w( Messages.get(ScrollOfTeleportation.class, "no_tele") ); } + } else { + ScrollOfTeleportation.appear(hero, tracker.pos); } + } else { + ScrollOfTeleportation.appear(hero, tracker.pos); } Invisibility.dispel(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/spells/BeaconOfReturning.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/spells/BeaconOfReturning.java index 569ddb63a..4123bf481 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/spells/BeaconOfReturning.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/spells/BeaconOfReturning.java @@ -28,6 +28,7 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob; +import com.shatteredpixel.shatteredpixeldungeon.effects.Pushing; import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.TimekeepersHourglass; import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfTeleportation; import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.exotic.ScrollOfPassage; @@ -43,6 +44,9 @@ import com.watabou.noosa.Game; import com.watabou.noosa.audio.Sample; import com.watabou.utils.Bundle; import com.watabou.utils.PathFinder; +import com.watabou.utils.Random; + +import java.util.ArrayList; public class BeaconOfReturning extends Spell { @@ -112,28 +116,35 @@ public class BeaconOfReturning extends Spell { if (returnDepth == Dungeon.depth && returnBranch == Dungeon.branch) { - Char moving = Actor.findChar(returnPos); - if (moving != null){ - moving.pos = returnPos+1; - } + Char existing = Actor.findChar(returnPos); + if (existing != null && existing != hero){ + Char toPush = !Char.hasProp(existing, Char.Property.IMMOVABLE) ? hero : existing; - if (ScrollOfTeleportation.teleportToLocation(hero, returnPos)){ - if (moving != null){ - moving.pos = returnPos; - for(int i : PathFinder.NEIGHBOURS8){ - if (Actor.findChar(moving.pos+i) == null - && Dungeon.level.passable[moving.pos + i] - && (!Char.hasProp(moving, Char.Property.LARGE) || Dungeon.level.openSpace[moving.pos + i])){ - moving.pos += i; - moving.sprite.point(moving.sprite.worldToCamera(moving.pos)); - break; - } + ArrayList candidates = new ArrayList<>(); + for (int n : PathFinder.NEIGHBOURS8) { + int cell = returnPos + n; + if (!Dungeon.level.solid[cell] && Actor.findChar( cell ) == null + && (!Char.hasProp(toPush, Char.Property.LARGE) || Dungeon.level.openSpace[cell])) { + candidates.add( cell ); } } - } else { - if (moving != null) { - moving.pos = returnPos; + Random.shuffle(candidates); + + if (!candidates.isEmpty()){ + if (toPush == hero){ + returnPos = candidates.get(0); + } else { + Actor.addDelayed( new Pushing( toPush, toPush.pos, candidates.get(0) ), -1 ); + toPush.pos = candidates.get(0); + Dungeon.level.occupyCell(toPush); + } + } else { + GLog.w( Messages.get(ScrollOfTeleportation.class, "no_tele") ); + return; } + } + + if (!ScrollOfTeleportation.teleportToLocation(hero, returnPos)){ return; }