-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMageUtility.lua
More file actions
193 lines (161 loc) · 5.03 KB
/
Copy pathMageUtility.lua
File metadata and controls
193 lines (161 loc) · 5.03 KB
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
-- MageUtility Core
-- Main addon initialization and event handling
local ADDON_NAME = "Mage Utility"
local ADDON_VERSION = "1.2.0"
if not MageUtility then
MageUtility = {}
end
-- Color configuration
MageUtility.Colors = {
MAGE_BLUE = "FF3FC7EB",
GOLD = "FFFFDB00",
RED = "FFFF0000"
}
-- Reagent constants
MageUtility.Reagents = {
TELEPORT_RUNE = {id = 17031, name = "Rune of Teleportation", count = 1},
PORTAL_RUNE = {id = 17032, name = "Rune of Portals", count = 1}
}
-- Mana cost constants
MageUtility.ManaCosts = {
TELEPORT = 120,
PORTAL = 850
}
-- Window close behavior constants
MageUtility.CloseOnCast = {
TELEPORTS = true,
PORTALS = true,
MANAGEMS = false
}
MageUtility.playerFaction = nil
MageUtility.playerClass = nil
MageUtility.initialized = false
-- Local reference to color constants
local Colors = MageUtility.Colors
-- Event frame
local eventFrame = CreateFrame("Frame")
-- Initialize addon
function MageUtility:Initialize()
-- Only initialize once
if self.initialized then
return
end
-- Detect player class
local _, classFilename = UnitClass("player")
self.playerClass = classFilename
-- Detect player faction (only if mage)
if self.playerClass == "MAGE" then
self:DetectFaction()
end
-- Initialize UI
if MageUtility.UI then
MageUtility.UI:Initialize()
end
-- Load saved position
if not MageUtility_Config then
MageUtility_Config = {
position = nil
}
end
-- Mark as initialized
self.initialized = true
end
-- Detect player faction (Alliance or Horde)
function MageUtility:DetectFaction()
local faction = UnitFactionGroup("player")
self.playerFaction = faction
end
-- Toggle main window
function MageUtility:ToggleWindow()
if MageUtility.UI then
MageUtility.UI:Toggle()
end
end
-- Check if player has learned a spell
function MageUtility:HasSpell(spellName)
local i = 1
while true do
local name = GetSpellName(i, BOOKTYPE_SPELL)
if not name then
break
end
if name == spellName then
return true
end
i = i + 1
end
return false
end
-- Check if player has reagent in bags
function MageUtility:HasReagent(itemID, count)
local totalCount = 0
for bag = 0, 4 do
for slot = 1, GetContainerNumSlots(bag) do
local link = GetContainerItemLink(bag, slot)
if link then
local _, stackCount = GetContainerItemInfo(bag, slot)
-- Extract itemID from link
local _, _, foundID = string.find(link, "item:(%d+)")
if foundID and tonumber(foundID) == itemID then
totalCount = totalCount + stackCount
end
end
end
end
return totalCount >= count, totalCount
end
-- Get current player mana
function MageUtility:GetCurrentMana()
return UnitMana("player")
end
-- Check if player is in combat
function MageUtility:IsInCombat()
return UnitAffectingCombat("player")
end
-- Cast spell by name
function MageUtility:CastSpell(spellName)
CastSpellByName(spellName)
end
-- Event handlers
local function OnEvent()
if event == "ADDON_LOADED" and arg1 == "MageUtility" then
DEFAULT_CHAT_FRAME:AddMessage("|c" .. Colors.MAGE_BLUE .. ADDON_NAME .. ":|c" .. Colors.GOLD .. " v" .. ADDON_VERSION .. "|r loaded successfully! Type |c".. Colors.MAGE_BLUE .."/mage|r or |c".. Colors.MAGE_BLUE .."/mu|r to open.|r")
elseif event == "PLAYER_ENTERING_WORLD" then
MageUtility:Initialize()
elseif event == "BAG_UPDATE" then
if MageUtility.UI and MageUtility.UI.frame and MageUtility.UI.frame:IsVisible() then
MageUtility.UI:RefreshAllButtons()
end
elseif event == "UNIT_MANA" then
-- Update buttons when mana changes
if arg1 == "player" then
if MageUtility.UI and MageUtility.UI.frame and MageUtility.UI.frame:IsVisible() then
MageUtility.UI:RefreshAllButtons()
end
end
elseif event == "PLAYER_REGEN_DISABLED" then
-- Entered combat
if MageUtility.UI and MageUtility.UI.frame and MageUtility.UI.frame:IsVisible() then
MageUtility.UI:RefreshAllButtons()
end
elseif event == "PLAYER_REGEN_ENABLED" then
-- Left combat
if MageUtility.UI and MageUtility.UI.frame and MageUtility.UI.frame:IsVisible() then
MageUtility.UI:RefreshAllButtons()
end
end
end
-- Register events
eventFrame:RegisterEvent("ADDON_LOADED")
eventFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
eventFrame:RegisterEvent("BAG_UPDATE")
eventFrame:RegisterEvent("UNIT_MANA")
eventFrame:RegisterEvent("PLAYER_REGEN_DISABLED")
eventFrame:RegisterEvent("PLAYER_REGEN_ENABLED")
eventFrame:SetScript("OnEvent", OnEvent)
-- Slash commands
SLASH_MAGEUTILITY1 = "/mage"
SLASH_MAGEUTILITY2 = "/mu"
SlashCmdList["MAGEUTILITY"] = function(msg)
MageUtility:ToggleWindow()
end