From 49ed3e4f8ba0cf556970f56b934f9e53c1e645a5 Mon Sep 17 00:00:00 2001
From: Evan Debenham <Evan@ShatteredPixel.com>
Date: Sat, 29 Aug 2020 15:47:02 -0400
Subject: [PATCH] v0.8.2d: adjusted door opening logic on fireblast, fixes bugs

---
 .../potions/exotic/PotionOfDragonsBreath.java   | 12 ++++++++++--
 .../items/wands/WandOfFireblast.java            | 10 +++++++++-
 .../mechanics/Ballistica.java                   | 17 ++++++-----------
 3 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/exotic/PotionOfDragonsBreath.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/exotic/PotionOfDragonsBreath.java
index 4668575a5..9edc879cf 100644
--- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/exotic/PotionOfDragonsBreath.java
+++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/exotic/PotionOfDragonsBreath.java
@@ -32,6 +32,8 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Burning;
 import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Cripple;
 import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
 import com.shatteredpixel.shatteredpixeldungeon.effects.MagicMissile;
+import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
+import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
 import com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica;
 import com.shatteredpixel.shatteredpixeldungeon.mechanics.ConeAOE;
 import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
@@ -80,12 +82,12 @@ public class PotionOfDragonsBreath extends ExoticPotion {
 						curUser.sprite.zap(cell);
 						Sample.INSTANCE.play( Assets.Sounds.BURNING );
 
-						final Ballistica bolt = new Ballistica(curUser.pos, cell, Ballistica.STOP_TERRAIN | Ballistica.OPEN_DOORS);
+						final Ballistica bolt = new Ballistica(curUser.pos, cell, Ballistica.STOP_TERRAIN | Ballistica.IGNORE_DOORS);
 
 						int maxDist = 6;
 						int dist = Math.min(bolt.dist, maxDist);
 
-						final ConeAOE cone = new ConeAOE(bolt, 6, 60, Ballistica.STOP_TERRAIN | Ballistica.STOP_TARGET | Ballistica.OPEN_DOORS );
+						final ConeAOE cone = new ConeAOE(bolt, 6, 60, Ballistica.STOP_TERRAIN | Ballistica.STOP_TARGET | Ballistica.IGNORE_DOORS );
 
 						//cast to cells at the tip, rather than all cells, better performance.
 						for (Ballistica ray : cone.rays){
@@ -111,6 +113,12 @@ public class PotionOfDragonsBreath extends ExoticPotion {
 												continue;
 											}
 
+											//knock doors open
+											if (Dungeon.level.map[cell] == Terrain.DOOR){
+												Level.set(cell, Terrain.OPEN_DOOR);
+												GameScene.updateMap(cell);
+											}
+
 											//only ignite cells directly near caster if they are flammable
 											if (Dungeon.level.adjacent(bolt.sourcePos, cell) && !Dungeon.level.flamable[cell]){
 												adjacentCells.add(cell);
diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfFireblast.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfFireblast.java
index a276e2027..ca0c15550 100644
--- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfFireblast.java
+++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfFireblast.java
@@ -34,6 +34,8 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Paralysis;
 import com.shatteredpixel.shatteredpixeldungeon.effects.MagicMissile;
 import com.shatteredpixel.shatteredpixeldungeon.items.weapon.enchantments.Blazing;
 import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.MagesStaff;
+import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
+import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
 import com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica;
 import com.shatteredpixel.shatteredpixeldungeon.mechanics.ConeAOE;
 import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
@@ -50,7 +52,7 @@ public class WandOfFireblast extends DamageWand {
 	{
 		image = ItemSpriteSheet.WAND_FIREBOLT;
 
-		collisionProperties = Ballistica.STOP_TERRAIN | Ballistica.OPEN_DOORS;
+		collisionProperties = Ballistica.STOP_TERRAIN | Ballistica.IGNORE_DOORS;
 	}
 
 	//1x/2x/3x damage
@@ -77,6 +79,12 @@ public class WandOfFireblast extends DamageWand {
 				continue;
 			}
 
+			//knock doors open
+			if (Dungeon.level.map[cell] == Terrain.DOOR){
+				Level.set(cell, Terrain.OPEN_DOOR);
+				GameScene.updateMap(cell);
+			}
+
 			//only ignite cells directly near caster if they are flammable
 			if (Dungeon.level.adjacent(bolt.sourcePos, cell) && !Dungeon.level.flamable[cell]){
 				adjacentCells.add(cell);
diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/mechanics/Ballistica.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/mechanics/Ballistica.java
index 81c74ab00..c8bb945d5 100644
--- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/mechanics/Ballistica.java
+++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/mechanics/Ballistica.java
@@ -24,9 +24,7 @@ package com.shatteredpixel.shatteredpixeldungeon.mechanics;
 import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
 import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
 import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
-import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
 import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
-import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -44,7 +42,7 @@ public class Ballistica {
 	public static final int STOP_TARGET = 1;    //ballistica will stop at the target cell
 	public static final int STOP_CHARS = 2;     //ballistica will stop on first char hit
 	public static final int STOP_TERRAIN = 4;   //ballistica will stop on solid terrain
-	public static final int OPEN_DOORS = 8;     //ballistica will open doors instead of colliding
+	public static final int IGNORE_DOORS = 8;   //ballistica will ignore doors instead of colliding
 
 	public static final int PROJECTILE =  	STOP_TARGET	| STOP_CHARS	| STOP_TERRAIN;
 
@@ -59,7 +57,7 @@ public class Ballistica {
 				(params & STOP_TARGET) > 0,
 				(params & STOP_CHARS) > 0,
 				(params & STOP_TERRAIN) > 0,
-				(params & OPEN_DOORS) > 0);
+				(params & IGNORE_DOORS) > 0);
 
 		if (collisionPos != null) {
 			dist = path.indexOf(collisionPos);
@@ -72,7 +70,7 @@ public class Ballistica {
 		}
 	}
 
-	private void build( int from, int to, boolean stopTarget, boolean stopChars, boolean stopTerrain, boolean openDoors ) {
+	private void build( int from, int to, boolean stopTarget, boolean stopChars, boolean stopTerrain, boolean ignoreDoors ) {
 		int w = Dungeon.level.width();
 
 		int x0 = from % w;
@@ -123,15 +121,12 @@ public class Ballistica {
 
 			path.add(cell);
 
-			if (openDoors && collisionPos == null && Dungeon.level.map[cell] == Terrain.DOOR){
-				Level.set(cell, Terrain.OPEN_DOOR);
-				GameScene.updateMap(cell);
-			}
-
 			if ((stopTerrain && cell != sourcePos && Dungeon.level.solid[cell])
 					|| (cell != sourcePos && stopChars && Actor.findChar( cell ) != null)
 					|| (cell == to && stopTarget)){
-				collide(cell);
+				if (!ignoreDoors || Dungeon.level.map[cell] != Terrain.DOOR) {
+					collide(cell); //only collide if this isn't a door, or we aren't ignoring doors
+				}
 			}
 
 			cell += stepA;