Quantcast

Enhance Name() script condition to accept a spell ID instead of a name.

Johnny C. Lam [12-15-14 - 22:36]
Enhance Name() script condition to accept a spell ID instead of a name.

The name of the spell is then used for comparison to the unit name.
Filename
SimulationCraft.lua
conditions.lua
diff --git a/SimulationCraft.lua b/SimulationCraft.lua
index e4e78f3..344836a 100644
--- a/SimulationCraft.lua
+++ b/SimulationCraft.lua
@@ -1772,19 +1772,16 @@ EmitExpression = function(parseNode, nodeList, annotation, action)
 			elseif (parseNode.operator == "=" or parseNode.operator == "!=") and (parseNode.child[1].name == "target" or parseNode.child[1].name == "current_target") then
 				--[[
 					Special handling for "target=X" or "current_target=X" expressions.
-					TODO: This whole section will need to be updated once Prismatic Crystals can be summoned.
 				--]]
 				local rhsNode = parseNode.child[2]
 				local name = rhsNode.name
-				if name == "prismatic_crystal" then
-					name = '"Prismatic Crystal"'
-				end
 				local code
 				if parseNode.operator == "=" then
 					code = format("target.Name(%s)", name)
 				else -- if parseNode.operator == "!=" then
 					code = format("not target.Name(%s)", name)
 				end
+				AddSymbol(annotation, name)
 				annotation.astAnnotation = annotation.astAnnotation or {}
 				node = OvaleAST:ParseCode("expression", code, nodeList, annotation.astAnnotation)
 			elseif (parseNode.operator == "=" or parseNode.operator == "!=") and parseNode.child[1].name == "last_judgment_target" then
diff --git a/conditions.lua b/conditions.lua
index d9b67fc..f37539c 100644
--- a/conditions.lua
+++ b/conditions.lua
@@ -3147,6 +3147,10 @@ do
 	local function Name(condition, state)
 		local name, yesno = condition[1], condition[2]
 		local target = ParseCondition(condition, state)
+		-- If the given name is a number, then look up the name of the corresponding spell.
+		if type(name) == "number" then
+			name = OvaleSpellBook:GetSpellName(name)
+		end
 		local targetName = API_UnitName(target)
 		local boolean = (name == targetName)
 		return TestBoolean(boolean, yesno)