-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrole.lua
122 lines (98 loc) · 3.19 KB
/
role.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
--[[--------------------------------------------------------------------
This role detection library is a barely modified version of Phanx's
from his oUF_Phanx layout.
Licensing for this file is roughly the following (since a license
file is not included):
oUF_Phanx
Copyright (c) 2008-2013 Phanx <[email protected]>. All rights reserved.
http://www.wowinterface.com/downloads/info13993-oUF_Phanx.html
http://www.curse.com/addons/wow/ouf-phanx
----------------------------------------------------------------------]]
local _, ns = ...
local lib = ns.Kln.lib
local playerClass = select(2, UnitClass("player"))
local CURRENT_ROLE = "DPS"
local getRole, updateEvents
if playerClass == "DEATHKNIGHT" then
updateEvents = "UPDATE_SHAPESHIFT_FORM"
getRole = function()
if GetSpecialization() == 1 then -- Blood 1, Frost 2, Unholy 3
return "TANK"
end
end
elseif playerClass == "DRUID" then
updateEvents = "UPDATE_SHAPESHIFT_FORM"
getRole = function()
local form = GetShapeshiftFormID() -- Aquatic 4, Bear 5, Cat 1, Flight 29, Moonkin 31, Swift Flight 27, Travel 3, Tree 2
if form == 5 then
return "TANK"
elseif GetSpecialization() == 4 then -- Balance 1, Feral 2, Guardian 3, Restoration 4
return "HEAL"
end
end
elseif playerClass == "MONK" then
updateEvents = "UPDATE_SHAPESHIFT_FORM"
getRole = function()
local form = GetShapeshiftFormID() -- Tiger 24, Ox 23, Serpent 20
if form == 23 then
return "TANK"
elseif form == 20 then
return "HEAL"
end
end
elseif playerClass == "PALADIN" then
local RIGHTEOUS_FURY = GetSpellInfo(25780)
updateEvents = "PLAYER_REGEN_DISABLED"
getRole = function()
if UnitAura("player", RIGHTEOUS_FURY, "HELPFUL") then
return "TANK"
elseif GetSpecialization() == 1 then -- Holy 1, Protection 2, Retribution 3
return "HEAL"
end
end
elseif playerClass == "PRIEST" then
getRole = function()
if GetSpecialization() ~= 3 then -- Discipline 1, Holy 2, Shadow 3
return "HEAL"
end
end
elseif playerClass == "SHAMAN" then
getRole = function()
if GetSpecialization() == 3 then -- Elemental 1, Enhancement 2, Restoration 3
return "HEAL"
end
end
elseif playerClass == "WARRIOR" then
updateEvents = "UPDATE_SHAPESHIFT_FORM"
getRole = function()
if GetSpecialization() == 3 and GetShapeshiftFormID() == 18 then -- Battle 17, Berserker 19, Defensive 18
return "TANK"
end
end
end
if getRole then
local eventFrame = CreateFrame("Frame")
eventFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
eventFrame:RegisterEvent("PLAYER_TALENT_UPDATE")
if updateEvents then
for event in gmatch(updateEvents, "%S+") do
eventFrame:RegisterEvent(event)
end
end
--[[
-- This layout doesn't have elements which update magically
-- on a spec change...yet.
eventFrame:SetScript("OnEvent", function(_, event, ...)
local role = getRole() or "DPS"
if role ~= CURRENT_ROLE then
CURRENT_ROLE = role
for _, frame in pairs(ns.objects) do
if frame.updateOnRoleChange then
ns.UpdatePlayerRole(frame, CURRENT_ROLE)
end
end
end
end)
--]]
end
lib.GetPlayerRole = function() return CURRENT_ROLE end