annotate Gear.lua @ 181:5c586ff5fee5 v85

gear ui should now show essence differences
author yellowfive
date Fri, 14 Feb 2020 14:53:46 -0800
parents d90a740a1d0b
children c6369f8f277c
rev   line source
yellowfive@57 1 local Amr = LibStub("AceAddon-3.0"):GetAddon("AskMrRobot")
yellowfive@57 2 local L = LibStub("AceLocale-3.0"):GetLocale("AskMrRobot", true)
yellowfive@57 3 local AceGUI = LibStub("AceGUI-3.0")
yellowfive@57 4
yellowfive@139 5 local _cboSetups
yellowfive@139 6 local _panelGear
yellowfive@139 7 local _activeSetupId
yellowfive@139 8
yellowfive@139 9 local function getSetupById(id)
yellowfive@139 10 if not id then
yellowfive@139 11 id = _activeSetupId
yellowfive@139 12 end
yellowfive@139 13 local setup
yellowfive@139 14 for i,s in ipairs(Amr.db.char.GearSetups) do
yellowfive@139 15 if s.Id == id then
yellowfive@139 16 setup = s
yellowfive@139 17 break
yellowfive@139 18 end
yellowfive@139 19 end
yellowfive@139 20 return setup
yellowfive@139 21 end
yellowfive@57 22
yellowfive@57 23 -- Returns a number indicating how different two items are (0 means the same, higher means more different)
yellowfive@57 24 local function countItemDifferences(item1, item2)
yellowfive@124 25 -- both nil, the same
yellowfive@124 26 if not item1 and not item2 then
yellowfive@124 27 return 0
yellowfive@124 28 end
yellowfive@124 29
yellowfive@124 30 -- one nil and other not, or different id, totally different
yellowfive@124 31 if (not item1 and item2) or (item1 and not item2) or item1.id ~= item2.id then
yellowfive@149 32 return 100000
yellowfive@124 33 end
yellowfive@124 34
yellowfive@124 35 -- different versions of same item (id + bonus ids + suffix + drop level, constitutes a different physical drop)
yellowfive@135 36 if Amr.GetItemUniqueId(item1, true, true) ~= Amr.GetItemUniqueId(item2, true, true) then
yellowfive@149 37 return 10000
yellowfive@57 38 end
yellowfive@57 39
yellowfive@81 40 -- different upgrade levels of the same item
yellowfive@57 41 if item1.upgradeId ~= item2.upgradeId then
yellowfive@149 42 return 1000
yellowfive@124 43 end
yellowfive@124 44
yellowfive@149 45 -- a change that requires reforging is considered more different than a change that does not;
yellowfive@149 46 -- it is assumed that item1 is how we want the item to be in the end, and item2 is how it currently is
yellowfive@149 47 local aztReforges = 0
yellowfive@149 48 local aztSelects = 0
yellowfive@149 49
yellowfive@149 50 if item1.id == item2.id and (item1.azerite or item2.azerite) then
yellowfive@149 51 -- azerite that needs to be reforged
yellowfive@149 52 if item2.azerite and not item1.azerite then
yellowfive@149 53 -- kind of a dumb case... but we would need to blank all azerite on item2 to match item1
yellowfive@149 54 aztReforges = #item2.azerite * 100
yellowfive@149 55 elseif item2.azerite then
yellowfive@149 56 -- count up azerite on item2 but not on item1, these would need to be reforged
yellowfive@149 57 for i = 1, #item2.azerite do
yellowfive@149 58 local missing = true
yellowfive@149 59 for j = 1, #item1.azerite do
yellowfive@149 60 if item1.azerite[j] == item2.azerite[i] then
yellowfive@149 61 missing = false
yellowfive@149 62 end
yellowfive@149 63 end
yellowfive@149 64 if missing then
yellowfive@149 65 aztReforges = aztReforges + 100
yellowfive@149 66 end
yellowfive@149 67 end
yellowfive@149 68 end
yellowfive@149 69
yellowfive@149 70 -- azerite that needs to be selected
yellowfive@124 71 if item1.azerite and not item2.azerite then
yellowfive@149 72 -- item2 is blank, so just need to choose all the right ones
yellowfive@149 73 aztSelects = #item1.azerite * 10
yellowfive@149 74 elseif item1.azerite then
yellowfive@149 75 -- count up azerite on item1 but not on item2, these would need to be selected
yellowfive@145 76 for i = 1, #item1.azerite do
yellowfive@145 77 local missing = true
yellowfive@124 78 for j = 1, #item2.azerite do
yellowfive@145 79 if item2.azerite[j] == item1.azerite[i] then
yellowfive@124 80 missing = false
yellowfive@124 81 end
yellowfive@124 82 end
yellowfive@124 83 if missing then
yellowfive@149 84 aztSelects = aztSelects + 10
yellowfive@124 85 end
yellowfive@124 86 end
yellowfive@149 87 end
yellowfive@124 88 end
yellowfive@57 89
yellowfive@57 90 -- different gems
yellowfive@57 91 local gemDiffs = 0
yellowfive@57 92 for i = 1, 3 do
yellowfive@57 93 if item1.gemIds[i] ~= item2.gemIds[i] then
yellowfive@57 94 gemDiffs = gemDiffs + 1
yellowfive@57 95 end
yellowfive@57 96 end
yellowfive@57 97
yellowfive@57 98 -- different enchants
yellowfive@57 99 local enchantDiff = 0
yellowfive@57 100 if item1.enchantId ~= item2.enchantId then
yellowfive@57 101 enchantDiff = 1
yellowfive@57 102 end
yellowfive@57 103
yellowfive@149 104 return aztReforges + aztSelects + gemDiffs + enchantDiff
yellowfive@57 105 end
yellowfive@57 106
yellowfive@57 107 -- given a table of items (keyed or indexed doesn't matter) find closest match to item, or nil if none are a match
yellowfive@124 108 local function findMatchingItemFromTable(item, list, bestItem, bestDiff, bestLoc, usedItems, tableType)
yellowfive@57 109 if not list then return nil end
yellowfive@57 110
yellowfive@73 111 local found = false
yellowfive@129 112 for k,listItem in pairs(list) do
yellowfive@57 113 if listItem then
yellowfive@57 114 local diff = countItemDifferences(item, listItem)
yellowfive@57 115 if diff < bestDiff then
yellowfive@57 116 -- each physical item can only be used once, the usedItems table has items we can't use in this search
yellowfive@57 117 local key = string.format("%s_%s", tableType, k)
yellowfive@57 118 if not usedItems[key] then
yellowfive@57 119 bestItem = listItem
yellowfive@57 120 bestDiff = diff
yellowfive@124 121 bestLoc = key
yellowfive@73 122 found = true
yellowfive@57 123 end
yellowfive@57 124 end
yellowfive@73 125 if found then break end
yellowfive@57 126 end
yellowfive@57 127 end
yellowfive@57 128
yellowfive@124 129 return bestItem, bestDiff, bestLoc
yellowfive@57 130 end
yellowfive@57 131
yellowfive@124 132 -- search the player's equipped gear, bag, and bank for an item that best matches the specified item
yellowfive@57 133 function Amr:FindMatchingItem(item, player, usedItems)
yellowfive@57 134 if not item then return nil end
yellowfive@57 135
yellowfive@57 136 local equipped = player.Equipped and player.Equipped[player.ActiveSpec] or nil
yellowfive@151 137 local bestItem, bestDiff, bestLoc = findMatchingItemFromTable(item, equipped, nil, 100000, nil, usedItems, "equip")
yellowfive@124 138 bestItem, bestDiff, bestLoc = findMatchingItemFromTable(item, player.BagItems, bestItem, bestDiff, bestLoc, usedItems, "bag")
yellowfive@124 139 if player.BankItems then
yellowfive@129 140 bestItem, bestDiff, bestLoc = findMatchingItemFromTable(item, player.BankItems, bestItem, bestDiff, bestLoc, usedItems, "bank")
yellowfive@124 141 end
yellowfive@57 142
yellowfive@149 143 if bestDiff >= 100000 then
yellowfive@149 144 return nil, 100000
yellowfive@57 145 else
yellowfive@57 146 usedItems[bestLoc] = true
yellowfive@124 147 return bestItem, bestDiff
yellowfive@57 148 end
yellowfive@57 149 end
yellowfive@57 150
yellowfive@57 151 local function renderEmptyGear(container)
yellowfive@57 152
yellowfive@57 153 local panelBlank = AceGUI:Create("AmrUiPanel")
yellowfive@57 154 panelBlank:SetLayout("None")
yellowfive@57 155 panelBlank:SetBackgroundColor(Amr.Colors.Black, 0.4)
yellowfive@124 156 container:AddChild(panelBlank)
yellowfive@57 157 panelBlank:SetPoint("TOPLEFT", container.content, "TOPLEFT", 6, 0)
yellowfive@57 158 panelBlank:SetPoint("BOTTOMRIGHT", container.content, "BOTTOMRIGHT")
yellowfive@57 159
yellowfive@57 160 local lbl = AceGUI:Create("AmrUiLabel")
yellowfive@124 161 panelBlank:AddChild(lbl)
yellowfive@57 162 lbl:SetText(L.GearBlank)
yellowfive@57 163 lbl:SetWidth(700)
yellowfive@57 164 lbl:SetJustifyH("MIDDLE")
yellowfive@57 165 lbl:SetFont(Amr.CreateFont("Italic", 16, Amr.Colors.TextTan))
yellowfive@57 166 lbl:SetPoint("BOTTOM", panelBlank.content, "CENTER", 0, 20)
yellowfive@57 167
yellowfive@57 168 local lbl2 = AceGUI:Create("AmrUiLabel")
yellowfive@124 169 panelBlank:AddChild(lbl2)
yellowfive@57 170 lbl2:SetText(L.GearBlank2)
yellowfive@57 171 lbl2:SetWidth(700)
yellowfive@57 172 lbl2:SetJustifyH("MIDDLE")
yellowfive@57 173 lbl2:SetFont(Amr.CreateFont("Italic", 16, Amr.Colors.TextTan))
yellowfive@57 174 lbl2:SetPoint("TOP", lbl.frame, "CENTER", 0, -20)
yellowfive@124 175 end
yellowfive@124 176
yellowfive@124 177 -- helper to create a widget for showing a socket or azerite power
yellowfive@124 178 local function createSocketWidget(panelMods, prevWidget, prevIsSocket, isEquipped)
yellowfive@124 179
yellowfive@124 180 -- highlight for socket that doesn't match
yellowfive@124 181 local socketBorder = AceGUI:Create("AmrUiPanel")
yellowfive@124 182 panelMods:AddChild(socketBorder)
yellowfive@124 183 if not prevIsSocket then
yellowfive@124 184 socketBorder:SetPoint("LEFT", prevWidget.frame, "RIGHT", 30, 0)
yellowfive@124 185 else
yellowfive@124 186 socketBorder:SetPoint("LEFT", prevWidget.frame, "RIGHT", 2, 0)
yellowfive@124 187 end
yellowfive@124 188 socketBorder:SetLayout("None")
yellowfive@124 189 socketBorder:SetBackgroundColor(Amr.Colors.Black, isEquipped and 0 or 1)
yellowfive@124 190 socketBorder:SetWidth(26)
yellowfive@124 191 socketBorder:SetHeight(26)
yellowfive@124 192 if isEquipped then
yellowfive@124 193 socketBorder:SetAlpha(0.3)
yellowfive@124 194 end
yellowfive@124 195
yellowfive@124 196 local socketBg = AceGUI:Create("AmrUiIcon")
yellowfive@124 197 socketBorder:AddChild(socketBg)
yellowfive@124 198 socketBg:SetPoint("TOPLEFT", socketBorder.content, "TOPLEFT", 1, -1)
yellowfive@124 199 socketBg:SetLayout("None")
yellowfive@124 200 socketBg:SetBorderWidth(2)
yellowfive@124 201 socketBg:SetIconBorderColor(Amr.Colors.Green, isEquipped and 0 or 1)
yellowfive@124 202 socketBg:SetWidth(24)
yellowfive@124 203 socketBg:SetHeight(24)
yellowfive@124 204
yellowfive@124 205 local socketIcon = AceGUI:Create("AmrUiIcon")
yellowfive@124 206 socketBg:AddChild(socketIcon)
yellowfive@124 207 socketIcon:SetPoint("CENTER", socketBg.content, "CENTER")
yellowfive@124 208 socketIcon:SetBorderWidth(1)
yellowfive@124 209 socketIcon:SetIconBorderColor(Amr.Colors.White)
yellowfive@124 210 socketIcon:SetWidth(18)
yellowfive@124 211 socketIcon:SetHeight(18)
yellowfive@124 212
yellowfive@124 213 return socketBorder, socketIcon
yellowfive@57 214 end
yellowfive@57 215
yellowfive@139 216 local function renderGear(setupId, container)
yellowfive@139 217
yellowfive@139 218 -- release all children that were previously rendered, we gonna redo it now
yellowfive@139 219 container:ReleaseChildren()
yellowfive@57 220
yellowfive@57 221 local player = Amr:ExportCharacter()
yellowfive@139 222
yellowfive@139 223 local gear
yellowfive@139 224 local spec
yellowfive@139 225 local setupIndex
yellowfive@181 226 local essences
yellowfive@139 227 for i, setup in ipairs(Amr.db.char.GearSetups) do
yellowfive@139 228 if setup.Id == setupId then
yellowfive@139 229 setupIndex = i
yellowfive@139 230 gear = setup.Gear
yellowfive@139 231 spec = setup.SpecSlot
yellowfive@165 232 essences = setup.Essences
yellowfive@139 233 break
yellowfive@139 234 end
yellowfive@139 235 end
yellowfive@139 236
yellowfive@57 237 local equipped = player.Equipped[player.ActiveSpec]
yellowfive@181 238 local equippedEssences = player.Essences[player.ActiveSpec]
yellowfive@181 239
yellowfive@57 240 if not gear then
yellowfive@57 241 -- no gear has been imported for this spec so show a message
yellowfive@57 242 renderEmptyGear(container)
yellowfive@57 243 else
yellowfive@57 244 local panelGear = AceGUI:Create("AmrUiPanel")
yellowfive@57 245 panelGear:SetLayout("None")
yellowfive@57 246 panelGear:SetBackgroundColor(Amr.Colors.Black, 0.3)
yellowfive@124 247 container:AddChild(panelGear)
yellowfive@57 248 panelGear:SetPoint("TOPLEFT", container.content, "TOPLEFT", 6, 0)
yellowfive@57 249 panelGear:SetPoint("BOTTOMRIGHT", container.content, "BOTTOMRIGHT", -300, 0)
yellowfive@57 250
yellowfive@57 251 local panelMods = AceGUI:Create("AmrUiPanel")
yellowfive@57 252 panelMods:SetLayout("None")
yellowfive@124 253 panelMods:SetBackgroundColor(Amr.Colors.Black, 0.3)
yellowfive@124 254 container:AddChild(panelMods)
yellowfive@57 255 panelMods:SetPoint("TOPLEFT", panelGear.frame, "TOPRIGHT", 15, 0)
yellowfive@57 256 panelMods:SetPoint("BOTTOMRIGHT", container.content, "BOTTOMRIGHT")
yellowfive@57 257
yellowfive@57 258 -- spec icon
yellowfive@57 259 local icon = AceGUI:Create("AmrUiIcon")
yellowfive@57 260 icon:SetIconBorderColor(Amr.Colors.Classes[player.Class])
yellowfive@57 261 icon:SetWidth(48)
yellowfive@57 262 icon:SetHeight(48)
yellowfive@57 263
yellowfive@57 264 local iconSpec
yellowfive@81 265 if player.SubSpecs and player.SubSpecs[spec] then
yellowfive@57 266 iconSpec = player.SubSpecs[spec]
yellowfive@57 267 else
yellowfive@57 268 iconSpec = player.Specs[spec]
yellowfive@57 269 end
yellowfive@57 270
yellowfive@57 271 icon:SetIcon("Interface\\Icons\\" .. Amr.SpecIcons[iconSpec])
yellowfive@124 272 panelGear:AddChild(icon)
yellowfive@57 273 icon:SetPoint("TOPLEFT", panelGear.content, "TOPLEFT", 10, -10)
yellowfive@57 274
yellowfive@57 275 local btnEquip = AceGUI:Create("AmrUiButton")
yellowfive@81 276 btnEquip:SetText(L.GearButtonEquip(L.SpecsShort[player.Specs[spec]]))
yellowfive@57 277 btnEquip:SetBackgroundColor(Amr.Colors.Green)
yellowfive@57 278 btnEquip:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.White))
yellowfive@57 279 btnEquip:SetWidth(300)
yellowfive@57 280 btnEquip:SetHeight(26)
yellowfive@57 281 btnEquip:SetCallback("OnClick", function(widget)
yellowfive@139 282 Amr:EquipGearSet(setupIndex)
yellowfive@57 283 end)
yellowfive@57 284 panelGear:AddChild(btnEquip)
yellowfive@124 285 btnEquip:SetPoint("LEFT", icon.frame, "RIGHT", 40, 0)
yellowfive@124 286 btnEquip:SetPoint("RIGHT", panelGear.content, "RIGHT", -40, 0)
yellowfive@57 287
yellowfive@57 288 -- each physical item can only be used once, this tracks ones we have already used
yellowfive@57 289 local usedItems = {}
yellowfive@57 290
yellowfive@57 291 -- gear list
yellowfive@57 292 local prevElem = icon
yellowfive@57 293 for slotNum = 1, #Amr.SlotIds do
yellowfive@57 294 local slotId = Amr.SlotIds[slotNum]
yellowfive@57 295
yellowfive@124 296 local equippedItem = equipped and equipped[slotId] or nil
yellowfive@133 297 --local equippedItemLink = equipped and equipped.link or nil
yellowfive@57 298 local optimalItem = gear[slotId]
yellowfive@57 299 local optimalItemLink = Amr.CreateItemLink(optimalItem)
yellowfive@57 300
yellowfive@57 301 -- see if item is currently equipped, is false if don't have any item for that slot (e.g. OH for a 2-hander)
yellowfive@57 302 local isEquipped = false
yellowfive@135 303 if equippedItem and optimalItem and Amr.GetItemUniqueId(equippedItem, false, true) == Amr.GetItemUniqueId(optimalItem, false, true) then
yellowfive@145 304
yellowfive@145 305 if slotId == 1 or slotId == 3 or slotId == 5 then
yellowfive@145 306 -- show the item as not equipped if azerite doesn't match... might mean they have to switch to another version of same item
yellowfive@149 307 local aztDiff = countItemDifferences(optimalItem, equippedItem)
yellowfive@153 308 if aztDiff < 10 then
yellowfive@145 309 isEquipped = true
yellowfive@145 310 end
yellowfive@145 311 else
yellowfive@145 312 isEquipped = true
yellowfive@145 313 end
yellowfive@57 314 end
yellowfive@124 315
yellowfive@124 316 local isAzerite = optimalItem and C_AzeriteEmpoweredItem.IsAzeriteEmpoweredItemByID(optimalItem.id)
yellowfive@165 317 local isEssence = essences and optimalItem and optimalItem.id == 158075
yellowfive@57 318
yellowfive@57 319 -- find the item in the player's inventory that best matches what the optimization wants to use
yellowfive@124 320 local matchItem = Amr:FindMatchingItem(optimalItem, player, usedItems)
yellowfive@57 321
yellowfive@57 322 -- slot label
yellowfive@57 323 local lbl = AceGUI:Create("AmrUiLabel")
yellowfive@124 324 panelGear:AddChild(lbl)
yellowfive@124 325 lbl:SetPoint("TOPLEFT", prevElem.frame, "BOTTOMLEFT", 0, -12)
yellowfive@57 326 lbl:SetText(Amr.SlotDisplayText[slotId])
yellowfive@57 327 lbl:SetWidth(85)
yellowfive@57 328 lbl:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.White))
yellowfive@57 329 prevElem = lbl
yellowfive@57 330
yellowfive@57 331 -- ilvl label
yellowfive@57 332 local lblIlvl = AceGUI:Create("AmrUiLabel")
yellowfive@124 333 panelGear:AddChild(lblIlvl)
yellowfive@124 334 lblIlvl:SetPoint("TOPLEFT", lbl.frame, "TOPRIGHT", 0, 0)
yellowfive@57 335 lblIlvl:SetWidth(45)
yellowfive@57 336 lblIlvl:SetFont(Amr.CreateFont("Italic", 14, Amr.Colors.TextTan))
yellowfive@57 337
yellowfive@57 338 -- equipped label
yellowfive@57 339 local lblEquipped = AceGUI:Create("AmrUiLabel")
yellowfive@124 340 panelGear:AddChild(lblEquipped)
yellowfive@124 341 lblEquipped:SetPoint("TOPLEFT", lblIlvl.frame, "TOPRIGHT", 0, 0)
yellowfive@57 342 lblEquipped:SetWidth(20)
yellowfive@57 343 lblEquipped:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.White))
yellowfive@57 344 lblEquipped:SetText(isEquipped and "E" or "")
yellowfive@57 345
yellowfive@57 346 -- item name/link label
yellowfive@57 347 local lblItem = AceGUI:Create("AmrUiLabel")
yellowfive@124 348 panelGear:AddChild(lblItem)
yellowfive@124 349 lblItem:SetPoint("TOPLEFT", lblEquipped.frame, "TOPRIGHT", 0, 0)
yellowfive@57 350 lblItem:SetWordWrap(false)
yellowfive@57 351 lblItem:SetWidth(345)
yellowfive@57 352 lblItem:SetFont(Amr.CreateFont(isEquipped and "Regular" or "Bold", isEquipped and 14 or 15, Amr.Colors.White))
yellowfive@57 353
yellowfive@133 354 -- fill the name/ilvl labels, which may require asynchronous loading of item information
yellowfive@57 355 if optimalItemLink then
yellowfive@133 356 local gameItem = Item:CreateFromItemLink(optimalItemLink)
yellowfive@133 357 if gameItem then
yellowfive@133 358 local q = gameItem:GetItemQuality()
yellowfive@133 359 if q == 6 then
yellowfive@133 360 -- for artifacts, we consider it equipped if the item id alone matches
yellowfive@133 361 if equippedItem and equippedItem.id == optimalItem.id then
yellowfive@133 362 isEquipped = true
yellowfive@133 363 end
yellowfive@133 364 lblEquipped:SetText(isEquipped and "E" or "")
yellowfive@133 365 end
yellowfive@124 366
yellowfive@137 367 lblItem:SetFont(Amr.CreateFont(isEquipped and "Regular" or "Bold", isEquipped and 14 or 15, Amr.Colors.Qualities[q] or Amr.Colors.White))
yellowfive@133 368 lblItem:SetText(gameItem:GetItemName())
yellowfive@133 369 lblIlvl:SetText(gameItem:GetCurrentItemLevel())
yellowfive@133 370 Amr:SetItemTooltip(lblItem, gameItem:GetItemLink(), "ANCHOR_TOPRIGHT")
yellowfive@133 371 end
yellowfive@57 372 end
yellowfive@57 373
yellowfive@57 374 -- modifications
yellowfive@57 375 if optimalItem then
yellowfive@57 376
yellowfive@165 377 -- gems or azerite powers or essences
yellowfive@124 378 local prevSocket = nil
yellowfive@124 379
yellowfive@124 380 if isAzerite then
yellowfive@124 381 local azt = optimalItem.azerite or {}
yellowfive@124 382 for i,spellId in ipairs(azt) do
yellowfive@124 383 if spellId and spellId ~= 0 then
yellowfive@135 384 local equippedAzt = matchItem and matchItem.azerite or {}
yellowfive@124 385 local isPowerActive = Amr.Contains(equippedAzt, spellId)
yellowfive@124 386
yellowfive@124 387 local socketBorder, socketIcon = createSocketWidget(panelMods, prevSocket or lblItem, prevSocket, isPowerActive)
yellowfive@124 388
yellowfive@124 389 -- set icon and tooltip
yellowfive@133 390 local _, _, spellIcon = GetSpellInfo(spellId)
yellowfive@124 391 socketIcon:SetIcon(spellIcon)
yellowfive@124 392 Amr:SetSpellTooltip(socketIcon, spellId, "ANCHOR_TOPRIGHT")
yellowfive@124 393
yellowfive@124 394 prevSocket = socketBorder
yellowfive@124 395 end
yellowfive@124 396 end
yellowfive@165 397 elseif isEssence then
yellowfive@181 398 for i = 1, 4 do
yellowfive@181 399 if essences and #essences >= i then
yellowfive@181 400 local essence = essences[i]
yellowfive@181 401 local equippedEssence = equippedEssences and #equippedEssences >= i and equippedEssences[i] or nil
yellowfive@181 402 if essence then
yellowfive@181 403 local essenceInfo = C_AzeriteEssence.GetEssenceInfo(essence[2])
yellowfive@181 404 if essenceInfo then
yellowfive@181 405 local isEssenceActive = equippedEssence and equippedEssence[2] == essence[2]
yellowfive@181 406
yellowfive@181 407 local socketBorder, socketIcon = createSocketWidget(panelMods, prevSocket or lblItem, prevSocket, isEssenceActive)
yellowfive@181 408
yellowfive@181 409 -- set icon and tooltip
yellowfive@181 410 socketIcon:SetIcon(essenceInfo.icon)
yellowfive@181 411 Amr:SetEssenceTooltip(socketIcon, string.format("azessence:%d:%d", essence[2], essence[3]) , "ANCHOR_TOPRIGHT")
yellowfive@181 412
yellowfive@181 413 --[[
yellowfive@181 414 if essence[1] and essence[1] > 4 then
yellowfive@181 415 Amr:SetSpellTooltip(socketIcon, essence[1], "ANCHOR_TOPRIGHT")
yellowfive@181 416 end]]
yellowfive@181 417
yellowfive@181 418 prevSocket = socketBorder
yellowfive@181 419 end
yellowfive@181 420 end
yellowfive@181 421 end
yellowfive@181 422 end
yellowfive@124 423 else
yellowfive@124 424 for i = 1, #optimalItem.gemIds do
yellowfive@124 425 -- we rely on the fact that the gear sets coming back from the site will almost always have all sockets filled,
yellowfive@124 426 -- because it's a pain to get the actual number of sockets on an item from within the game
yellowfive@57 427 local g = optimalItem.gemIds[i]
yellowfive@124 428 if g == 0 then break end
yellowfive@124 429
yellowfive@124 430 local isGemEquipped = matchItem and matchItem.gemIds and matchItem.gemIds[i] == g
yellowfive@57 431
yellowfive@124 432 local socketBorder, socketIcon = createSocketWidget(panelMods, prevSocket or lblItem, prevSocket, isGemEquipped)
yellowfive@57 433
yellowfive@57 434 -- get icon for optimized gem
yellowfive@133 435 local gameItem = Item:CreateFromItemID(g)
yellowfive@133 436 if gameItem then
yellowfive@133 437 socketIcon:SetIcon(gameItem:GetItemIcon())
yellowfive@133 438 Amr:SetItemTooltip(socketIcon, gameItem:GetItemLink(), "ANCHOR_TOPRIGHT")
yellowfive@133 439 end
yellowfive@89 440
yellowfive@89 441 prevSocket = socketBorder
yellowfive@57 442 end
yellowfive@57 443 end
yellowfive@124 444
yellowfive@57 445 -- enchant
yellowfive@57 446 if optimalItem.enchantId and optimalItem.enchantId ~= 0 then
yellowfive@57 447 local isEnchantEquipped = matchItem and matchItem.enchantId and matchItem.enchantId == optimalItem.enchantId
yellowfive@135 448
yellowfive@57 449 local lblEnchant = AceGUI:Create("AmrUiLabel")
yellowfive@124 450 panelMods:AddChild(lblEnchant)
yellowfive@124 451 lblEnchant:SetPoint("TOPLEFT", lblItem.frame, "TOPRIGHT", 130, 0)
yellowfive@57 452 lblEnchant:SetWordWrap(false)
yellowfive@57 453 lblEnchant:SetWidth(170)
yellowfive@57 454 lblEnchant:SetFont(Amr.CreateFont(isEnchantEquipped and "Regular" or "Bold", 14, isEnchantEquipped and Amr.Colors.TextGray or Amr.Colors.White))
yellowfive@57 455
yellowfive@124 456 local enchInfo = Amr.db.char.ExtraEnchantData[optimalItem.enchantId]
yellowfive@57 457 if enchInfo then
yellowfive@57 458 lblEnchant:SetText(enchInfo.text)
yellowfive@57 459
yellowfive@133 460 local gameItem = Item:CreateFromItemID(enchInfo.itemId)
yellowfive@133 461 if gameItem then
yellowfive@133 462 Amr:SetItemTooltip(lblEnchant, gameItem:GetItemLink(), "ANCHOR_TOPRIGHT")
yellowfive@133 463 end
yellowfive@57 464 end
yellowfive@124 465
yellowfive@57 466 end
yellowfive@57 467 end
yellowfive@57 468
yellowfive@57 469 prevElem = lbl
yellowfive@57 470 end
yellowfive@57 471 end
yellowfive@57 472 end
yellowfive@57 473
yellowfive@139 474 local function onSetupChange(widget, eventName, value)
yellowfive@139 475 _activeSetupId = value
yellowfive@139 476 renderGear(_activeSetupId, _panelGear)
yellowfive@57 477 end
yellowfive@57 478
yellowfive@57 479 local function onImportClick(widget)
yellowfive@57 480 Amr:ShowImportWindow()
yellowfive@57 481 end
yellowfive@57 482
yellowfive@139 483 function Amr:PickFirstSetupForSpec()
yellowfive@139 484 local specSlot = GetSpecialization()
yellowfive@139 485 for i, setup in ipairs(Amr.db.char.GearSetups) do
yellowfive@139 486 if setup.SpecSlot == specSlot then
yellowfive@139 487 _activeSetupId = setup.Id
yellowfive@139 488 break
yellowfive@139 489 end
yellowfive@139 490 end
yellowfive@139 491 end
yellowfive@139 492
yellowfive@139 493 function Amr:GetActiveSetupId()
yellowfive@139 494 return _activeSetupId
yellowfive@139 495 end
yellowfive@139 496
yellowfive@139 497 function Amr:SetActiveSetupId(setupId)
yellowfive@139 498 _activeSetupId = setupId
yellowfive@139 499 end
yellowfive@139 500
yellowfive@139 501 function Amr:GetActiveSetupLabel()
yellowfive@139 502 if not _activeSetupId then
yellowfive@139 503 return nil
yellowfive@139 504 end
yellowfive@139 505 local setup = getSetupById(_activeSetupId)
yellowfive@139 506 if not setup then
yellowfive@139 507 return nil
yellowfive@139 508 else
yellowfive@139 509 return setup.Label
yellowfive@139 510 end
yellowfive@139 511 end
yellowfive@139 512
yellowfive@57 513 -- renders the main UI for the Gear tab
yellowfive@57 514 function Amr:RenderTabGear(container)
yellowfive@57 515
yellowfive@57 516 local btnImport = AceGUI:Create("AmrUiButton")
yellowfive@57 517 btnImport:SetText(L.GearButtonImportText)
yellowfive@57 518 btnImport:SetBackgroundColor(Amr.Colors.Orange)
yellowfive@57 519 btnImport:SetFont(Amr.CreateFont("Bold", 16, Amr.Colors.White))
yellowfive@57 520 btnImport:SetWidth(120)
yellowfive@57 521 btnImport:SetHeight(26)
yellowfive@57 522 btnImport:SetCallback("OnClick", onImportClick)
yellowfive@57 523 container:AddChild(btnImport)
yellowfive@124 524 btnImport:SetPoint("TOPLEFT", container.content, "TOPLEFT", 0, -81)
yellowfive@57 525
yellowfive@57 526 local lbl = AceGUI:Create("AmrUiLabel")
yellowfive@124 527 container:AddChild(lbl)
yellowfive@57 528 lbl:SetText(L.GearImportNote)
yellowfive@57 529 lbl:SetWidth(100)
yellowfive@57 530 lbl:SetFont(Amr.CreateFont("Italic", 12, Amr.Colors.TextTan))
yellowfive@57 531 lbl:SetJustifyH("MIDDLE")
yellowfive@57 532 lbl:SetPoint("TOP", btnImport.frame, "BOTTOM", 0, -5)
yellowfive@57 533
yellowfive@57 534 local lbl2 = AceGUI:Create("AmrUiLabel")
yellowfive@124 535 container:AddChild(lbl2)
yellowfive@57 536 lbl2:SetText(L.GearTipTitle)
yellowfive@57 537 lbl2:SetWidth(140)
yellowfive@57 538 lbl2:SetFont(Amr.CreateFont("Italic", 20, Amr.Colors.Text))
yellowfive@57 539 lbl2:SetJustifyH("MIDDLE")
yellowfive@57 540 lbl2:SetPoint("TOP", lbl.frame, "BOTTOM", 0, -50)
yellowfive@57 541
yellowfive@57 542 lbl = AceGUI:Create("AmrUiLabel")
yellowfive@124 543 container:AddChild(lbl)
yellowfive@57 544 lbl:SetText(L.GearTipText)
yellowfive@57 545 lbl:SetWidth(140)
yellowfive@57 546 lbl:SetFont(Amr.CreateFont("Italic", 12, Amr.Colors.Text))
yellowfive@57 547 lbl:SetJustifyH("MIDDLE")
yellowfive@57 548 lbl:SetPoint("TOP", lbl2.frame, "BOTTOM", 0, -5)
yellowfive@57 549
yellowfive@57 550 lbl2 = AceGUI:Create("AmrUiLabel")
yellowfive@124 551 container:AddChild(lbl2)
yellowfive@57 552 lbl2:SetText(L.GearTipCommands)
yellowfive@57 553 lbl2:SetWidth(130)
yellowfive@57 554 lbl2:SetFont(Amr.CreateFont("Italic", 12, Amr.Colors.Text))
yellowfive@57 555 lbl2:SetPoint("TOP", lbl.frame, "BOTTOM", 10, -5)
yellowfive@57 556
yellowfive@139 557 _cboSetups = AceGUI:Create("AmrUiDropDown")
yellowfive@139 558 _cboSetups:SetWidth(300)
yellowfive@139 559 container:AddChild(_cboSetups)
yellowfive@139 560 _cboSetups:SetPoint("TOPLEFT", container.content, "TOPLEFT", 150, -27.5)
yellowfive@81 561
yellowfive@139 562 _panelGear = AceGUI:Create("AmrUiPanel")
yellowfive@139 563 _panelGear:SetLayout("None")
yellowfive@139 564 _panelGear:SetBackgroundColor(Amr.Colors.Bg)
yellowfive@139 565 container:AddChild(_panelGear)
yellowfive@139 566 _panelGear:SetPoint("TOPLEFT", container.content, "TOPLEFT", 144, -58)
yellowfive@139 567 _panelGear:SetPoint("BOTTOMRIGHT", container.content, "BOTTOMRIGHT")
yellowfive@57 568
yellowfive@61 569 local btnShop = AceGUI:Create("AmrUiButton")
yellowfive@161 570 container:AddChild(btnShop)
yellowfive@61 571 btnShop:SetText(L.GearButtonShop)
yellowfive@61 572 btnShop:SetBackgroundColor(Amr.Colors.Blue)
yellowfive@61 573 btnShop:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.White))
yellowfive@161 574 btnShop:SetWidth(200)
yellowfive@61 575 btnShop:SetHeight(26)
yellowfive@61 576 btnShop:SetCallback("OnClick", function(widget) Amr:ShowShopWindow() end)
yellowfive@161 577 btnShop:SetPoint("TOPRIGHT", container.content, "TOPRIGHT", -42, -25)
yellowfive@161 578
yellowfive@161 579 local btnJunk = AceGUI:Create("AmrUiButton")
yellowfive@161 580 container:AddChild(btnJunk)
yellowfive@161 581 btnJunk:SetText(L.GearButtonJunk)
yellowfive@161 582 btnJunk:SetBackgroundColor(Amr.Colors.Blue)
yellowfive@161 583 btnJunk:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.White))
yellowfive@161 584 btnJunk:SetWidth(200)
yellowfive@161 585 btnJunk:SetHeight(26)
yellowfive@161 586 btnJunk:SetCallback("OnClick", function(widget) Amr:ShowJunkWindow() end)
yellowfive@161 587 btnJunk:SetPoint("CENTER", btnShop.frame, "CENTER", 0, 36)
yellowfive@139 588
yellowfive@139 589 -- pick a default tab based on player's current spec if none is already specified
yellowfive@139 590 if not _activeSetupId then
yellowfive@139 591 Amr:PickFirstSetupForSpec()
yellowfive@57 592 end
yellowfive@139 593
yellowfive@139 594 Amr:RefreshGearDisplay()
yellowfive@139 595
yellowfive@139 596 -- set event on dropdown after UI has been initially rendered
yellowfive@139 597 _cboSetups:SetCallback("OnChange", onSetupChange)
yellowfive@57 598 end
yellowfive@57 599
yellowfive@57 600 function Amr:ReleaseTabGear()
yellowfive@139 601 _cboSetups = nil
yellowfive@139 602 _panelGear = nil
yellowfive@57 603 end
yellowfive@57 604
yellowfive@57 605 -- refresh display of the current gear tab
yellowfive@139 606 function Amr:RefreshGearDisplay()
yellowfive@139 607
yellowfive@139 608 if not _panelGear then
yellowfive@139 609 return
yellowfive@139 610 end
yellowfive@139 611
yellowfive@139 612 -- fill the gear setup picker
yellowfive@139 613 local setupList = {}
yellowfive@139 614 for i, setup in ipairs(Amr.db.char.GearSetups) do
yellowfive@139 615 table.insert(setupList, { text = setup.Label, value = setup.Id })
yellowfive@139 616 end
yellowfive@139 617 _cboSetups:SetItems(setupList)
yellowfive@139 618
yellowfive@139 619 -- set selected value
yellowfive@139 620 local prev = _activeSetupId
yellowfive@139 621 _cboSetups:SelectItem(_activeSetupId)
yellowfive@139 622
yellowfive@139 623 if prev == _activeSetupId then
yellowfive@139 624 -- selecting will trigger the change event if it changed; if it didn't change, do a render now
yellowfive@139 625 renderGear(_activeSetupId, _panelGear)
yellowfive@139 626 end
yellowfive@57 627 end
yellowfive@57 628
yellowfive@57 629
yellowfive@57 630 ------------------------------------------------------------------------------------------------
yellowfive@57 631 -- Gear Set Management
yellowfive@57 632 ------------------------------------------------------------------------------------------------
yellowfive@57 633 local _waitingForSpec = 0
yellowfive@124 634 local _pendingGearOps = nil
yellowfive@124 635 local _currentGearOp = nil
yellowfive@124 636 local _itemLockAction = nil
yellowfive@124 637 local _gearOpPasses = 0
yellowfive@124 638 local _gearOpWaiting = nil
yellowfive@57 639
yellowfive@124 640 local beginEquipGearSet, processCurrentGearOp, nextGearOp
yellowfive@89 641
yellowfive@57 642 -- find the first empty slot in the player's backpack+bags
yellowfive@161 643 local function findFirstEmptyBagSlot(usedBagSlots)
yellowfive@57 644
yellowfive@57 645 local bagIds = {}
yellowfive@57 646 table.insert(bagIds, BACKPACK_CONTAINER)
yellowfive@57 647 for bagId = 1, NUM_BAG_SLOTS do
yellowfive@57 648 table.insert(bagIds, bagId)
yellowfive@57 649 end
yellowfive@57 650
yellowfive@57 651 for i, bagId in ipairs(bagIds) do
yellowfive@57 652 local numSlots = GetContainerNumSlots(bagId)
yellowfive@57 653 for slotId = 1, numSlots do
yellowfive@161 654 if not usedBagSlots or not usedBagSlots[bagId] or not usedBagSlots[bagId][slotId] then
yellowfive@161 655 local _, _, _, _, _, _, itemLink = GetContainerItemInfo(bagId, slotId)
yellowfive@161 656 if not itemLink then
yellowfive@161 657 -- this prevents repeated calls to this from returning the same bag slot if desired
yellowfive@161 658 if usedBagSlots then
yellowfive@161 659 if not usedBagSlots[bagId] then
yellowfive@161 660 usedBagSlots[bagId] = {}
yellowfive@161 661 end
yellowfive@161 662 usedBagSlots[bagId][slotId] = true
yellowfive@161 663 end
yellowfive@161 664
yellowfive@161 665 return bagId, slotId
yellowfive@161 666 end
yellowfive@57 667 end
yellowfive@57 668 end
yellowfive@57 669 end
yellowfive@57 670
yellowfive@57 671 return nil, nil
yellowfive@57 672 end
yellowfive@57 673
yellowfive@161 674
yellowfive@161 675
yellowfive@124 676 -- scan a bag for the best matching item
yellowfive@124 677 local function scanBagForItem(item, bagId, bestItem, bestDiff, bestLink)
yellowfive@124 678 local numSlots = GetContainerNumSlots(bagId)
yellowfive@149 679 local loc = ItemLocation.CreateEmpty()
yellowfive@124 680 for slotId = 1, numSlots do
yellowfive@124 681 local _, _, _, _, _, _, itemLink = GetContainerItemInfo(bagId, slotId)
yellowfive@124 682 -- we skip any stackable item, as far as we know, there is no equippable gear that can be stacked
yellowfive@124 683 if itemLink then
yellowfive@124 684 local bagItem = Amr.ParseItemLink(itemLink)
yellowfive@124 685 if bagItem ~= nil then
yellowfive@149 686 -- see if this is an azerite item and read azerite power ids
yellowfive@149 687 loc:SetBagAndSlot(bagId, slotId)
yellowfive@149 688 if C_AzeriteEmpoweredItem.IsAzeriteEmpoweredItem(loc) then
yellowfive@149 689 local powers = Amr.ReadAzeritePowers(loc)
yellowfive@149 690 if powers then
yellowfive@149 691 bagItem.azerite = powers
yellowfive@149 692 end
yellowfive@149 693 end
yellowfive@149 694
yellowfive@124 695 local diff = countItemDifferences(item, bagItem)
yellowfive@124 696 if diff < bestDiff then
yellowfive@124 697 bestItem = { bag = bagId, slot = slotId }
yellowfive@124 698 bestDiff = diff
yellowfive@124 699 bestLink = itemLink
yellowfive@124 700 end
yellowfive@124 701 end
yellowfive@124 702 end
yellowfive@57 703 end
yellowfive@124 704 return bestItem, bestDiff, bestLink
yellowfive@57 705 end
yellowfive@57 706
yellowfive@124 707 -- find the item in the player's inventory that best matches the current gear op item, favoring stuff already equipped, then in bags, then in bank
yellowfive@124 708 local function findCurrentGearOpItem()
yellowfive@124 709
yellowfive@124 710 local item = _currentGearOp.items[_currentGearOp.nextSlot]
yellowfive@124 711
yellowfive@57 712 local bestItem = nil
yellowfive@57 713 local bestLink = nil
yellowfive@124 714 local bestDiff = 10000
yellowfive@57 715
yellowfive@73 716 -- inventory
yellowfive@73 717 bestItem, bestDiff, bestLink = scanBagForItem(item, BACKPACK_CONTAINER, bestItem, bestDiff, bestLink)
yellowfive@73 718 for bagId = 1, NUM_BAG_SLOTS do
yellowfive@73 719 bestItem, bestDiff, bestLink = scanBagForItem(item, bagId, bestItem, bestDiff, bestLink)
yellowfive@73 720 end
yellowfive@73 721
yellowfive@129 722 -- with new approach, the item to use should never be equipped, should be in bags at this point
yellowfive@129 723 --[[
yellowfive@61 724 -- equipped items, but skip slots we have just equipped (to avoid e.g. just moving 2 of the same item back and forth between mh oh weapon slots)
yellowfive@57 725 for slotNum = 1, #Amr.SlotIds do
yellowfive@57 726 local slotId = Amr.SlotIds[slotNum]
yellowfive@124 727 if _currentGearOp.slotsRemaining[slotId] then
yellowfive@61 728 local itemLink = GetInventoryItemLink("player", slotId)
yellowfive@61 729 if itemLink then
yellowfive@61 730 local invItem = Amr.ParseItemLink(itemLink)
yellowfive@124 731 if invItem then
yellowfive@61 732 local diff = countItemDifferences(item, invItem)
yellowfive@61 733 if diff < bestDiff then
yellowfive@61 734 bestItem = { slot = slotId }
yellowfive@61 735 bestDiff = diff
yellowfive@61 736 bestLink = itemLink
yellowfive@61 737 end
yellowfive@57 738 end
yellowfive@57 739 end
yellowfive@57 740 end
yellowfive@57 741 end
yellowfive@129 742 ]]
yellowfive@129 743
yellowfive@57 744 -- bank
yellowfive@124 745 if bestDiff > 0 then
yellowfive@124 746 bestItem, bestDiff, bestLink = scanBagForItem(item, BANK_CONTAINER, bestItem, bestDiff, bestLink)
yellowfive@124 747 for bagId = NUM_BAG_SLOTS + 1, NUM_BAG_SLOTS + NUM_BANKBAGSLOTS do
yellowfive@124 748 bestItem, bestDiff, bestLink = scanBagForItem(item, bagId, bestItem, bestDiff, bestLink)
yellowfive@124 749 end
yellowfive@57 750 end
yellowfive@124 751
yellowfive@124 752 return bestItem, bestDiff, bestLink
yellowfive@124 753 end
yellowfive@124 754
yellowfive@143 755 local function createAmrEquipmentSet()
yellowfive@133 756
yellowfive@143 757 -- clear any currently ignored slots, ignore shirt and tabard
yellowfive@143 758 C_EquipmentSet.ClearIgnoredSlotsForSave()
yellowfive@133 759 C_EquipmentSet.IgnoreSlotForSave(INVSLOT_BODY) -- shirt
yellowfive@133 760 C_EquipmentSet.IgnoreSlotForSave(INVSLOT_TABARD)
yellowfive@133 761
yellowfive@133 762 -- for now use icon of the spec
yellowfive@133 763 local _, specName, _, setIcon = GetSpecializationInfo(GetSpecialization())
yellowfive@57 764
yellowfive@133 765 --[[
yellowfive@124 766 local item = Amr.ParseItemLink(GetInventoryItemLink("player", INVSLOT_MAINHAND))
yellowfive@124 767 if not item then
yellowfive@124 768 item = Amr.ParseItemLink(GetInventoryItemLink("player", INVSLOT_OFFHAND))
yellowfive@124 769 end
yellowfive@124 770 if item then
yellowfive@133 771 local itemObj = Item:CreateFromItemID(item.id)
yellowfive@133 772 if itemObj then
yellowfive@133 773 setIcon = itemObj:GetItemIcon()
yellowfive@133 774 end
yellowfive@133 775 end
yellowfive@133 776 ]]
yellowfive@133 777
yellowfive@139 778 local setup = getSetupById(_activeSetupId)
yellowfive@139 779 local setname = setup.Label -- "AMR " .. specName
yellowfive@133 780 local setid = C_EquipmentSet.GetEquipmentSetID(setname)
yellowfive@133 781 if setid then
yellowfive@145 782 local oldName, oldIcon = C_EquipmentSet.GetEquipmentSetInfo(setid)
yellowfive@145 783 setIcon = oldIcon
yellowfive@133 784 C_EquipmentSet.SaveEquipmentSet(setid, setIcon)
yellowfive@133 785 else
yellowfive@133 786 C_EquipmentSet.CreateEquipmentSet(setname, setIcon)
yellowfive@124 787 end
yellowfive@124 788 end
yellowfive@124 789
yellowfive@143 790 -- on completion, create an equipment manager set if desired
yellowfive@143 791 local function onEquipGearSetComplete()
yellowfive@143 792 if Amr.db.profile.options.disableEm then return end
yellowfive@143 793
yellowfive@143 794 -- create an equipment manager set
yellowfive@143 795 createAmrEquipmentSet()
yellowfive@143 796
yellowfive@143 797 -- need to call it twice because on first load the WoW equipment manager just doesn't work
yellowfive@143 798 Amr.Wait(1, function()
yellowfive@143 799 createAmrEquipmentSet()
yellowfive@143 800 end)
yellowfive@143 801 end
yellowfive@143 802
yellowfive@124 803 -- stop any currently in-progress gear swapping operation and clean up
yellowfive@124 804 local function disposeGearOp()
yellowfive@124 805 _pendingGearOps = nil
yellowfive@124 806 _currentGearOp = nil
yellowfive@124 807 _itemLockAction = nil
yellowfive@124 808 _gearOpPasses = 0
yellowfive@124 809 _gearOpWaiting = nil
yellowfive@124 810
yellowfive@124 811 -- make sure the gear tab is still in sync
yellowfive@139 812 Amr:RefreshGearDisplay()
yellowfive@124 813 end
yellowfive@124 814
yellowfive@124 815 -- initialize a gear op to start running it
yellowfive@139 816 local function initializeGearOp(op, setupId, pos)
yellowfive@124 817 op.pos = pos
yellowfive@139 818 op.setupId = setupId
yellowfive@124 819
yellowfive@124 820 -- fill the remaining slot list and set the starting slot
yellowfive@124 821 op.nextSlot = nil
yellowfive@124 822 op.slotsRemaining = {}
yellowfive@124 823 op.isWaiting = false
yellowfive@124 824 for slotId, item in pairs(op.items) do
yellowfive@124 825 op.slotsRemaining[slotId] = true
yellowfive@124 826 if not op.nextSlot then
yellowfive@124 827 op.nextSlot = slotId
yellowfive@124 828 end
yellowfive@124 829 end
yellowfive@124 830 end
yellowfive@124 831
yellowfive@124 832 function processCurrentGearOp()
yellowfive@124 833 if not _currentGearOp then return end
yellowfive@124 834
yellowfive@124 835 if _currentGearOp.remove then
yellowfive@124 836 -- remove the next item
yellowfive@124 837
yellowfive@124 838 -- check if the slot is already empty
yellowfive@124 839 local itemLink = GetInventoryItemLink("player", _currentGearOp.nextSlot)
yellowfive@124 840 if not itemLink then
yellowfive@124 841 nextGearOp()
yellowfive@124 842 return
yellowfive@124 843 end
yellowfive@124 844
yellowfive@57 845 -- find first empty bag slot
yellowfive@57 846 local invBag, invSlot = findFirstEmptyBagSlot()
yellowfive@57 847 if not invBag then
yellowfive@57 848 -- stop if bags are too full
yellowfive@57 849 Amr:Print(L.GearEquipErrorBagFull)
yellowfive@124 850 disposeGearOp()
yellowfive@57 851 return
yellowfive@57 852 end
yellowfive@57 853
yellowfive@124 854 PickupInventoryItem(_currentGearOp.nextSlot)
yellowfive@57 855 PickupContainerItem(invBag, invSlot)
yellowfive@57 856
yellowfive@124 857 -- set an action to happen on ITEM_UNLOCKED, triggered by ClearCursor
yellowfive@124 858 _itemLockAction = {
yellowfive@57 859 bagId = invBag,
yellowfive@124 860 slotId = invSlot,
yellowfive@124 861 isRemove = true
yellowfive@57 862 }
yellowfive@124 863
yellowfive@124 864 ClearCursor()
yellowfive@124 865 -- wait for remove to complete
yellowfive@124 866 else
yellowfive@124 867 -- equip the next item
yellowfive@57 868
yellowfive@124 869 local bestItem, bestDiff, bestLink = findCurrentGearOpItem()
yellowfive@124 870
yellowfive@124 871 _itemLockAction = nil
yellowfive@57 872 ClearCursor()
yellowfive@124 873
yellowfive@124 874 if not bestItem then
yellowfive@124 875 -- stop if we can't find an item
yellowfive@124 876 Amr:Print(L.GearEquipErrorNotFound)
yellowfive@124 877 Amr:Print(L.GearEquipErrorNotFound2)
yellowfive@124 878 disposeGearOp()
yellowfive@124 879
yellowfive@124 880 elseif bestItem and bestItem.bag and (bestItem.bag == BANK_CONTAINER or bestItem.bag >= NUM_BAG_SLOTS + 1 and bestItem.bag <= NUM_BAG_SLOTS + NUM_BANKBAGSLOTS) then
yellowfive@124 881 -- find first empty bag slot
yellowfive@124 882 local invBag, invSlot = findFirstEmptyBagSlot()
yellowfive@124 883 if not invBag then
yellowfive@124 884 -- stop if bags are too full
yellowfive@124 885 Amr:Print(L.GearEquipErrorBagFull)
yellowfive@124 886 disposeGearOp()
yellowfive@124 887 return
yellowfive@124 888 end
yellowfive@124 889
yellowfive@124 890 -- move from bank to bag
yellowfive@124 891 PickupContainerItem(bestItem.bag, bestItem.slot)
yellowfive@124 892 PickupContainerItem(invBag, invSlot)
yellowfive@124 893
yellowfive@124 894 -- set an action to happen on ITEM_UNLOCKED, triggered by ClearCursor
yellowfive@124 895 _itemLockAction = {
yellowfive@124 896 bagId = invBag,
yellowfive@124 897 slotId = invSlot,
yellowfive@124 898 isBank = true
yellowfive@124 899 }
yellowfive@124 900
yellowfive@124 901 ClearCursor()
yellowfive@124 902 -- now we need to wait for game event to continue and try this item again after it is in our bag and unlocked
yellowfive@124 903
yellowfive@124 904 elseif (bestItem.bag or bestItem.bag == 0) and not Amr:CanEquip(bestItem.bag, bestItem.slot) then
yellowfive@57 905 -- if an item is not soulbound, then warn the user and quit
yellowfive@57 906 Amr:Print(L.GearEquipErrorSoulbound(bestLink))
yellowfive@124 907 disposeGearOp()
yellowfive@124 908
yellowfive@57 909 else
yellowfive@124 910
yellowfive@129 911 --print("equipping " .. bestLink .. " in slot " .. _currentGearOp.nextSlot)
yellowfive@129 912
yellowfive@57 913 -- an item in the player's bags or already equipped, equip it
yellowfive@57 914 if bestItem.bag then
yellowfive@57 915 PickupContainerItem(bestItem.bag, bestItem.slot)
yellowfive@57 916 else
yellowfive@124 917 _gearOpWaiting.inventory[bestItem.slot] = true
yellowfive@57 918 PickupInventoryItem(bestItem.slot)
yellowfive@57 919 end
yellowfive@124 920 _gearOpWaiting.inventory[_currentGearOp.nextSlot] = true
yellowfive@124 921 PickupInventoryItem(_currentGearOp.nextSlot)
yellowfive@124 922
yellowfive@124 923 -- don't wait for now, do all equips at once
yellowfive@124 924 --[[
yellowfive@124 925 -- set an action to happen on ITEM_UNLOCKED, triggered by ClearCursor
yellowfive@124 926 _itemLockAction = {
yellowfive@124 927 bagId = bestItem.bag,
yellowfive@124 928 slotId = bestItem.slot,
yellowfive@124 929 invSlot = _currentGearOp.nextSlot,
yellowfive@124 930 isEquip = true
yellowfive@124 931 }
yellowfive@124 932 ]]
yellowfive@124 933
yellowfive@124 934 ClearCursor()
yellowfive@124 935 nextGearOp()
yellowfive@124 936 end
yellowfive@124 937
yellowfive@124 938 end
yellowfive@124 939 end
yellowfive@124 940
yellowfive@124 941 -- when a gear op completes successfully, this will advance to the next op or finish
yellowfive@124 942 function nextGearOp()
yellowfive@124 943 if not _currentGearOp then return end
yellowfive@124 944
yellowfive@139 945 local setupId = _currentGearOp.setupId
yellowfive@124 946 local pos = _currentGearOp.pos
yellowfive@124 947 local passes = _gearOpPasses
yellowfive@124 948
yellowfive@124 949 -- mark the slot as done and move to the next
yellowfive@124 950 if _currentGearOp.nextSlot then
yellowfive@124 951 _currentGearOp.slotsRemaining[_currentGearOp.nextSlot] = nil
yellowfive@124 952 _currentGearOp.nextSlot = nil
yellowfive@124 953 for slotId, item in pairs(_currentGearOp.items) do
yellowfive@124 954 if _currentGearOp.slotsRemaining[slotId] then
yellowfive@124 955 _currentGearOp.nextSlot = slotId
yellowfive@124 956 break
yellowfive@124 957 end
yellowfive@124 958 end
yellowfive@124 959 end
yellowfive@124 960
yellowfive@124 961 if not _currentGearOp.nextSlot then
yellowfive@124 962 -- see if anything is still in progress and we want to wait for it before continuing
yellowfive@124 963 local inProgress = not Amr.IsEmpty(_gearOpWaiting.inventory)
yellowfive@124 964
yellowfive@124 965 if (_currentGearOp.wait or _currentGearOp.remove) and inProgress then
yellowfive@124 966 -- this will cause the item unlock handler to call nextGearOp again when all in-progress swaps have unlocked related slots
yellowfive@124 967 _currentGearOp.isWaiting = true
yellowfive@124 968 else
yellowfive@124 969 _currentGearOp = _pendingGearOps[pos + 1]
yellowfive@124 970 if _currentGearOp then
yellowfive@124 971 -- we have another op, do it
yellowfive@139 972 initializeGearOp(_currentGearOp, setupId, pos + 1)
yellowfive@124 973 processCurrentGearOp()
yellowfive@124 974 else
yellowfive@124 975 -- we are done
yellowfive@124 976 disposeGearOp()
yellowfive@124 977
yellowfive@124 978 -- this will check if not all items were swapped, and either finish up, try again, or abort if have tried too many times
yellowfive@139 979 beginEquipGearSet(setupId, passes + 1)
yellowfive@124 980 end
yellowfive@124 981 end
yellowfive@124 982 else
yellowfive@124 983 -- do the next item
yellowfive@124 984 processCurrentGearOp()
yellowfive@124 985 end
yellowfive@124 986
yellowfive@124 987 end
yellowfive@124 988
yellowfive@124 989 local function handleItemUnlocked(bagId, slotId)
yellowfive@124 990
yellowfive@124 991 -- mark anything that is waiting as unlocked if it is no longer locked
yellowfive@124 992 if _currentGearOp and _gearOpWaiting then
yellowfive@124 993 for i,s in ipairs(Amr.SlotIds) do
yellowfive@124 994 if not IsInventoryItemLocked(s) then
yellowfive@124 995 _gearOpWaiting.inventory[s] = nil
yellowfive@124 996 end
yellowfive@124 997 end
yellowfive@124 998 end
yellowfive@124 999
yellowfive@124 1000 if _itemLockAction then
yellowfive@124 1001 if _itemLockAction.isRemove then
yellowfive@124 1002 -- waiting for a specific remove op to finish before continuing
yellowfive@124 1003 if bagId == _itemLockAction.bagId and slotId == _itemLockAction.slotId then
yellowfive@124 1004 _itemLockAction = nil
yellowfive@124 1005 nextGearOp()
yellowfive@124 1006 end
yellowfive@124 1007 elseif _itemLockAction.isBank then
yellowfive@124 1008 -- waiting for an item to move from bank into inventory, then reprocess the current op
yellowfive@124 1009 if bagId == _itemLockAction.bagId and slotId == _itemLockAction.slotId then
yellowfive@124 1010 _itemLockAction = nil
yellowfive@124 1011 processCurrentGearOp()
yellowfive@124 1012 end
yellowfive@124 1013
yellowfive@124 1014 elseif _itemLockAction.isEquip then
yellowfive@124 1015 -- this is not currently used... we do all equips at once usually, but could go back to this if it causes problems
yellowfive@124 1016
yellowfive@124 1017 -- waiting for a specific equip op to finish
yellowfive@61 1018
yellowfive@124 1019 -- inventory slot we're swapping to is still locked, can't continue yet
yellowfive@124 1020 if IsInventoryItemLocked(_itemLockAction.invSlot) then return end
yellowfive@124 1021
yellowfive@124 1022 if _itemLockAction.bagId then
yellowfive@124 1023 local _, _, locked = GetContainerItemInfo(_itemLockAction.bagId, _itemLockAction.slotId)
yellowfive@124 1024 -- the bag slot we're swapping from is still locked, can't continue yet
yellowfive@124 1025 if locked then return end
yellowfive@124 1026 else
yellowfive@124 1027 -- inventory slot we're swapping from is still locked, can't continue yet
yellowfive@124 1028 if IsInventoryItemLocked(_itemLockAction.slotId) then return end
yellowfive@124 1029 end
yellowfive@124 1030
yellowfive@124 1031 _itemLockAction = nil
yellowfive@124 1032 nextGearOp()
yellowfive@124 1033 else
yellowfive@124 1034 -- unknown... shouldn't happen
yellowfive@124 1035 _itemLockAction = nil
yellowfive@57 1036 end
yellowfive@124 1037 else
yellowfive@124 1038
yellowfive@124 1039 -- not waiting on a specific action, check if we are waiting for all locked slots to open up and they are done
yellowfive@124 1040 if _currentGearOp and _gearOpWaiting and _currentGearOp.isWaiting and Amr.IsEmpty(_gearOpWaiting.inventory) then
yellowfive@124 1041 nextGearOp()
yellowfive@124 1042 end
yellowfive@57 1043 end
yellowfive@57 1044
yellowfive@57 1045 end
yellowfive@57 1046
yellowfive@124 1047 local function shuffle(tbl)
yellowfive@124 1048 local size = #tbl
yellowfive@124 1049 for i = size, 1, -1 do
yellowfive@124 1050 local rand = math.random(size)
yellowfive@124 1051 tbl[i], tbl[rand] = tbl[rand], tbl[i]
yellowfive@89 1052 end
yellowfive@124 1053 return tbl
yellowfive@89 1054 end
yellowfive@89 1055
yellowfive@129 1056 local _ohFirst = {
yellowfive@129 1057 [20] = true, -- PaladinProtection
yellowfive@129 1058 [32] = true, -- WarlockDemonology
yellowfive@129 1059 [36] = true -- WarriorProtection
yellowfive@129 1060 }
yellowfive@129 1061
yellowfive@139 1062 function beginEquipGearSet(setupId, passes)
yellowfive@57 1063
yellowfive@139 1064 local setup = getSetupById(setupId)
yellowfive@139 1065
yellowfive@139 1066 if not setup or not setup.Gear then
yellowfive@57 1067 Amr:Print(L.GearEquipErrorEmpty)
yellowfive@57 1068 return
yellowfive@57 1069 end
yellowfive@124 1070
yellowfive@139 1071 local gear = setup.Gear
yellowfive@139 1072 local spec = setup.SpecSlot
yellowfive@139 1073
yellowfive@139 1074 -- ensure all our stored data is up to date
yellowfive@57 1075 local player = Amr:ExportCharacter()
yellowfive@129 1076 local doOhFirst = _ohFirst[player.Specs[spec]]
yellowfive@57 1077
yellowfive@124 1078 local itemsToEquip = {
yellowfive@124 1079 legendaries = {},
yellowfive@124 1080 weapons = {},
yellowfive@129 1081 mh = {},
yellowfive@129 1082 oh = {},
yellowfive@124 1083 rings = {},
yellowfive@124 1084 trinkets = {},
yellowfive@124 1085 others = {},
yellowfive@124 1086 blanks = {}
yellowfive@124 1087 }
yellowfive@57 1088 local remaining = 0
yellowfive@129 1089 local usedItems = {}
yellowfive@124 1090
yellowfive@124 1091 -- check for items that need to be equipped, do in a random order to try and defeat any unique constraint issues we might hit
yellowfive@124 1092 local slots = {}
yellowfive@124 1093 for i,s in ipairs(Amr.SlotIds) do
yellowfive@124 1094 table.insert(slots, s)
yellowfive@124 1095 end
yellowfive@124 1096 shuffle(slots)
yellowfive@124 1097
yellowfive@124 1098 for i,slotId in ipairs(slots) do
yellowfive@124 1099
yellowfive@124 1100 -- we do stuff in batches that avoids most unique conflicts
yellowfive@124 1101 local list = itemsToEquip.others
yellowfive@129 1102 if slotId == 16 then
yellowfive@129 1103 list = itemsToEquip.mh
yellowfive@129 1104 elseif slotId == 17 then
yellowfive@129 1105 list = itemsToEquip.oh
yellowfive@124 1106 elseif slotId == 11 or slotId == 12 then
yellowfive@124 1107 list = itemsToEquip.rings
yellowfive@124 1108 elseif slotId == 13 or slotId == 14 then
yellowfive@124 1109 list = itemsToEquip.trinkets
yellowfive@124 1110 end
yellowfive@124 1111
yellowfive@57 1112 local old = player.Equipped[spec][slotId]
yellowfive@57 1113 local new = gear[slotId]
yellowfive@124 1114 local prevRemaining = remaining
yellowfive@69 1115 if new then
yellowfive@124 1116 -- if the new thing is an artifact, only match the item id
yellowfive@124 1117 local newItem = Item:CreateFromItemID(new.id)
yellowfive@124 1118 local quality = newItem and newItem:GetItemQuality() or 0
yellowfive@124 1119 if quality == 6 then
yellowfive@124 1120 if not old or new.id ~= old.id then
yellowfive@124 1121 list[slotId] = new
yellowfive@129 1122 if list == itemsToEquip.mh or list == itemsToEquip.oh then
yellowfive@129 1123 itemsToEquip.weapons[slotId] = {}
yellowfive@129 1124 end
yellowfive@69 1125 remaining = remaining + 1
yellowfive@69 1126 end
yellowfive@129 1127 else
yellowfive@145 1128
yellowfive@129 1129 -- find the best matching item anywhere in the player's gear
yellowfive@129 1130 local bestItem, bestDiff = Amr:FindMatchingItem(new, player, usedItems)
yellowfive@129 1131 new = bestItem
yellowfive@129 1132
yellowfive@149 1133 local diff = countItemDifferences(new, old)
yellowfive@124 1134
yellowfive@129 1135 if diff > 0 then
yellowfive@124 1136 list[slotId] = new
yellowfive@129 1137 if list == itemsToEquip.mh or list == itemsToEquip.oh then
yellowfive@129 1138 itemsToEquip.weapons[slotId] = {}
yellowfive@129 1139 end
yellowfive@124 1140 remaining = remaining + 1
yellowfive@124 1141 end
yellowfive@124 1142 end
yellowfive@129 1143 elseif old then
yellowfive@124 1144 -- need to remove this item
yellowfive@124 1145 itemsToEquip.blanks[slotId] = {}
yellowfive@124 1146 remaining = remaining + 1
yellowfive@124 1147 end
yellowfive@124 1148
yellowfive@124 1149 if remaining > prevRemaining then
yellowfive@124 1150 -- if we need to swap this slot, see if the old item is a legendary, add a step to remove those first to avoid conflicts
yellowfive@124 1151 if old then
yellowfive@124 1152 local oldItem = Item:CreateFromItemID(old.id)
yellowfive@124 1153 if oldItem and oldItem:GetItemQuality() == 5 then
yellowfive@124 1154 itemsToEquip.legendaries[slotId] = {}
yellowfive@124 1155 end
yellowfive@57 1156 end
yellowfive@57 1157 end
yellowfive@57 1158 end
yellowfive@124 1159
yellowfive@124 1160 if remaining > 0 then
yellowfive@57 1161
yellowfive@124 1162 if passes < 5 then
yellowfive@124 1163 _pendingGearOps = {}
yellowfive@124 1164
yellowfive@129 1165 if not Amr.IsEmpty(itemsToEquip.blanks) then
yellowfive@124 1166 -- if gear set wants slots to be blank, do that first
yellowfive@124 1167 table.insert(_pendingGearOps, { items = itemsToEquip.blanks, remove = true, label = "blanks" })
yellowfive@129 1168 end
yellowfive@124 1169 if not Amr.IsEmpty(itemsToEquip.weapons) then
yellowfive@129 1170 -- change weapons first: remove both, wait, then equip each weapon one by one, waiting after each
yellowfive@129 1171 table.insert(_pendingGearOps, { items = itemsToEquip.weapons, remove = true, label = "remove weapons" })
yellowfive@129 1172 local thisWeapon = doOhFirst and itemsToEquip.oh or itemsToEquip.mh
yellowfive@129 1173 if not Amr.IsEmpty(thisWeapon) then
yellowfive@129 1174 table.insert(_pendingGearOps, { items = thisWeapon, wait = true, label = "equip weapon 1" })
yellowfive@129 1175 end
yellowfive@129 1176 thisWeapon = doOhFirst and itemsToEquip.mh or itemsToEquip.oh
yellowfive@129 1177 if not Amr.IsEmpty(thisWeapon) then
yellowfive@129 1178 table.insert(_pendingGearOps, { items = thisWeapon, wait = true, label = "equip weapon 2" })
yellowfive@129 1179 end
yellowfive@124 1180 end
yellowfive@124 1181 if not Amr.IsEmpty(itemsToEquip.legendaries) then
yellowfive@124 1182 -- remove any legendaries, wait
yellowfive@124 1183 table.insert(_pendingGearOps, { items = itemsToEquip.legendaries, remove = true, label = "remove legendaries" })
yellowfive@124 1184 end
yellowfive@124 1185 if not Amr.IsEmpty(itemsToEquip.rings) then
yellowfive@124 1186 -- remove both rings, wait, then equip new ones
yellowfive@124 1187 table.insert(_pendingGearOps, { items = itemsToEquip.rings, remove = true, label = "remove rings" })
yellowfive@124 1188 table.insert(_pendingGearOps, { items = itemsToEquip.rings, wait = true, label = "equip rings" })
yellowfive@124 1189 end
yellowfive@124 1190 if not Amr.IsEmpty(itemsToEquip.trinkets) then
yellowfive@124 1191 -- remove both trinkets, wait, then equip new ones
yellowfive@124 1192 table.insert(_pendingGearOps, { items = itemsToEquip.trinkets, remove = true, label = "remove trinkets" })
yellowfive@124 1193 table.insert(_pendingGearOps, { items = itemsToEquip.trinkets, wait = true, label = "equip trinkets" })
yellowfive@124 1194 end
yellowfive@124 1195 if not Amr.IsEmpty(itemsToEquip.others) then
yellowfive@124 1196 -- equip all other items, wait for completion
yellowfive@124 1197 table.insert(_pendingGearOps, { items = itemsToEquip.others, wait = true, label = "equip others" })
yellowfive@124 1198 end
yellowfive@124 1199
yellowfive@169 1200 if #_pendingGearOps > 0 then
yellowfive@169 1201 -- make the last operation wait no matter what, before this gets called again to check if everything succeeded
yellowfive@169 1202 _pendingGearOps[#_pendingGearOps].wait = true
yellowfive@124 1203
yellowfive@169 1204 if not _gearOpWaiting then
yellowfive@169 1205 _gearOpWaiting = { inventory = {} }
yellowfive@169 1206 end
yellowfive@169 1207
yellowfive@169 1208 _gearOpPasses = passes
yellowfive@169 1209 _currentGearOp = _pendingGearOps[1]
yellowfive@169 1210 initializeGearOp(_currentGearOp, setupId, 1)
yellowfive@169 1211
yellowfive@169 1212 processCurrentGearOp()
yellowfive@169 1213 else
yellowfive@169 1214 -- TODO: print message that gear set couldn't be equipped
yellowfive@124 1215 end
yellowfive@169 1216
yellowfive@124 1217 else
yellowfive@124 1218 -- TODO: print message that gear set couldn't be equipped
yellowfive@89 1219 end
yellowfive@57 1220
yellowfive@57 1221 else
yellowfive@89 1222 onEquipGearSetComplete()
yellowfive@124 1223 end
yellowfive@57 1224 end
yellowfive@57 1225
yellowfive@57 1226 local function onActiveTalentGroupChanged()
yellowfive@81 1227
yellowfive@57 1228 local auto = Amr.db.profile.options.autoGear
yellowfive@81 1229 local currentSpec = GetSpecialization()
yellowfive@129 1230 local waitingSpec = _waitingForSpec
yellowfive@129 1231 _waitingForSpec = 0
yellowfive@57 1232
yellowfive@139 1233 -- when spec changes, change active setup to first one for this spec (does nothing if they have no setups for this spec)
yellowfive@139 1234 if _activeSetupId then
yellowfive@139 1235 local currentSetup = getSetupById(_activeSetupId)
yellowfive@139 1236 if currentSetup.SpecSlot ~= currentSpec then
yellowfive@139 1237 Amr:PickFirstSetupForSpec()
yellowfive@139 1238 end
yellowfive@139 1239 end
yellowfive@139 1240
yellowfive@129 1241 if currentSpec == waitingSpec or auto then
yellowfive@129 1242 -- spec is what we want, now equip the gear but after a short delay because the game auto-swaps artifact weapons
yellowfive@129 1243 Amr.Wait(2, function()
yellowfive@139 1244 beginEquipGearSet(_activeSetupId, 0)
yellowfive@129 1245 end)
yellowfive@57 1246 end
yellowfive@57 1247 end
yellowfive@57 1248
yellowfive@81 1249 -- activate the specified spec and then equip the saved gear set
yellowfive@139 1250 function Amr:EquipGearSet(setupIndex)
yellowfive@57 1251
yellowfive@139 1252 -- if no argument, then cycle
yellowfive@139 1253 if not setupIndex then
yellowfive@139 1254 if not _activeSetupId then
yellowfive@139 1255 Amr:PickFirstSetupForSpec()
yellowfive@139 1256 end
yellowfive@139 1257 for i,setup in ipairs(Amr.db.char.GearSetups) do
yellowfive@139 1258 if setup.Id == _activeSetupId then
yellowfive@139 1259 setupIndex = i
yellowfive@139 1260 break
yellowfive@139 1261 end
yellowfive@139 1262 end
yellowfive@139 1263 if not setupIndex then
yellowfive@139 1264 setupIndex = 1
yellowfive@139 1265 else
yellowfive@139 1266 setupIndex = setupIndex + 1
yellowfive@139 1267 end
yellowfive@57 1268 end
yellowfive@81 1269
yellowfive@139 1270 setupIndex = tonumber(setupIndex)
yellowfive@81 1271
yellowfive@139 1272 if setupIndex > #Amr.db.char.GearSetups then
yellowfive@139 1273 setupIndex = 1
yellowfive@139 1274 end
yellowfive@139 1275
yellowfive@57 1276 if UnitAffectingCombat("player") then
yellowfive@57 1277 Amr:Print(L.GearEquipErrorCombat)
yellowfive@57 1278 return
yellowfive@57 1279 end
yellowfive@57 1280
yellowfive@139 1281 _activeSetupId = Amr.db.char.GearSetups[setupIndex].Id
yellowfive@139 1282 Amr:RefreshGearDisplay()
yellowfive@139 1283
yellowfive@139 1284 local setup = Amr.db.char.GearSetups[setupIndex]
yellowfive@81 1285 local currentSpec = GetSpecialization()
yellowfive@139 1286 if currentSpec ~= setup.SpecSlot then
yellowfive@139 1287 _waitingForSpec = setup.SpecSlot
yellowfive@139 1288 SetSpecialization(setup.SpecSlot)
yellowfive@57 1289 else
yellowfive@129 1290 -- spec is what we want, now equip the gear
yellowfive@139 1291 beginEquipGearSet(_activeSetupId, 0)
yellowfive@57 1292 end
yellowfive@57 1293 end
yellowfive@57 1294
yellowfive@124 1295 -- moves any gear in bags to the bank if not part of a gear set
yellowfive@57 1296 function Amr:CleanBags()
yellowfive@57 1297 -- TODO: implement
yellowfive@57 1298 end
yellowfive@57 1299
yellowfive@181 1300
yellowfive@81 1301 local function testfunc(message)
yellowfive@81 1302 print(strsub(message, 13))
yellowfive@81 1303 end
yellowfive@181 1304
yellowfive@81 1305
yellowfive@57 1306 function Amr:InitializeGear()
yellowfive@87 1307 Amr:AddEventHandler("ACTIVE_TALENT_GROUP_CHANGED", onActiveTalentGroupChanged)
yellowfive@57 1308
yellowfive@181 1309 Amr:AddEventHandler("CHAT_MSG_CHANNEL", testfunc)
yellowfive@81 1310
yellowfive@57 1311 Amr:AddEventHandler("UNIT_INVENTORY_CHANGED", function(unitID)
yellowfive@57 1312 if unitID and unitID ~= "player" then return end
yellowfive@124 1313
yellowfive@124 1314 -- don't update during a gear operation, wait until it is totally finished
yellowfive@124 1315 if _pendingGearOps then return end
yellowfive@124 1316
yellowfive@139 1317 Amr:RefreshGearDisplay()
yellowfive@57 1318 end)
yellowfive@57 1319
yellowfive@124 1320 Amr:AddEventHandler("ITEM_UNLOCKED", handleItemUnlocked)
yellowfive@122 1321 end
yellowfive@161 1322
yellowfive@161 1323
yellowfive@161 1324 -- export some local methods we need elsewhere
yellowfive@161 1325 Amr.CountItemDifferences = countItemDifferences
yellowfive@161 1326 Amr.FindFirstEmptyBagSlot = findFirstEmptyBagSlot