Quantcast

Fix for ticket 135.

Johnny C. Lam [09-16-12 - 16:45]
Fix for ticket 135.

* Add additional druid "self" buffs that increase damage done.

* Add Mastery() and LastSpellMastery(id) script conditions

* Track the mastery information at the time a spell is cast.

* Add a SpellData(id key) script condition that takes two parameters, a
  spell ID and a key, and returns the data associated with that key from
  the SpellInfo() for that spell ID.

  SpellInfo()/SpellData() can be used together to stash and retrieve extra
  spell information that may be referenced within the script.

* Get the damage multiplier using OvaleAura:GetDamageMultiplier(spellId),
  which factors in the multipliers for the presence of the buffs and
  debuffs in the given spell's damageAura table (from OvaleData).

* Add new script statements SpellDamageBuff() and SpellDamageDebuff(),
  which take a spellId followed by a list of aura1=x1, aura2=x2, etc.,
  where auraN is the aura spell ID and xN is the damage multiplier if
  auraN is present.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@524 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
OvaleAura.lua
OvaleCompile.lua
OvaleCondition.lua
OvaleData.lua
OvaleFuture.lua
diff --git a/OvaleAura.lua b/OvaleAura.lua
index 689fbf4..8443437 100644
--- a/OvaleAura.lua
+++ b/OvaleAura.lua
@@ -8,10 +8,13 @@ OvaleAura.aura = {}
 OvaleAura.serial = 0
 OvaleAura.spellHaste = 1
 OvaleAura.meleeHaste = 1
-OvaleAura.damageMultiplier = 1
 OvaleAura.playerGUID = nil
 --</public-static-properties>

+--<private-static-properties>
+local baseDamageMultiplier = 1
+--</private-static-properties>
+
 -- Events
 --<public-static-methods>
 function OvaleAura:OnEnable()
@@ -190,7 +193,7 @@ function OvaleAura:UpdateAuras(unitId, unitGUID)
 	if unitId == "player" then
 		self.spellHaste = 1 + (hateBase + hateCommune + hateSorts + hateHero + hateClasse)/100
 		self.meleeHaste = 1 + (hateBase + hateCommune + hateCaC + hateHero + hateClasse)/100
-		self.damageMultiplier = damageMultiplier
+		baseDamageMultiplier = damageMultiplier
 	end

 	Ovale.refreshNeeded[unitId] = true
@@ -280,6 +283,27 @@ function OvaleAura:GetExpirationTimeOnAnyTarget(spellId, excludingTarget)
 	return starting, ending, count
 end

+function OvaleAura:GetDamageMultiplier(spellId)
+	local damageMultiplier = baseDamageMultiplier
+	if spellId then
+		local si = OvaleData:GetSpellInfo(spellId)
+		if si and si.damageAura then
+			self:UpdateAuras("player", self.playerGUID)
+			auraTable = self.aura[self.playerGUID]
+			if auraTable then
+				for filter, filterInfo in pairs(si.damageAura) do
+					for auraSpellId, multiplier in pairs(filterInfo) do
+						if auraTable[auraSpellId] then
+							damageMultiplier = damageMultiplier * multiplier
+						end
+					end
+				end
+			end
+		end
+	end
+	return damageMultiplier
+end
+
 function OvaleAura:Debug()
 	Ovale:Print("------")
 	for guid,auraTable in pairs(self.aura) do
diff --git a/OvaleCompile.lua b/OvaleCompile.lua
index 6f5a7b0..c8cd23f 100644
--- a/OvaleCompile.lua
+++ b/OvaleCompile.lua
@@ -206,6 +206,25 @@ local function ParseSpellAddTargetDebuff(params)
 	return ""
 end

+local function ParseSpellDamageBuff(params)
+	local paramList = ParseParameters(params)
+	local spellId = paramList[1]
+	if spellId then
+		paramList[1] = nil
+		OvaleData:GetSpellInfo(spellId).damageAura.HELPFUL = paramList
+	end
+	return ""
+end
+
+local function ParseSpellDamageDebuff(params)
+	local paramList = ParseParameters(params)
+	local spellId = paramList[1]
+	if spellId then
+		paramList[1] = nil
+		OvaleData:GetSpellInfo(spellId).damageAura.HARMFUL = paramList
+	end
+	return ""
+end

 local function ParseSpellInfo(params)
 	local paramList = ParseParameters(params)
@@ -528,6 +547,8 @@ function OvaleCompile:Compile(text)
 	text = string.gsub(text, "SpellAddBuff%s*%((.-)%)", ParseSpellAddBuff)
 	text = string.gsub(text, "SpellAddDebuff%s*%((.-)%)", ParseSpellAddDebuff)
 	text = string.gsub(text, "SpellAddTargetDebuff%s*%((.-)%)", ParseSpellAddTargetDebuff)
+	text = string.gsub(text, "SpellDamageBuff%s*%((.-)%)", ParseSpellDamageBuff)
+	text = string.gsub(text, "SpellDamageDebuff%s*%((.-)%)", ParseSpellDamageDebuff)
 	text = string.gsub(text, "SpellInfo%s*%((.-)%)", ParseSpellInfo)
 	text = string.gsub(text, "ScoreSpells%s*%((.-)%)", ParseScoreSpells)
 	text = string.gsub(text, "SpellList%s*%(%s*(%w+)%s*(.-)%)", ParseSpellList)
