forked from ipzaur/ipmythictimer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeaths.lua
More file actions
162 lines (152 loc) · 5.23 KB
/
deaths.lua
File metadata and controls
162 lines (152 loc) · 5.23 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
local AddonName, Addon = ...
Addon.deaths = {}
function Addon.deaths:Toggle(show, wFake)
if (show == nil) then
show = not Addon.fDeaths:IsShown()
end
if show then
if not Addon.opened.options or wFake then
Addon.deaths:Show(wFake)
end
else
Addon.fDeaths:Hide()
end
end
function Addon.deaths:Show(wFake)
if not IPMTDungeon.deathes or not IPMTDungeon.deathes.list or #IPMTDungeon.deathes.list == 0 then
if wFake then
Addon.deaths:Record(nil, true)
else
return false
end
end
local counts = {}
for i, death in ipairs(IPMTDungeon.deathes.list) do
if counts[death.playerName] then
counts[death.playerName] = counts[death.playerName] + 1
else
counts[death.playerName] = 1
end
Addon:FillDeathRow(i, death, counts[death.playerName])
end
local deaths = #IPMTDungeon.deathes.list
local rows = #Addon.fDeaths.line
if deaths < rows then
for i = deaths+1,rows do
Addon.fDeaths.line[i]:Hide()
end
end
Addon.fDeaths:Show()
Addon.fDeaths.lines:SetHeight(Addon.deathRowHeight * deaths)
end
function Addon.deaths:Record(playerName, isFake)
local spellId, spellIcon, enemy, color, deathTime, damage
if isFake then
spellId = 197137
spellIcon = 135128
deathTime = 585
playerName = UnitName("player")
local _, class = UnitClass("player")
color = RAID_CLASS_COLORS[class] or HIGHLIGHT_FONT_COLOR
damage = 7700
enemy = "Ловчий из клана Колец Ненависти"
else
if IPMTDungeon.lastHit[playerName] == nil then
spellId = nil
spellIcon = nil
enemy = Addon.localization.UNKNOWN
damage = ''
else
spellId = IPMTDungeon.lastHit[playerName].spellId
enemy = IPMTDungeon.lastHit[playerName].enemy
damage = IPMTDungeon.lastHit[playerName].damage
if spellId > 1 then
spellIcon = C_Spell.GetSpellInfo(spellId).iconID
else
spellIcon = 130730 -- Melee Attack Icon
end
end
color = HIGHLIGHT_FONT_COLOR
if IPMTDungeon.players[playerName] and IPMTDungeon.players[playerName].color then
color = IPMTDungeon.players[playerName].color
end
deathTime = IPMTDungeon.time
end
if IPMTDungeon.deathes == nil then
IPMTDungeon.deathes = {}
end
if IPMTDungeon.deathes.list == nil or IPMTDungeon.deathes.list[1].isFake then
IPMTDungeon.deathes.list = {}
end
local record = {
playerName = playerName,
time = deathTime,
enemy = enemy,
damage = damage,
color = color,
spell = {
id = spellId,
icon = spellIcon,
},
}
if isFake then
record.isFake = true
end
table.insert(IPMTDungeon.deathes.list, record)
IPMTDungeon.lastHit[playerName] = nil
end
function Addon.deaths:ShowTooltip(self)
if not IPMTDungeon.deathes or not IPMTDungeon.deathes.list or #IPMTDungeon.deathes.list == 0 then
return false
end
if not Addon.opened.options then
local deathes, timeLost = C_ChallengeMode.GetDeathCount()
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetText(Addon.localization.DEATHCOUNT .. " : " .. deathes, 1, 1, 1)
GameTooltip:AddLine(Addon.localization.DEATHTIME .. " : " .. SecondsToClock(timeLost), .8, 0, 0)
GameTooltip:AddLine(" ")
local counts = {}
for i, death in ipairs(IPMTDungeon.deathes.list) do
if counts[death.playerName] ~= nil then
counts[death.playerName].count = counts[death.playerName].count + 1
else
counts[death.playerName] = {
count = 1,
color = death.color,
}
end
end
local list = {}
for playerName, deathInfo in pairs(counts) do
table.insert(list, {
count = deathInfo.count,
playerName = playerName,
color = deathInfo.color,
})
end
table.sort(list, function(a, b)
if a.count ~= b.count then
return a.count > b.count
else
return a.playerName < b.playerName
end
end)
for i, item in ipairs(list) do
GameTooltip:AddDoubleLine(item.playerName, item.count, item.color.r, item.color.g, item.color.b, HIGHLIGHT_FONT_COLOR:GetRGB())
end
GameTooltip:AddLine(" ")
GameTooltip:AddLine(Addon.localization.DEATHSHOW)
GameTooltip:Show()
end
end
function Addon.deaths:Update()
local deathes, timeLost = C_ChallengeMode.GetDeathCount()
if deathes > 0 then
Addon.fMain.deathTimer.text:SetText("-" .. SecondsToClock(timeLost) .. " [" .. deathes .. "]")
if Addon.opened.themes or not IPMTTheme[IPMTOptions.theme].elements.deathTimer.hidden then
Addon.fMain.deathTimer:Show()
end
elseif not Addon.opened.themes then
Addon.fMain.deathTimer:Hide()
end
end