You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
58 KiB

5 years ago
--[[
GetDetailedItemLevelInfo Polyfill, v 1.0
by Erorus for The Undermine Journal
https://theunderminejournal.com/
Based on these "specs" for a GetDetailedItemLevelInfo function coming in 7.1
https://www.reddit.com/r/woweconomy/comments/50hp5d/warning_be_careful_flipping/d74olsy
Pass in an itemstring/link to GetDetailedItemLevelInfo
Returns effectiveItemLevel, previewItemLevel, baseItemLevel
This should use the in-game function if it already exists,
otherwise it'll define a function that does what *I think* the official function would do.
]]
local addonName, addonTable = ...
local bonusLevelBoost = {[15]=4,[44]=1,[171]=2,[448]=2,[449]=3,[450]=4,[451]=-3,[497]=50,[499]=1,[526]=1,[527]=2,[545]=2,[546]=1,[547]=1,[558]=1,[559]=2,[560]=1,[561]=1,[562]=1,[566]=1,[567]=2,[571]=1,[575]=4,[576]=6,[577]=2,[591]=4,[592]=5,[593]=3,[594]=3,[595]=2,[596]=-4,[597]=-3,[598]=-2,[599]=-1,[609]=8,[617]=4,[618]=6,[619]=4,[620]=6,[622]=1,[623]=2,[624]=3,[625]=4,[626]=5,[627]=6,[628]=7,[629]=8,[630]=9,[631]=10,[632]=11,[633]=12,[634]=13,[635]=14,[636]=15,[637]=16,[638]=17,[639]=18,[640]=19,[641]=20,[644]=4,[646]=6,[648]=5,[651]=3,[665]=3,[666]=0,[667]=1,[668]=2,[669]=3,[670]=1,[671]=2,[672]=3,[673]=4,[674]=5,[675]=6,[676]=7,[677]=8,[678]=9,[679]=10,[680]=20,[681]=22,[682]=24,[694]=15,[695]=30,[696]=45,[697]=60,[698]=75,[699]=100,[700]=5,[701]=10,[702]=3,[703]=6,[704]=12,[706]=30,[707]=15,[708]=2,[709]=4,[710]=14,[754]=1,[755]=2,[756]=3,[757]=5,[758]=6,[759]=7,[760]=8,[761]=2,[762]=3,[763]=4,[764]=6,[765]=7,[766]=8,[769]=5,[1372]=-100,[1373]=-99,[1374]=-98,[1375]=-97,[1376]=-96,[1377]=-95,[1378]=-94,[1379]=-93,[1380]=-92,[1381]=-91,[1382]=-90,[1383]=-89,[1384]=-88,[1385]=-87,[1386]=-86,[1387]=-85,[1388]=-84,[1389]=-83,[1390]=-82,[1391]=-81,[1392]=-80,[1393]=-79,[1394]=-78,[1395]=-77,[1396]=-76,[1397]=-75,[1398]=-74,[1399]=-73,[1400]=-72,[1401]=-71,[1402]=-70,[1403]=-69,[1404]=-68,[1405]=-67,[1406]=-66,[1407]=-65,[1408]=-64,[1409]=-63,[1410]=-62,[1411]=-61,[1412]=-60,[1413]=-59,[1414]=-58,[1415]=-57,[1416]=-56,[1417]=-55,[1418]=-54,[1419]=-53,[1420]=-52,[1421]=-51,[1422]=-50,[1423]=-49,[1424]=-48,[1425]=-47,[1426]=-46,[1427]=-45,[1428]=-44,[1429]=-43,[1430]=-42,[1431]=-41,[1432]=-40,[1433]=-39,[1434]=-38,[1435]=-37,[1436]=-36,[1437]=-35,[1438]=-34,[1439]=-33,[1440]=-32,[1441]=-31,[1442]=-30,[1443]=-29,[1444]=-28,[1445]=-27,[1446]=-26,[1447]=-25,[1448]=-24,[1449]=-23,[1450]=-22,[1451]=-21,[1452]=-20,[1453]=-19,[1454]=-18,[1455]=-17,[1456]=-16,[1457]=-15,[1458]=-14,[1459]=-13,[1460]=-12,[1461]=-11,[1462]=-10,[1463]=-9,[1464]=-8,[1465]=-7,[1466]=-6,[1467]=-5,[1468]=-4,[1469]=-3,[1470]=-2,[1471]=-1,[1472]=0,[1473]=1,[1474]=2,[1475]=3,[1476]=4,[1477]=5,[1478]=6,[1479]=7,[1480]=8,[1481]=9,[1482]=10,[1483]=11,[1484]=12,[1485]=13,[1486]=14,[1487]=15,[1488]=16,[1489]=17,[1490]=18,[1491]=19,[1492]=20,[1493]=21,[1494]=22,[1495]=23,[1496]=24,[1497]=25,[1498]=26,[1499]=27,[1500]=28,[1501]=29,[1502]=30,[1503]=31,[1504]=32,[1505]=33,[1506]=34,[1507]=35,[1508]=36,[1509]=37,[1510]=38,[1511]=39,[1512]=40,[1513]=41,[1514]=42,[1515]=43,[1516]=44,[1517]=45,[1518]=46,[1519]=47,[1520]=48,[1521]=49,[1522]=50,[1523]=51,[1524]=52,[1525]=53,[1526]=54,[1527]=55,[1528]=56,[1529]=57,[1530]=58,[1531]=59,[1532]=60,[1533]=61,[1534]=62,[1535]=63,[1536]=64,[1537]=65,[1538]=66,[1539]=67,[1540]=68,[1541]=69,[1542]=70,[1543]=71,[1544]=72,[1545]=73,[1546]=74,[1547]=75,[1548]=76,[1549]=77,[1550]=78,[1551]=79,[1552]=80,[1553]=81,[1554]=82,[1555]=83,[1556]=84,[1557]=85,[1558]=86,[1559]=87,[1560]=88,[1561]=89,[1562]=90,[1563]=91,[1564]=92,[1565]=93,[1566]=94,[1567]=95,[1568]=96,[1569]=97,[1570]=98,[1571]=99,[1572]=100,[1573]=101,[1574]=102,[1575]=103,[1576]=104,[1577]=105,[1578]=106,[1579]=107,[1580]=108,[1581]=109,[1582]=110,[1583]=111,[1584]=112,[1585]=113,[1586]=114,[1587]=115,[1588]=116,[1589]=117,[1590]=118,[1591]=119,[1592]=120,[1593]=121,[1594]=122,[1595]=123,[1596]=124,[1597]=125,[1598]=126,[1599]=127,[1600]=128,[1601]=129,[1602]=130,[1603]=131,[1604]=132,[1605]=133,[1606]=134,[1607]=135,[1608]=136,[1609]=137,[1610]=138,[1611]=139,[1612]=140,[1613]=141,[1614]=142,[1615]=143,[1616]=144,[1617]=145,[1618]=146,[1619]=147,[1620]=148,[1621]=149,[1622]=150,[1623]=151,[1624]=152,[1625]=153,[1626]=154,[1627]=155,[1628]=156,[1629]=157,[1630]=158,[1631]=159,[1632]=160,[1633]=161,[1634]=162,[1635]=163,[1636]=164,[1637]=165,[1638]=166,[1639]=167,[1640]=168,[1641]=169,[1642]=170,[1643]=171,[1644]=172,[1645]=173,[1646]=174,[1647]=175,[1648]=176,[1649]=177,[1650]=178,[1651]=179,[1652]=180,[1653]=181,[1654]=182,[1655]=183,[1656]=184,[1657]=185,[1658]=186,[1659]=187,[1660]=188,[1661]=189,[1662]=190,[1663]=191,[1664]=192,[1665]=193,[1666]=194,[1667]=195,[1668]=196,[1
local bonusPreviewLevel = {[1726]=845,[1727]=865,[1798]=705,[1799]=720,[1801]=690,[1805]=865,[1806]=880,[1807]=850,[1824]=0,[1825]=0,[1826]=825,[3379]=835,[3394]=0,[3395]=0,[3396]=0,[3397]=0,[3399]=840,[3410]=870,[3411]=870,[3412]=875,[3413]=875,[3414]=880,[3415]=880,[3416]=885,[3417]=885,[3418]=890,[3427]=805,[3428]=840,[3432]=0,[3437]=830,[3443]=870,[3444]=885,[3445]=900,[3446]=855,[3449]=850,[3450]=860,[3451]=865,[3452]=855,[3453]=860,[3454]=875,[3457]=810,[3460]=810,[3461]=815,[3462]=855,[3463]=865,[3464]=875,[3465]=885,[3466]=860,[3467]=860,[3468]=875,[3469]=890,[3470]=845,[3473]=0,[3474]=0,[3476]=870,[3477]=875,[3478]=880,[3479]=890,[3480]=900,[3481]=880,[3482]=815,[3483]=820,[3484]=825,[3485]=830,[3486]=835,[3487]=820,[3488]=825,[3489]=830,[3490]=835,[3491]=840,[3505]=850,[3506]=865,[3507]=880,[3508]=895,[3509]=895,[3510]=895,[3514]=875,[3515]=880,[3516]=890,[3517]=895,[3518]=905,[3519]=910,[3520]=860,[3521]=865,[3534]=900,[3535]=905,[3536]=910,[3561]=870,[3562]=885,[3563]=900,[3564]=855,[3565]=810,[3566]=810,[3567]=810,[3568]=810,[3572]=0,[3575]=855,[3576]=855,[3577]=855,[3579]=810,[3580]=810,[3581]=810,[3582]=810,[3583]=810,[3584]=810,[3610]=870,[3611]=885,[3612]=900,[3613]=855,[3614]=860,[5119]=0,[5479]=0,}
local bonusLevelCurve = {[615]=2794,[645]=3157,[656]=3157,[664]=1648,[692]=1617,[767]=1558,[768]=1688,[1723]=1746,[1724]=1748,[1725]=1749,[1729]=1751,[1730]=1752,[1731]=1753,[1732]=1648,[1733]=1758,[1734]=1759,[1735]=1759,[1736]=1756,[1737]=1757,[1738]=1757,[1739]=1760,[1740]=1761,[1741]=1761,[1788]=1787,[1789]=1788,[1790]=1789,[1791]=1790,[1792]=1756,[1793]=1760,[1794]=1758,[1795]=5449,[1796]=1824,[1812]=2002,[3342]=2202,[3380]=2196,[3387]=2208,[3388]=2209,[3389]=2210,[3398]=2247,[3448]=2466,[3502]=2794,[3578]=3039,[3585]=3157,[3589]=3170,[3590]=3171,[3596]=2794,[3621]=4801,[3622]=3171,[3623]=4242,[3624]=4243,[3625]=4244,[3626]=4245,[3627]=4246,[3628]=4242,[3631]=5063,[3632]=3039,[3633]=5063,[3634]=5063,[3635]=5063,[3636]=5063,[3637]=5063,[3638]=5063,[3639]=5063,[3640]=5063,[3641]=5063,[3642]=5063,[3643]=5063,[3644]=5063,[3645]=5063,[3646]=5063,[3647]=5063,[3648]=5063,[3649]=5063,[3650]=5063,[3651]=5063,[3652]=5063,[3653]=5063,[3654]=5063,[3655]=5063,[3656]=5063,[3657]=5063,[3658]=5063,[3659]=5063,[3660]=5063,[3661]=5063,[3662]=5063,[3663]=5063,[3664]=5063,[3665]=5063,[3666]=5063,[3667]=5063,[3668]=5063,[3669]=5063,[3670]=5063,[3671]=5063,[3672]=5063,[3673]=5063,[3674]=5063,[3675]=5063,[3676]=5063,[3677]=5063,[3678]=5063,[3679]=5063,[3680]=5063,[3681]=5063,[3682]=5063,[3683]=5063,[3684]=5063,[3685]=5063,[3686]=5063,[3687]=5063,[3688]=5063,[3689]=5063,[3690]=5063,[3691]=5063,[3692]=5063,[3693]=5063,[3694]=5063,[3695]=5063,[3696]=5063,[3697]=5063,[3698]=5063,[3699]=5063,[3700]=5063,[3701]=5063,[3702]=5063,[3703]=5063,[3704]=5063,[3705]=5063,[3706]=5063,[3707]=5063,[3708]=5063,[3709]=5063,[3710]=5063,[3711]=5063,[3712]=5064,[3713]=5064,[3714]=5064,[3715]=5064,[3716]=5064,[3717]=5064,[3718]=5064,[3719]=5064,[3720]=5064,[3721]=5064,[3722]=5064,[3723]=5064,[3724]=5064,[3725]=5064,[3726]=5064,[3727]=5064,[3728]=5064,[3729]=5064,[3730]=5064,[3731]=5064,[3732]=5064,[3733]=5064,[3734]=5064,[3735]=5064,[3736]=5064,[3737]=5064,[3738]=5064,[3739]=5064,[3740]=5064,[3741]=5064,[3742]=5064,[3743]=5064,[3744]=5064,[3745]=5064,[3746]=5064,[3747]=5064,[3748]=5064,[3749]=5064,[3750]=5064,[3751]=5064,[3752]=5064,[3753]=5064,[3754]=5064,[3755]=5064,[3756]=5064,[3757]=5064,[3758]=5064,[3759]=5064,[3760]=5064,[3761]=5064,[3762]=5064,[3763]=5064,[3764]=5064,[3765]=5064,[3766]=5064,[3767]=5064,[3768]=5064,[3769]=5064,[3770]=5064,[3771]=5064,[3772]=5064,[3773]=5064,[3774]=5064,[3775]=5064,[3776]=5064,[3777]=17258,[3778]=5064,[3779]=5064,[3780]=5064,[3781]=5064,[3782]=5064,[3783]=5064,[3784]=5064,[3785]=5064,[3786]=5064,[3787]=5064,[3788]=5064,[3789]=5064,[3790]=5064,[3791]=5063,[3792]=5064,[3793]=5063,[3794]=5063,[3795]=5063,[3796]=5063,[3797]=5063,[3798]=5063,[3799]=5063,[3800]=5063,[3801]=5063,[3802]=5063,[3803]=5063,[3804]=5086,[3805]=5086,[3806]=5086,[3807]=5091,[3808]=5100,[3809]=5099,[3810]=5098,[3811]=5097,[3812]=5096,[3813]=5095,[3814]=5094,[3815]=5093,[3816]=5092,[3817]=5101,[3818]=5102,[3819]=5103,[3820]=5086,[3821]=5086,[3823]=5086,[3828]=5234,[3829]=5235,[3830]=5236,[3831]=5237,[3832]=5238,[3833]=5239,[3834]=5240,[3835]=5241,[3836]=5242,[3837]=5243,[3838]=5244,[3839]=5245,[3840]=5273,[3841]=5274,[3842]=5278,[3843]=5282,[3844]=5286,[3845]=5292,[3846]=5296,[3847]=5300,[3848]=5304,[3849]=5277,[3850]=5281,[3851]=6033,[3852]=5291,[3853]=5295,[3854]=5299,[3855]=6093,[3856]=5307,[3857]=5246,[3858]=5247,[3859]=5248,[3860]=5249,[3861]=5250,[3862]=5251,[3863]=5252,[3864]=5253,[3865]=5254,[3866]=5255,[3867]=5256,[3868]=5257,[3869]=5258,[3870]=5276,[3871]=5280,[3872]=6035,[3873]=6036,[3874]=5294,[3875]=5298,[3876]=6091,[3877]=5306,[3878]=5259,[3879]=5260,[3880]=5261,[3881]=5262,[3882]=5263,[3883]=5264,[3884]=5265,[3885]=5266,[3886]=5267,[3887]=5268,[3888]=5270,[3889]=5271,[3890]=5272,[3891]=5275,[3892]=5279,[3893]=5283,[3894]=5289,[3895]=5293,[3896]=5297,[3897]=5301,[3898]=5305,[3899]=5309,[3900]=5310,[3901]=5312,[3902]=5313,[3903]=5314,[3904]=5315,[3905]=5318,[3906]=5319,[3907]=5320,[3908]=5321,[3909]=5322,[3910]=5323,[3911]=5324,[3912]=6029,[3913]=5326,[3914]=5327,[3915]=5328,[3916]=6153,[3917]=5330,[3918]=5331,[3919]=5332,[3920]=5333,[3921]=5
local curvePoints = {[1558]={{32,36},{39,43},{40,44},{42,47},{43,48},{44,49},},[1617]={{1,5},{3,5},{24,29},{24,30},{26,32},{27,33},{30,35},{30,36},{32,37},{33,38},{35,39},{35,42},{38,44},{39,44},{40,44},{40,45},{44,49},{45,50},},[1648]={{32,36},{39,44},{40,45},{42,47},{43,49},{44,50},},[1688]={{32,36},{39,45},{40,45},{42,48},{43,49},{44,50},},[1746]={{1,3},{25,31},{26,31},{27,32},{28,33},{31,37},{32,37},{39,45},{40,45},{42,48},{43,49},{44,50},{45,50},{46,50},{49,56},{50,56},{51,90},{59,138},{60,138},{70,138},},[1748]={{1,6},{25,31},{26,32},{27,33},{28,34},{31,38},{32,39},{39,46},{40,47},{42,50},{43,50},{44,50},{45,50},{46,51},{49,57},{50,57},{51,98},{59,146},{60,146},{70,146},},[1749]={{1,11},{25,32},{26,33},{27,33},{28,35},{31,40},{32,40},{39,48},{40,49},{42,50},{43,50},{44,50},{45,50},{46,52},{49,58},{50,58},{51,110},{59,158},{60,158},{70,158},},[1751]={{650,0},{689,0},{690,1},{691,0},{850,0},},[1752]={{650,0},{809,0},{810,1},{811,0},{850,0},},[1753]={{37,1},{40,6},{44,12},{45,12},{47,18},},[1756]={{32,37},{39,46},{40,46},{42,49},{43,50},{44,50},},[1757]={{32,39},{39,47},{40,48},{42,50},{43,50},{44,50},},[1758]={{32,37},{39,45},{40,46},{42,48},{43,50},{44,50},},[1759]={{32,39},{39,47},{40,48},{42,50},{43,50},{44,50},},[1760]={{32,37},{39,46},{40,47},{42,50},{43,50},{44,50},},[1761]={{32,39},{39,48},{40,49},{42,50},{43,50},{44,50},},[1787]={{1,5},{3,5},{17,22},},[1788]={{1,5},{3,6},{17,24},},[1789]={{1,5},{3,8},{17,25},},[1790]={{1,5},{3,5},{24,29},},[1824]={{39,42},{39,44},{40,44},{44,49},},[2002]={{39,44},{40,44},{44,49},},[2196]={{1,5},{3,5},{24,28},{24,29},{26,30},{27,32},{30,35},{32,37},{33,37},{35,39},{35,40},{38,43},{39,43},{39,44},{40,44},},[2202]={{39,44},{40,44},{44,47},},[2208]={{1,5},{3,5},{24,29},{26,31},{27,32},{30,35},{32,37},{33,37},{35,39},{35,41},{38,44},{39,44},{40,45},{45,45},},[2209]={{1,5},{3,8},{24,29},{24,30},{26,32},{27,33},{30,35},{32,37},{33,37},{35,39},{35,41},{38,44},{39,44},{40,46},{45,46},},[2210]={{1,5},{3,12},{24,29},{24,30},{26,32},{27,33},{30,35},{30,36},{32,37},{33,38},{35,39},{35,42},{38,44},{39,44},{39,45},{40,46},{45,46},},[2247]={{38,39},{39,47},{44,50},},[2466]={{1,5},{3,5},{24,28},{24,29},{26,30},{27,32},{30,35},{32,37},{33,37},{35,39},{35,40},{38,43},{39,43},{39,44},{40,44},{44,48},{45,50},},[2794]={{1,5},{3,5},{24,29},{26,31},{27,32},{30,35},{32,37},{33,37},{35,39},{35,41},{38,43},{39,44},{40,44},{40,46},{44,50},{45,50},},[3039]={{1,5},{5,5},{10,11},{23,28},{24,29},{26,31},{27,32},{30,35},{32,37},{33,37},{35,39},{35,41},{38,44},{39,44},{40,45},{45,50},{50,58},{51,75},{60,144},},[3157]={{1,5},{3,9},{24,29},{24,30},{26,32},{27,33},{30,35},{32,37},{33,37},{35,39},{35,41},{38,44},{39,44},{40,44},{40,47},{44,50},{45,50},},[3170]={{1,5},{3,5},{24,29},{26,31},{27,32},{30,35},{32,37},{33,37},{35,39},{35,41},{38,43},{39,44},{40,44},{40,46},{44,50},{45,50},},[3171]={{1,5},{3,9},{24,29},{24,30},{26,32},{27,33},{30,35},{32,37},{33,37},{35,39},{35,41},{38,44},{39,44},{40,44},{40,47},{44,50},{45,50},},[4242]={{1,5},{3,5},{24,29},{26,31},{27,32},{30,35},{32,37},{33,37},{35,39},{35,41},{38,43},{39,44},{40,44},{40,46},{44,50},{45,50},},[4243]={{1,5},{3,9},{24,29},{24,30},{26,32},{27,33},{30,35},{32,37},{33,37},{35,39},{35,41},{38,44},{39,44},{40,44},{40,47},{44,50},{45,50},},[4244]={{1,5},{3,5},{24,29},{26,31},{27,32},{30,35},{32,37},{33,37},{35,39},{35,41},{38,43},{39,44},{40,44},{40,46},{44,50},{45,50},},[4245]={{1,5},{3,9},{24,29},{24,30},{26,32},{27,33},{30,35},{32,37},{33,37},{35,39},{35,41},{38,44},{39,44},{40,44},{40,47},{44,50},{45,52},},[4246]={{1,5},{3,5},{24,29},{24,30},{26,32},{27,33},{30,35},{30,36},{32,37},{33,38},{35,39},{35,42},{38,44},{39,44},{40,44},{40,45},{44,49},{45,50},},[4801]={{1,5},{3,5},{24,29},{26,31},{27,32},{30,35},{32,37},{33,37},{35,39},{35,41},{38,43},{39,44},{40,44},{40,46},{44,50},{45,50},},[5063]={{1,1},{25,30},{26,30},{27,31},{28,32},{31,35},{32,36},{39,43},{40,44},{42,47},{43,48},{44,49},{45,50},{46,51},{49,58},{50,58},{70,58},},[5064]={{1,3},{25,31},{26,31},{27,32},{28,33},{31,37},{32,37},{39,45},{40,46},{42,48},{43,50},{44,50},{45,50},{46,52},{49,58},{50
local function round(num)
return floor(num + 0.5)
end
local function GetCurvePoint(curveId, point)
local curve = curvePoints[curveId]
if not curve then
return nil
end
local lastKey, lastValue = curve[1][1], curve[1][2]
if lastKey > point then
return lastValue
end
for x = 1,#curve,1 do
if point == curve[x][1] then
return curve[x][2]
end
if point < curve[x][1] then
return round((curve[x][2] - lastValue) / (curve[x][1] - lastKey) * (point - lastKey) + lastValue)
end
lastKey = curve[x][1]
lastValue = curve[x][2]
end
return lastValue
end
addonTable.GetDetailedItemLevelInfo = function(item)
local _, link, _, origLevel = GetItemInfo(item)
if not link then
return nil, nil, nil
end
local itemString = string.match(link, "item[%-?%d:]+")
local itemStringParts = { strsplit(":", itemString) }
local numBonuses = tonumber(itemStringParts[14],10) or 0
if numBonuses == 0 then
return origLevel, nil, origLevel
end
local effectiveLevel, previewLevel, curve
effectiveLevel = origLevel
previewLevel = 0
for y = 1,numBonuses,1 do
local bonus = tonumber(itemStringParts[14+y],10) or 0
origLevel = origLevel - (bonusLevelBoost[bonus] or 0)
previewLevel = bonusPreviewLevel[bonus] or previewLevel
curve = bonusLevelCurve[bonus] or curve
end
if curve and itemStringParts[12] == "512" then
effectiveLevel = GetCurvePoint(curve, tonumber(itemStringParts[15+numBonuses],10)) or effectiveLevel
end
return effectiveLevel, previewLevel, origLevel
end