forked from ipzaur/ipmythictimer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprognosis.lua
More file actions
158 lines (138 loc) · 5.48 KB
/
prognosis.lua
File metadata and controls
158 lines (138 loc) · 5.48 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
local AddonName, Addon = ...
local STONEBORN_ID = 174175
local STONEBORN_SPELL = 342171
local DEVOURING_MAGGOT_ID = 134024
local DEVOURING_MAGGOT_SPELL = 278444
local UnitExists = UnitExists
local UnitCanAttack = UnitCanAttack
local UnitIsDead = UnitIsDead
local UnitThreatSituation = UnitThreatSituation
local UnitPlayerControlled = UnitPlayerControlled
local UnitAffectingCombat = UnitAffectingCombat
function Addon:GetNameplateInfo(nameplate)
local unitName, unitExists = nil, nil
if nameplate and nameplate.UnitFrame then
unitExists = nameplate.UnitFrame.unitExists
unitName = nameplate.UnitFrame.displayedUnit
end
return unitName, unitExists
end
local function GrabPrognosis()
local inCombat = false
if UnitAffectingCombat("player") then
inCombat = true
else
for i=1,4 do
local unit = "party" .. i
if UnitExists(unit) and UnitAffectingCombat(unit) then
inCombat = true
break
end
end
end
if inCombat then
for _, nameplate in pairs(C_NamePlate.GetNamePlates()) do
local unitName, unitExists = Addon:GetNameplateInfo(nameplate)
if unitExists and unitName and UnitCanAttack("player", unitName) and not UnitIsDead(unitName) then
local threat = UnitThreatSituation("player", unitName) or -1
local allow = false
if threat >= 0 then
allow = true
else
local targetUnit = unitName .. "target"
if UnitExists(targetUnit) and UnitPlayerControlled(targetUnit) then
allow = true
end
end
if allow then
local npcID = nil
if Addon.GetNPCIDFromUnit then
npcID = Addon:GetNPCIDFromUnit(unitName)
end
if npcID then
local npcUID = unitName -- fallback unique key
if not IPMTDungeon.checkmobs[npcUID] and not IPMTDungeon.prognosis[npcUID] then
local forces = Addon:GetEnemyForces(npcID, Addon.PROGRESS_FORMAT_FORCES)
if forces then
IPMTDungeon.prognosis[npcUID] = forces
end
end
end
end
end
end
else
IPMTDungeon.prognosis = {}
end
end
function Addon:ShowPrognosis()
GrabPrognosis()
local prognosis = 0
for _, percent in pairs(IPMTDungeon.prognosis) do
if percent then
prognosis = prognosis + percent
end
end
if prognosis > 0 then
local progress = IPMTDungeon.trash.current + prognosis
if Addon.season and Addon.season.isActive and Addon.season.Prognosis then
Addon.season:Prognosis(progress)
end
if IPMTOptions.progress == Addon.PROGRESS_FORMAT_PERCENT then
progress = progress / IPMTDungeon.trash.total * 100
if IPMTOptions.limitProgress then
progress = math.min(100, progress)
end
if IPMTOptions.direction == Addon.PROGRESS_DIRECTION_DESC then
progress = 100 - progress
end
Addon.fMain.prognosis.text:SetFormattedText("%.2f%%", progress)
else
if IPMTOptions.direction == Addon.PROGRESS_DIRECTION_ASC then
if IPMTOptions.limitProgress then
progress = math.min(progress, IPMTDungeon.trash.total)
end
else
if IPMTOptions.limitProgress then
progress = math.max(IPMTDungeon.trash.total - progress, 0)
else
progress = IPMTDungeon.trash.total - progress
end
end
Addon.fMain.prognosis.text:SetText(progress)
end
Addon.fMain.prognosis:Show()
elseif not Addon.opened.themes then
Addon.fMain.prognosis:Hide()
end
end
function Addon:PrognosisCheck()
local _, event, _, sourceGUID, _, _, _, destGUID, _, _, _, spellId =
CombatLogGetCurrentEventInfo()
if event == "SPELL_AURA_APPLIED" then
if sourceGUID then
local _, _, _, _, _, npcID, spawnID = strsplit("-", sourceGUID)
-- Devouring Maggot applied "Infest" and despawn (no more give force)
if tonumber(npcID) == DEVOURING_MAGGOT_ID and tonumber(spellId) == DEVOURING_MAGGOT_SPELL then
if spawnID then
local npcUID = spawnID .. "_" .. npcID
IPMTDungeon.prognosis[npcUID] = 0
IPMTDungeon.checkmobs[npcUID] = true
end
return
end
end
if destGUID then
local _, _, _, _, _, npcID, spawnID = strsplit("-", destGUID)
-- Loyal Stoneborn mind control by Ventyr's
if tonumber(npcID) == STONEBORN_ID and tonumber(spellId) == STONEBORN_SPELL then
if spawnID then
local npcUID = spawnID .. "_" .. npcID
IPMTDungeon.prognosis[npcUID] = 0
IPMTDungeon.checkmobs[npcUID] = true
end
return
end
end
end
end