-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeyRoller.lua
287 lines (255 loc) · 9.33 KB
/
KeyRoller.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
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
-- KeyRoller.lua
local addonName, addon = ...
local frame = CreateFrame("Frame")
local playerKeys = {}
local isRollInProgress = false
local rollResults = {}
local rollHistory = {}
local minKeyLevel = 0
local maxKeyLevel = 99
local text = nil
frame:RegisterEvent("CHAT_MSG_ADDON")
frame:RegisterEvent("BAG_UPDATE")
frame:RegisterEvent("GROUP_ROSTER_UPDATE")
frame:RegisterEvent("CHAT_MSG_SYSTEM")
local ADDON_PREFIX = "KR"
C_ChatInfo.RegisterAddonMessagePrefix(ADDON_PREFIX)
local function GetPlayerMythicKey()
for bag = 0, 4 do
for slot = 1, C_Container.GetContainerNumSlots(bag) do
local itemInfo = C_Container.GetContainerItemInfo(bag, slot)
if itemInfo then
local itemID = itemInfo.itemID
if itemID == 180653 then -- Keystone ID
local itemLink = itemInfo.hyperlink
if itemLink then
local keyLevel = C_MythicPlus.GetOwnedKeystoneLevel()
local dungeonID = C_MythicPlus.GetOwnedKeystoneChallengeMapID()
if keyLevel and dungeonID then
local dungeonName = C_ChallengeMode.GetMapUIInfo(dungeonID)
if dungeonName and keyLevel > 0 then
return dungeonName, keyLevel
end
end
end
end
end
end
end
return nil, nil
end
local function GetGroupType()
return IsInRaid() and "RAID" or "PARTY"
end
local function BroadcastKey()
local dungeonName, level = GetPlayerMythicKey()
if dungeonName and level then
local message = string.format("%s:%d", dungeonName, level)
if IsInGroup() then
C_ChatInfo.SendAddonMessage(ADDON_PREFIX, "KEY:" .. message, GetGroupType())
end
end
end
local function RequestKeys()
if not IsInGroup() then
print("Tu dois être dans un groupe pour demander les clefs!")
return
end
playerKeys = {} -- Réinitialise la liste des clefs
BroadcastKey() -- Envoie votre clef
C_ChatInfo.SendAddonMessage(ADDON_PREFIX, "REQUEST_KEY", GetGroupType()) -- Demande les clefs
print("Demande de clefs envoyée au groupe.")
end
local function ExportKeysToChat()
if not IsInGroup() then
print("Tu dois être dans un groupe pour exporter les clefs!")
return
end
SendChatMessage("=== Clefs Mythiques du Groupe ===", GetGroupType())
for player, key in pairs(playerKeys) do
if key.level >= minKeyLevel and key.level <= maxKeyLevel then
local message = string.format("%s: %s +%d", player, key.dungeon, key.level)
SendChatMessage(message, GetGroupType())
end
end
end
local function StartRoll()
if not IsInGroup() then
print("Tu dois être dans un groupe pour lancer un roll!")
return
end
isRollInProgress = true
rollResults = {}
C_ChatInfo.SendAddonMessage(ADDON_PREFIX, "ROLL", GetGroupType())
local timestamp = date("%H:%M:%S")
table.insert(rollHistory, {time = timestamp, results = {}})
end
local function UpdateKeyList(content)
if not content then
return
end
if text == nil then
text = content:CreateFontString(nil, "OVERLAY", "GameFontNormal")
end
for _, child in ipairs({content:GetChildren()}) do
child:Hide()
child:SetParent(nil)
end
local formattedDisplay = ""
local returnStr = "\n"
for player, key in pairs(playerKeys) do
if key.level >= minKeyLevel and key.level <= maxKeyLevel then
formattedDisplay =
formattedDisplay .. string.format("%s: %s +%d %s %s", player, key.dungeon, key.level, returnStr, returnStr)
end
end
text:SetJustifyH("LEFT");
text:SetPoint("TOPLEFT", 0, 0)
text:SetText(formattedDisplay)
content:SetHeight(math.max(20, 0))
end
local function CreateMainFrame()
local f = CreateFrame("Frame", "KRFrame", UIParent, "BasicFrameTemplateWithInset")
f:SetSize(400, 350) -- Largeur - Hauteur
f:SetPoint("CENTER")
f:SetMovable(true)
f:EnableMouse(true)
f:RegisterForDrag("LeftButton")
f:SetScript("OnDragStart", f.StartMoving)
f:SetScript("OnDragStop", f.StopMovingOrSizing)
f:Hide()
f.title = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
f.title:SetPoint("TOP", 0, -5)
f.title:SetText("Key Roller")
f.requestButton = CreateFrame("Button", nil, f, "GameMenuButtonTemplate")
f.requestButton:SetPoint("TOPLEFT", 10, -40)
f.requestButton:SetSize(120, 25)
f.requestButton:SetText("Request Keys")
f.requestButton:SetScript(
"OnClick",
function()
RequestKeys()
end
)
f.exportButton = CreateFrame("Button", nil, f, "GameMenuButtonTemplate")
f.exportButton:SetPoint("TOPRIGHT", -10, -40)
f.exportButton:SetSize(120, 25)
f.exportButton:SetText("Export Keys")
f.exportButton:SetScript(
"OnClick",
function()
ExportKeysToChat()
end
)
f.rollButton = CreateFrame("Button", nil, f, "GameMenuButtonTemplate")
f.rollButton:SetPoint("BOTTOM", 10, 10)
f.rollButton:SetSize(120, 25)
f.rollButton:SetText("Roll the Keys !")
f.rollButton:SetScript(
"OnClick",
function()
StartRoll()
end
)
-- Zone de défilement pour afficher les clefs
f.keyList = CreateFrame("ScrollFrame", nil, f, "UIPanelScrollFrameTemplate")
f.keyList:SetPoint("TOPLEFT", 10, -80)
f.keyList:SetPoint("BOTTOMRIGHT", -30, 40)
local content = CreateFrame("Frame", nil, f.keyList)
content:SetSize(f.keyList:GetWidth(), 400)
f.keyList:SetScrollChild(content)
f.keyList.content = content
return f
end
-- Event manager
frame:SetScript(
"OnEvent",
function(self, event, ...)
if event == "CHAT_MSG_ADDON" then
local prefix, message, channel, sender = ...
if prefix == ADDON_PREFIX then
if string.find(message, "^KEY:") then
local _, _, dungeonName, level = string.find(message, "KEY:(.+):(%d+)")
if dungeonName and level then
playerKeys[sender] = {dungeon = dungeonName, level = tonumber(level)}
UpdateKeyList(KRFrame.keyList.content)
end
elseif message == "REQUEST_KEY" then
BroadcastKey()
elseif message == "ROLL" and sender ~= UnitName("player") then
RandomRoll(1, 100)
end
end
elseif event == "CHAT_MSG_SYSTEM" then
local message = ...
local player, roll, min, max = string.match(message, "(.+) rolls (%d+) %((%d+)%-(%d+)%)")
if player and isRollInProgress then
rollResults[player] = tonumber(roll)
local currentRoll = rollHistory[#rollHistory]
if currentRoll then
table.insert(currentRoll.results, {player = player, roll = roll})
end
local allRolled = true
for i = 1, GetNumGroupMembers() do
local name = GetRaidRosterInfo(i)
if not rollResults[name] then
allRolled = false
break
end
end
if allRolled then
isRollInProgress = false
local highestRoll = 0
local winner = nil
for matchedPlayer, matchedRoll in pairs(rollResults) do
if matchedRoll > highestRoll then
highestRoll = matchedRoll
winner = matchedPlayer
end
end
if winner then
SendChatMessage(
string.format("Le gagnant est %s avec un roll de %d!", winner, highestRoll),
GetGroupType()
)
end
end
end
elseif event == "BAG_UPDATE" then
BroadcastKey()
elseif event == "GROUP_ROSTER_UPDATE" then
BroadcastKey()
end
end
)
-- Commandes
-- luacheck: globals SLASH_KR1
SLASH_KR1 = "/kr" -- SlashCommand to start
SlashCmdList["KR"] = function(msg)
local command, arg1, arg2 = string.match(msg, "^(%w+)%s*(%w*)%s*(%w*)$")
if command == "show" then
KRFrame:Show()
elseif command == "hide" then
KRFrame:Hide()
elseif command == "roll" then
StartRoll()
elseif command == "filter" then
minKeyLevel = tonumber(arg1) or 0
maxKeyLevel = tonumber(arg2) or 99
UpdateKeyList(KRFrame.keyList.content)
elseif command == "export" then
ExportKeysToChat()
elseif command == "request" then
RequestKeys()
else
print("Key Roller - Commandes disponibles:")
print("/kr show - Affiche la fenêtre")
print("/kr hide - Cache la fenêtre")
print("/kr roll - Lance un roll")
print("/kr filter min max - Définit les filtres de niveau")
print("/kr export - Exporte les clefs dans le chat")
print("/kr request - Demande les clefs au groupe")
end
end
-- Initialisation
local mainFrame = CreateMainFrame()