From db23db28c599d1411932d6a3583f9d18ac7b5159 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Sat, 18 Jun 2016 11:09:24 -0400 Subject: [PATCH] v0.4.0: fixed bugs with projecting enchant on thrown weapons --- .../shatteredpixeldungeon/items/Item.java | 2 +- .../items/weapon/missiles/MissileWeapon.java | 13 +++++-------- .../shatteredpixeldungeon/ui/QuickSlotButton.java | 13 +++++++++---- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/Item.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/Item.java index 3d5200547..49d207706 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/Item.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/Item.java @@ -466,7 +466,7 @@ public class Item implements Bundlable { } } - protected int throwPos( Hero user, int dst){ + public int throwPos( Hero user, int dst){ return new Ballistica( user.pos, dst, Ballistica.PROJECTILE ).collisionPos; } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/MissileWeapon.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/MissileWeapon.java index e2f394667..eee4ae9b1 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/MissileWeapon.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/MissileWeapon.java @@ -31,7 +31,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.rings.RingOfSharpshooting; import com.shatteredpixel.shatteredpixeldungeon.items.weapon.Weapon; import com.shatteredpixel.shatteredpixeldungeon.items.weapon.enchantments.Projecting; -import com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica; +import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.watabou.utils.Random; @@ -55,13 +55,10 @@ abstract public class MissileWeapon extends Weapon { } @Override - protected int throwPos(Hero user, int dst) { - int defaultPos = super.throwPos(user, dst); - if (defaultPos == dst) return dst; - else if (hasEnchant(Projecting.class)){ - Ballistica ProjectingTrajectory = new Ballistica( user.pos, dst, Ballistica.STOP_TARGET ); - if (ProjectingTrajectory.dist <= 4) return ProjectingTrajectory.collisionPos; - else return super.throwPos(user, dst); + public int throwPos(Hero user, int dst) { + if (hasEnchant(Projecting.class) + && !Level.solid[dst] && Level.distance(user.pos, dst) <= 4){ + return dst; } else { return super.throwPos(user, dst); } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java b/src/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java index 4a596e24b..2afe57f3c 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java @@ -26,7 +26,6 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.levels.Level; -import com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; @@ -76,7 +75,7 @@ public class QuickSlotButton extends Button implements WndBag.Listener { @Override protected void onClick() { if (targeting) { - int cell = autoAim(lastTarget); + int cell = autoAim(lastTarget, select(slotNum)); if (cell != -1){ GameScene.handleCell(cell); @@ -191,14 +190,20 @@ public class QuickSlotButton extends Button implements WndBag.Listener { } public static int autoAim(Char target){ + //will use generic projectile logic if no item is specified + return autoAim(target, new Item()); + } + + public static int autoAim(Char target, Item item){ + //first try to directly target - if (new Ballistica(Dungeon.hero.pos, target.pos, Ballistica.PROJECTILE).collisionPos == target.pos) { + if (item.throwPos(Dungeon.hero, target.pos) == target.pos) { return target.pos; } //Otherwise pick nearby tiles to try and 'angle' the shot, auto-aim basically. for (int i : Level.NEIGHBOURS9DIST2) { - if (new Ballistica(Dungeon.hero.pos, target.pos+i, Ballistica.PROJECTILE).collisionPos == target.pos){ + if (item.throwPos(Dungeon.hero, target.pos) == target.pos){ return target.pos+i; } }