Quantcast

- bug fix (critical): if {a or b} c won't work

Sidoine De Wispelaere [06-06-09 - 11:04]
- bug fix (critical): if {a or b} c won't work
- added some PvP-related conditions

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@59 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
Condition.lua
Ovale.lua
Ovale.toc
OvaleCompile.lua
diff --git a/Condition.lua b/Condition.lua
index 17ce316..c22022c 100644
--- a/Condition.lua
+++ b/Condition.lua
@@ -16,6 +16,99 @@ local totemType =
 	air = 4
 }

+local fearSpellIdList =
+{
+	5782, -- Fear
+	5484, -- Howl of terror
+	5246, -- Intimidating Shout
+	8122, -- Psychic scream
+}
+local fearSpellList = nil
+
+local stunSpellIdList =
+{
+	5211, -- Bash
+	44415, -- Blackout
+	6409, -- Cheap Shot
+	22427, -- Concussion Blow
+	853, -- Hammer of Justice
+	408, -- Kidney Shot
+	12798, -- Revenge Stun
+}
+local stunSpellList = nil
+
+local incapacitateSpellIdList =
+{
+	6770, -- Sap
+	12540, -- Gouge
+	20066, -- Repentance
+}
+local incapacitateSpellList = nil
+
+local rootSpellIdList =
+{
+	23694, -- Improved Hamstring
+	339, -- Entangling Roots
+	122, -- Frost Nova
+	47168, -- Improved Wing Clip
+}
+local rootSpellList = nil
+
+local function buildRootSpellList()
+	if (rootSpellList) then
+		return
+	end
+	rootSpellList = {}
+	for k, v in pairs(rootSpellIdList) do
+		rootSpellList[Ovale:GetSpellInfoOrNil(v)] = true
+	end
+end
+
+local function buildStunSpellList()
+	if (stunSpellList) then
+		return
+	end
+	stunSpellList = {}
+	for k, v in pairs(stunSpellIdList) do
+		stunListList[Ovale:GetSpellInfoOrNil(v)] = true
+	end
+end
+
+local function buildIncapacitateSpellList()
+	if (incapacitateSpellList) then
+		return
+	end
+	incapacitateSpellList = {}
+	for k, v in pairs(incapacitateSpellIdList) do
+		incapacitateSpellList[Ovale:GetSpellInfoOrNil(v)] = true
+	end
+end
+
+local function buildFearSpellList()
+	if (fearSpellList) then
+		return
+	end
+	fearSpellList = {}
+	for k, v in pairs(fearSpellIdList) do
+		fearSpellList[Ovale:GetSpellInfoOrNil(v)] = true
+	end
+end
+
+local function isDebuffInList(list)
+	local i=1;
+	while (true) do
+		local name, rank, icon, count, debuffType, duration, expirationTime, unitCaster, isStealable =  UnitDebuff("player", i);
+		if (not name) then
+			break
+		end
+		if (list[name]) then
+			return true
+		end
+		i = i +1
+	end
+	return false
+end
+
 local function avecHate(temps, hate)
 	if (not hate) then
 		return temps
@@ -45,7 +138,7 @@ local function compare(a, comparison, b)
 end

 local function testbool(a, condition)
-	if (condition == "yes") then
+	if (condition == "yes" or not condition) then
 		if (a) then
 			return 0
 		else
@@ -60,6 +153,14 @@ local function testbool(a, condition)
 	end
 end

+local function getTarget(condition)
+	if (not condition) then
+		return "target"
+	else
+		return condition
+	end
+end
+
 local function GetTargetAura(condition, filter, target)
 	local spellId = condition[1]
 	local auraName, auraRank, auraIcon = Ovale:GetSpellInfoOrNil(spellId)
@@ -194,18 +295,33 @@ Ovale.conditions=
 			return timeLeft-tempsMax
 		end
 	end,
+	HasFullControl = function(condition)
+		return testbool(HasFullControl(), condition[1])
+	end,
 	HasShield = function(condition)
 		local _,_,id = string.find(GetInventoryItemLink("player",GetInventorySlotInfo("SecondaryHandSlot")) or "","(item:%d+:%d+:%d+:%d+)")
 		if (not id) then
-			return nil
+			return testbool(false, condition[1])
 		end

 		local _,_,_,_,_,_,_,_,itemLoc = GetItemInfo(id)
-		if (itemLoc=="INVTYPE_SHIELD") then
-			return 0
-		else
-			return nil
-		end
+		return testbool(itemLoc=="INVTYPE_SHIELD", condition[1])
+	end,
+	IsFeared = function(condition)
+		buildFearSpellList()
+		return testbool(not HasFullControl() and isDebuffInList(fearSpellList), condition[1])
+	end,
+	IsIncapacitated = function(condition)
+		buildIncapacitateSpellList()
+		return testbool(not HasFullControl() and isDebuffInList(incapacitateSpellList), condition[1])
+	end,
+	IsRooted = function(condition)
+		buildRootSpellList()
+		return testbool(not HasFullControl() and isDebuffInList(rootSpellList), condition[1])
+	end,
+	IsStunned = function(condition)
+		buildStunSpellList()
+		return testbool(not HasFullControl() and isDebuffInList(stunSpellList), condition[1])
 	end,
 	-- Compare with the player level
 	-- 1 : "less" or "more"
