-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathClassUtil.lua
More file actions
144 lines (130 loc) · 6.43 KB
/
ClassUtil.lua
File metadata and controls
144 lines (130 loc) · 6.43 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
-- Enhanced Cooldown Manager addon for World of Warcraft
-- Author: Argium
-- Licensed under the GNU General Public License v3.0
local _, ns = ...
local C = ns.Constants
local ClassUtil = {}
ns.ClassUtil = ClassUtil
--- Gets the resource type for the class, spec and current shapeshift form (if applicable).
--- @return string|number|nil resourceType - returns a string for special tracked resources (souls, devourer normal/meta, maelstrom weapon), or a power type enum value for standard resources. Returns nil if no relevant resource type is found for the player's class/spec.
function ClassUtil.GetResourceType(class, specIndex, shapeshiftForm)
if class == "DEMONHUNTER" then
if specIndex == C.DEMONHUNTER_DEVOURER_SPEC_INDEX then
local voidMeta = C_UnitAuras.GetPlayerAuraBySpellID(C.SPELLID_VOID_META)
local collapsingStar = C_UnitAuras.GetPlayerAuraBySpellID(C.SPELLID_COLLAPSING_STAR)
if voidMeta or collapsingStar then
return C.RESOURCEBAR_TYPE_DEVOURER_META
else
return C.RESOURCEBAR_TYPE_DEVOURER_NORMAL
end
elseif specIndex == C.DEMONHUNTER_VENGEANCE_SPEC_INDEX then
return C.RESOURCEBAR_TYPE_VENGEANCE_SOULS
end
elseif class == "MAGE" then
if specIndex == C.MAGE_ARCANE_SPEC_INDEX then
return Enum.PowerType.ArcaneCharges
end
if specIndex == C.MAGE_FROST_SPEC_INDEX then
return C.RESOURCEBAR_TYPE_ICICLES
end
elseif class == "SHAMAN" then
-- Enhancement tracks Maelstrom Weapon stacks (aura-based), not Elemental's Maelstrom power type.
if specIndex == C.SHAMAN_ENHANCEMENT_SPEC_INDEX then
return C.RESOURCEBAR_TYPE_MAELSTROM_WEAPON
end
elseif class == "MONK" then
if specIndex == C.MONK_WINDWALKER_SPEC_INDEX then
return Enum.PowerType.Chi
end
else
if class == "EVOKER" then
return Enum.PowerType.Essence
elseif class == "PALADIN" then
return Enum.PowerType.HolyPower
elseif class == "ROGUE" then
return Enum.PowerType.ComboPoints
elseif class == "WARLOCK" then
return Enum.PowerType.SoulShards
elseif class == "DRUID" then
if shapeshiftForm == C.DRUID_CAT_FORM_INDEX then
return Enum.PowerType.ComboPoints
end
end
end
end
--- Gets the resource type for the player given their class, spec and current shapeshift form (if applicable).
--- @return string|number|nil resourceType - returns a string for special tracked resources (souls, devourer normal/meta, maelstrom weapon), or a power type enum value for standard resources. Returns nil if no relevant resource type is found for the player's class/spec.
function ClassUtil.GetPlayerResourceType()
local _, class = UnitClass("player")
return ClassUtil.GetResourceType(class, GetSpecialization(), GetShapeshiftForm())
end
--- Gets the max Maelstrom value that can diff based on talents
local function getMaelstromWeaponMax()
if C_SpellBook.IsSpellKnown(C.RESOURCEBAR_RAGING_MAELSTROM_SPELLID) then
return C.RESOURCEBAR_MAELSTROM_WEAPON_MAX_TALENTED
end
return C.RESOURCEBAR_MAELSTROM_WEAPON_MAX_BASE
end
-- Gets the max devourer soul fragments needed for void meta form based on talents
local function getDevourerSoulFragmentsMax()
if C_SpellBook.IsSpellKnown(C.SPELLID_SOUL_GLUTTEN) then
return C.RESOURCEBAR_DEVOURER_SOUL_FRAGMENTS_MAX - 15
end
return C.RESOURCEBAR_DEVOURER_SOUL_FRAGMENTS_MAX
end
local function getDevourerSoulFragmentsAura()
local aura = C_UnitAuras.GetPlayerAuraBySpellID(C.SPELLID_DEVOURER_SOUL_FRAGMENTS)
if aura ~= nil then
return aura
end
return C_UnitAuras.GetPlayerAuraBySpellID(C.SPELLID_DEVOURER_SOUL_FRAGMENTS_ALT)
end
--- Returns max, current, and a safe discrete count for the given resource type.
--- The 3rd return (safeMax) is always a non-secret number suitable for comparison
--- and arithmetic (e.g., tick layout). For special resource types, max and safeMax
--- are identical constants. For standard power types, max may be secret while
--- safeMax will be nil when the value is tainted.
---@param resourceType string|number|nil
---@return number|nil max
---@return number|nil current
---@return number|nil safeMax Non-secret discrete count for tick layout
function ClassUtil.GetCurrentMaxResourceValues(resourceType)
-- Demon hunter souls can still be tracked by their aura stacks (thank the lord)
if resourceType == C.RESOURCEBAR_TYPE_VENGEANCE_SOULS then
-- Vengeance use the same type of soul fragments. The value can be tracked by checking
-- the number of times spirit bomb can be cast, of all things.
local count = C_Spell.GetSpellCastCount(C.RESOURCEBAR_SPIRIT_BOMB_SPELLID) or 0
return C.RESOURCEBAR_VENGEANCE_SOULS_MAX, count, C.RESOURCEBAR_VENGEANCE_SOULS_MAX
end
if resourceType == C.RESOURCEBAR_TYPE_ICICLES then
local aura = C_UnitAuras.GetPlayerAuraBySpellID(C.RESOURCEBAR_ICICLES_SPELLID)
return C.RESOURCEBAR_ICICLES_MAX, aura and aura.applications or 0, C.RESOURCEBAR_ICICLES_MAX
end
if resourceType == C.RESOURCEBAR_TYPE_DEVOURER_META then
local collapsingStar = C_UnitAuras.GetPlayerAuraBySpellID(C.SPELLID_COLLAPSING_STAR)
local max = C.RESOURCEBAR_COLLAPSING_STAR_MAX / 5
return max, collapsingStar and collapsingStar.applications / 5 or 0, max
end
if resourceType == C.RESOURCEBAR_TYPE_DEVOURER_NORMAL then
local soulFragments = getDevourerSoulFragmentsAura()
local max = getDevourerSoulFragmentsMax() / 5
return max, soulFragments and soulFragments.applications / 5 or 0, max
end
if resourceType == C.RESOURCEBAR_TYPE_MAELSTROM_WEAPON then
-- The max can be 5 or 10 depending on talent choices
local aura = C_UnitAuras.GetPlayerAuraBySpellID(C.SPELLID_MAELSTROM_WEAPON)
local stacks = aura and aura.applications or 0
local mwMax = getMaelstromWeaponMax()
return mwMax, stacks, mwMax
end
ns.DebugAssert(type(resourceType) == "number", "Expected resourceType to be a power type enum value")
if resourceType then
local max = UnitPowerMax("player", resourceType)
local current = UnitPower("player", resourceType)
local safeMax = max
if issecretvalue(max) then
safeMax = nil
end
return max, current, safeMax
end
end