Skip to content

Commit dd217cc

Browse files
Fixed major bug causing eqMan to not re-equip swapped out offhand weapons when a 2 handed weapon is saved to the Angleur Set
1 parent dba55bf commit dd217cc

1 file changed

Lines changed: 82 additions & 38 deletions

File tree

eqMan/eqMan_base.lua

Lines changed: 82 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ local colorGrae = CreateColor(0.85, 0.85, 0.85)
99

1010
local retail = AngleurEqManRetail
1111

12+
local updatingSet = false
1213

1314
local function getItemLinkID(itemID)
1415
local _, link = C_Item.GetItemInfo(itemID)
@@ -22,13 +23,18 @@ local function getItemLinkBag(bagID, slotIndex)
2223
itemLocation:Clear()
2324
return link
2425
end
26+
2527
local function getItemLinkEquipped(equipmentSlotIndex)
28+
local inventoryItemID = GetInventoryItemID("player", equipmentSlotIndex)
29+
if not inventoryItemID then return nil end
2630
itemLocation:SetEquipmentSlot(equipmentSlotIndex)
2731
local link = C_Item.GetItemLink(itemLocation)
2832
itemLocation:Clear()
2933
return link
3034
end
3135
local function getItemGUIDEquiped(equipmentSlotIndex)
36+
local inventoryItemID = GetInventoryItemID("player", equipmentSlotIndex)
37+
if not inventoryItemID then return nil end
3238
itemLocation:SetEquipmentSlot(equipmentSlotIndex)
3339
local guid = C_Item.GetItemLink(itemLocation)
3440
itemLocation:Clear()
@@ -42,6 +48,13 @@ SlashCmdList["ANGSAVEDITEMS"] = function()
4248
print(v)
4349
end
4450
end
51+
52+
SLASH_ANGSAVEDRESET1 = "/angsavedres"
53+
SlashCmdList["ANGSAVEDRESET"] = function()
54+
print(colorDebug3:WrapTextInColorCode("Reset swapout items"))
55+
Angleur_SwapoutItemsSaved = {}
56+
end
57+
4558
SLASH_ANGTEST1 = "/angtest"
4659
SlashCmdList["ANGTEST"] = function()
4760
local setID = C_EquipmentSet.GetEquipmentSetID("Angleur")
@@ -79,6 +92,8 @@ function Angleur_EquipmentManager()
7992
Angleur_CreateWeaponSwapFrames()
8093
end
8194

95+
96+
8297
function Angleur_CreateSetAndAdd_UpdateState()
8398
if AngleurCharacter.angleurSet == true then
8499
Angleur.configPanel.tab2.contents.createSetAndAdd.defaultTexture:Hide()
@@ -197,25 +212,21 @@ local function isSetEquipped(setID)
197212
end
198213

199214

