SHARE
TWEET

GetUpgradedItemLevel.lua

a guest Dec 30th, 2015 146 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.         = (number) return value is the modified itemLevel based on the item's upgrade
  7.         = (nil) invalid input
  8.     Changelog:
  9.     * REV-08 (15.09.08) Patch 6.2.3:    Added patterns, tables, etc for Timewarped and Timewarped Warforged items to work. (Cidrei)
  10.     * REV-07 (15.07.02) Patch 6.2:      A new field in the item string was added "specializationID", pushing the "upgradeId" field to the 11th place.
  11.     * REV-06 (14.10.15) Patch 6.0.2:    Updated the pattern match for "upgradeId" to work for WoD.
  12.     * REV-05 (14.05.24) Patch 5.4.8:    Added IDs 504 to 507.
  13.     * REV-04 (13.09.21) Patch 5.4:      Added IDs 491 to 498 to the table.
  14.     * REV-03 (13.05.22) Patch 5.3:      Added the 465/466/467 IDs (0/4/8 lvls) to the table.
  15.     * REV-02 (13.xx.xx) Patch 5.2:      Added the 470 ID (8 lvls) to the table.
  16. --]]
  17.  
  18. -- Make sure we do not override a newer revision. NOTE: Make sure to ALWAYS increase the REVISION number when changing code
  19. local REVISION = 8;
  20. if (type(GET_UPGRADED_ITEM_LEVEL_REV) == "number") and (GET_UPGRADED_ITEM_LEVEL_REV >= REVISION) then
  21.     return;
  22. end
  23. GET_UPGRADED_ITEM_LEVEL_REV = REVISION;
  24.  
  25. --[[
  26.     [Item links data change in 6.0, WoD]
  27.         itemID:enchant:gem1:gem2:gem3:gem4:suffixID:uniqueID:level:reforgeId:upgradeId
  28.         itemID:enchant:gem1:gem2:gem3:gem4:suffixID:uniqueID:level:upgradeId:instanceDifficultyID:numBonusIDs:bonusID1:bonusID2
  29.     [ItemLinks in 6.2 -- Added: 10th param, specializationID]
  30.         itemID:enchant:gem1:gem2:gem3:gem4:suffixID:uniqueID:level:specializationID:upgradeId:instanceDifficultyID:numBonusIDs:bonusID1:bonusID2
  31.     [ItemLinks in 6.2.x -- Added: numBonusIDs? -- The number of bonus IDs are now dynamic, the 13th parameter tells how many there are -- Total Count (???): 14 + numBonusIDs (???)]
  32.         itemID:enchant:gemID1:gemID2:gemID3:gemID4:suffixID:uniqueID:linkLevel:specializationID:upgradeTypeID:instanceDifficultyID:numBonusIDs:bonusID1:bonusID2:...:upgradeID
  33. --]]
  34.  
  35. -- Extraction pattern for the complete itemLink, including all its properties
  36. local ITEMLINK_PATTERN = "(item:[^|]+)";
  37. -- Matches the 11th property, upgradeId, of an itemLink. This pattern now scans from the start of the itemLink to make it future-proof with further property additions to itemLinks.
  38. local ITEMLINK_PATTERN_UPGRADE = "item:"..("[^:]+:"):rep(10).."(%d+)";
  39. -- Matches the 14th property, which is used for Timewarped items.
  40. local ITEMLINK_PATTERN_TIMEWARP = "item:"..("[^:]+:"):rep(13).."(%d+)";
  41. -- Matches the 15th property, which is used for Timewarped Warforged items.
  42. local ITEMLINK_PATTERN_TWWF = "item:"..("[^:]+:"):rep(14).."(%d+)";
  43. -- Last property of an itemString
  44. local ITEMLINK_PATTERN_UPGRADEID = "%d+$"
  45.  
  46. -- Table for adjustment of levels due to upgrade -- Source: http://www.wowinterface.com/forums/showthread.php?t=45388
  47. local UPGRADED_LEVEL_ADJUST = {
  48.     [001] = 8, -- 1/1
  49.     -- Patch 5.1 --
  50.     [373] = 4, -- 1/2
  51.     [374] = 8, -- 2/2
  52.     [375] = 4, -- 1/3
  53.     [376] = 4, -- 2/3
  54.     [377] = 4, -- 3/3
  55.     [379] = 4, -- 1/2
  56.     [380] = 4, -- 2/2
  57. --  [445] = 0, -- 0/2
  58.     [446] = 4, -- 1/2
  59.     [447] = 8, -- 2/2
  60. --  [451] = 0, -- 0/1
  61.     [452] = 8, -- 1/1
  62. --  [453] = 0, -- 0/2
  63.     [454] = 4, -- 1/2
  64.     [455] = 8, -- 2/2
  65. --  [456] = 0, -- 0/1
  66.     [457] = 8, -- 1/1
  67. --  [458] = 0, -- 0/4
  68.     [459] = 4, -- 1/4
  69.     [460] = 8, -- 2/4
  70.     [461] = 12, -- 3/4
  71.     [462] = 16, -- 4/4
  72.     -- Patch 5.3 --
  73. --  [465] = 0,
  74.     [466] = 4,
  75.     [467] = 8,
  76.     -- Patch ?? --
  77. --  [468] = 0,
  78.     [469] = 4,
  79.     [470] = 8,
  80.     [471] = 12,
  81.     [472] = 16,
  82.     -- Patch 5.4 --
  83. --  [491] = 0,
  84.     [492] = 4,
  85.     [493] = 8,
  86. --  [494] = 0,
  87.     [495] = 4,
  88.     [496] = 8,
  89.     [497] = 12,
  90.     [498] = 16,
  91.     -- Patch 5.4.8 --
  92.     [504] = 12, -- US/EU upgrade 3/4
  93.     [505] = 16, -- US/EU upgrade 4/4
  94.     [506] = 20, -- Asia upgrade 5/6
  95.     [507] = 24, -- Asis upgrade 6/6
  96.     -- Patch 6.2.3 --
  97.     [530] = 5,  -- WoD upgrade 1/2
  98.     [531] = 10, -- WoD upgrade 2/2
  99. };
  100.  
  101. -- Table for adjustment of levels due to Timewarped. These are fixed itemLevels, not upgrade amounts.
  102. local TIMEWARPED_LEVEL_ADJUST = {
  103.     -- Patch 6.2 --
  104.     [615] = 660, -- Dungeon drops.
  105.     [692] = 675, -- Timewarped badge vendors.
  106. };
  107.  
  108. -- Table for adjustment of levels due to Timewarped Warforged. These are fixed itemLevels, not upgrade amounts.
  109. local TIMEWARPED_WARFORGED_LEVEL_ADJUST = {
  110.     -- Patch 6.2 --
  111.     [656] = 675, -- Dungeon drops.
  112. };
  113.  
  114. -- Analyses the itemLink and checks for upgrades that affects itemLevel -- Only itemLevel 450 and above will have this
  115. function GetUpgradedItemLevelFromItemLink(itemLink)
  116.        
  117.     -- Ensure we only have the raw itemLink, and not the full itemString
  118.     itemLink = itemLink:match(ITEMLINK_PATTERN);
  119.     local name, _, _, itemLevel = GetItemInfo(itemLink);
  120.     --local upgradeId = tonumber(itemLink:match(ITEMLINK_PATTERN_UPGRADE));
  121.     local upgradeId = tonumber(itemLink:match(ITEMLINK_PATTERN_UPGRADEID));
  122.            
  123.     local tw = tonumber(itemLink:match(ITEMLINK_PATTERN_TIMEWARP));
  124.     local twwf = tonumber(itemLink:match(ITEMLINK_PATTERN_TWWF));
  125.     -- Return the actual itemLevel based on the itemLink properties
  126.     if not (itemLevel) then
  127.         return nil;
  128.     elseif (itemLevel >= 450) and (upgradeId) and (UPGRADED_LEVEL_ADJUST[upgradeId]) then
  129.         return itemLevel + UPGRADED_LEVEL_ADJUST[upgradeId];
  130.     elseif (TIMEWARPED_WARFORGED_LEVEL_ADJUST[twwf]) then
  131.         return TIMEWARPED_WARFORGED_LEVEL_ADJUST[twwf];
  132.     elseif (TIMEWARPED_LEVEL_ADJUST[tw]) then
  133.         return TIMEWARPED_LEVEL_ADJUST[tw];
  134.     else
  135.         return itemLevel;
  136.     end
  137. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top