Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Until Blizzard adds an easier solution, this function can be used to get the true upgraded itemLevel.
- The Lua file is easily portable between addons. The function is placed in the global namespace.
- Syntax:
- GetUpgradedItemLevelFromItemLink(itemLink)
- = return value is the modified itemLevel based on the item's upgrade
- Changelog:
- * REV-07 (15.09.xx) Patch 6.2.2: Updated to work with Heirlooms and Timewarped items.
- * REV-06 (14.10.15) Patch 6.0.2: Updated the pattern match for "upgradeId" to work for WoD.
- * REV-05 (14.05.24) Patch 5.4.8: Added IDs 504 to 507.
- * REV-04 (13.09.21) Patch 5.4: Added IDs 491 to 498 to the table.
- * REV-03 (13.05.22) Patch 5.3: Added the 465/466/467 IDs (0/4/8 lvls) to the table.
- * REV-02 (13.xx.xx) Patch 5.2: Added the 470 ID (8 lvls) to the table.
- --]]
- -- Make sure we do not override a newer revision.
- local REVISION = 7;
- if (type(GET_UPGRADED_ITEM_LEVEL_REV) == "number") and (GET_UPGRADED_ITEM_LEVEL_REV >= REVISION) then
- return;
- end
- GET_UPGRADED_ITEM_LEVEL_REV = REVISION;
- -- Item links data change in 6.0:
- -- itemID:enchant:gem1:gem2:gem3:gem4:suffixID:uniqueID:level:reforgeId:upgradeId
- -- itemID:enchant:gem1:gem2:gem3:gem4:suffixID:uniqueID:level:upgradeId:instanceDifficultyID:numBonusIDs:bonusID1:bonusID2
- --Item links data change in 6.2:
- -- itemID:enchant:gem1:gem2:gem3:gem4:suffixID:uniqueID:level:specID:upgradeTypeID:instanceDifficultyID:numBonusIDs:bonusID1:bonusID2:...:upgradeID
- -- Extraction pattern for the complete itemString, including all its properties
- local ITEMSTRING_PATTERN = "(item:[^|]+)";
- -- Matches the 11th property, upgradeType, of an itemString.
- local ITEMSTRING_PATTERN_UPGRADETYPE = "item:"..("[^:]+:"):rep(10).."(%d+)";
- -- Last property of an itemString
- local ITEMSTRING_PATTERN_UPGRADEID = "%d+$"
- -- Table for adjustment of levels due to upgrade -- Source: http://www.wowinterface.com/forums/showthread.php?t=45388
- local UPGRADED_LEVEL_ADJUST = {
- [001] = 8, -- 1/1
- -- Patch 5.1 --
- [373] = 4, -- 1/2
- [374] = 8, -- 2/2
- [375] = 4, -- 1/3
- [376] = 4, -- 2/3
- [377] = 4, -- 3/3
- [379] = 4, -- 1/2
- [380] = 4, -- 2/2
- -- [445] = 0, -- 0/2
- [446] = 4, -- 1/2
- [447] = 8, -- 2/2
- -- [451] = 0, -- 0/1
- [452] = 8, -- 1/1
- -- [453] = 0, -- 0/2
- [454] = 4, -- 1/2
- [455] = 8, -- 2/2
- -- [456] = 0, -- 0/1
- [457] = 8, -- 1/1
- -- [458] = 0, -- 0/4
- [459] = 4, -- 1/4
- [460] = 8, -- 2/4
- [461] = 12, -- 3/4
- [462] = 16, -- 4/4
- -- Patch 5.3 --
- -- [465] = 0,
- [466] = 4,
- [467] = 8,
- -- Patch ?? --
- -- [468] = 0,
- [469] = 4,
- [470] = 8,
- [471] = 12,
- [472] = 16,
- -- Patch 5.4 --
- -- [491] = 0,
- [492] = 4,
- [493] = 8,
- -- [494] = 0,
- [495] = 4,
- [496] = 8,
- [497] = 12,
- [498] = 16,
- -- Patch 5.4.8 --
- [504] = 12, -- US/EU upgrade 3/4
- [505] = 16, -- US/EU upgrade 4/4
- [506] = 20, -- Asia upgrade 5/6
- [507] = 24, -- Asis upgrade 6/6
- -- Patch 6.2.3 --
- [530] = 5, -- WoD upgrade 1/2
- [531] = 10, -- WoD upgrade 2/2
- };
- local CachedActualiLevel = { };
- -- Analyses the itemString and checks for upgrades that affects itemLevel
- function GetUpgradedItemLevelFromItemLink(itemString)
- -- Ensure we only have the raw itemString, and not the full itemLink
- itemString = itemString:match(ITEMSTRING_PATTERN);
- local itemName, _, itemRarity, itemLevel = GetItemInfo(itemString);
- local upgradeType = tonumber(itemString:match(ITEMSTRING_PATTERN_UPGRADETYPE));
- local upgradeId = tonumber(itemString:match(ITEMSTRING_PATTERN_UPGRADEID));
- if itemLevel then
- if (upgradeType ==4) and (UPGRADED_LEVEL_ADJUST[upgradeId]) then -- MoP Item Level Upgrading
- return itemLevel + UPGRADED_LEVEL_ADJUST[upgradeId];
- elseif (itemRarity == 7) or (upgradeType == 512) then -- Heirloom or Timewarped
- return GetActualiLevel(itemString)
- else
- return itemLevel;
- end
- end
- end
- function GetActualiLevel(itemString)
- local itemLevel = CachedActualiLevel[itemString]
- if itemLevel then
- return itemLevel
- end
- if not scanningTooltip then
- scanningTooltip = _G.CreateFrame("GameTooltip", "GetUpgradedItemLevelTooltip", nil, "GameTooltipTemplate")
- scanningTooltip:SetOwner(_G.WorldFrame, "ANCHOR_NONE")
- end
- scanningTooltip:ClearLines()
- scanningTooltip:SetHyperlink(itemString)
- -- line 1 is the item name
- -- line 2 may be the item level, or it may be a modifier like "Heroic"
- -- check up to line 4 just in case
- for i = 2, 4 do
- itemLevel = tonumber(_G["GetUpgradedItemLevelTooltipTextLeft"..i]:GetText():match(_G.ITEM_LEVEL:match("[^%%]*").."(%d+)"))
- if itemLevel then
- CachedActualiLevel[itemString] = itemLevel
- return itemLevel
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement