@@ -1479,18 +1479,80 @@ function ItemsTabClass:DeleteItem(item, deferUndoState)
14791479 end
14801480end
14811481
1482+ local function isAnointable (item )
1483+ return (item .canBeAnointed or item .base .type == " Amulet" )
1484+ end
1485+
1486+ local function isAugmentable (item )
1487+ return (item .sockets and # item .sockets > 0 ) or (item .base .socketLimit and item .base .socketLimit > 0 )
1488+ end
1489+
1490+ function ItemsTabClass :copyAnointsAndAugments (newItem , copyAugments , overwrite , sourceSlotName )
1491+ local isWeapon = newItem .base .tags and (newItem .base .tags .onehand or newItem .base .tags .twohand )
1492+ local isShield = newItem .base .tags and (newItem .base .tags .shield or newItem .base .tags .focus )
1493+ local newItemType = sourceSlotName or (isWeapon and " Weapon 1" ) or (isShield and " Weapon 2" ) or newItem .base .type
1494+ -- tabula rasa has jewel sockets which don't apply here
1495+ if newItem .name == " Tabula Rasa, Garment" then return end
1496+ if self .activeItemSet [newItemType ] then
1497+ local currentItem = self .activeItemSet [newItemType ].selItemId and self .items [self .activeItemSet [newItemType ].selItemId ]
1498+ -- if you don't have an equipped item that matches the type of the newItem, no need to do anything
1499+ if currentItem then
1500+ local modifiableItem = not (newItem .corrupted or newItem .mirrored or newItem .sanctified )
1501+ -- if the new item is anointable and does not have an anoint and your current respective item does, apply that anoint to the new item
1502+ if isAnointable (newItem ) and (# newItem .enchantModLines == 0 or overwrite ) and self .activeItemSet [newItemType ].selItemId > 0 and modifiableItem then
1503+ local currentAnoint = currentItem .enchantModLines
1504+ newItem .enchantModLines = currentAnoint
1505+ end
1506+
1507+ -- https://www.poe2wiki.net/wiki/Augment_socket
1508+ -- augments, given there are enough sockets
1509+
1510+ local hasEmptySockets = true
1511+ for i = 1 , # newItem .runes do
1512+ if newItem .runes [i ] ~= " None" then
1513+ hasEmptySockets = false
1514+ break
1515+ end
1516+ end
1517+ local shouldChangeAugments = copyAugments and isAugmentable (newItem ) and
1518+ (# newItem .runes == 0 or hasEmptySockets or overwrite )
1519+
1520+ -- current runes sans "None"
1521+ local currentRunes = {}
1522+ for i = 1 , # currentItem .runes do
1523+ if currentItem .runes [i ] ~= " None" then
1524+ table.insert (currentRunes , currentItem .runes [i ])
1525+ end
1526+ end
1527+ -- add sockets, if necessary and possible
1528+ if shouldChangeAugments and isAugmentable (newItem ) and modifiableItem and # newItem .sockets < # currentItem .sockets then
1529+ local maxSockets = modifiableItem and math.min (# currentItem .sockets , newItem .base .socketLimit )
1530+ local neededSockets = math.max (0 , maxSockets - # newItem .sockets )
1531+ for i = 1 , neededSockets do
1532+ table.insert (newItem .runes , " None" )
1533+ table.insert (newItem .sockets , { group = # newItem .sockets + 1 })
1534+ end
1535+ newItem .itemSocketCount = # newItem .sockets
1536+ newItem :UpdateRunes ()
1537+ end
1538+ -- replace runes with current ones, or set to none
1539+ if shouldChangeAugments then
1540+ for i = 1 , # newItem .sockets do
1541+ newItem .runes [i ] = currentRunes [i ] or " None"
1542+ end
1543+ newItem :UpdateRunes ()
1544+ end
1545+
1546+ newItem :BuildAndParseRaw ()
1547+ end
1548+ end
1549+ end
1550+
14821551-- Attempt to create a new item from the given item raw text and sets it as the new display item
14831552function ItemsTabClass :CreateDisplayItemFromRaw (itemRaw , normalise )
14841553 local newItem = new (" Item" , itemRaw )
14851554 if newItem .base then
1486- -- if the new item is an amulet and does not have an anoint and your current amulet does, apply that anoint to the new item
1487- if newItem .base .type == " Amulet" and # newItem .enchantModLines == 0 and self .activeItemSet [" Amulet" ].selItemId > 0 then
1488- local currentAnoint = self .items [self .activeItemSet [" Amulet" ].selItemId ].enchantModLines
1489- if currentAnoint and # currentAnoint == 1 then -- skip if amulet has more than one anoint e.g. Stranglegasp
1490- newItem .enchantModLines = currentAnoint
1491- newItem :BuildAndParseRaw ()
1492- end
1493- end
1555+ self :copyAnointsAndAugments (newItem , main .migrateAugments , false )
14941556 if normalise then
14951557 newItem :NormaliseQuality ()
14961558 newItem :BuildModList ()
@@ -3375,49 +3437,108 @@ function ItemsTabClass:AddItemTooltip(tooltip, item, slot, dbMode)
33753437 t_insert (compareSlots , slot )
33763438 end
33773439 end
3378- table.sort (compareSlots , function (a , b )
3379- if a ~= b then
3380- if slot == a then
3381- return true
3382- end
3383- if slot == b then
3384- return false
3440+
3441+ tooltip :AddLine (14 , colorCodes .TIP .. " Tip: Press Ctrl+D to disable the display of stat differences." , " VAR" )
3442+
3443+ local function getReplacedItemAndOutput (compareSlot )
3444+ local selItem = self .items [compareSlot .selItemId ]
3445+ local output = calcFunc ({ repSlotName = compareSlot .slotName , repItem = item ~= selItem and item or nil })
3446+ return selItem , output
3447+ end
3448+ local function addCompareForSlot (compareSlot , selItem , output )
3449+ if not selItem or not output then
3450+ selItem , output = getReplacedItemAndOutput (compareSlot )
3451+ end
3452+ local header
3453+ if item == selItem then
3454+ header = " ^7Removing this item from " .. compareSlot .label .. " will give you:"
3455+ else
3456+ header = string.format (" ^7Equipping this item in %s will give you:%s" ,
3457+ compareSlot .label or compareSlot .slotName ,
3458+ selItem and " \n (replacing " .. colorCodes [selItem .rarity ] .. selItem .name .. " ^7)" or " " )
3459+ end
3460+ self .build :AddStatComparesToTooltip (tooltip , calcBase , output , header )
3461+ end
3462+
3463+ -- if we have a specific slot to compare to, and the user has "Show
3464+ -- tooltips only for affected slots" checked, we can just compare that
3465+ -- one slot
3466+ if main .slotOnlyTooltips and slot then
3467+ slot = type (slot ) ~= " string" and slot or self .slots [slot ]
3468+ if slot then addCompareForSlot (slot ) end
3469+ return
3470+ end
3471+
3472+
3473+ local slots = {}
3474+ local isUnique = item .rarity == " UNIQUE" or item .rarity == " RELIC"
3475+ local currentSameUniqueCount = 0
3476+ for _ , compareSlot in ipairs (compareSlots ) do
3477+ local selItem , output = getReplacedItemAndOutput (compareSlot )
3478+ local isSameUnique = isUnique and selItem and item .name == selItem .name
3479+ if isUnique and isSameUnique and item .limit then
3480+ currentSameUniqueCount = currentSameUniqueCount + 1
3481+ end
3482+ table.insert (slots ,
3483+ { selItem = selItem , output = output , compareSlot = compareSlot , isSameUnique = isSameUnique })
3484+ end
3485+
3486+ -- limited uniques: only compare to slots with the same item if more don't fit
3487+ if currentSameUniqueCount == item .limit then
3488+ for _ , slotEntry in ipairs (slots ) do
3489+ if slotEntry .isSameUnique then
3490+ addCompareForSlot (slotEntry .compareSlot , slotEntry .selItem , slotEntry .output )
33853491 end
33863492 end
3387- if a .selItemId ~= b .selItemId then
3388- if item == self .items [a .selItemId ] then
3493+ return
3494+ end
3495+
3496+
3497+ -- either the same unique or same base type
3498+ local function similar (compareItem , sameUnique )
3499+ -- empty slot
3500+ if not compareItem then return 0 end
3501+
3502+ local sameBaseType = not isUnique
3503+ and compareItem .rarity ~= " UNIQUE" and compareItem .rarity ~= " RELIC"
3504+ and item .base .type == compareItem .base .type
3505+ and item .base .subType == compareItem .base .subType
3506+ if sameBaseType or sameUnique then
3507+ return 1
3508+ else
3509+ return 0
3510+ end
3511+ end
3512+ -- sort by:
3513+ -- 1. empty sockets
3514+ -- 2. same base group jewel or unique
3515+ -- 3. DPS
3516+ -- 4. EHP
3517+ local function sortFunc (a , b )
3518+ if a == b then return end
3519+
3520+ local aParams = { a .compareSlot .selItemId == 0 and 1 or 0 , similar (a .selItem , a .isSameUnique ), a .output
3521+ .FullDPS , a .output .CombinedDPS , a .output .TotalEHP , a .compareSlot .label , a .compareSlot .slotName }
3522+ local bParams = { b .compareSlot .selItemId == 0 and 1 or 0 , similar (b .selItem , b .isSameUnique ), b .output
3523+ .FullDPS , b
3524+ .output .CombinedDPS , b .output .TotalEHP , b .compareSlot .label , b .compareSlot .slotName }
3525+ for i = 1 , # aParams do
3526+ if aParams [i ] == nil or bParams [i ] == nil then
3527+ -- continue
3528+ elseif aParams [i ] > bParams [i ] then
33893529 return true
3390- end
3391- if item == self .items [b .selItemId ] then
3530+ elseif aParams [i ] < bParams [i ] then
33923531 return false
33933532 end
33943533 end
3395- local aNum = tonumber (a .slotName :match (" %d+" ))
3396- local bNum = tonumber (b .slotName :match (" %d+" ))
3397- if aNum and bNum then
3398- return aNum < bNum
3399- else
3400- return a .slotName < b .slotName
3401- end
3402- end )
3534+ return false
3535+ end
3536+ table.sort (slots , sortFunc )
34033537
3404- -- Add comparisons for each slot
3405- for _ , compareSlot in pairs (compareSlots ) do
3406- if not main .slotOnlyTooltips or (slot and (slot .nodeId == compareSlot .nodeId or slot .slotName == compareSlot .slotName )) or not slot or slot == compareSlot then
3407- local selItem = self .items [compareSlot .selItemId ]
3408- local output = calcFunc ({ repSlotName = compareSlot .slotName , repItem = item ~= selItem and item or nil })
3409- local header
3410- if item == selItem then
3411- header = " ^7Removing this item from " .. compareSlot .label .. " will give you:"
3412- else
3413- header = string.format (" ^7Equipping this item in %s will give you:%s" , compareSlot .label , selItem and " \n (replacing " .. colorCodes [selItem .rarity ].. selItem .name .. " ^7)" or " " )
3414- end
3415- self .build :AddStatComparesToTooltip (tooltip , calcBase , output , header )
3416- end
3538+ for _ , slotEntry in ipairs (slots ) do
3539+ addCompareForSlot (slotEntry .compareSlot , slotEntry .selItem , slotEntry .output )
34173540 end
34183541 end
3419- tooltip :AddLine (14 , colorCodes .TIP .. " Tip: Press Ctrl+D to disable the display of stat differences." , " VAR" )
3420-
34213542 if launch .devModeAlt then
34223543 -- Modifier debugging info
34233544 tooltip :AddSeparator (10 )
0 commit comments