From 06207dd8e29feba037df436f113bf09ce8fd03e3 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Wed, 22 Feb 2023 19:38:46 -0500 Subject: [PATCH] v2.0.0: fixed various bugs with charged shot and displacing darts --- .../items/weapon/missiles/darts/Dart.java | 18 ++++++++++++------ .../weapon/missiles/darts/DisplacingDart.java | 8 ++++++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/darts/Dart.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/darts/Dart.java index 7dd4172e3..fd10d78f2 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/darts/Dart.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/darts/Dart.java @@ -141,7 +141,7 @@ public class Dart extends MissileWeapon { int dmg = super.proc(attacker, defender, damage); if (!processingChargedShot) { - processChargedShot(defender.pos, damage); + processChargedShot(defender, damage); } return dmg; } @@ -155,17 +155,22 @@ public class Dart extends MissileWeapon { @Override protected void onThrow(int cell) { updateCrossbow(); + //we have to set this here, as on-hit effects can move the target we aim at + chargedShotPos = cell; super.onThrow(cell); } private boolean processingChargedShot = false; - protected void processChargedShot( int cell, int dmg ){ + private int chargedShotPos; + protected void processChargedShot( Char target, int dmg ){ //don't update xbow here, as dart may be the active weapon atm processingChargedShot = true; - if (bow != null && Dungeon.hero.buff(Crossbow.ChargedShot.class) != null) { - PathFinder.buildDistanceMap(cell, Dungeon.level.passable, 1); + if (chargedShotPos != -1 && bow != null && Dungeon.hero.buff(Crossbow.ChargedShot.class) != null) { + PathFinder.buildDistanceMap(chargedShotPos, Dungeon.level.passable, 1); + //necessary to clone as some on-hit effects use Pathfinder + int[] distance = PathFinder.distance.clone(); for (Char ch : Actor.chars()){ - if (ch.pos == cell){ + if (ch == target){ Actor.add(new Actor() { { actPriority = VFX_PRIO; } @Override @@ -177,11 +182,12 @@ public class Dart extends MissileWeapon { return true; } }); - } else if (PathFinder.distance[ch.pos] != Integer.MAX_VALUE){ + } else if (distance[ch.pos] != Integer.MAX_VALUE){ proc(Dungeon.hero, ch, dmg); } } } + chargedShotPos = -1; processingChargedShot = false; } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/darts/DisplacingDart.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/darts/DisplacingDart.java index 04247c393..286c0e86d 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/darts/DisplacingDart.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/darts/DisplacingDart.java @@ -28,6 +28,7 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.TalismanOfForesight; import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfTeleportation; import com.shatteredpixel.shatteredpixeldungeon.mechanics.ShadowCaster; +import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.shatteredpixel.shatteredpixeldungeon.utils.BArray; import com.watabou.utils.PathFinder; @@ -91,10 +92,13 @@ public class DisplacingDart extends TippedDart { if (chosenPos != -1){ ScrollOfTeleportation.appear( defender, chosenPos ); - if (!Dungeon.level.heroFOV[chosenPos]){ + Dungeon.level.occupyCell(defender ); + if (defender == Dungeon.hero){ + Dungeon.observe(); + GameScene.updateFog(); + } else if (!Dungeon.level.heroFOV[chosenPos]){ Buff.affect(attacker, TalismanOfForesight.CharAwareness.class, 5f).charID = defender.id(); } - Dungeon.level.occupyCell(defender ); } }