Quantcast

Adopted new AP calculation thing

Darth Predator [04-01-17 - 15:18]
Adopted new AP calculation thing
Filename
ElvUI_SLE/modules/Armory/CharacterArmory/CharacterArmory.lua
ElvUI_SLE/modules/bags/artifactpower.lua
diff --git a/ElvUI_SLE/modules/Armory/CharacterArmory/CharacterArmory.lua b/ElvUI_SLE/modules/Armory/CharacterArmory/CharacterArmory.lua
index 3b2cd73..b8b4e4f 100644
--- a/ElvUI_SLE/modules/Armory/CharacterArmory/CharacterArmory.lua
+++ b/ElvUI_SLE/modules/Armory/CharacterArmory/CharacterArmory.lua
@@ -1139,6 +1139,24 @@ end

 do --<< Artifact Monitor >>
 	local EnchantError, EnchantError_MainHand, EnchantError_SecondaryHand
+	local apItemCache = {}
+	local apStringValueMillion = {
+		["enUS"] = "(%d+)[%p%s]?[(%d+)]? million",
+		["enGB"] = "(%d+)[%p%s]?[(%d+)]? million",
+		["ptBR"] = "(%d+)[%p%s]?[(%d+)]? [[milhao][milhoes]]?",
+		["esMX"] = "(%d+)[%p%s]?[(%d+)]? [[millon][millones]]?",
+		["deDE"] = "(%d+)[%p%s]?[(%d+)]? [[Million][Millionen]]?",
+		["esES"] = "(%d+)[%p%s]?[(%d+)]? [[millon][millones]]?",
+		["frFR"] = "(%d+)[%p%s]?[(%d+)]? [[million][millions]]?",
+		["itIT"] = "(%d+)[%p%s]?[(%d+)]? [[milione][milioni]]?",
+		["ruRU"] = "(%d+)[%p%s]?[(%d+)]? ",
+		["koKR"] = "(%d+)[%p%s]?[(%d+)]??",
+		["zhTW"] = "(%d+)[%p%s]?[(%d+)]??",
+		["zhCN"] = "(%d+)[%p%s]?[(%d+)]??",
+	}
+	local apStringValueMillionLocal = apStringValueMillion[GetLocale()]
+	local empoweringSpellName = GetSpellInfo(227907)
+
 	function CA:LegionArtifactMonitor_UpdateLayout()
 		if Legion_ArtifactData.ItemID then
 			self.SecondaryHandSlot.Gradation:SetAlpha(0)
@@ -1308,43 +1326,70 @@ do --<< Artifact Monitor >>
 						if GetItemInfo(PowerItemLink) then
 							-- print(GetItemInfo(PowerItemLink))
 							-- print(PowerItemLink)
-							self:ClearTooltip(self.ArtifactMonitor.ScanTT)
-							self.ArtifactMonitor.ScanTT:SetHyperlink(PowerItemLink)
-							SearchingPhase = 1
 							CurrentItemPower = 0
-
-							for i = 1, self.ArtifactMonitor.ScanTT:NumLines() do
-								SearchingText = CleanString(_G['Knight_CharacterArmory_ArtifactScanTTTextLeft' .. i]:GetText())
-
-								if SearchingPhase == 1 and SearchingText == ARTIFACT_POWER then
-									SearchingPhase = 2
-								elseif SearchingPhase == 2 and SearchingText:find(ITEM_SPELL_TRIGGER_ONUSE) then
-									CurrentItemPower = T.gsub(strmatch(SearchingText, "(%d+[,.%s]%d+)"), "[,.%s]", "")
-									CurrentItemPower = T.tonumber(CurrentItemPower)
-									TotalPower = TotalPower + CurrentItemPower
-
+							if apItemCache[PowerItemLink] then
+								if apItemCache[PowerItemLink] ~= false then
+									CurrentItemPower = apItemCache[PowerItemLink]
 									if not LowestPower or LowestPower > CurrentItemPower then
 										LowestPower = CurrentItemPower
 										LowestPower_BagID = BagID
 										LowestPower_SlotID = SlotID
 										LowestPower_Link = PowerItemLink
 									end
