-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLCUtils.lua
More file actions
250 lines (233 loc) · 7.61 KB
/
LCUtils.lua
File metadata and controls
250 lines (233 loc) · 7.61 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
LCU = {};
LCU.addonName = "LostControl"
LCU.addonVer = GetAddOnMetadata("LostControl","Version");
LCU.debugMode = false;
LCU.optionsPanel = nil;
LCU.debuffs = {};
LCU.player = {
role = nil
,spec = nil
,hasControl = true
,name = UnitName("player")
,lastInterrupt = nil
,updateRole = function(who)
who = who or "player";
local role = string.lower(UnitGroupRolesAssigned(who));
if(role == "none" and who == "player") then
local isLeader, isTank, isHealer, isDPS = GetLFGRoles();
if(isTank==true) then role = LCLang.get('tank') end
if(isHealer==true) then role = LCLang.get('healer') end
if(isDPS==true) then role = LCLang.get('dps') end
if(role=="none") then role = LCLang.get('player') end
end
LCU.player.role = role;
LCU.player.name = UnitName(who);
return role;
end
,updateSpec = function()
local currentSpec = GetSpecialization();
local currentSpecName = nil;
local currentSpecRole = nil;
if(currentSpec ~= nil) then
currentSpecName = select(2, GetSpecializationInfo(currentSpec));
currentSpecRole = GetSpecializationRole(currentSpec);
currentSpecRole = (currentSpecRole~=nil and currentSpecRole~=0) and string.lower(currentSpecRole) or nil;
if(currentSpecRole=='damager') then currentSpecRole = 'dps'; end
end
LCU.player.spec = {
index = LCU.tern(currentSpec~=nil, currentSpec, nil)
,name = LCU.tern(currentSpecName~=nil, currentSpecName, nil)
,role = LCU.tern(currentSpecRole~=nil, currentSpecRole, nil)
};
-- If we found valid spec info, ensure our configs have their defaults set
if(LCU.player.spec and LCU.player.spec.role) then LCcfg.setDefaults(); end
end
,inInstance = nil
,instanceType = 'none'
,updateInstanceInfo = function()
LCU.player.inInstance, LCU.player.instanceType = IsInInstance();
end
}
LCU.round = function(val, decimal)
if (type(val) ~= 'number') then return nil; end
local exp = decimal and 10^decimal or 1;
return math.ceil(val * exp - 0.5) / exp;
end
LCU.upperFirst = function(str)
return str:gsub("^%l", string.upper)
end
LCU.str = function(val)
return tostring(val);
end
LCU.trim = function(s)
return (LCU.str(s):gsub("^%s*(.-)%s*$", "%1"));
end
LCU.bool = function(val)
return not not val;
end
LCU.deepcopy = function(orig)
local orig_type = type(orig)
local copy
if orig_type == 'table' then
copy = {}
for orig_key, orig_value in next, orig, nil do
copy[orig_key] = LCU.deepcopy(orig_value)
end
setmetatable(copy, LCU.deepcopy(getmetatable(orig)))
else -- number, string, boolean, etc
copy = orig
end
return copy
end
LCU.cloneTable = function(tbl,deep)
if(type(deep)~="boolean") then deep = true; end
if(deep) then
return LCU.deepcopy(tbl);
else
local cloned = {};
i,v = next(tbl, nil);
while i do
cloned[i] = (type(v)=="table") and LCU.cloneTable(v) or v;
i,v = next(tbl,i);
end
return cloned;
end
end
LCU.tern = function(check,tru,fals)
if(check) then return tru;
else return fals; end
end
LCU.sendMsg = function(msg,priv)
priv = priv or LCU.debugMode
if(priv == true) then print(msg)
else LCMessage(msg) end
end
LCU.announcePlayer = function(action)
local role = LCcfg.getPlayerSpecRole();
local msgStart = role=='dps' and LCLang.get('A DPS') or LCLang.get('The '..role);
local msg = msgStart..' ('..LCU.player.name..') '..action
LCU.sendMsg(msg)
return msg
end
LCU.foreach = function(tbl,func,useIpairs)
if(useIpairs) then for k,v in ipairs(tbl) do func(v,k,tbl); end
else for k,v in pairs(tbl) do func(v,k,tbl); end end
end
LCU.spellSchoolByNum = function(num)
local spellSchools = {
[1] = "Physical",
[2] = "Holy",
[4] = "Fire",
[8] = "Nature",
[16] = "Frost",
[32] = "Shadow",
[64] = "Arcane",
[3] = "Holystrike",
[5] = "Flamestrike",
[6] = "Holyfire",
[9] = "Stormstrike",
[10] = "Holystorm",
[12] = "Firestorm",
[17] = "Froststrike",
[18] = "Holyfrost",
[20] = "Frostfire",
[24] = "Froststorm",
[33] = "Shadowstrike",
[34] = "Shadowlight",
[36] = "Shadowflame",
[40] = "Shadowstorm",
[48] = "Shadowfrost",
[65] = "Spellstrike",
[66] = "Divine",
[68] = "Spellfire",
[72] = "Spellstorm",
[80] = "Spellfrost",
[96] = "Spellshadow",
[28] = "Elemental",
[124] = "Chromatic",
[126] = "Magic",
[127] = "Chaos",
};
return spellSchools[num];
end
LCU.player.updateInstanceInfo();
LCU.player.updateRole();
LCU.player.updateSpec();
--------------------------------------
--- REGISTERING CHAT SLASH COMMANDS
--------------------------------------
SLASH_LostControl1 = "/lsctrl"
SLASH_LostControl2 = "/lostcontrol"
local SlashCmd = {}
function SlashCmd:help()
print(LCU.addonName, "slash commands:")
print(' - disable [debuff type] (e.g. '..SLASH_LostControl1..' disable silence)')
print(' - enable [debuff type] (e.g. '..SLASH_LostControl1..' enable slow)')
print(' - status [debuff type] (e.g. '..SLASH_LostControl1..' status incap)')
end
function SlashCmd:debug(value)
if value == "on" then
LCU.debugMode = true
print(LCU.addonName, LCLang.get("debugging enabled")..".")
elseif value == "off" then
LCU.debugMode = false
print(LCU.addonName, LCLang.get("debugging disabled")..".")
end
end
function SlashCmd:enable(value)
if(Debuffs and Debuffs.types and Debuffs.types[value]) then
local prevVal = Debuffs.types[value].enabled;
Debuffs.types[value].enabled = true;
LCcfg.disableWatch(value,false);
if(Debuffs.types[value].enabled and not prevVal) then print('"'..LCU.upperFirst(value)..'" '..LCLang.get('checks have been enabled')); end
end
end
function SlashCmd:disable(value)
if(Debuffs and Debuffs.types and Debuffs.types[value]) then
local prevVal = Debuffs.types[value].enabled;
Debuffs.types[value].enabled = false;
LCcfg.disableWatch(value,true);
if(not Debuffs.types[value].enabled and prevVal) then print('"'..LCU.upperFirst(value)..'" '..LCLang.get('checks have been disabled')); end
end
end
function SlashCmd:status(value)
if(type(value)=="string") then
if(Debuffs and Debuffs.types and Debuffs.types[value]) then
print('"'..LCU.upperFirst(value)..'" checks are currently '..(Debuffs.types[value].enabled and LCLang.get('enabled') or LCLang.get('disabled')));
end
else
print('--- --- --- --- --- --- --- --- --- --- --- --- --- --- ---');
for k,v in pairs(Debuffs.types) do
print('"'..LCU.upperFirst(k)..'" checks are currently '..(LCcfg.watching(k) and LCLang.get('enabled') or LCLang.get('- disabled -')));
end
print('--- --- --- --- --- --- --- --- --- --- --- --- --- --- ---');
end
end
function SlashCmd:instchan(value)
if(value=="SAY" or value=="PARTY" or value=="INSTANCE_CHAT") then
LCcfg.set('instanceChat',value);
end
if(value=="s" or value=="S" or value=="say") then LCcfg.set('instanceChat','SAY'); end
if(value=="p" or value=="P" or value=="party") then LCcfg.set('instanceChat','PARTY'); end
if(value=="i" or value=="I" or value=="instance" or value=="INSTANCE") then LCcfg.set('instanceChat','INSTANCE_CHAT'); end
end
function SlashCmd:raidchan(value)
if(value=="SAY" or value=="PARTY" or value=="RAID") then
LCcfg.set('raidChat',value);
end
if(value=="s" or value=="S" or value=="say") then LCcfg.set('raidChat','SAY'); end
if(value=="p" or value=="P" or value=="party") then LCcfg.set('raidChat','PARTY'); end
if(value=="r" or value=="R" or value=="raid") then LCcfg.set('raidChat','RAID'); end
end
SlashCmdList[LCU.addonName] = function(cmd)
local args = {}
for word in cmd:lower():gmatch("%S+") do
tinsert(args, word)
end
if SlashCmd[args[1]] then
SlashCmd[args[1]](unpack(args))
else
print(LCU.addonName, ': Type "'..SLASH_LostControl1..' help" for more options.')
InterfaceOptionsFrame_OpenToCategory(LCU.optionsPanel or LCU.addonName)
end
end