-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
KillOnSight.lua
276 lines (251 loc) · 9.23 KB
/
KillOnSight.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
local addonName = "KillOnSight"
KillOnSight = LibStub("AceAddon-3.0"):NewAddon(addonName, "AceConsole-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale(addonName)
local LDBIcon = LibStub("LibDBIcon-1.0")
local eventFrame = CreateFrame("Frame")
local defaultProfile = {
profile = {
settings = {
enableInBG = false,
enableInArena = false,
enableAlertSound = true,
enableAlertText = true,
enableAlertOnNameplateRegistered = true,
enableAlertOnMouseOver = true,
enableAlertOnTarget = true,
enableOnAllies = false,
alertMinTimer = 10,
},
minimapButton = {
hide = false,
},
},
char = {
kos = {},
history = {}
},
}
function KillOnSight:OnInitialize()
local globalProfile = true
self.db = LibStub("AceDB-3.0"):New("kosDB", defaultProfile, globalProfile)
KillOnSight:RegisterOptionsTable()
KillOnSight:InitGUI()
LDBIcon:Register(addonName, LibStub("LibDataBroker-1.1"):NewDataObject(addonName,
{
type = "data source",
text = addonName,
icon = "135271",
OnClick = function(self, button)
if (button == "LeftButton") then
KillOnSight:ToggleGUI()
elseif (button == "RightButton") then
InterfaceOptionsFrame_Show()
InterfaceOptionsFrame_OpenToCategory(addonName)
elseif (button == "MiddleButton") then
LDBIcon:Hide(addonName)
end
end,
OnTooltipShow = function(tooltip)
tooltip:AddLine(addonName)
tooltip:AddLine(string.format("|cff888888%s|r |cffffffff%s|r", "Left Click :", "Open KoS main window"))
tooltip:AddLine(string.format("|cff888888%s|r |cffffffff%s|r", "Middle Click :", "Hide KoS minimap icon"))
tooltip:AddLine(string.format("|cff888888%s|r |cffffffff%s|r", "Right Click :", "Open addon interface window"))
end
}), self.db.profile.minimapButton)
eventFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
eventFrame:RegisterEvent("PLAYER_TARGET_CHANGED")
eventFrame:RegisterEvent("UPDATE_MOUSEOVER_UNIT")
eventFrame:RegisterEvent("NAME_PLATE_UNIT_ADDED")
end
function KillOnSight:OnEnable()
end
local function OnEvent(self, event, ...)
if event == "COMBAT_LOG_EVENT_UNFILTERED" then
local timestamp, subevent, _, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags = CombatLogGetCurrentEventInfo()
if subevent == "SWING_DAMAGE" then
amount, overkill, school, resisted, blocked, absorbed, critical, glancing, crushing, isOffHand = select(12, CombatLogGetCurrentEventInfo())
if overkill >= 0 then
KillOnSight:UpdateHistoryLogs(sourceName, destName)
end
elseif subevent == "SPELL_DAMAGE" or subevent == "SPELL_PERIODIC_DAMAGE" or subevent == "RANGE_DAMAGE" then
spellId, spellName, spellSchool, amount, overkill, school, resisted, blocked, absorbed, critical, glancing, crushing, isOffHand = select(12, CombatLogGetCurrentEventInfo())
if overkill >= 0 then
KillOnSight:UpdateHistoryLogs(sourceName, destName)
end
end
elseif event == "NAME_PLATE_UNIT_ADDED" then
local nameplate = ...
local name = UnitName(nameplate)
KillOnSight:AlertEvent(name, "nameplate")
elseif event == "UPDATE_MOUSEOVER_UNIT" then
local name = UnitName("mouseover")
KillOnSight:AlertEvent(name, "mouseover")
elseif event == "PLAYER_TARGET_CHANGED" then
local name = UnitName("target")
KillOnSight:AlertEvent(name, "target")
end
end
eventFrame:SetScript("OnEvent", function(self,event,...) OnEvent(self, event, ...) end)
function KillOnSight:AlertEvent(name, type)
if type == "nameplate" and self.db.profile.settings.enableAlertOnNameplateRegistered == false then
return
end
if type == "mouseover" and self.db.profile.settings.enableAlertOnMouseOver == false then
return
end
if type == "target" and self.db.profile.settings.enableAlertOnTarget == false then
return
end
local currentZone = GetRealZoneText()
if self.db.profile.settings.enableInArena == false then
for arenaUS, arenaLocale in pairs(Arena_List) do
if currentZone == arenaLocale then
return
end
end
end
if self.db.profile.settings.enableInBG == false then
for bgUS, bgLocale in pairs(BG_List) do
if currentZone == bgLocale then
return
end
end
end
for i,v in ipairs(self.db.char.kos) do
if name == v.name then
if (time() > (v.lastUpdated + self.db.profile.settings.alertMinTimer)) then
KillOnSight:UpdateEnemy(v)
if self.db.profile.settings.enableAlertSound then
PlaySound(8959)
end
if self.db.profile.settings.enableAlertText then
KillOnSight:EnemyFoundMessage(v.name)
end
end
end
end
end
function KillOnSight:AddEnemy()
local playerFaction = UnitFactionGroup("player")
local zoneName = GetRealZoneText()
local targetName = UnitName("target")
if targetName then
local targetGUID = UnitGUID("target")
local targetFaction = UnitFactionGroup("target")
local targetLevel = UnitLevel("target")
if targetLevel == -1 then
targetLevel = UnitLevel("player") + 10 .. "+"
end
local targetClass = UnitClass("target")
if (not UnitIsPlayer("target")) then
KillOnSight:Print(string.format("|cffff0000%s|r", "This target is not a player !"))
else
if self.db.profile.settings.enableOnAllies == false then
if playerFaction ~= targetFaction then
KillOnSight:AddEnemyToKos(targetName, targetLevel, targetClass, zoneName)
else
KillOnSight:Print(string.format("|cffff0000%s|r", "This target is from your faction !"))
end
else
KillOnSight:AddEnemyToKos(targetName, targetLevel, targetClass, zoneName)
end
end
else
KillOnSight:Print(string.format("|cffff0000%s|r", "You must target an enemy !"))
end
end
function KillOnSight:UpdateEnemy(enemy)
local zoneName = GetRealZoneText()
enemy.zone = zoneName
enemy.lastUpdated = time()
KillOnSight:RefreshKosList()
end
function KillOnSight:DeleteEnemy(enemyName)
if enemyName == nil then
KillOnSight:Print(string.format("|cffff0000%s|r", "You must target or select an enemy !"))
return
end
if enemyName == "" then
KillOnSight:Print(string.format("|cffff0000%s|r", "You must type the enemy name !"))
return
end
local foundIndex = -1
for i,v in ipairs(self.db.char.kos) do
if enemyName == v.name then
foundIndex = i
break
end
end
if (foundIndex ~= -1) then
table.remove(self.db.char.kos, foundIndex)
KillOnSight:Print(string.format("%s has been successfully removed from your KoS list !", enemyName))
else
KillOnSight:Print(string.format("|cffff0000'%s' %s|r", enemyName, "was not found in your list !"))
return
end
KillOnSight:RefreshKosList()
end
function KillOnSight:AddEnemyToKos(targetName, targetLevel, targetClass, zoneName)
local enemy = {
['name'] = targetName,
['level'] = targetLevel,
['class'] = targetClass,
['zone'] = zoneName,
['date'] = time(),
['lastUpdated'] = time(),
}
local alreadyExists = false
for i,v in ipairs(self.db.char.kos) do
if targetName == v.name then
alreadyExists = true
end
end
if alreadyExists == false then
table.insert(self.db.char.kos, enemy)
KillOnSight:RefreshKosList()
KillOnSight:Print(string.format("'%s' has been successfully added to your KoS list !", targetName))
else
KillOnSight:Print(string.format("|cffff0000%s|r", "This target is already on your KoS list !"))
end
end
function KillOnSight:UpdateHistoryLogs(sourceName, destName)
local playerName, enemyName, win, lose
if sourceName == UnitName("player") then
playerName = sourceName
enemyName = destName
win = 1
lose = 0
elseif destName == UnitName("player") then
playerName = destName
enemyName = sourceName
win = 0
lose = 1
else
return
end
local alreadyExists = false
for i,v in ipairs(self.db.char.history) do
if enemyName == v.name then
alreadyExists = true
v.win = v.win + win
v.lose = v.lose + lose
end
end
local logs = {
['name'] = enemyName,
['win'] = win,
['lose'] = lose,
}
if alreadyExists == false then
table.insert(self.db.char.history, logs)
end
KillOnSight:RefreshHistoryLogs()
end
function KillOnSight:ResetKosList()
self.db.char.kos = {}
KillOnSight:RefreshKosList()
end
function KillOnSight:ResetHistoryLogs()
self.db.char.history = {}
KillOnSight:RefreshHistoryLogs()
end