-
-									break
+								end
+							else
+								local itemSpell = GetItemSpell(PowerItemLink)
+								if itemSpell and itemSpell == empoweringSpellName then
+									self:ClearTooltip(self.ArtifactMonitor.ScanTT)
+									local success = pcall(self.ArtifactMonitor.ScanTT.SetHyperlink, self.ArtifactMonitor.ScanTT, PowerItemLink)
+									if success then
+										local apFound
+										for i = 4,5 do
+											local tooltipText = _G["Knight_CharacterArmory_ArtifactScanTTTextLeft"..i]:GetText()
+											if tooltipText then
+												local digit1, digit2, digit3, ap
+												if T.match(tooltipText, apStringValueMillionLocal) then
+													digit1, digit2 = T.match(tooltipText, apStringValueMillionLocal)
+													if digit2 then
+														ap = T.tonumber(T.format("%s.%s", digit1, digit2)) * 1e6 --Multiply by one million
+													else
+														ap = T.tonumber(digit1) * 1e6 --Multiply by one million
+													end
+												else
+													digit1, digit2, digit3 = T.match(tooltipText,"(%d+)[%p%s]?(%d+)[%p%s]?(%d+)")
+													ap = T.tonumber(T.format("%s%s%s", digit1 or "", digit2 or "", (digit2 and digit3) and digit3 or ""))
+												end
+
+												if ap then
+													CurrentItemPower = ap
+													CurrentItemPower = T.tonumber(CurrentItemPower)
+													apItemCache[PowerItemLink] = CurrentItemPower
+													apFound = true
+													if not LowestPower or LowestPower > CurrentItemPower then
+														LowestPower = CurrentItemPower
+														LowestPower_BagID = BagID
+														LowestPower_SlotID = SlotID
+														LowestPower_Link = PowerItemLink
+													end
+													break
+												end
+											end
+										end
+
+										if (not apFound) then
+											apItemCache[PowerItemLink] = false --Cache item as not granting AP
+										end
+									end
+								else
+									apItemCache[PowerItemLink] = false --Cache item as not granting AP
 								end
 							end
-
-							if SearchingPhase == 2 and not (LowestPower and LowestPower > 0) then
-								LowestPower = CurrentItemPower
-								LowestPower_BagID = BagID
-								LowestPower_SlotID = SlotID
-								LowestPower_Link = PowerItemLink
-							end
+							TotalPower = TotalPower + CurrentItemPower
 						end
 					end
 				end
 			end
-
+
 			if LowestPower then
 				self.ArtifactMonitor.AddPower.Texture:Show()
 				self.ArtifactMonitor.AddPower.Button.Link = LowestPower_Link
diff --git a/ElvUI_SLE/modules/bags/artifactpower.lua b/ElvUI_SLE/modules/bags/artifactpower.lua
index ebf91bf..bd023e9 100644
--- a/ElvUI_SLE/modules/bags/artifactpower.lua
+++ b/ElvUI_SLE/modules/bags/artifactpower.lua
@@ -10,9 +10,28 @@ local arcanePower
 local AP_NAME = T.format("|cFFE6CC80%s|r", ARTIFACT_POWER)
 local pcall = pcall

-local apLineIndex
+-- local apLineIndex
+local apItemCache = {}
+local apStringValueMillion = {
+	["enUS"] = "(%d+)[%p%s]?[(%d+)]? million",
+	["enGB"] = "(%d+)[%p%s]?[(%d+)]? million",
+	["ptBR"] = "(%d+)[%p%s]?[(%d+)]? [[milhao][milhoes]]?",
+	["esMX"] = "(%d+)[%p%s]?[(%d+)]? [[millon][millones]]?",
+	["deDE"] = "(%d+)[%p%s]?[(%d+)]? [[Million][Millionen]]?",
+	["esES"] = "(%d+)[%p%s]?[(%d+)]? [[millon][millones]]?",
+	["frFR"] = "(%d+)[%p%s]?[(%d+)]? [[million][millions]]?",
+	["itIT"] = "(%d+)[%p%s]?[(%d+)]? [[milione][milioni]]?",
+	["ruRU"] = "(%d+)[%p%s]?[(%d+)]? ",
+	["koKR"] = "(%d+)[%p%s]?[(%d+)]??",
+	["zhTW"] = "(%d+)[%p%s]?[(%d+)]??",
+	["zhCN"] = "(%d+)[%p%s]?[(%d+)]??",
+}
+local apStringValueMillionLocal = apStringValueMillion[GetLocale()]
 local function GetItemLinkArtifactPower(slotLink)