@@ -299,6 +415,9 @@ Ovale.conditions=
 		end
 		return compare(Ovale.pointsTalent[condition[1]], condition[2], condition[3])
 	end,
+	TargetClass = function(condition)
+		return testbool(UnitClass("target") == condition[1], condition[2])
+	end,
 	-- Test the target classification
 	-- 1 : normal, elite, or worldboss
 	TargetClassification = function(condition)
@@ -358,11 +477,18 @@ Ovale.conditions=
 			return nil
 		end
 	end,
+	TargetInRange = function(condition)
+		return testbool(IsSpellInRange(Ovale:GetSpellInfoOrNil(condition[1]),getTarget(condition.target))==1,condition[2])
+	end,
+	TargetIsCasting = function(condition)
+		return testbool(UnitCastingInfo(getTarget(condition.target)), condition[1])
+	end,
 	-- Test if the target life is bellow/above a given value in percent
 	-- 1 : "less" or "more"
 	-- 2 : the limit, in percents
 	TargetLifePercent = function(condition)
-		return compare(UnitHealth("target")/UnitHealthMax("target"), condition[1], condition[2]/100)
+		local target = getTarget(condition.target)
+		return compare(UnitHealth(target)/UnitHealthMax(target), condition[1], condition[2]/100)
 	end,
 	-- Test the target level difference with the player
 	-- 1 : "less" or "more"
diff --git a/Ovale.lua b/Ovale.lua
index c6f045f..26bb7ea 100644
--- a/Ovale.lua
+++ b/Ovale.lua
@@ -189,6 +189,10 @@ local options =
 	}
 }

+function Ovale:Debug()
+	self:Print(self:DebugNode(self.masterNodes[1]))
+end
+
 function Ovale:OnInitialize()
 	self.AceConfig = LibStub("AceConfig-3.0");
 	self.AceConfigDialog = LibStub("AceConfigDialog-3.0");
@@ -616,6 +620,14 @@ function Ovale:InitCalculerMeilleureAction()
 	end
 end

+local function printTime(temps)
+	if (temps == nil) then
+		Ovale:Print("> nil")
+	else
+		Ovale:Print("> "..temps)
+	end
+end
+
 function Ovale:CalculerMeilleureAction(element)
 	if (self.bug and not self.trace) then
 		return nil
@@ -756,8 +768,10 @@ function Ovale:CalculerMeilleureAction(element)
 		local tempsA = Ovale:CalculerMeilleureAction(element.a)
 		local tempsB = Ovale:CalculerMeilleureAction(element.b)
 		if (tempsB==nil or (tempsA~=nil and tempsB>tempsA)) then
+			if (Ovale.trace) then printTime(tempsA) end
 			return tempsA
 		else
+			if (Ovale.trace) then printTime(tempsB) end
 			return tempsB
 		end
 	elseif (element.type == "group") then
@@ -808,7 +822,7 @@ function Ovale:CalculerMeilleureAction(element)
 			end
 		end

-		if (meilleurFils) then
+		if (meilleurTempsFils) then
 			if (Ovale.trace) then
 				self:Print("Best action "..meilleurFils.." remains "..meilleurTempsFils)
 			end
@@ -816,6 +830,7 @@ function Ovale:CalculerMeilleureAction(element)
 			self.retourAction = meilleurFils
 			return meilleurTempsFils
 		else
+			if (Ovale.trace) then printTime(nil) end
 			return nil
 		end
 	end
diff --git a/Ovale.toc b/Ovale.toc
index f0678b8..9c8f9cd 100644
--- a/Ovale.toc
+++ b/Ovale.toc
@@ -3,7 +3,7 @@
 ## Notes: Show the icon of the next spell to cast
 ## Notes-frFR: Affiche l'icône du prochain sort à lancer
 ## Author: Sidoine
-## Version: 3.1.8
+## Version: 3.1.9
 ## OptionalDeps: Ace3
 ## SavedVariables: OvaleDB
 ## SavedVariablesPerCharacter: OvaleDBPC
diff --git a/OvaleCompile.lua b/OvaleCompile.lua
index cc015e9..bf32382 100644
--- a/OvaleCompile.lua
+++ b/OvaleCompile.lua
@@ -288,6 +288,8 @@ function Ovale:DebugNode(node)
 		text = self:DebugNode(node.a).." and "..self:DebugNode(node.b)
 	elseif (node.type == "or") then
 		text = self:DebugNode(node.a).." or "..self:DebugNode(node.b)
+	elseif (node.type == "before") then
+		text = node.time .. "s before "..self:DebufNode(node.b)
 	else
 		text = "#unknown node type#"
 	end