Quantcast

Allow for SpellInfo() overrides for Damage() and LastEstimatedDamage().

Johnny C. Lam [04-25-14 - 20:56]
Allow for SpellInfo() overrides for Damage() and LastEstimatedDamage().

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1327 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
conditions/Damage.lua
conditions/LastEstimatedDamage.lua
diff --git a/conditions/Damage.lua b/conditions/Damage.lua
index d6e697e..fe8fc01 100644
--- a/conditions/Damage.lua
+++ b/conditions/Damage.lua
@@ -16,6 +16,7 @@ do

 	local Compare = OvaleCondition.Compare
 	local ComputeParameter = OvaleCondition.ComputeParameter
+	local ParseCondition = OvaleCondition.ParseCondition
 	local state = OvaleState.state

 	-- Return the non-critical-strike damage of a spell, given the player's current stats.
@@ -31,6 +32,23 @@ do
 		return OvaleData:GetDamage(spellId, ap, sp, mh, oh, combo) * bdm * dm
 	end

+	-- Return the damage reduction from armor, assuming the target is boss-level.
+	local BOSS_ARMOR = 24835
+	local WEAKENED_ARMOR_DEBUFF = 113746
+
+	local function BossArmorDamageReduction(target)
+		local aura = state:GetAura(target, WEAKENED_ARMOR_DEBUFF, "HARMFUL")
+		local armor = BOSS_ARMOR
+		if state:IsActiveAura(aura) then
+			armor = armor * (1 - 0.04 * aura.stacks)
+		end
+		local constant = 4037.5 * state.level - 317117.5
+		if constant < 0 then
+			constant = 0
+		end
+		return armor / (armor + constant)
+	end
+
 	--- Get the current estimated damage of a spell on the target if it is a critical strike.
 	-- @name CritDamage
 	-- @paramsig number or boolean
@@ -46,10 +64,16 @@ do

 	local function CritDamage(condition)
 		local spellId, comparator, limit = condition[1], condition[2], condition[3]
+		local target = ParseCondition(condition, "target")
 		local value = ComputeParameter(spellId, "damage", state)
 		if not value then
 			value = GetDamage(spellId)
 		end
+		-- Reduce by armor damage reduction for physical attacks.
+		local si = OvaleData:GetSpellInfo(spellId)
+		if si and si.physical then
+			value = value * (1 - BossArmorDamageReduction(target))
+		end
 		-- TODO: Need to account for increased crit effect from meta-gems.
 		local critFactor = 2
 		local value = critFactor * value
@@ -80,10 +104,16 @@ do

 	local function Damage(condition)
 		local spellId, comparator, limit = condition[1], condition[2], condition[3]
+		local target = ParseCondition(condition, "target")
 		local value = ComputeParameter(spellId, "damage", state)
 		if not value then
 			value = GetDamage(spellId)
 		end
+		-- Reduce by armor damage reduction for physical attacks.
+		local si = OvaleData:GetSpellInfo(spellId)
+		if si and si.physical then
+			value = value * (1 - BossArmorDamageReduction(target))
+		end
 		return Compare(value, comparator, limit)
 	end

diff --git a/conditions/LastEstimatedDamage.lua b/conditions/LastEstimatedDamage.lua
index 8a10b03..703dd05 100644
--- a/conditions/LastEstimatedDamage.lua
+++ b/conditions/LastEstimatedDamage.lua
@@ -14,9 +14,29 @@ do
 	local OvaleData = Ovale.OvaleData
 	local OvaleGUID = Ovale.OvaleGUID
 	local OvaleFuture = Ovale.OvaleFuture
+	local OvaleState = Ovale.OvaleState

 	local Compare = OvaleCondition.Compare
+	local ComputeParameter = OvaleCondition.ComputeParameter
 	local ParseCondition = OvaleCondition.ParseCondition
+	local state = OvaleState.state
+
+	-- Return the damage reduction from armor, assuming the target is boss-level.
+	local BOSS_ARMOR = 24835
+	local WEAKENED_ARMOR_DEBUFF = 113746
+
+	local function BossArmorDamageReduction(target)
+		local aura = state:GetAura(target, WEAKENED_ARMOR_DEBUFF, "HARMFUL")
+		local armor = BOSS_ARMOR
+		if state:IsActiveAura(aura) then
+			armor = armor * (1 - 0.04 * aura.stacks)
+		end
+		local constant = 4037.5 * state.level - 317117.5
+		if constant < 0 then
+			constant = 0
+		end
+		return armor / (armor + constant)
+	end

 	--- Get the estimated damage of the most recent cast of the player's spell on the target.
 	-- The calculated damage takes into account the values of attack power, spellpower, weapon damage and combo points (if used)
@@ -42,15 +62,23 @@ do
 	local function LastEstimatedDamage(condition)
 		local spellId, comparator, limit = condition[1], condition[2], condition[3]
 		local target = ParseCondition(condition, "target")
-		local guid = OvaleGUID:GetGUID(target)
-		local ap = OvaleFuture:GetLastSpellInfo(guid, spellId, "attackPower") or 0
-		local sp = OvaleFuture:GetLastSpellInfo(guid, spellId, "spellBonusDamage") or 0
-		local mh = OvaleFuture:GetLastSpellInfo(guid, spellId, "mainHandWeaponDamage") or 0
-		local oh = OvaleFuture:GetLastSpellInfo(guid, spellId, "offHandWeaponDamage") or 0
-		local combo = OvaleFuture:GetLastSpellInfo(guid, spellId, "combo") or 0
-		local bdm = OvaleFuture:GetLastSpellInfo(guid, spellId, "baseDamageMultiplier") or 1
-		local dm = OvaleFuture:GetLastSpellInfo(guid, spellId, "damageMultiplier") or 1
-		local value = OvaleData:GetDamage(spellId, ap, sp, mh, oh, combo) * bdm * dm
+		local value = ComputeParameter(spellId, "lastEstimatedDamage", state)
+		if not value then
+			local guid = OvaleGUID:GetGUID(target)
+			local ap = OvaleFuture:GetLastSpellInfo(guid, spellId, "attackPower") or 0
+			local sp = OvaleFuture:GetLastSpellInfo(guid, spellId, "spellBonusDamage") or 0
+			local mh = OvaleFuture:GetLastSpellInfo(guid, spellId, "mainHandWeaponDamage") or 0
+			local oh = OvaleFuture:GetLastSpellInfo(guid, spellId, "offHandWeaponDamage") or 0
+			local combo = OvaleFuture:GetLastSpellInfo(guid, spellId, "combo") or 0
+			local bdm = OvaleFuture:GetLastSpellInfo(guid, spellId, "baseDamageMultiplier") or 1
+			local dm = OvaleFuture:GetLastSpellInfo(guid, spellId, "damageMultiplier") or 1
+			value = OvaleData:GetDamage(spellId, ap, sp, mh, oh, combo) * bdm * dm
+		end
+		-- Reduce by armor damage reduction for physical attacks.
+		local si = OvaleData:GetSpellInfo(spellId)
+		if si and si.physical then
+			value = value * (1 - BossArmorDamageReduction(target))
+		end
 		return Compare(value, comparator, limit)
 	end