From ca0d8bbda79dd65ac469777493ac52b218dc3010 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Thu, 8 Jun 2023 12:07:46 -0400 Subject: [PATCH] v2.1.1: added checks for knockback and teleporting on-hit enemies --- .../actors/buffs/Combo.java | 5 ++++- .../actors/buffs/MonkEnergy.java | 3 ++- .../hero/abilities/duelist/ElementalStrike.java | 17 ++++++++++++++++- .../items/weapon/melee/Spear.java | 3 ++- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Combo.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Combo.java index 195b25088..0581b5a51 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Combo.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Combo.java @@ -340,6 +340,7 @@ public class Combo extends Buff implements ActionIndicator.Action { break; } + int oldPos = enemy.pos; if (hero.attack(enemy, dmgMulti, dmgBonus, Char.INFINITE_ACCURACY)){ //special on-hit effects switch (moveBeingUsed) { @@ -360,7 +361,9 @@ public class Combo extends Buff implements ActionIndicator.Action { dist--; } } - WandOfBlastWave.throwChar(enemy, trajectory, dist, true, false, hero); + if (enemy.pos == oldPos) { + WandOfBlastWave.throwChar(enemy, trajectory, dist, true, false, hero); + } break; case PARRY: hit(enemy); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/MonkEnergy.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/MonkEnergy.java index 8e7a7dfae..37de90d3d 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/MonkEnergy.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/MonkEnergy.java @@ -561,11 +561,12 @@ public class MonkEnergy extends Buff implements ActionIndicator.Action { AttackIndicator.target(enemy); boolean empowered = Buff.affect(hero, MonkEnergy.class).abilitiesEmpowered(hero); + int oldPos = enemy.pos; if (hero.attack(enemy, empowered ? 4.5f : 3f, 0, Char.INFINITE_ACCURACY)){ Sample.INSTANCE.play(Assets.Sounds.HIT_STRONG); } - if (enemy.isAlive()){ + if (enemy.isAlive() && oldPos == enemy.pos){ //trace a ballistica to our target (which will also extend past them Ballistica trajectory = new Ballistica(hero.pos, enemy.pos, Ballistica.STOP_TARGET); //trim it to just be the part that goes past them diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/abilities/duelist/ElementalStrike.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/abilities/duelist/ElementalStrike.java index 76ce266db..33b92218c 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/abilities/duelist/ElementalStrike.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/abilities/duelist/ElementalStrike.java @@ -94,6 +94,8 @@ import com.watabou.utils.Callback; import com.watabou.utils.Random; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; public class ElementalStrike extends ArmorAbility { @@ -201,6 +203,7 @@ public class ElementalStrike extends ArmorAbility { if (enemy != null){ AttackIndicator.target(enemy); + oldEnemyPos = enemy.pos; if (hero.attack(enemy, 1, 0, Char.INFINITE_ACCURACY)) { Sample.INSTANCE.play(Assets.Sounds.HIT_STRONG); } @@ -347,6 +350,8 @@ public class ElementalStrike extends ArmorAbility { } } + private int oldEnemyPos; + //effects that affect the characters within the cone AOE private void perCharEffect(ConeAOE cone, Hero hero, Char primaryTarget, Weapon.Enchantment ench) { @@ -389,8 +394,18 @@ public class ElementalStrike extends ArmorAbility { //*** Elastic *** } else if (ench instanceof Elastic){ - //TODO sort affected by distance first? So further ones get knocked back first + + //sorts affected from furthest to closest + Collections.sort(affected, new Comparator() { + @Override + public int compare(Char a, Char b) { + return Dungeon.level.distance(hero.pos, a.pos) - Dungeon.level.distance(hero.pos, b.pos); + } + }); + for (Char ch : affected){ + if (ch == primaryTarget && oldEnemyPos != primaryTarget.pos) continue; + Ballistica aim = new Ballistica(hero.pos, ch.pos, Ballistica.WONT_STOP); int knockback = Math.round(5*powerMulti); WandOfBlastWave.throwChar(ch, diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/melee/Spear.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/melee/Spear.java index d6fa77ffa..777e5d2a8 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/melee/Spear.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/melee/Spear.java @@ -88,8 +88,9 @@ public class Spear extends MeleeWeapon { public void call() { wep.beforeAbilityUsed(hero, enemy); AttackIndicator.target(enemy); + int oldPos = enemy.pos; if (hero.attack(enemy, dmgMulti, 0, Char.INFINITE_ACCURACY)) { - if (enemy.isAlive()){ + if (enemy.isAlive() && enemy.pos == oldPos){ //trace a ballistica to our target (which will also extend past them Ballistica trajectory = new Ballistica(hero.pos, enemy.pos, Ballistica.STOP_TARGET); //trim it to just be the part that goes past them