/
GrimReaper.lua
147 lines (122 loc) · 4.67 KB
/
GrimReaper.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
--[[
Addon created by Dorann
Shows the last three hits after a player dies.
--]]
------------------------------
-- Initialization --
------------------------------
local L = AceLibrary("AceLocale-2.2"):new("Grim Reaper")
GrimReaper = AceLibrary("AceAddon-2.0"):new("AceEvent-2.0", "AceConsole-2.0", "AceDB-2.0", "AceDebug-2.0")
GrimReaper.revision = 1
GrimReaper:RegisterDB("GrimReaperDB")
GrimReaper.cmdtable = {
type = "group",
handler = GrimReaper,
args = {
--[[ version = {
type = "execute",
name = L["Version Query"],
desc = L["Runs a version query on GrimReaper."],
func = function() GrimReaper:QueryVersion() end,
},]]
}
}
GrimReaper:RegisterChatCommand({"/grimreaper"}, GrimReaper.cmdtable)
GrimReaper.defaultDB = {
}
function GrimReaper:OnInitialize()
-- Called when the addon is loaded
end
function GrimReaper:OnEnable()
-- Called when the addon is enabled
self:RegisterEvent("PLAYER_REGEN_DISABLED")
self:RegisterEvent("CHAT_MSG_COMBAT_CREATURE_VS_CREATURE_HITS", "CombatLog")
self:RegisterEvent("CHAT_MSG_COMBAT_CREATURE_VS_PARTY_HITS", "CombatLog")
self:RegisterEvent("CHAT_MSG_COMBAT_CREATURE_VS_SELF_HITS", "CombatLog")
self:RegisterEvent("CHAT_MSG_COMBAT_FRIENDLYPLAYER_HITS", "CombatLog")
self:RegisterEvent("CHAT_MSG_COMBAT_HOSTILEPLAYER_HITS", "CombatLog")
self:RegisterEvent("CHAT_MSG_SPELL_CREATURE_VS_CREATURE_DAMAGE", "CombatLog")
self:RegisterEvent("CHAT_MSG_SPELL_CREATURE_VS_SELF_DAMAGE", "CombatLog")
self:RegisterEvent("CHAT_MSG_SPELL_DAMAGESHIELDS_ON_OTHERS", "CombatLog")
self:RegisterEvent("CHAT_MSG_SPELL_FRIENDLYPLAYER_DAMAGE", "CombatLog")
self:RegisterEvent("CHAT_MSG_SPELL_HOSTILEPLAYER_DAMAGE", "CombatLog")
self:RegisterEvent("CHAT_MSG_SPELL_PARTY_DAMAGE", "CombatLog")
self:RegisterEvent("CHAT_MSG_SPELL_PERIODIC_CREATURE_DAMAGE", "CombatLog")
self:RegisterEvent("CHAT_MSG_SPELL_PERIODIC_FRIENDLYPLAYER_DAMAGE", "CombatLog")
self:RegisterEvent("CHAT_MSG_SPELL_PERIODIC_HOSTILEPLAYER_DAMAGE", "CombatLog")
self:RegisterEvent("CHAT_MSG_SPELL_PERIODIC_PARTY_DAMAGE", "CombatLog")
self:RegisterEvent("CHAT_MSG_SPELL_PERIODIC_SELF_DAMAGE", "CombatLog")
self:RegisterEvent("CHAT_MSG_SPELL_SELF_DAMAGE", "CombatLog")
self:RegisterEvent("CHAT_MSG_COMBAT_PARTY_HITS", "CombatLog")
self:RegisterEvent("CHAT_MSG_COMBAT_SELF_HITS", "CombatLog")
self:RegisterEvent("CHAT_MSG_SPELL_CREATURE_VS_PARTY_DAMAGE", "CombatLog")
self:RegisterEvent("CHAT_MSG_COMBAT_FRIENDLY_DEATH")
end
function GrimReaper:OnDisable()
-- Called when the addon is disabled
end
------------------------------
-- Variables --
------------------------------
local raid = {}
----------------------
-- Event Handlers --
----------------------
function GrimReaper:PLAYER_REGEN_DISABLED()
raid = {}
for i = 1, GetNumRaidMembers() do
--local _name, _rank, _subgroup, _level, _class, _fileName, _zone, _online, _isDead, _role, _isML = GetRaidRosterInfo(i)
local name = GetRaidRosterInfo(i)
raid[name] = {
[1] = { t = nil, m = nil },
[2] = { t = nil, m = nil },
[3] = { t = nil, m = nil }
}
end
end
function GrimReaper:CombatLog(msg)
local start, ending, source, target, _ = string.find(msg, L["trigger_hit"])
if not start then
start, ending, source, target = string.find(msg, L["trigger_crit"])
end
if not start then
start, ending, target = string.find(msg, L["trigger_dot"])
end
if start then
if target and raid[target] ~= nil then
table.insert(raid[target], { t = GetTime(), m = msg })
table.remove(raid[target], 1)
end
end
end
local function getTimeDifference(time1, time2)
local digits = 1
local shift = 10 ^ digits
local result = floor((time2 - time1) * shift + 0.5) / shift
return result
end
local function formatMessage(msg, time)
local start, ending, _a, _b, _c = string.find(msg, "(.+) ([%d]+)(.+)");
local t = getTimeDifference(time, GetTime())
local formatted = "\n|c0000ff00" .. t .. "s|r: " .. _a .. " |cffA60000" .. _b .. "|r" .. _c
return formatted
end
function GrimReaper:CHAT_MSG_COMBAT_FRIENDLY_DEATH(msg)
local start, ending, name = string.find(msg, L["trigger_death"])
if name and raid[name] then
local log = "|cffA60000" .. name .. "|r" .. " died:"
for row, data in pairs(raid[name]) do
if data["m"] then
log = log .. formatMessage(data["m"], data["t"])
end
end
GrimReaper:Print(log)
end
end
function GrimReaper:Test()
GrimReaper:PLAYER_REGEN_DISABLED()
GrimReaper:CombatLog("Someone hits "..UnitName("player").." for 123.")
GrimReaper:CombatLog("Someone's Fireball crits "..UnitName("player").." for 456.")
GrimReaper:CombatLog("Someone hits "..UnitName("player").." for 789. (123 blocked)")
GrimReaper:CHAT_MSG_COMBAT_FRIENDLY_DEATH(UnitName("player").." dies.")
end