-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathOpen-Sesame.lua
198 lines (173 loc) · 6.67 KB
/
Open-Sesame.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
-- Open Sesame Add-on
local OpenSesame = {}
OpenSesame.AllowedItems = OpenSesame_AllowedOpenItems or {}
-- Constants
local BAG_FULL_DELAY = 10 -- Delay before showing "Bag Full" messages again (seconds)
local OPEN_ITEM_DELAY = 0.1 -- Delay between opening items
local WORLD_LOAD_DELAY = 10 -- Delay before processing items after login
local ADDON_NAME = "OpenSesame"
-- State Variables
OpenSesame.lastBagFullTime = 0
OpenSesame.isProcessing = false
OpenSesame.isEnabled = true
OpenSesame.isPaused = false
-- Minimap Icons
local ICONS = {
enabled = "Interface\\Icons\\inv_jewelcrafting_gem_01",
disabled = "Interface\\Icons\\inv_jewelcrafting_gem_04",
paused = "Interface\\Icons\\inv_jewelcrafting_gem_03"
}
-- Minimap Button Setup
local LDB = LibStub:GetLibrary("LibDataBroker-1.1")
local LDBIcon = LibStub("LibDBIcon-1.0")
local minimapButton =
LDB:NewDataObject(
ADDON_NAME,
{
type = "launcher",
text = ADDON_NAME,
icon = ICONS.enabled,
OnClick = function(_, button)
if button == "LeftButton" then
OpenSesame.isEnabled = not OpenSesame.isEnabled
OpenSesame.isPaused = false
UpdateMinimapIcon()
print(
"|cff4FC3F7Open Sesame|r : Auto-Open " ..
(OpenSesame.isEnabled and "|cff00FF00On|r" or "|cffFF0000Off|r")
)
if OpenSesame.isEnabled then
ProcessItems()
end
end
end,
OnTooltipShow = function(tooltip)
tooltip:AddLine("|cff4FC3F7Open Sesame|r", 1, 1, 1)
tooltip:AddLine(" ", 1, 1, 1)
local status =
OpenSesame.isPaused and "|cffFFFF00Paused|r" or
(OpenSesame.isEnabled and "|cff00FF00On|r" or "|cffFF0000Off|r")
tooltip:AddDoubleLine("Auto-Open :", status, 1, 1, 1, 1, 1, 1)
tooltip:AddLine(" ", 1, 1, 1)
tooltip:AddLine("Click to turn Auto-Open On or Off.", 0.8, 0.8, 0.8)
end
}
)
LDBIcon:Register(ADDON_NAME, minimapButton, {})
function UpdateMinimapIcon()
if minimapButton then
minimapButton.icon =
ICONS[OpenSesame.isPaused and "paused" or (OpenSesame.isEnabled and "enabled" or "disabled")]
end
end
local function GetBagSpace()
local freeSlots = 0
for bag = 0, 4 do
local slots, bagType = C_Container.GetContainerNumFreeSlots(bag)
if bagType == 0 then
freeSlots = freeSlots + slots
end
end
return freeSlots
end
-- Check if any UI windows are open
local function IsAnyWindowOpen()
return (AuctionFrame and AuctionFrame:IsVisible()) or (BankFrame and BankFrame:IsVisible()) or
(ContainerFrame1 and ContainerFrame1:IsVisible()) or
(ContainerFrame2 and ContainerFrame2:IsVisible()) or
(ContainerFrame3 and ContainerFrame3:IsVisible()) or
(ContainerFrame4 and ContainerFrame4:IsVisible()) or
(ContainerFrame5 and ContainerFrame5:IsVisible()) or
(CraftFrame and CraftFrame:IsVisible()) or
(GossipFrame and GossipFrame:IsVisible()) or
(LootFrame and LootFrame:IsVisible()) or
(MailFrame and MailFrame:IsVisible()) or
(MerchantFrame and MerchantFrame:IsVisible()) or
(ReagentBankFrame and ReagentBankFrame:IsVisible()) or
(TradeFrame and TradeFrame:IsVisible()) or
(TradeSkillFrame and TradeSkillFrame:IsVisible())
end
local function IsPlayerCasting()
return UnitCastingInfo("player") ~= nil
end
-- Opens items one by one with a delay
function ProcessItems()
if not OpenSesame.isEnabled then
return
end
if OpenSesame.isProcessing or UnitAffectingCombat("player") or IsPlayerCasting() or IsAnyWindowOpen() then
return
end
OpenSesame.isProcessing = true
local freeSlots = GetBagSpace()
if freeSlots < 4 then
if not OpenSesame.isPaused then
print("|cff4FC3F7Open Sesame|r : Paused until you have at least 4 free bag slots!")
end
OpenSesame.isPaused = true
UpdateMinimapIcon()
OpenSesame.isProcessing = false
return
end
if OpenSesame.isPaused and freeSlots >= 4 then
OpenSesame.isPaused = false
UpdateMinimapIcon()
print("|cff4FC3F7Open Sesame|r : Auto-Open Resuming!")
end
for bag = 0, 4 do
for slot = 1, C_Container.GetContainerNumSlots(bag) do
local itemInfo = C_Container.GetContainerItemInfo(bag, slot)
if itemInfo and OpenSesame.AllowedItems[itemInfo.itemID] then
C_Container.UseContainerItem(bag, slot)
-- Open one item at a time with delay
C_Timer.After(
OPEN_ITEM_DELAY,
function()
OpenSesame.isProcessing = false
ProcessItems()
end
)
return -- Exit loop so only one item is processed at a time
end
end
end
OpenSesame.isProcessing = false
end
-- Event Handling
local eventFrame = CreateFrame("Frame")
eventFrame:RegisterEvent("BAG_UPDATE")
eventFrame:RegisterEvent("LOOT_OPENED")
eventFrame:RegisterEvent("LOOT_READY")
eventFrame:RegisterEvent("PLAYER_REGEN_ENABLED")
eventFrame:RegisterEvent("PLAYER_ENTERING_WORLD") -- Waits 10 seconds after login before processing items
eventFrame:RegisterEvent("UI_ERROR_MESSAGE")
eventFrame:SetScript(
"OnEvent",
function(_, event, ...)
if not OpenSesame.isEnabled then
return
end
if event == "PLAYER_ENTERING_WORLD" then
C_Timer.After(
WORLD_LOAD_DELAY,
function()
OpenSesame.isProcessing = false -- Reset processing flag on login
ProcessItems()
end
)
elseif event == "BAG_UPDATE" then
local freeSlots = GetBagSpace()
if freeSlots >= 4 and OpenSesame.isPaused then
print("|cff4FC3F7Open Sesame|r : Auto-Open Resuming!")
OpenSesame.isPaused = false
UpdateMinimapIcon()
ProcessItems()
end
elseif event == "LOOT_OPENED" or event == "LOOT_READY" or event == "PLAYER_REGEN_ENABLED" then
ProcessItems()
elseif event == "UI_ERROR_MESSAGE" and select(2, ...) == ERR_INV_FULL then
print("|cff4FC3F7Open Sesame|r : Inventory is full!")
end
end
)
C_Timer.After(1, UpdateMinimapIcon)