-	if slotLink then
+	local apValue
+	if not slotLink then return nil end
+	local itemSpell = GetItemSpell(slotLink)
+	if itemSpell and itemSpell == empoweringSpellName then
 		tooltipScanner:ClearLines()
 		local success = pcall(tooltipScanner.SetHyperlink, tooltipScanner, slotLink)
 		if (not success) then
@@ -20,31 +39,40 @@ local function GetItemLinkArtifactPower(slotLink)
 		end

 		local apFound
-		if (_G[tooltipName.."TextLeft2"]:GetText() == AP_NAME) then
-			apLineIndex = 4
-			apFound = true
-		elseif (_G[tooltipName.."TextLeft3"]:GetText() == AP_NAME) then --When using colorblind mode then line 2 becomes the rarity, pushing ap text down 1 line
-			apLineIndex = 5
-			apFound = true
-		end
-
-		if not (apFound) then
-			return nil
-		end
-
-		local apValue
-		if T.find(_G[tooltipName.."TextLeft"..apLineIndex]:GetText(), "(%d+)[,.%s](%d+)") then
-			apValue = T.gsub(strmatch(_G[tooltipName.."TextLeft"..apLineIndex]:GetText(), "(%d+[,.%s]%d+)"), "[,.%s]", "")
-			apValue = T.tonumber(apValue)
-		elseif T.find(_G[tooltipName.."TextLeft"..apLineIndex]:GetText(), "%d+") then
-			apValue = T.tonumber(strmatch(_G[tooltipName.."TextLeft"..apLineIndex]:GetText(), "%d+"))
+		for i = 4,5 do
+			local tooltipText = _G[tooltipName.."TextLeft"..i]:GetText()
+			if tooltipText then
+				local digit1, digit2, digit3, ap
+				if T.match(tooltipText, apStringValueMillionLocal) then
+					digit1, digit2 = T.match(tooltipText, apStringValueMillionLocal)
+					if digit2 then
+						ap = T.tonumber(T.format("%s.%s", digit1, digit2)) * 1e6 --Multiply by one million
+					else
+						ap = T.tonumber(digit1) * 1e6 --Multiply by one million
+					end
+				else
+					digit1, digit2, digit3 = T.match(tooltipText,"(%d+)[%p%s]?(%d+)[%p%s]?(%d+)")
+					ap = T.tonumber(T.format("%s%s%s", digit1 or "", digit2 or "", (digit2 and digit3) and digit3 or ""))
+				end
+
+				if ap then
+					apValue = ap
+					apValue = T.tonumber(apValue)
+					apFound = true
+					break
+				end
+			end
 		end
-		if E.db.sle.bags.artifactPower.short then apValue = E:ShortValue(apValue) end

-		return apValue
+		if (not apFound) then
+			apItemCache[slotLink] = false --Cache item as not granting AP
+		end
 	else
-		return nil
+		apItemCache[slotLink] = false --Cache item as not granting AP
 	end
+
+	-- if E.db.sle.bags.artifactPower.short and apValue then apValue = E:ShortValue(apValue) end
+	return apValue
 end

 local function SlotUpdate(self, bagID, slotID)
@@ -69,7 +97,16 @@ local function SlotUpdate(self, bagID, slotID)
 			local ID = select(10, T.GetContainerItemInfo(bagID, slotID))
 			local slotLink = T.GetContainerItemLink(bagID,slotID)
 			if (ID and slotLink) then
-				arcanePower = GetItemLinkArtifactPower(slotLink)
+				local arcanePower
+				if apItemCache[slotLink] then
+					if apItemCache[slotLink] ~= false then
+						arcanePower = apItemCache[slotLink]
+					end
+				else
+					arcanePower = GetItemLinkArtifactPower(slotLink)
+					apItemCache[slotLink] = arcanePower
+				end
+				if E.db.sle.bags.artifactPower.short and arcanePower then arcanePower = E:ShortValue(arcanePower) end
 				frame.artifactpowerinfo:SetText(arcanePower)
 			end
 		end