Advertisement
Guest User

GetUpgradedItemLevel.lua

a guest
Nov 22nd, 2015
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.56 KB | None | 0 0
  1. --[[
  2.     Until Blizzard adds an easier solution, this function can be used to get the true upgraded itemLevel.
  3.     The Lua file is easily portable between addons. The function is placed in the global namespace.
  4.     Syntax:
  5.         GetUpgradedItemLevelFromItemLink(itemLink)
  6.         = return value is the modified itemLevel based on the item's upgrade
  7.     Changelog:
  8.     * REV-07 (15.09.xx) Patch 6.2.2:    Updated to work with Heirlooms and Timewarped items.
  9.     * REV-06 (14.10.15) Patch 6.0.2:    Updated the pattern match for "upgradeId" to work for WoD.
  10.     * REV-05 (14.05.24) Patch 5.4.8:    Added IDs 504 to 507.
  11.     * REV-04 (13.09.21) Patch 5.4:      Added IDs 491 to 498 to the table.
  12.     * REV-03 (13.05.22) Patch 5.3:      Added the 465/466/467 IDs (0/4/8 lvls) to the table.
  13.     * REV-02 (13.xx.xx) Patch 5.2:      Added the 470 ID (8 lvls) to the table.
  14. --]]
  15.  
  16. -- Make sure we do not override a newer revision.
  17. local REVISION = 7;
  18. if (type(GET_UPGRADED_ITEM_LEVEL_REV) == "number") and (GET_UPGRADED_ITEM_LEVEL_REV >= REVISION) then
  19.     return;
  20. end
  21. GET_UPGRADED_ITEM_LEVEL_REV = REVISION;
  22.  
  23. -- Item links data change in 6.0:
  24. --  itemID:enchant:gem1:gem2:gem3:gem4:suffixID:uniqueID:level:reforgeId:upgradeId
  25. --  itemID:enchant:gem1:gem2:gem3:gem4:suffixID:uniqueID:level:upgradeId:instanceDifficultyID:numBonusIDs:bonusID1:bonusID2
  26.  
  27. --Item links data change in 6.2:
  28. --  itemID:enchant:gem1:gem2:gem3:gem4:suffixID:uniqueID:level:specID:upgradeTypeID:instanceDifficultyID:numBonusIDs:bonusID1:bonusID2:...:upgradeID
  29.  
  30.  
  31. -- Extraction pattern for the complete itemString, including all its properties
  32. local ITEMSTRING_PATTERN = "(item:[^|]+)";
  33. -- Matches the 11th property, upgradeType, of an itemString.
  34. local ITEMSTRING_PATTERN_UPGRADETYPE = "item:"..("[^:]+:"):rep(10).."(%d+)";
  35. -- Last property of an itemString
  36. local ITEMSTRING_PATTERN_UPGRADEID = "%d+$"
  37.  
  38. -- Table for adjustment of levels due to upgrade -- Source: http://www.wowinterface.com/forums/showthread.php?t=45388
  39. local UPGRADED_LEVEL_ADJUST = {
  40.     [001] = 8, -- 1/1
  41.     -- Patch 5.1 --
  42.     [373] = 4, -- 1/2
  43.     [374] = 8, -- 2/2
  44.     [375] = 4, -- 1/3
  45.     [376] = 4, -- 2/3
  46.     [377] = 4, -- 3/3
  47.     [379] = 4, -- 1/2
  48.     [380] = 4, -- 2/2
  49. --  [445] = 0, -- 0/2
  50.     [446] = 4, -- 1/2
  51.     [447] = 8, -- 2/2
  52. --  [451] = 0, -- 0/1
  53.     [452] = 8, -- 1/1
  54. --  [453] = 0, -- 0/2
  55.     [454] = 4, -- 1/2
  56.     [455] = 8, -- 2/2
  57. --  [456] = 0, -- 0/1
  58.     [457] = 8, -- 1/1
  59. --  [458] = 0, -- 0/4
  60.     [459] = 4, -- 1/4
  61.     [460] = 8, -- 2/4
  62.     [461] = 12, -- 3/4
  63.     [462] = 16, -- 4/4
  64.     -- Patch 5.3 --
  65. --  [465] = 0,
  66.     [466] = 4,
  67.     [467] = 8,
  68.     -- Patch ?? --
  69. --  [468] = 0,
  70.     [469] = 4,
  71.     [470] = 8,
  72.     [471] = 12,
  73.     [472] = 16,
  74.     -- Patch 5.4 --
  75. --  [491] = 0,
  76.     [492] = 4,
  77.     [493] = 8,
  78. --  [494] = 0,
  79.     [495] = 4,
  80.     [496] = 8,
  81.     [497] = 12,
  82.     [498] = 16,
  83.     -- Patch 5.4.8 --
  84.     [504] = 12, -- US/EU upgrade 3/4
  85.     [505] = 16, -- US/EU upgrade 4/4
  86.     [506] = 20, -- Asia upgrade 5/6
  87.     [507] = 24, -- Asis upgrade 6/6
  88.     -- Patch 6.2.3 --
  89.     [530] = 5, -- WoD upgrade 1/2
  90.     [531] = 10, -- WoD upgrade 2/2
  91. };
  92.  
  93. local CachedActualiLevel = { };
  94.  
  95. -- Analyses the itemString and checks for upgrades that affects itemLevel
  96. function GetUpgradedItemLevelFromItemLink(itemString)
  97.     -- Ensure we only have the raw itemString, and not the full itemLink
  98.     itemString = itemString:match(ITEMSTRING_PATTERN);
  99.     local itemName, _, itemRarity, itemLevel = GetItemInfo(itemString);
  100.     local upgradeType = tonumber(itemString:match(ITEMSTRING_PATTERN_UPGRADETYPE));
  101.     local upgradeId = tonumber(itemString:match(ITEMSTRING_PATTERN_UPGRADEID));
  102.     if itemLevel then
  103.         if (upgradeType ==4) and (UPGRADED_LEVEL_ADJUST[upgradeId]) then    -- MoP Item Level Upgrading
  104.             return itemLevel + UPGRADED_LEVEL_ADJUST[upgradeId];
  105.         elseif (itemRarity == 7) or (upgradeType == 512) then   -- Heirloom or Timewarped
  106.             return GetActualiLevel(itemString)
  107.         else
  108.             return itemLevel;
  109.         end
  110.     end
  111. end
  112.  
  113. function GetActualiLevel(itemString)
  114.     local itemLevel = CachedActualiLevel[itemString]
  115.     if itemLevel then
  116.         return itemLevel
  117.     end
  118.     if not scanningTooltip then
  119.         scanningTooltip = _G.CreateFrame("GameTooltip", "GetUpgradedItemLevelTooltip", nil, "GameTooltipTemplate")
  120.         scanningTooltip:SetOwner(_G.WorldFrame, "ANCHOR_NONE")
  121.     end
  122.     scanningTooltip:ClearLines()
  123.     scanningTooltip:SetHyperlink(itemString)
  124.     -- line 1 is the item name
  125.     -- line 2 may be the item level, or it may be a modifier like "Heroic"
  126.     -- check up to line 4 just in case
  127.     for i = 2, 4 do
  128.         itemLevel = tonumber(_G["GetUpgradedItemLevelTooltipTextLeft"..i]:GetText():match(_G.ITEM_LEVEL:match("[^%%]*").."(%d+)"))
  129.         if itemLevel then
  130.             CachedActualiLevel[itemString] = itemLevel
  131.             return itemLevel
  132.         end
  133.     end
  134. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement