Quantcast
Heirloom actual item level - WoWInterface
Thread Tools Display Modes
06-02-16, 04:37 AM   #1
Oniya
A Wyrmkin Dreamwalker
Join Date: Feb 2015
Posts: 57
Question Heirloom actual item level

If there already any more short solution, than below, or we still have to use this to get actual item level for heirloom?

Lua Code:
  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: [url]http://www.wowinterface.com/forums/showthread.php?t=45388[/url]
  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 --
  89. };
  90.  
  91. local CachedActualiLevel = { };
  92.  
  93. -- Analyses the itemString and checks for upgrades that affects itemLevel
  94. function GetUpgradedItemLevelFromItemLink(itemString)
  95.     -- Ensure we only have the raw itemString, and not the full itemLink
  96.     itemString = itemString:match(ITEMSTRING_PATTERN);
  97.     local itemName, _, itemRarity, itemLevel = GetItemInfo(itemString);
  98.     local upgradeType = tonumber(itemString:match(ITEMSTRING_PATTERN_UPGRADETYPE));
  99.     local upgradeId = tonumber(itemString:match(ITEMSTRING_PATTERN_UPGRADEID));
  100.     if itemLevel then
  101.         if (upgradeType ==4) and (UPGRADED_LEVEL_ADJUST[upgradeId]) then    -- MoP Item Level Upgrading
  102.             return itemLevel + UPGRADED_LEVEL_ADJUST[upgradeId];
  103.         elseif (itemRarity == 7) or (upgradeType == 512) then   -- Heirloom or Timewarped
  104.             return GetActualiLevel(itemString)
  105.         else
  106.             return itemLevel;
  107.         end
  108.     end
  109. end
  110.  
  111. function GetActualiLevel(itemString)
  112.     local itemLevel = CachedActualiLevel[itemString]
  113.     if itemLevel then
  114.         return itemLevel
  115.     end
  116.     if not scanningTooltip then
  117.         scanningTooltip = _G.CreateFrame("GameTooltip", "GetUpgradedItemLevelTooltip", nil, "GameTooltipTemplate")
  118.         scanningTooltip:SetOwner(_G.WorldFrame, "ANCHOR_NONE")
  119.     end
  120.     scanningTooltip:ClearLines()
  121.     scanningTooltip:SetHyperlink(itemString)
  122.     -- line 1 is the item name
  123.     -- line 2 may be the item level, or it may be a modifier like "Heroic"
  124.     -- check up to line 4 just in case
  125.     for i = 2, 4 do
  126.         itemLevel = tonumber(_G["GetUpgradedItemLevelTooltipTextLeft"..i]:GetText():match(_G.ITEM_LEVEL:match("[^%%]*").."(%d+)"))
  127.         if itemLevel then
  128.             CachedActualiLevel[itemString] = itemLevel
  129.             return itemLevel
  130.         end
  131.     end
  132. end
  Reply With Quote
06-02-16, 07:06 AM   #2
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
I'm not sure what the question or the problem is. GetItemInfo gives you the item leve.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
06-02-16, 07:16 AM   #3
Wetxius
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 7
GetItemInfo returns 1 for heirloom.
Oniya, you can look at http://www.wowinterface.com/download...yUnitInfo.html. It uses another way to calculate item level depend of unit level.
  Reply With Quote
06-02-16, 07:20 AM   #4
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Originally Posted by Wetxius View Post
GetItemInfo returns 1 for heirloom.
No, it does not. I just tried it before posting my last post.

Edit: Ok, apparently the ones from Siege of Orgrimmar works differently. They return proper item level.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
06-02-16, 01:06 PM   #5
Oniya
A Wyrmkin Dreamwalker
Join Date: Feb 2015
Posts: 57
Originally Posted by Wetxius View Post
GetItemInfo returns 1 for heirloom.
Oniya, you can look at http://www.wowinterface.com/download...yUnitInfo.html. It uses another way to calculate item level depend of unit level.
yup, it use same not "clean" way. apparently there is no better solution still :-\
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Heirloom actual item level

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off