You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1002 lines
34 KiB

local AceLocale = LibStub ("AceLocale-3.0")
4 years ago
local Loc = AceLocale:GetLocale ("Details_Threat")
local detailsFramework = _G.DetailsFramework
4 years ago
local _GetNumSubgroupMembers = GetNumSubgroupMembers --> wow api
local _GetNumGroupMembers = GetNumGroupMembers --> wow api
local _UnitIsFriend = UnitIsFriend --> wow api
local _UnitName = UnitName --> wow api
local _IsInRaid = IsInRaid --> wow api
local _IsInGroup = IsInGroup --> wow api
local _UnitGroupRolesAssigned = DetailsFramework.UnitGroupRolesAssigned --> wow api
4 years ago
local GetUnitName = GetUnitName
local Details = _G.Details
local GetSpellInfo = Details.GetSpellInfo
4 years ago
local _ipairs = ipairs --> lua api
local _table_sort = table.sort --> lua api
local _cstr = string.format --> lua api
4 years ago
local _unpack = unpack
local _math_floor = math.floor
local _math_abs = math.abs
4 years ago
local RAID_CLASS_COLORS = RAID_CLASS_COLORS
--> Create the plugin Object
local ThreatMeter = Details:NewPluginObject ("Details_TinyThreat")
4 years ago
--> Main Frame
4 years ago
local ThreatMeterFrame = ThreatMeter.Frame
ThreatMeter:SetPluginDescription ("Small tool for track the threat you and other raid members have in your current target.")
local _
local UnitDetailedThreatSituation = UnitDetailedThreatSituation
local _UnitDetailedThreatSituation
if (detailsFramework.IsTimewalkWoW()) then
4 years ago
_UnitDetailedThreatSituation = function(source, target)
local isTanking, status, threatpct, rawthreatpct, threatvalue = UnitDetailedThreatSituation(source, target)
if (threatvalue) then
threatvalue = floor(threatvalue / 100)
end
return isTanking, status, threatpct, rawthreatpct, threatvalue
end
else
_UnitDetailedThreatSituation = UnitDetailedThreatSituation
end
local function CreatePluginFrames (data)
3 years ago
--> catch Details! main object
local _detalhes = _G.Details
4 years ago
local DetailsFrameWork = _detalhes.gump
--> data
4 years ago
ThreatMeter.data = data or {}
3 years ago
--> defaults
4 years ago
ThreatMeter.RowWidth = 294
ThreatMeter.RowHeight = 14
--> amount of row wich can be displayed
4 years ago
ThreatMeter.CanShow = 0
--> all rows already created
4 years ago
ThreatMeter.Rows = {}
--> current shown rows
4 years ago
ThreatMeter.ShownRows = {}
-->
ThreatMeter.Actived = false
3 years ago
--> localize functions
4 years ago
ThreatMeter.percent_color = ThreatMeter.percent_color
3 years ago
4 years ago
ThreatMeter.GetOnlyName = ThreatMeter.GetOnlyName
3 years ago
--> window reference
4 years ago
local instance
local player
3 years ago
--> OnEvent Table
4 years ago
function ThreatMeter:OnDetailsEvent (event, ...)
3 years ago
4 years ago
if (event == "DETAILS_STARTED") then
ThreatMeter:RefreshRows()
3 years ago
elseif (event == "HIDE") then --> plugin hidded, disabled
4 years ago
ThreatMeter.Actived = false
ThreatMeter:Cancel()
3 years ago
4 years ago
elseif (event == "SHOW") then
3 years ago
instance = ThreatMeter:GetInstance (ThreatMeter.instance_id)
3 years ago
4 years ago
ThreatMeter.RowWidth = instance.baseframe:GetWidth()-6
3 years ago
4 years ago
ThreatMeter:UpdateContainers()
ThreatMeter:UpdateRows()
3 years ago
4 years ago
ThreatMeter:SizeChanged()
3 years ago
player = GetUnitName ("player", true)
3 years ago
4 years ago
ThreatMeter.Actived = false
if (ThreatMeter:IsInCombat() or UnitAffectingCombat ("player")) then
4 years ago
if (not ThreatMeter.initialized) then
return
end
ThreatMeter.Actived = true
ThreatMeter:Start()
end
3 years ago
4 years ago
elseif (event == "COMBAT_PLAYER_ENTER") then
if (not ThreatMeter.Actived) then
ThreatMeter.Actived = true
ThreatMeter:Start()
end
3 years ago
4 years ago
elseif (event == "DETAILS_INSTANCE_ENDRESIZE" or event == "DETAILS_INSTANCE_SIZECHANGED") then
3 years ago
local what_window = select (1, ...)
4 years ago
if (what_window == instance) then
ThreatMeter:SizeChanged()
ThreatMeter:RefreshRows()
end
3 years ago
4 years ago
elseif (event == "DETAILS_OPTIONS_MODIFIED") then
local what_window = select (1, ...)
4 years ago
if (what_window == instance) then
ThreatMeter:RefreshRows()
end
3 years ago
4 years ago
elseif (event == "DETAILS_INSTANCE_STARTSTRETCH") then
ThreatMeterFrame:SetFrameStrata ("TOOLTIP")
ThreatMeterFrame:SetFrameLevel (instance.baseframe:GetFrameLevel()+1)
3 years ago
4 years ago
elseif (event == "DETAILS_INSTANCE_ENDSTRETCH") then
ThreatMeterFrame:SetFrameStrata ("MEDIUM")
3 years ago
4 years ago
elseif (event == "PLUGIN_DISABLED") then
ThreatMeterFrame:UnregisterEvent ("PLAYER_TARGET_CHANGED")
ThreatMeterFrame:UnregisterEvent ("PLAYER_REGEN_DISABLED")
ThreatMeterFrame:UnregisterEvent ("PLAYER_REGEN_ENABLED")
3 years ago
4 years ago
elseif (event == "PLUGIN_ENABLED") then
ThreatMeterFrame:RegisterEvent ("PLAYER_TARGET_CHANGED")
ThreatMeterFrame:RegisterEvent ("PLAYER_REGEN_DISABLED")
ThreatMeterFrame:RegisterEvent ("PLAYER_REGEN_ENABLED")
4 years ago
end
end
3 years ago
ThreatMeterFrame:SetWidth (300)
ThreatMeterFrame:SetHeight (100)
3 years ago
4 years ago
function ThreatMeter:UpdateContainers()
for _, row in _ipairs (ThreatMeter.Rows) do
4 years ago
row:SetContainer (instance.baseframe)
end
end
3 years ago
4 years ago
function ThreatMeter:UpdateRows()
for _, row in _ipairs (ThreatMeter.Rows) do
4 years ago
row.width = ThreatMeter.RowWidth
end
end
3 years ago
4 years ago
function ThreatMeter:HideBars()
for _, row in _ipairs (ThreatMeter.Rows) do
4 years ago
row:Hide()
end
end
3 years ago
4 years ago
local target = nil
local timer = 0
local interval = 1.0
3 years ago
4 years ago
local RoleIconCoord = {
["TANK"] = {0, 0.28125, 0.328125, 0.625},
["HEALER"] = {0.3125, 0.59375, 0, 0.296875},
["DAMAGER"] = {0.3125, 0.59375, 0.328125, 0.625},
["NONE"] = {0.3125, 0.59375, 0.328125, 0.625}
}
3 years ago
4 years ago
function ThreatMeter:SizeChanged()
local instance = ThreatMeter:GetPluginInstance()
3 years ago
4 years ago
local w, h = instance:GetSize()
ThreatMeterFrame:SetWidth (w)
ThreatMeterFrame:SetHeight (h)
4 years ago
ThreatMeter.RowHeight = instance.row_info.height
ThreatMeter.CanShow = math.floor ( h / (instance.row_info.height+1))
4 years ago
for i = #ThreatMeter.Rows+1, ThreatMeter.CanShow do
ThreatMeter:NewRow (i)
end
ThreatMeter.ShownRows = {}
3 years ago
4 years ago
for i = 1, ThreatMeter.CanShow do
ThreatMeter.ShownRows [i] = ThreatMeter.Rows[i]
if (_detalhes.in_combat) then
ThreatMeter.Rows[i]:Show()
end
ThreatMeter.Rows[i].width = w-5
end
3 years ago
4 years ago
for i = #ThreatMeter.ShownRows+1, #ThreatMeter.Rows do
ThreatMeter.Rows [i]:Hide()
end
3 years ago
4 years ago
end
3 years ago
4 years ago
local SharedMedia = LibStub:GetLibrary ("LibSharedMedia-3.0")
function ThreatMeter:RefreshRow (row)
3 years ago
4 years ago
local instance = ThreatMeter:GetPluginInstance()
3 years ago
4 years ago
if (instance) then
local font = SharedMedia:Fetch ("font", instance.row_info.font_face, true) or instance.row_info.font_face
3 years ago
4 years ago
row.textsize = instance.row_info.font_size
row.textfont = font
row.texture = instance.row_info.texture
row.shadow = instance.row_info.textL_outline
3 years ago
4 years ago
row.width = instance.baseframe:GetWidth()-5
row.height = instance.row_info.height
local rowHeight = - ( (row.rowId -1) * (instance.row_info.height + 1) )
row:ClearAllPoints()
row:SetPoint ("topleft", ThreatMeterFrame, "topleft", 1, rowHeight)
row:SetPoint ("topright", ThreatMeterFrame, "topright", -1, rowHeight)
3 years ago
4 years ago
end
end
3 years ago
4 years ago
function ThreatMeter:RefreshRows()
for i = 1, #ThreatMeter.Rows do
ThreatMeter:RefreshRow (ThreatMeter.Rows [i])
end
end
3 years ago
4 years ago
function ThreatMeter:NewRow (i)
local newrow = DetailsFrameWork:NewBar (ThreatMeterFrame, nil, "DetailsThreatRow"..i, nil, 300, ThreatMeter.RowHeight)
newrow:SetPoint (3, -((i-1)*(ThreatMeter.RowHeight+1)))
4 years ago
newrow.lefttext = "bar " .. i
newrow.color = "skyblue"
newrow.fontsize = 9.9
newrow.fontface = "GameFontHighlightSmall"
newrow:SetIcon ("Interface\\LFGFRAME\\UI-LFG-ICON-PORTRAITROLES", RoleIconCoord ["DAMAGER"])
newrow.rowId = i
ThreatMeter.Rows [#ThreatMeter.Rows+1] = newrow
3 years ago
4 years ago
ThreatMeter:RefreshRow (newrow)
3 years ago
4 years ago
newrow:Hide()
3 years ago
4 years ago
return newrow
end
3 years ago
local absoluteSort = function (table1, table2)
3 years ago
if (table1[6] > table2[6]) then
return true
else
return false
end
end
local relativeSort = function (table1, table2)
4 years ago
if (table1[2] > table2[2]) then
return true
else
return false
end
end
function ThreatMeter:GetUnitId()
local unitId
if (ThreatMeter.saveddata.usefocus) then
unitId = "focus"
if (not UnitExists(unitId)) then
unitId = "target"
end
else
unitId = "target"
end
return unitId
end
3 years ago
local UpdateTableFromThreatSituation = function(threat_table, threatening, threatened)
local isTanking, status, threatpct, rawthreatpct, threatvalue = _UnitDetailedThreatSituation (threatening, threatened)
if (status) then
threat_table [2] = threatpct
threat_table [3] = isTanking
threat_table [6] = threatvalue
threat_table [7] = isTanking and 100 or rawthreatpct -- rawthreatpct returns invalid values for the main tank
else
threat_table [2] = 0
threat_table [3] = false
threat_table [6] = 0
threat_table [7] = 0
end
end
local gougeSpells = {
[15687] = 29425, -- Moroes: Gouge
[22948] = 40491, -- Gurtogg Bloodboil: Bewildering Strike
[25165] = 45256, -- Lady Sacrolash: Confounding Blow
}
local FindGougeSpellForUnit = function(unitId)
local npcId = _detalhes:GetNpcIdFromGuid(UnitGUID(unitId))
return gougeSpells[npcId]
end
4 years ago
local Threater = function()
local options = ThreatMeter.options
3 years ago
4 years ago
local unitId = ThreatMeter:GetUnitId()
if (ThreatMeter.Actived and UnitExists(unitId) and not _UnitIsFriend("player", unitId)) then
--> get the threat of all players
if (_IsInRaid()) then
for i = 1, _GetNumGroupMembers(), 1 do
3 years ago
local thisplayer_name = GetUnitName ("raid"..i, true)
4 years ago
local threat_table_index = ThreatMeter.player_list_hash [thisplayer_name]
local threat_table = ThreatMeter.player_list_indexes [threat_table_index]
3 years ago
4 years ago
if (not threat_table) then
--> some one joined the group while the player are in combat
4 years ago
ThreatMeter:Start()
return
end
3 years ago
UpdateTableFromThreatSituation(threat_table, "raid"..i, unitId)
4 years ago
end
3 years ago
elseif (_IsInGroup()) then
for i = 1, _GetNumGroupMembers()-1, 1 do
local thisplayer_name = GetUnitName ("party"..i, true)
4 years ago
local threat_table_index = ThreatMeter.player_list_hash [thisplayer_name]
local threat_table = ThreatMeter.player_list_indexes [threat_table_index]
3 years ago
4 years ago
if (not threat_table) then
--> some one joined the group while the player are in combat
4 years ago
ThreatMeter:Start()
return
end
3 years ago
UpdateTableFromThreatSituation(threat_table, "party"..i, unitId)
4 years ago
end
3 years ago
local thisplayer_name = GetUnitName ("player", true)
4 years ago
local threat_table_index = ThreatMeter.player_list_hash [thisplayer_name]
local threat_table = ThreatMeter.player_list_indexes [threat_table_index]
3 years ago
UpdateTableFromThreatSituation(threat_table, "player", unitId)
4 years ago
else
3 years ago
--> player
local thisplayer_name = GetUnitName ("player", true)
4 years ago
local threat_table_index = ThreatMeter.player_list_hash [thisplayer_name]
local threat_table = ThreatMeter.player_list_indexes [threat_table_index]
3 years ago
UpdateTableFromThreatSituation(threat_table, "player", unitId)
--> pet
if (UnitExists ("pet")) then
local thisplayer_name = GetUnitName ("pet", true) .. " *PET*"
4 years ago
local threat_table_index = ThreatMeter.player_list_hash [thisplayer_name]
local threat_table = ThreatMeter.player_list_indexes [threat_table_index]
3 years ago
if threat_table then
UpdateTableFromThreatSituation(threat_table, "pet", unitId)
4 years ago
end
end
end
3 years ago
local disableGougeMode = ThreatMeter.saveddata.disable_gouge
local gougeSpellId = (not disableGougeMode) and FindGougeSpellForUnit(unitId)
local useAbsoluteMode = gougeSpellId or ThreatMeter.saveddata.absolute_mode
--> sort
3 years ago
_table_sort (ThreatMeter.player_list_indexes, useAbsoluteMode and absoluteSort or relativeSort)
local needMainTankDummyBar = true
for index, t in _ipairs (ThreatMeter.player_list_indexes) do
4 years ago
ThreatMeter.player_list_hash [t[1]] = index
3 years ago
if t[3] then
needMainTankDummyBar = false
end
4 years ago
end
--> no threat on this enemy
3 years ago
if (ThreatMeter.player_list_indexes [1][7] < 1) then
4 years ago
ThreatMeter:HideBars()
return
end
--> find main tank threat, even if they are not in group
3 years ago
local mainTankAbsoluteThreat = ThreatMeter.player_list_indexes[1][6]/(ThreatMeter.player_list_indexes[1][7]/100)
4 years ago
local lastIndex = 0
local shownMe = false
local me = ThreatMeter.player_list_indexes [ ThreatMeter.player_list_hash [player] ]
local hidePullBar = ThreatMeter.saveddata.hide_pull_bar
3 years ago
local needRangedPullBar = (not hidePullBar) and useAbsoluteMode
local needMeleePullBar = (not hidePullBar) and useAbsoluteMode
local needRelativePullBar = (not hidePullBar) and (not useAbsoluteMode) and me and (me[2] > 0) and (not me[3])
--> find out scaling factor for bars
3 years ago
local barValueUnit
if useAbsoluteMode then
barValueUnit = max(ThreatMeter.player_list_indexes[1][7]/100, needRangedPullBar and 1.3 or needMeleePullBar and 1.1 or 1.0)
else
barValueUnit = 1.0
end
4 years ago
--> find out gouge threshold (highest offtank threat, divided by 110%; this prevents the offtank from taking the boss back)
3 years ago
local gougeThreshold = nil
if gougeSpellId then
for _, t in _ipairs (ThreatMeter.player_list_indexes) do
3 years ago
if not t[3] then
gougeThreshold = t[6] / 1.1
break
end
end
end
4 years ago
3 years ago
local index = 1
local lastIndex = #ThreatMeter.ShownRows
local dummyBarCount = 0
while index <= lastIndex do
local thisRow = ThreatMeter.ShownRows[index]
local threatActor = ThreatMeter.player_list_indexes[index-dummyBarCount]
4 years ago
3 years ago
if needRelativePullBar then
thisRow._icon:SetTexture ([[Interface\PVPFrame\Icon-Combat]])
thisRow._icon:SetTexCoord (0, 1, 0, 1)
4 years ago
3 years ago
local myPullThreat = me[6]*(100/me[2])
local r,g = ThreatMeter:percent_color(me[2], true)
4 years ago
3 years ago
thisRow:SetLeftText("You pull at")
thisRow:SetRightText("+" .. ThreatMeter:ToK2 (myPullThreat - me[6]) .. " (" .. _cstr ("%.1f", 100-me[2]) .. "%)")
thisRow:SetValue(me[2]/barValueUnit)
thisRow:SetColor (r, g, 0, 1)
thisRow:Show()
4 years ago
3 years ago
needRelativePullBar = false
index = index+1
dummyBarCount = dummyBarCount+1
if index > lastIndex then break end
thisRow = ThreatMeter.ShownRows[index]
4 years ago
end
3 years ago
if needRangedPullBar and ((not threatActor) or (threatActor[7] < 130)) then
thisRow._icon:SetTexture ([[Interface\PaperDoll\UI-PaperDoll-Slot-Ranged]])
thisRow._icon:SetTexCoord (0, 1, 0, 1)
3 years ago
thisRow:SetLeftText ("Ranged pull at")
thisRow:SetRightText(ThreatMeter:ToK2 (mainTankAbsoluteThreat*1.3) .. " (130.0%)")
thisRow:SetValue(130/barValueUnit)
thisRow:SetColor(1, 0, 0, 1)
thisRow:Show()
needRangedPullBar = false
index = index+1
dummyBarCount = dummyBarCount+1
if index > lastIndex then break end
thisRow = ThreatMeter.ShownRows[index]
4 years ago
end
3 years ago
if needMeleePullBar and ((not threatActor) or (threatActor[7] < 110)) then
thisRow._icon:SetTexture ([[Interface\PaperDoll\UI-PaperDoll-Slot-MainHand]])
thisRow._icon:SetTexCoord (0, 1, 0, 1)
3 years ago
thisRow:SetLeftText ("Melee pull at")
thisRow:SetRightText(ThreatMeter:ToK2 (mainTankAbsoluteThreat*1.1) .. " (110.0%)")
thisRow:SetValue(110/barValueUnit)
thisRow:SetColor(1, 0, 0, 1)
thisRow:Show()
needMeleePullBar = false
index = index+1
dummyBarCount = dummyBarCount+1
if index > lastIndex then break end
thisRow = ThreatMeter.ShownRows[index]
end
if needMainTankDummyBar and ((not threatActor) or (not useAbsoluteMode) or (threatActor[6] < mainTankAbsoluteThreat)) then
thisRow._icon:SetTexture ([[Interface\LFGFrame\UI-LFG-Icon-PortraitRoles]])
thisRow._icon:SetTexCoord (_unpack (RoleIconCoord ["TANK"]))
4 years ago
3 years ago
thisRow:SetLeftText ("Current Tank")
thisRow:SetRightText(ThreatMeter:ToK2 (mainTankAbsoluteThreat) .. " (100.0%)")
thisRow:SetValue(100/barValueUnit)
4 years ago
3 years ago
-- color main tank based on highest non-tank threat
local r,g = 0,1
for _, t in _ipairs (ThreatMeter.player_list_indexes) do
3 years ago
if not t[3] then
local otherPct = t[useAbsoluteMode and 7 or 2]
r,g = (otherPct*0.01), (_math_abs(otherPct-100)*0.01)
3 years ago
break
end
end
thisRow:SetColor(r, g, 0, 1)
thisRow:Show()
4 years ago
3 years ago
needMainTankDummyBar = false
4 years ago
3 years ago
index = index+1
dummyBarCount = dummyBarCount+1
if index > lastIndex then break end
thisRow = ThreatMeter.ShownRows[index]
end
if gougeThreshold and ((not threatActor) or (threatActor[6] < gougeThreshold)) then
local spellName, _, spellTexture = GetSpellInfo (gougeSpellId)
thisRow._icon:SetTexture (spellTexture)
thisRow._icon:SetTexCoord (0, 1, 0, 1)
3 years ago
local pct = gougeThreshold * 100 / mainTankAbsoluteThreat
thisRow:SetLeftText (spellName .. " pull at")
thisRow:SetRightText(ThreatMeter:ToK2 (gougeThreshold) .. " (" .. _cstr ("%.1f", pct) .. "%)")
thisRow:SetValue(pct/barValueUnit)
thisRow:SetColor(1, 0, 0, 1)
thisRow:Show()
gougeThreshold = false
index = index+1
dummyBarCount = dummyBarCount+1
if index > lastIndex then break end
thisRow = ThreatMeter.ShownRows[index]
end
if (threatActor) then
local role = threatActor[4]
thisRow._icon:SetTexture ([[Interface\LFGFrame\UI-LFG-Icon-PortraitRoles]])
thisRow._icon:SetTexCoord (_unpack (RoleIconCoord [role]))
3 years ago
thisRow:SetLeftText (ThreatMeter:GetOnlyName (threatActor [1]))
3 years ago
local pct = threatActor [useAbsoluteMode and 7 or 2]
thisRow:SetRightText (ThreatMeter:ToK2 (threatActor [6]) .. " (" .. _cstr ("%.1f", pct) .. "%)")
thisRow:SetValue (pct/barValueUnit)
3 years ago
4 years ago
if (options.useplayercolor and threatActor [1] == player) then
thisRow:SetColor (_unpack (options.playercolor))
3 years ago
4 years ago
elseif (options.useclasscolors) then
local color = RAID_CLASS_COLORS [threatActor [5]]
if (color) then
thisRow:SetColor (color.r, color.g, color.b)
else
thisRow:SetColor (1, 1, 1, 1)
end
else
3 years ago
if threatActor[3] then
-- color main tank based on highest non-tank threat
local r,g = 0,1
for _, t in _ipairs (ThreatMeter.player_list_indexes) do
3 years ago
if not t[3] then
local otherPct = t[useAbsoluteMode and 7 or 2]
r,g = (otherPct*0.01), (_math_abs(otherPct-100)*0.01)
3 years ago
break
end
end
thisRow:SetColor (r, g, 0, 1)
4 years ago
else
local r, g = ThreatMeter:percent_color (pct, true)
thisRow:SetColor (r, g, 0, 1)
end
end
3 years ago
4 years ago
if (not thisRow.statusbar:IsShown()) then
thisRow:Show()
end
if (threatActor [1] == player) then
shownMe = true
end
else
thisRow:Hide()
end
3 years ago
index = index+1
4 years ago
end
3 years ago
4 years ago
if (not shownMe) then
--> show my self into last bar
4 years ago
local threat_actor = ThreatMeter.player_list_indexes [ ThreatMeter.player_list_hash [player] ]
if (threat_actor) then
if (threat_actor [2] and threat_actor [2] > 0.1) then
local thisRow = ThreatMeter.ShownRows [#ThreatMeter.ShownRows]
thisRow:SetLeftText (player)
--thisRow.textleft:SetTextColor (unpack (RAID_CLASS_COLORS [threat_actor [5]]))
4 years ago
local role = threat_actor [4]
thisRow._icon:SetTexture ([[Interface\LFGFrame\UI-LFG-Icon-PortraitRoles]])
thisRow._icon:SetTexCoord (_unpack (RoleIconCoord [role]))
4 years ago
thisRow:SetRightText (ThreatMeter:ToK2 (threat_actor [6]) .. " (" .. _cstr ("%.1f", threat_actor [2]) .. "%)")
thisRow:SetValue (threat_actor [2])
3 years ago
4 years ago
if (options.useplayercolor) then
thisRow:SetColor (_unpack (options.playercolor))
4 years ago
else
local r, g = ThreatMeter:percent_color (threat_actor [2], true)
thisRow:SetColor (r, g, 0, .3)
end
end
end
end
else
--print ("nao tem target")
4 years ago
end
end
3 years ago
4 years ago
function ThreatMeter:TargetChanged()
if (not ThreatMeter.Actived) then
return
end
local unitId = ThreatMeter:GetUnitId()
local NewTarget = _UnitName(unitId)
if (NewTarget and not _UnitIsFriend("player", unitId)) then
target = NewTarget
Threater()
else
ThreatMeter:HideBars()
end
end
3 years ago
4 years ago
function ThreatMeter:Tick()
Threater()
end
function ThreatMeter:Start()
ThreatMeter:HideBars()
if (ThreatMeter.Actived) then
if (ThreatMeter.job_thread) then
ThreatMeter:CancelTimer (ThreatMeter.job_thread)
4 years ago
ThreatMeter.job_thread = nil
end
3 years ago
4 years ago
ThreatMeter.player_list_indexes = {}
ThreatMeter.player_list_hash = {}
3 years ago
--> pre build player list
if (_IsInRaid()) then
5 months ago
if (not ThreatMeter.saveddata.only_my_group) then
for i = 1, _GetNumGroupMembers(), 1 do
local thisplayer_name = GetUnitName ("raid"..i, true)
local role = _UnitGroupRolesAssigned (thisplayer_name)
local _, class = UnitClass (thisplayer_name)
local t = {thisplayer_name, 0, false, role, class, 0, 0}
ThreatMeter.player_list_indexes [#ThreatMeter.player_list_indexes+1] = t
ThreatMeter.player_list_hash [thisplayer_name] = #ThreatMeter.player_list_indexes
end
else
for i = 1, 4, 1 do
local thisplayer_name = GetUnitName ("party"..i, true)
if (thisplayer_name) then
local role = _UnitGroupRolesAssigned (thisplayer_name)
local _, class = UnitClass (thisplayer_name)
local t = {thisplayer_name, 0, false, role, class, 0, 0}
ThreatMeter.player_list_indexes [#ThreatMeter.player_list_indexes+1] = t
ThreatMeter.player_list_hash [thisplayer_name] = #ThreatMeter.player_list_indexes
end
end
local thisplayer_name = GetUnitName ("player", true)
local role = _UnitGroupRolesAssigned (thisplayer_name)
local _, class = UnitClass (thisplayer_name)
local t = {thisplayer_name, 0, false, role, class, 0, 0}
ThreatMeter.player_list_indexes [#ThreatMeter.player_list_indexes+1] = t
ThreatMeter.player_list_hash [thisplayer_name] = #ThreatMeter.player_list_indexes
end
3 years ago
elseif (_IsInGroup()) then
for i = 1, _GetNumGroupMembers()-1, 1 do
local thisplayer_name = GetUnitName ("party"..i, true)
local role = _UnitGroupRolesAssigned (thisplayer_name)
local _, class = UnitClass (thisplayer_name)
3 years ago
local t = {thisplayer_name, 0, false, role, class, 0, 0}
4 years ago
ThreatMeter.player_list_indexes [#ThreatMeter.player_list_indexes+1] = t
ThreatMeter.player_list_hash [thisplayer_name] = #ThreatMeter.player_list_indexes
5 months ago
if (ThreatMeter.saveddata.show_party_pets and UnitExists ("partypet" .. i)) then
local thispet_name = GetUnitName ("partypet" .. i, true) .. " *PET*"
local role = "DAMAGER"
local t = {thispet_name, 0, false, role, class, 0, 0}
ThreatMeter.player_list_indexes [#ThreatMeter.player_list_indexes+1] = t
ThreatMeter.player_list_hash [thispet_name] = #ThreatMeter.player_list_indexes
end
4 years ago
end
local thisplayer_name = GetUnitName ("player", true)
local role = _UnitGroupRolesAssigned (thisplayer_name)
local _, class = UnitClass (thisplayer_name)
3 years ago
local t = {thisplayer_name, 0, false, role, class, 0, 0}
4 years ago
ThreatMeter.player_list_indexes [#ThreatMeter.player_list_indexes+1] = t
ThreatMeter.player_list_hash [thisplayer_name] = #ThreatMeter.player_list_indexes
3 years ago
5 months ago
if (ThreatMeter.saveddata.show_party_pets and UnitExists ("pet")) then
local thispet_name = GetUnitName ("pet", true) .. " *PET*"
local role = "DAMAGER"
local t = {thispet_name, 0, false, role, class, 0, 0}
ThreatMeter.player_list_indexes [#ThreatMeter.player_list_indexes+1] = t
ThreatMeter.player_list_hash [thispet_name] = #ThreatMeter.player_list_indexes
end
4 years ago
else
local thisplayer_name = GetUnitName ("player", true)
local role = _UnitGroupRolesAssigned (thisplayer_name)
local _, class = UnitClass (thisplayer_name)
3 years ago
local t = {thisplayer_name, 0, false, role, class, 0, 0}
4 years ago
ThreatMeter.player_list_indexes [#ThreatMeter.player_list_indexes+1] = t
ThreatMeter.player_list_hash [thisplayer_name] = #ThreatMeter.player_list_indexes
3 years ago
if (UnitExists ("pet")) then
local thispet_name = GetUnitName ("pet", true) .. " *PET*"
4 years ago
local role = "DAMAGER"
3 years ago
local t = {thispet_name, 0, false, role, class, 0, 0}
4 years ago
ThreatMeter.player_list_indexes [#ThreatMeter.player_list_indexes+1] = t
ThreatMeter.player_list_hash [thispet_name] = #ThreatMeter.player_list_indexes
end
end
3 years ago
4 years ago
local job_thread = ThreatMeter:ScheduleRepeatingTimer ("Tick", ThreatMeter.options.updatespeed)
ThreatMeter.job_thread = job_thread
end
end
3 years ago
4 years ago
function ThreatMeter:End()
ThreatMeter:HideBars()
if (ThreatMeter.job_thread) then
ThreatMeter:CancelTimer (ThreatMeter.job_thread)
4 years ago
ThreatMeter.job_thread = nil
end
end
3 years ago
4 years ago
function ThreatMeter:Cancel()
ThreatMeter:HideBars()
if (ThreatMeter.job_thread) then
ThreatMeter:CancelTimer (ThreatMeter.job_thread)
4 years ago
ThreatMeter.job_thread = nil
end
ThreatMeter.Actived = false
end
3 years ago
4 years ago
end
local build_options_panel = function()
local options_frame = ThreatMeter:CreatePluginOptionsFrame ("ThreatMeterOptionsWindow", "Tiny Threat Options", 1)
local menu = {
--[=[]]
4 years ago
{
type = "range",
get = function() return ThreatMeter.saveddata.updatespeed end,
set = function (self, fixedparam, value) ThreatMeter.saveddata.updatespeed = value end,
4 years ago
min = 0.2,
max = 3,
step = 0.2,
desc = "How fast the window get updates.",
name = "Update Speed",
usedecimals = true,
},
--]=]
4 years ago
{
type = "toggle",
get = function() return ThreatMeter.saveddata.useplayercolor end,
set = function (self, fixedparam, value) ThreatMeter.saveddata.useplayercolor = value end,
4 years ago
desc = "When enabled, your bar get the following color.",
name = "Player Color Enabled"
},
{
type = "color",
get = function() return ThreatMeter.saveddata.playercolor end,
set = function (self, r, g, b, a)
4 years ago
local current = ThreatMeter.saveddata.playercolor
current[1], current[2], current[3], current[4] = r, g, b, a
end,
desc = "If Player Color is enabled, your bar have this color.",
name = "Color"
},
{
type = "toggle",
get = function() return ThreatMeter.saveddata.useclasscolors end,
set = function (self, fixedparam, value) ThreatMeter.saveddata.useclasscolors = value end,
4 years ago
desc = "When enabled, threat bars uses the class color of the character.",
name = "Use Class Colors"
},
{type = "blank"},
{
type = "toggle",
get = function() return ThreatMeter.saveddata.usefocus end,
set = function (self, fixedparam, value) ThreatMeter.saveddata.usefocus = value end,
4 years ago
desc = "Show threat for the focus target if there's one.",
name = "Track Focus Target (if any)"
},
{
type = "toggle",
3 years ago
get = function() return not ThreatMeter.saveddata.hide_pull_bar end,
set = function (self, fixedparam, value) ThreatMeter.saveddata.hide_pull_bar = not value end,
3 years ago
desc = "Show Pull Aggro Bar",
name = "Show Pull Aggro Bar"
},
{
type = "toggle",
get = function() return ThreatMeter.saveddata.absolute_mode end,
set = function(self, fixedparam, value) ThreatMeter.saveddata.absolute_mode = value end,
desc = "If this is disabled, you see weighted threat percentages – aggro switches at 100%.\nIf this is enabled, you see absolute threat percentages – aggro switches at 110% in melee, and 130% at range.",
name = "Display absolute threat",
},
{
type = "toggle",
get = function() return not ThreatMeter.saveddata.disable_gouge end,
set = function(self, fixedparam, value) ThreatMeter.saveddata.disable_gouge = not value end,
desc = "If this is enabled, certain bosses will show an additional threat threshold at 90.9% of the off-tank's threat. Any player above this threshold might be targeted after the Main Tank is incapacitated.",
name = "Enable Gouge mode",
4 years ago
},
5 months ago
{
type = "toggle",
get = function() return ThreatMeter.saveddata.show_party_pets end,
set = function(self, fixedparam, value) ThreatMeter.saveddata.show_party_pets = value end,
desc = "If this is enabled, you will see pets while in a party but not while in a raid",
name = "Show pets in party"
},
{
type = "toggle",
get = function() return ThreatMeter.saveddata.only_my_group end,
set = function(self, fixedparam, value) ThreatMeter.saveddata.only_my_group = value end,
desc = "If this is enabled, you will only see members in your group while in a raid",
name = "Show only my group"
},
4 years ago
--[=[
{
type = "toggle",
get = function() return ThreatMeter.saveddata.playSound end,
set = function (self, fixedparam, value) ThreatMeter.saveddata.playSound = value end,
4 years ago
desc = "Except for tanks",
name = "Play Audio On High Threat"
},
--]=]
}
3 years ago
local options_text_template = detailsFramework:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")
local options_dropdown_template = detailsFramework:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")
local options_switch_template = detailsFramework:GetTemplate ("switch", "OPTIONS_CHECKBOX_TEMPLATE")
local options_slider_template = detailsFramework:GetTemplate ("slider", "OPTIONS_SLIDER_TEMPLATE")
local options_button_template = detailsFramework:GetTemplate ("button", "OPTIONS_BUTTON_TEMPLATE")
menu.always_boxfirst = true
detailsFramework:BuildMenu (options_frame, menu, 15, -35, 160, false, options_text_template, options_dropdown_template, options_switch_template, true, options_slider_template, options_button_template)
3 years ago
options_frame:SetHeight(160)
4 years ago
end
ThreatMeter.OpenOptionsPanel = function()
if (not ThreatMeterOptionsWindow) then
build_options_panel()
end
ThreatMeterOptionsWindow:Show()
end
function ThreatMeter:OnEvent (_, event, ...)
if (event == "PLAYER_TARGET_CHANGED") then
ThreatMeter:TargetChanged()
3 years ago
4 years ago
elseif (event == "PLAYER_REGEN_DISABLED") then
ThreatMeter.Actived = true
ThreatMeter:Start()
--print ("tiny theat: regen disabled")
3 years ago
4 years ago
elseif (event == "PLAYER_REGEN_ENABLED") then
ThreatMeter:End()
ThreatMeter.Actived = false
--print ("tiny theat: regen enabled")
3 years ago
4 years ago
elseif (event == "ADDON_LOADED") then
local AddonName = select (1, ...)
4 years ago
if (AddonName == "Details_TinyThreat") then
if (_G.Details) then
4 years ago
if (DetailsFramework.IsClassicWow()) then
--return
end
--> create widgets
4 years ago
CreatePluginFrames (data)
local MINIMAL_DETAILS_VERSION_REQUIRED = 1
3 years ago
--> Install
local install, saveddata = _G.Details:InstallPlugin ("RAID", Loc ["STRING_PLUGIN_NAME"], "Interface\\Icons\\Ability_Druid_Cower", ThreatMeter, "DETAILS_PLUGIN_TINY_THREAT", MINIMAL_DETAILS_VERSION_REQUIRED, "Terciob", "v2.20")
if (type (install) == "table" and install.error) then
print (install.error)
4 years ago
end
3 years ago
--> Register needed events
_G.Details:RegisterEvent (ThreatMeter, "COMBAT_PLAYER_ENTER")
_G.Details:RegisterEvent (ThreatMeter, "COMBAT_PLAYER_LEAVE")
_G.Details:RegisterEvent (ThreatMeter, "DETAILS_INSTANCE_ENDRESIZE")
_G.Details:RegisterEvent (ThreatMeter, "DETAILS_INSTANCE_SIZECHANGED")
_G.Details:RegisterEvent (ThreatMeter, "DETAILS_INSTANCE_STARTSTRETCH")
_G.Details:RegisterEvent (ThreatMeter, "DETAILS_INSTANCE_ENDSTRETCH")
_G.Details:RegisterEvent (ThreatMeter, "DETAILS_OPTIONS_MODIFIED")
ThreatMeterFrame:RegisterEvent ("PLAYER_TARGET_CHANGED")
ThreatMeterFrame:RegisterEvent ("PLAYER_REGEN_DISABLED")
ThreatMeterFrame:RegisterEvent ("PLAYER_REGEN_ENABLED")
4 years ago
--> Saved data
4 years ago
ThreatMeter.saveddata = saveddata or {}
3 years ago
4 years ago
ThreatMeter.saveddata.updatespeed = ThreatMeter.saveddata.updatespeed or 1
ThreatMeter.saveddata.animate = ThreatMeter.saveddata.animate or false
ThreatMeter.saveddata.showamount = ThreatMeter.saveddata.showamount or false
ThreatMeter.saveddata.useplayercolor = ThreatMeter.saveddata.useplayercolor or false
ThreatMeter.saveddata.playercolor = ThreatMeter.saveddata.playercolor or {1, 1, 1}
ThreatMeter.saveddata.useclasscolors = ThreatMeter.saveddata.useclasscolors or false
ThreatMeter.saveddata.usefocus = ThreatMeter.saveddata.usefocus or false
ThreatMeter.saveddata.hide_pull_bar = ThreatMeter.saveddata.hide_pull_bar or false
3 years ago
ThreatMeter.saveddata.absolute_mode = ThreatMeter.saveddata.absolute_mode or false
ThreatMeter.saveddata.disable_gouge = ThreatMeter.saveddata.disable_gouge or false
5 months ago
ThreatMeter.saveddata.show_party_pets = ThreatMeter.saveddata.show_party_pets or false
ThreatMeter.saveddata.only_my_group = ThreatMeter.saveddata.only_my_group or false
4 years ago
ThreatMeter.saveddata.playSound = ThreatMeter.saveddata.playSound or false
ThreatMeter.saveddata.playSoundFile = ThreatMeter.saveddata.playSoundFile or "Details Threat Warning Volume 3"
ThreatMeter.options = ThreatMeter.saveddata
3 years ago
--> Register slash commands
SLASH_DETAILS_TINYTHREAT1 = "/tinythreat"
3 years ago
4 years ago
function SlashCmdList.DETAILS_TINYTHREAT (msg, editbox)
3 years ago
4 years ago
local command, rest = msg:match("^(%S*)%s*(.-)$")
3 years ago
4 years ago
if (command == Loc ["STRING_SLASH_ANIMATE"]) then
3 years ago
4 years ago
elseif (command == Loc ["STRING_SLASH_SPEED"]) then
3 years ago
4 years ago
if (rest) then
local speed = tonumber (rest)
4 years ago
if (speed) then
if (speed > 3) then
speed = 3
elseif (speed < 0.3) then
speed = 0.3
end
3 years ago
4 years ago
ThreatMeter.saveddata.updatespeed = speed
ThreatMeter:Msg (Loc ["STRING_SLASH_SPEED_CHANGED"] .. speed)
4 years ago
else
ThreatMeter:Msg (Loc ["STRING_SLASH_SPEED_CURRENT"] .. ThreatMeter.saveddata.updatespeed)
4 years ago
end
end
elseif (command == Loc ["STRING_SLASH_AMOUNT"]) then
3 years ago
4 years ago
else
ThreatMeter:Msg (Loc ["STRING_COMMAND_LIST"])
print ("|cffffaeae/tinythreat " .. Loc ["STRING_SLASH_SPEED"] .. "|r: " .. Loc ["STRING_SLASH_SPEED_DESC"])
3 years ago
4 years ago
end
end
ThreatMeter.initialized = true
end
end
end
end