forked from ollidiemaus/AutoPotion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.lua
executable file
·174 lines (156 loc) · 4.81 KB
/
code.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
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
163
164
165
166
167
168
169
170
171
172
173
174
local addonName, ham = ...
local macroName = "AutoPotion"
local isClassic = (WOW_PROJECT_ID == WOW_PROJECT_CLASSIC)
local isWrath = (WOW_PROJECT_ID == WOW_PROJECT_WRATH_CLASSIC)
local isCata = (WOW_PROJECT_ID == WOW_PROJECT_CATACLYSM_CLASSIC)
local isRetail = (WOW_PROJECT_ID == WOW_PROJECT_MAINLINE)
ham.myPlayer = ham.Player.new()
local spellsMacroString = ''
local itemsMacroString = ''
local macroStr = ''
local resetType = "combat"
local shortestCD = nil
local function addPlayerHealingItemIfAvailable()
for i, value in ipairs(ham.myPlayer.getHealingItems()) do
if value.getCount() > 0 then
table.insert(ham.itemIdList, value.getId())
break;
end
end
end
local function addHealthstoneIfAvailable()
if isClassic == true or isWrath == true then
for i, value in ipairs(ham.getHealthstonesClassic()) do
if value.getCount() > 0 then
table.insert(ham.itemIdList, value.getId())
--we break because all Healthstones share a cd so we only want the highest healing one
break;
end
end
else
if ham.healthstone.getCount() > 0 then
table.insert(ham.itemIdList, ham.healthstone.getId())
end
end
end
local function addPotIfAvailable()
for i, value in ipairs(ham.getPots()) do
if value.getCount() > 0 then
table.insert(ham.itemIdList, value.getId())
-- if healthstone does not has priority, remember healing potion's CD
if isRetail and HAMDB.raidStone and IsInRaid() and IsInInstance() then
shortestCD = 300 --potion CD
end
--we break because all Pots share a cd so we only want the highest healing one
break;
end
end
end
function ham.updateHeals()
ham.itemIdList = {}
ham.spellIDs = ham.myPlayer.getHealingSpells()
addPlayerHealingItemIfAvailable()
-- lower the priority of healthstones in a raid environment if selected
if HAMDB.raidStone and IsInRaid() and IsInInstance() then
addPotIfAvailable()
addHealthstoneIfAvailable()
else
addHealthstoneIfAvailable()
addPotIfAvailable()
end
end
local function createMacroIfMissing()
local name = GetMacroInfo(macroName)
if name == nil then
CreateMacro(macroName, "INV_Misc_QuestionMark")
end
end
local function buildSpellMacroString()
spellsMacroString = ''
if next(ham.spellIDs) ~= nil then
for i, spell in ipairs(ham.spellIDs) do
local name, rank, icon, castTime, minRange, maxRange = GetSpellInfo(spell)
if HAMDB.cdReset then
local cooldownMS, gcdMS = GetSpellBaseCooldown(spell)
local cd = cooldownMS / 1000
if shortestCD == nil then
shortestCD = cd
end
if cd < shortestCD then
shortestCD = cd
end
end
--TODO HEALING Elixir Twice because it has two charges ?! kinda janky but will work for now
if spell == ham.healingElixir then
name = name .. ", " .. name
end
if i == 1 then
spellsMacroString = name;
else
spellsMacroString = spellsMacroString .. ", " .. name;
end
end
end
--add if ham.cdReset == true then combat/spelltime
if HAMDB.cdReset and shortestCD ~= nil then
resetType = "combat/" .. shortestCD
end
end
local function buildItemMacroString()
if next(ham.itemIdList) ~= nil then
for i, v in ipairs(ham.itemIdList) do
if i == 1 then
itemsMacroString = "item:" .. v;
else
itemsMacroString = itemsMacroString .. ", " .. "item:" .. v;
end
end
end
end
function ham.updateMacro()
if next(ham.itemIdList) == nil and next(ham.spellIDs) == nil then
macroStr = "#showtooltip"
else
resetType = "combat"
buildItemMacroString()
buildSpellMacroString()
macroStr = "#showtooltip \n/castsequence reset=" .. resetType .. " "
if spellsMacroString ~= "" then
macroStr = macroStr .. spellsMacroString
end
if spellsMacroString ~= "" and itemsMacroString ~= "" then
macroStr = macroStr .. ", "
end
if itemsMacroString ~= "" then
macroStr = macroStr .. itemsMacroString
end
end
createMacroIfMissing()
EditMacro(macroName, macroName, nil, macroStr)
end
local onCombat = true
local updateFrame = CreateFrame("Frame")
updateFrame:RegisterEvent("BAG_UPDATE")
updateFrame:RegisterEvent("PLAYER_LOGIN")
updateFrame:RegisterEvent("PLAYER_ENTERING_WORLD") -- Initial login and UI reload
if isClassic == false then
updateFrame:RegisterEvent("TRAIT_CONFIG_UPDATED")
end
updateFrame:RegisterEvent("PLAYER_REGEN_ENABLED")
updateFrame:RegisterEvent("PLAYER_REGEN_DISABLED")
updateFrame:SetScript("OnEvent", function(self, event, ...)
if event == "PLAYER_LOGIN" then
onCombat = false
end
if event == "PLAYER_REGEN_DISABLED" then
onCombat = true
return
end
if event == "PLAYER_REGEN_ENABLED" then
onCombat = false
end
if onCombat == false then
ham.updateHeals()
ham.updateMacro()
end
end)