200-
201-
--**********************[1]************************
202-
--* Automatically adding slotted items to the set *
203-
--**********************[1]************************
204-
205-
local function showAndPlayAnimation()
206-
local gameVersion = Angleur_CheckVersion()
207-
if gameVersion == 3 then return end
208-
if not CharacterFrame:IsShown() then
209-
ToggleCharacter("PaperDollFrame")
215+
-- _____________________________________________________________ MANUAL EQUIP TRACKER__________________________________________________________________________________________
216+
-- When player manually changes items, regardless of sleep state, add the EQUIPPED items to 'Angleur_SwapoutItemsSaved' (if they have a counterpart in the Angleur Set)
217+
local function handleEquip2HanderAndOffhand(setsMainhandItem, slot)
218+
if slot == INVSLOT_OFFHAND then
219+
-- 17 is INVTYPE_2HWEAPON for C_Item.GetItemInventoryTypeByID
220+
if setsMainhandItem and setsMainhandItem ~= -1 and C_Item.GetItemInventoryTypeByID(setsMainhandItem) == 17 then
221+
local itemLink = getItemLinkEquipped(INVSLOT_OFFHAND)
222+
Angleur_BetaPrint(colorDebug1:WrapTextInColorCode("ManualEquipTracker ") .. ": The new item, " .. itemLink .. " is equipped to offhand, and the Set Main Hand is a 2-Hander. Adding to Swapout Table.")
223+
Angleur_SwapoutItemsSaved[INVSLOT_OFFHAND] = itemLink
224+
end
210225
end
211-
PaperDollFrame_SetSidebar(PaperDollFrame, 3)
212-
if gameVersion == 1 then retail:showShiny() end
213226
end
214-
-- When player manually changes items, add them to the 'Angleur_SwapoutItemsSaved' regardless of sleep state
215-
local updatingSet = false
216-
local equipmentChangeTrackFrame = CreateFrame("Frame")
217-
equipmentChangeTrackFrame:RegisterEvent("PLAYER_EQUIPMENT_CHANGED")
218-
equipmentChangeTrackFrame:SetScript("OnEvent", function(self, event, slot, empty)
227+
local ManualEquipTracker = CreateFrame("Frame")
228+
ManualEquipTracker:RegisterEvent("PLAYER_EQUIPMENT_CHANGED")
229+
ManualEquipTracker:SetScript("OnEvent", function(self, event, slot, empty)
219230
if AngleurCharacter.angleurSet == false then return end
220231
if event == "PLAYER_EQUIPMENT_CHANGED" then
221232
if empty == true then
@@ -225,24 +236,43 @@ equipmentChangeTrackFrame:SetScript("OnEvent", function(self, event, slot, empty
225236
local angleurSetItemIDs = C_EquipmentSet.GetItemIDs(C_EquipmentSet.GetEquipmentSetID("Angleur"))
226237
local setItem = angleurSetItemIDs[slot]
227238
if not setItem or setItem == -1 then
228-
Angleur_BetaPrint(colorDebug1:WrapTextInColorCode("EquipmentChangeTrack ") .. ": No set counterpart in the slot, not overwriting")
239+
local setsMainhandItem = angleurSetItemIDs[INVSLOT_MAINHAND]
240+
handleEquip2HanderAndOffhand(setsMainhandItem, slot)
241+
Angleur_BetaPrint(colorDebug1:WrapTextInColorCode("ManualEquipTracker ") .. ": No set counterpart in the slot, not overwriting")
229242
return
230243
end
231-
Angleur_BetaPrint(colorDebug1:WrapTextInColorCode("EquipmentChangeTrack ") .. ": Newly Equipped Item: ", getItemLinkEquipped(slot))
232-
Angleur_BetaPrint(colorDebug1:WrapTextInColorCode("EquipmentChangeTrack ") .. ": Angleur Set Counterpart: ", getItemLinkID(setItem))
244+
Angleur_BetaPrint(colorDebug1:WrapTextInColorCode("ManualEquipTracker ") .. ": Newly Equipped Item: ", getItemLinkEquipped(slot))
245+
Angleur_BetaPrint(colorDebug1:WrapTextInColorCode("ManualEquipTracker ") .. ": Angleur Set Counterpart: ", getItemLinkID(setItem))
233246
if newItem == setItem then
234-
Angleur_BetaPrint(colorDebug1:WrapTextInColorCode("EquipmentChangeTrack ") .. ": The new item is the set item...")
247+
Angleur_BetaPrint(colorDebug1:WrapTextInColorCode("ManualEquipTracker ") .. ": The new item is the set item...")
235248
elseif updatingSet == false then
236249
Angleur_SwapoutItemsSaved[slot] = getItemLinkEquipped(slot)
237-
Angleur_BetaPrint(colorDebug1:WrapTextInColorCode("EquipmentChangeTrack ") .. ": OVERWRITTEN: ", Angleur_SwapoutItemsSaved[slot])
250+
Angleur_BetaPrint(colorDebug1:WrapTextInColorCode("ManualEquipTracker ") .. ": OVERWRITTEN: ", Angleur_SwapoutItemsSaved[slot])
238251
end
239252
end
240253
end
241254
end)
255+
--_________________________________________________________________________________________________________________________________________________________________________
242256

243257

244258

245259

260+
--**********************[1]************************
261+
--* Automatically adding slotted items to the set *
262+
--**********************[1]************************
263+
-- Play a glow animation around the "Angleur" Equipment Set in the Equipment Manager menu
264+
local function showAndPlayAnimation()
265+
local gameVersion = Angleur_CheckVersion()
266+
if gameVersion == 3 then return end
267+
if not CharacterFrame:IsShown() then
268+
ToggleCharacter("PaperDollFrame")
269+
end
270+
PaperDollFrame_SetSidebar(PaperDollFrame, 3)
271+
if gameVersion == 1 then retail:showShiny() end
272+
end
273+
274+
275+
246276
-- Will periodically call 'Equip Item' for items in wantToEquip until it's empty(all items have been equipped)
247277
local wantToEquip = {}
248278
local equipFrame = CreateFrame("Frame")
@@ -444,8 +474,8 @@ local function wepSwapFrame_OnEvent(self, event, unit, ...)
444474
local arg4, arg5 = ...
445475
local children = {self:GetChildren()}
446476
if event == "PLAYER_REGEN_DISABLED" then
447-
swapWepTable[16] = Angleur_SwapoutItemsSaved[16]
448-
swapWepTable[17] = Angleur_SwapoutItemsSaved[17]
477+
swapWepTable[INVSLOT_MAINHAND] = Angleur_SwapoutItemsSaved[INVSLOT_MAINHAND]
478+
swapWepTable[INVSLOT_OFFHAND] = Angleur_SwapoutItemsSaved[INVSLOT_OFFHAND]
449479
Angleur_RepositionWeaponSwapFrames()
450480
for i, child in pairs(children) do
451481
child:setMacro(swapWepTable)
@@ -458,11 +488,11 @@ local function wepSwapFrame_OnEvent(self, event, unit, ...)
458488
return
459489
end
460490
local setItems = C_EquipmentSet.GetItemIDs(setID)
461-
if setItems[16] and setItems[16] ~= -1 then
462-
swapWepTable[16] = setItems[16]
491+
if setItems[INVSLOT_MAINHAND] and setItems[INVSLOT_MAINHAND] ~= -1 then
492+
swapWepTable[INVSLOT_MAINHAND] = setItems[INVSLOT_MAINHAND]
463493
end
464-
if setItems[17] and setItems[17] ~= -1 then
465-
swapWepTable[17] = setItems[17]
494+
if setItems[INVSLOT_OFFHAND] and setItems[INVSLOT_OFFHAND] ~= -1 then
495+
swapWepTable[INVSLOT_OFFHAND] = setItems[INVSLOT_OFFHAND]
466496
end
467497
swapCombatWeapons_Single()
468498
if next(swapWepTable) ~= nil then
@@ -539,24 +569,36 @@ end
539569
--**********************[3]************************
540570
--****************** Equip Set ********************
541571
--**********************[3]************************
542-
--
543-
local equipFrameSet = CreateFrame("Frame")
544-
equipFrameSet:RegisterEvent("EQUIPMENT_SWAP_FINISHED")
572+
573+
local function handleOffhandSwapout(itemIDs)
574+
if not itemIDs[INVSLOT_OFFHAND] or itemIDs[INVSLOT_OFFHAND] == -1 then
575+
local setsMainhandItem = itemIDs[INVSLOT_MAINHAND]
576+
-- 17 is INVTYPE_2HWEAPON for C_Item.GetItemInventoryTypeByID, == 17 means the weapon in the set is a 2 hander
577+
if setsMainhandItem and setsMainhandItem ~= -1 and C_Item.GetItemInventoryTypeByID(setsMainhandItem) == 17 then
578+
local itemLink = getItemLinkEquipped(INVSLOT_OFFHAND)
579+
if itemLink then
580+
Angleur_SwapoutItemsSaved[INVSLOT_OFFHAND] = itemLink
581+
Angleur_BetaPrint(colorDebug2:WrapTextInColorCode("fillSwapoutTable ") .. "Angleur Set has 2-Handed Weapon, adding equipped offhand " .. "[" .. itemLink .. "]" .. " to Swapout Table")
582+
end
583+
end
584+
end
585+
end
545586
local function fillSwapoutTable(setID)
546587
itemIDs = C_EquipmentSet.GetItemIDs(setID)
547588
Angleur_BetaPrint(colorDebug2:WrapTextInColorCode("fillSwapoutTable ") .. ": Table ItemIDs:")
548589
Angleur_BetaTableToString(itemIDs)
590+
handleOffhandSwapout(itemIDs)
549591
for location = 1, 19 do
550592
if itemIDs[location] ~= nil and itemIDs[location] ~= -1 then
551-
Angleur_BetaPrint(colorDebug2:WrapTextInColorCode("fillSwapoutTable ") .. ": Slot is set to equip item: ", itemIDs[location])
552-
local inventoryItemID = GetInventoryItemID("player", location)
553-
Angleur_BetaPrint(inventoryItemID)
554-
if inventoryItemID then
593+
Angleur_BetaPrint(colorDebug2:WrapTextInColorCode("fillSwapoutTable ") .. ": Slot " .. location .. " is set to equip item " .. "[" .. itemIDs[location] .. "]")
594+
local itemLink = getItemLinkEquipped(location)
595+
if itemLink then
596+
Angleur_BetaPrint(colorDebug2:WrapTextInColorCode("fillSwapoutTable ") .. ": item " .. "[" .. itemLink .. "]" .. " in Slot " .. location .. " is set to be unequipped.")
555597
if inventoryItemID == itemIDs[location] then
556598
Angleur_BetaPrint(colorDebug2:WrapTextInColorCode("fillSwapoutTable ") .. ": Set item was previously equipped, not overriding previous re-requip table.")
557-
elseif Angleur_SwapoutItemsSaved[location] ~= nil and Angleur_SwapoutItemsSaved[location] ~= -1 then
558-
local _, itemLink = GetItemInfo(Angleur_SwapoutItemsSaved[location])
559-
Angleur_BetaPrint(location, itemLink)
599+
else
600+
Angleur_SwapoutItemsSaved[location] = itemLink
601+
Angleur_BetaPrint(colorDebug2:WrapTextInColorCode("fillSwapoutTable ") .. ": adding item " .. "[" .. itemLink .. "]" .. " to Swapouts.\n\n")
560602
end
561603
end
562604
end
@@ -579,6 +621,8 @@ local function checkSetBug()
579621
end
580622
return true
581623
end
624+
local equipFrameSet = CreateFrame("Frame")
625+
equipFrameSet:RegisterEvent("EQUIPMENT_SWAP_FINISHED")
582626
-- Starts off the periodical calling of 'Equip Set' until player enters combat or set is succesfully equipped
583627
function Angleur_EquipAngleurSet(overrideSwapoutItems)
584628
local setID = C_EquipmentSet.GetEquipmentSetID("Angleur")

0 commit comments

Comments
 (0)