-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore.lua
More file actions
179 lines (141 loc) · 5.1 KB
/
Core.lua
File metadata and controls
179 lines (141 loc) · 5.1 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
-- TODO: Version number
-- TODO: Autocomplete names
-- TODO: ScrollPane for saved layouts
ReturnRaidManager = AceLibrary("AceAddon-2.0"):new("AceConsole-2.0", "AceDB-2.0")
ReturnRaidManager:RegisterChatCommand({"/ReturnRaidManager", "/rrm"}, {type = 'execute', func = "ToggleUI"})
ReturnRaidManager:RegisterDB("ReturnRaidManagerDB", "ReturnRaidManagerDBPerChar")
ReturnRaidManager:RegisterDefaults("account", {
SavedLayouts = {}
})
ReturnRaidManager:RegisterDefaults("char", {
MinimapButtonPosition = 336,
MinimapButtonRadius = 78
})
ReturnRaidManager.PlayerInfoByName = {}
ReturnRaidManager.PlayerInfoByRaidIndex = {}
function ReturnRaidManager:UpdatePlayerInfo()
ReturnRaidManager.PlayerInfoByName = {}
ReturnRaidManager.PlayerInfoByRaidIndex = {}
for i = 1,40 do
name, _, subgroup, _, _, class = GetRaidRosterInfo(i)
if name then
playerInfo = {}
playerInfo.name = name
playerInfo.raidIndex = i
playerInfo.currentSubGroupId = subgroup
playerInfo.newSubGroupId = nil
playerInfo.class = class
ReturnRaidManager.PlayerInfoByName[name] = playerInfo
ReturnRaidManager.PlayerInfoByRaidIndex[i] = playerInfo
end
end
end
ReturnRaidManager.RaidConfigByName = {}
function ReturnRaidManager:LoadRaidConfig()
ReturnRaidManager.RaidConfigByName = {}
for i = 1,40 do
name = ReturnRaidManager.UI["NameBox"..i]:GetText()
if ReturnRaidManager.PlayerInfoByName[name] then
ReturnRaidManager.RaidConfigByName[name] = {
name = name,
subGroup = floor((i - 1) / 5) + 1
}
end
end
end
function ReturnRaidManager:ExecuteLayout()
self:UpdatePlayerInfo()
self:LoadRaidConfig()
for name, playerInfo in pairs(ReturnRaidManager.PlayerInfoByName) do
config = ReturnRaidManager.RaidConfigByName[name]
if config then
ReturnRaidManager.PlayerInfoByName[name].newSubGroupId = config.subGroup
end
end
for i = 1,40 do
local pi1 = ReturnRaidManager.PlayerInfoByRaidIndex[i]
if pi1 and pi1.newSubGroupId and pi1.currentSubGroupId ~= pi1.newSubGroupId then
found = false
for j = 1,40 do
local pi2 = ReturnRaidManager.PlayerInfoByRaidIndex[j]
if pi2 and pi2.currentSubGroupId == pi1.newSubGroupId and pi2.newSubGroupId == pi1.currentSubGroupId and pi2.currentSubGroupId ~= pi2.newSubGroupId then
SwapRaidSubgroup(pi1.raidIndex, pi2.raidIndex)
pi2.currentSubGroupId = pi1.currentSubGroupId;
pi1.currentSubGroupId = pi1.newSubGroupId;
found = true
end
end
if not found then
for j = 1,40 do
local pi2 = ReturnRaidManager.PlayerInfoByRaidIndex[j]
if pi2 and pi2.currentSubGroupId == pi1.newSubGroupId and pi2.currentSubGroupId ~= pi2.newSubGroupId then
SwapRaidSubgroup(pi1.raidIndex, pi2.raidIndex)
pi2.currentSubGroupId = pi1.currentSubGroupId;
pi1.currentSubGroupId = pi1.newSubGroupId;
found = true
end
end
end
if not found then
SetRaidSubgroup(pi1.raidIndex, pi1.newSubGroupId)
pi1.currentSubGroupId = pi1.newSubGroupId;
end
end
end
end
function ReturnRaidManager:CheckName(editbox)
text = editbox:GetText()
if string.len(text) < 3 then
return
end
for i = 1,40 do
name, _, _, _, _, class = GetRaidRosterInfo(i)
if text == name then
local color = ReturnRaidManager.Constants.ClassColors[class]
editbox:SetTextColor(color.r, color.g, color.b, 1)
return
end
end
editbox:SetTextColor(1, 0, 0)
end
function ReturnRaidManager:KickInvitePlayers()
playerName = UnitName("player")
playerRank = 0
for i = 1,40 do
name, rank = GetRaidRosterInfo(i)
if name == playerName then
playerRank = rank
end
end
if playerRank == 0 then
self:Print("Removing and Inviting players to the raid requires raid lead or assist.")
return
end
layout = {}
for i = 1, 40 do
name = ReturnRaidManager.UI["NameBox"..i]:GetText()
if name and string.len(name) > 2 then
layout[name] = name
end
end
raid = {}
for i = 1,40 do
name, rank = GetRaidRosterInfo(i)
if name then
if layout[name] then
raid[name] = name
else
if rank > playerRank then
self:Print("Can't remove raid leader " .. name .. " from the raid.")
else
UninviteByName(name)
end
end
end
end
for i, name in layout do
if raid[name] == nil then
InviteByName(name)
end
end
end