diff --git a/OvaleCondition.lua b/OvaleCondition.lua
index dba6044..570a5dc 100644
--- a/OvaleCondition.lua
+++ b/OvaleCondition.lua
@@ -703,13 +703,13 @@ OvaleCondition.conditions=
 		if spellInfo.bonusspholy then
 			ret = ret + spellInfo.bonusspholy * GetSpellBonusDamage(2) * OvaleState.state.holy
 		end
-		return 0, nil, ret * OvaleAura.damageMultiplier, 0, 0
+		return 0, nil, ret * OvaleAura:GetDamageMultiplier(condition[1]), 0, 0
 	end,
 	-- Get the current damage multiplier
 	-- TODO: use OvaleState
 	-- returns: number
 	damagemultiplier = function(condition)
-		local ret = OvaleAura.damageMultiplier
+		local ret = OvaleAura:GetDamageMultiplier(condition[1])
 		if condition[1] then
 			local si = OvaleData:GetSpellInfo(condition[1])
 			if si and si.combo == 0 then
@@ -915,6 +915,12 @@ OvaleCondition.conditions=
 	lastspellspellpower = function(condition)
 		return compare(OvaleFuture.lastSpellSP[condition[1]], condition[2], condition[3])
 	end,
+	-- Get the last spell mastery
+	-- 1: the spell id
+	-- returns: number or bool
+	lastspellmastery = function(condition)
+		return compare(OvaleFuture.lastSpellMastery[condition[1]], condition[2], condition[3])
+	end,
 	-- Get the time elasped since the last swing
 	-- 1: main or off
 	-- returns: number
@@ -985,6 +991,15 @@ OvaleCondition.conditions=
 			return compare(UnitPower(target, 0)*100/powerMax, condition[1], condition[2])
 		end
 	end,
+	-- Get the mastery
+	-- returns : bool or number
+	mastery = function(condition)
+		local mastery = 0
+		if UnitLevel("player") >= 80 then
+			mastery = GetMasteryEffect()
+		end
+		return compare(mastery, condition[1], condition[2])
+	end,
 	-- Get the target maximum health
 	-- return: bool or number
 	maxhealth = function(condition)
@@ -1170,6 +1185,20 @@ OvaleCondition.conditions=
 			return 0, nil, actionCooldownDuration, actionCooldownStart, -1
 		end
 	end,
+	-- Get the spell data listed in SpellInfo()
+	-- 1: spell ID
+	-- 2: key
+	-- return: number
+	spelldata = function(condition)
+		local si = OvaleData.spellInfo[condition[1]]
+		if si then
+			local ret = si[condition[2]]
+			if ret then
+				return 0, nil, ret, 0, 0
+			end
+		end
+		return nil
+	end,
 	-- Get the spell power
 	-- return: number or bool
 	spellpower = function(condition)
diff --git a/OvaleData.lua b/OvaleData.lua
index 6765d1b..a08c652 100644
--- a/OvaleData.lua
+++ b/OvaleData.lua
@@ -46,7 +46,9 @@ OvaleData.selfHasteBuff =
 OvaleData.selfDamageBuff =
 {
 	[5217] = 1.15, -- Tiger's fury
-	[57933] = 1.15 -- Tricks of the trade
+	[57933] = 1.15, -- Tricks of the trade
+	[124974] = 1.20, -- Nature's Vigil
+	[127538] = 1.30, -- Savage Roar
 }

 OvaleData.buffSpellList =
@@ -371,7 +373,11 @@ end

 function OvaleData:GetSpellInfo(spellId)
 	if (not self.spellInfo[spellId]) then
-		self.spellInfo[spellId] = { aura = {player = {}, target = {}} }
+		self.spellInfo[spellId] =
+		{
+			aura = {player = {}, target = {}},
+			damageAura = {},
+		}
 	end
 	return self.spellInfo[spellId]
 end
diff --git a/OvaleFuture.lua b/OvaleFuture.lua
index 4243863..472af71 100644
--- a/OvaleFuture.lua
+++ b/OvaleFuture.lua
@@ -13,6 +13,7 @@ OvaleFuture.lastSpellId = nil
 OvaleFuture.lastSpellAP = {}
 OvaleFuture.lastSpellSP = {}
 OvaleFuture.lastSpellDM = {}
+OvaleFuture.lastSpellMastery = {}
 OvaleFuture.playerGUID = nil
 OvaleFuture.nextSpellTarget = nil
 OvaleFuture.nextSpellLineID = nil
@@ -213,7 +214,12 @@ function OvaleFuture:AddSpellToList(spellId, lineId, startTime, endTime, channel
 	self.lastSpellId = spellId
 	self.lastSpellAP[spellId] = UnitAttackPower("player")
 	self.lastSpellSP[spellId] = GetSpellBonusDamage(2)
-	self.lastSpellDM[spellId] = OvaleAura.damageMultiplier
+	self.lastSpellDM[spellId] = OvaleAura:GetDamageMultiplier(spellId)
+	if UnitLevel("player") < 80 then
+		self.lastSpellMastery[spellId] = 0
+	else
+		self.lastSpellMastery[spellId] = GetMasteryEffect()
+	end
 	self.lastSpell[#self.lastSpell+1] = newSpell
 	--Ovale:Print("on ajoute "..spellId..": ".. newSpell.start.." to "..newSpell.stop.." ("..tostring(OvaleState.maintenant)..")" ..#self.lastSpell .. " " ..tostring(newSpell.target))