-
Notifications
You must be signed in to change notification settings - Fork 0
/
LGCMain.lua
executable file
·284 lines (225 loc) · 8.42 KB
/
LGCMain.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
--[[
Let's Get Critical
Copyright 2024 iAchieved.it LLC
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
]]--
local addonName, addon = ...
local LGCritical = addon
local module = {}
local moduleName = "LGCMain"
LGCritical[moduleName] = module
-- Imports
local clearCharacterStats = LGCritical.Database.clearCharacterStats
local damageTypes = {
RANGE_DAMAGE = {
title = "Range Damage"
},
RANGE_DAMAGE_CRITICAL = {
title = "Critical Range Damage"
},
SPELL_DAMAGE = {
title = "Spell Damage"
},
SPELL_DAMAGE_CRITICAL = {
title = "Critical Spell Damage"
},
SPELL_PERIODIC_DAMAGE = {
title = "Periodic Spell Damage"
},
PERIODIC_SPELL_DAMAGE_CRITICAL = {
title = "Critical Periodic Spell Damage"
}
}
-- type is (record, critical, criticalrecord)
function playSound(type)
-- Are sounds off?
if LGC_CharacterDB.sounds == "off" then
-- If so, do nothing
return
end
-- If not, play the appropriate sound
if type == "record" then
PlaySoundFile("Interface\\AddOns\\LetsGetCritical\\Sounds\\Sweet.mp3")
elseif type == "critical" then
PlaySoundFile("Interface\\AddOns\\LetsGetCritical\\Sounds\\Yo.mp3")
elseif type == "criticalrecord" then
PlaySoundFile("Interface\\AddOns\\LetsGetCritical\\Sounds\\HotDamn.mp3")
end
end
-- Commands
-- lgc clear
-- lgc stats
-- lgc sounds off|on
-- lgc window off|on
SLASH_LGC1 = "/lgc"
function displayStats()
for k,v in pairs(damageTypes) do
damageTypeTitle = v.title
damageFrame:AddMessage(damageTypeTitle, 1.0, 0.0, 0.0)
if LGC_CharacterDB[k] then
for key, value in pairs(LGC_CharacterDB[k]) do
dmgString = key..": "..value
damageFrame:AddMessage(dmgString)
end
end
end
end
SlashCmdList["LGC"] = function(msg)
if msg == 'stats' then
displayStats()
elseif msg == 'clear' then
clearCharacterStats()
else
local tbl = { strsplit(" ", msg) }
if tbl[1] == "window" then
if tbl[2] == "off" then
damageFrame:Hide()
else
damageFrame:Show()
end
elseif tbl[1] == "sounds" then
if tbl[2] == "off" then
LGC_CharacterDB.sounds = "off"
elseif tbl[2] == "on" then
LGC_CharacterDB.sounds = "on"
end
end
end
end
-- Indexes into CombatLog
local SPELL_DAMAGE = 2
local SOURCE_GUID = 4
local SPELL_ID = 12
local SPELL_NAME = 13
local DAMAGE_AMOUNT = 15
local CRITICAL = 21
-- Only for events
local eventFrame = CreateFrame("Frame", "LGC_Frame")
local width = 240
local height = 120
local titleBarHeight = 20
-- Parent frame
parentFrame = CreateFrame("Frame", nil, UIParent)
parentFrame:SetSize(width,height)
-- This needs to be global
damageFrame = CreateFrame("ScrollingMessageFrame", "LGC_Message_Frame", parentFrame)
-- Create the title bar font string
local titleBar = damageFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
titleBar:SetText("Let's Get Critical")
titleBar:SetPoint("TOP", damageFrame, "TOP", 0, -5)
-- Create a child frame for the actual messages
--messageContainer = CreateFrame("ScrollingMessageFrame", "nil", damageFrame)
--messageContainer:SetSize(width, height - titleBarHeight) -- Adjust the height to account for the title bar
--messageContainer:SetPoint("TOP", damageFrame, "TOP", 0, -titleBarHeight)
-- Apply the insets to the damageFrame
--damageFrame:SetClipsChildren(true) -- This ensures content doesn't overflow
--damageFrame:SetClampRectInsets(insetLeft, insetRight, insetTop, insetBottom)
-- Create button frame for resizing
br = CreateFrame("Button", nil, damageFrame)
br:EnableMouse(true)
br:SetPoint("BOTTOMRIGHT")
br:SetSize(16, 16)
br:SetNormalTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
br:SetHighlightTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
br:SetPushedTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
br:SetScript("OnMouseDown", function(self)
self:GetParent():StartSizing("BOTTOMRIGHT")
end)
br:SetScript("OnMouseUp", function(self)
self:GetParent():StopMovingOrSizing()
end)
local tex = damageFrame:CreateTexture(nil, "ARTWORK")
tex:SetAllPoints()
tex:SetColorTexture(0.1, 0.1, 0.1, 0.3)
damageFrame:SetHeight(120)
damageFrame:SetWidth(240)
damageFrame:SetPoint("CENTER", UIParent, 0, 0)
damageFrame:SetFontObject(GameFontNormal)
damageFrame:SetTextColor(GameFontNormal:GetTextColor())
damageFrame:SetMovable(true)
damageFrame:EnableMouse(true)
damageFrame:SetResizable(true)
damageFrame:RegisterForDrag("MiddleButton")
damageFrame:SetInsertMode("TOP")
damageFrame:SetScript("OnDragStart", function(self)
self:StartMoving()
end)
damageFrame:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing()
end)
damageFrame:Show()
local playerGUID = UnitGUID("player")
eventFrame:Show()
eventFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
local function eventHandler(self, event, ...)
local eventInfo = {CombatLogGetCurrentEventInfo()}
local type = eventInfo[SPELL_DAMAGE]
local sourceGUID = eventInfo[SOURCE_GUID]
if (event == "COMBAT_LOG_EVENT_UNFILTERED") then
-- Ignore events we didn't cause
if (sourceGUID ~= playerGUID) then
return
end
if (type == "RANGE_DAMAGE") or (type == "SPELL_DAMAGE") or (type == "SPELL_PERIODIC_DAMAGE") then
local critTableKey = type.."_CRITICAL"
if not LGC_CharacterDB[critTableKey] then
LGC_CharacterDB[critTableKey] = {}
end
if not LGC_CharacterDB[type] then
LGC_CharacterDB[type] = {}
end
local damageAmount = eventInfo[DAMAGE_AMOUNT]
local critical = eventInfo[CRITICAL]
local spellName = eventInfo[SPELL_NAME]
-- Is this a crit?
if (critical) then
-- Play on any crit
damageFrame:AddMessage("Let's Get Critical!", 1.0, 0.0, 0.0, 53, 5)
if not LGC_CharacterDB[critTableKey][spellName] then
damageFrame:AddMessage("First critical record of "..damageAmount.." for "..spellName.."!")
LGC_CharacterDB[critTableKey][spellName] = damageAmount
playSound("criticalrecord")
return
end
-- Otherwise, we have a record, see if it's broken
if (damageAmount > LGC_CharacterDB[critTableKey][spellName]) then
damageFrame:AddMessage("New critical record of "..damageAmount.." for "..spellName.."!")
LGC_CharacterDB[critTableKey][spellName] = damageAmount
playSound("criticalrecord")
return
end
-- Non-record crit
playSound("critical")
damageFrame:AddMessage("Critical damage "..damageAmount.." for "..spellName.."!")
else -- Not critical
if not LGC_CharacterDB[type][spellName] then
damageFrame:AddMessage("First damage record of "..damageAmount.." for "..spellName.."!")
LGC_CharacterDB[type][spellName] = damageAmount
playSound("record")
return
end
-- Otherwise, we have a record, see if it's broken
if damageAmount > LGC_CharacterDB[type][spellName] then
damageFrame:AddMessage("New damage record of "..damageAmount.." for "..spellName.."!")
LGC_CharacterDB[type][spellName] = damageAmount
playSound("record")
end
end
end
end
end
eventFrame:SetScript("OnEvent", eventHandler)