-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAutoConsumableMacros.lua
156 lines (124 loc) · 4.71 KB
/
AutoConsumableMacros.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
local sscConsumables = {
["hp"] = 32904, -- Cenarion Healing Salve
["mana"] = 32903 -- Cenarion Mana Salve
};
local tkConsumables = {
["hp"] = 32905, -- Super Healing Potion
["mana"] = 32902 -- Super Mana Potion
};
local defaultConsumables = {
["hp"] = 22829, -- Super Healing Potion
["mana"] = 22832 -- Super Mana Potion
}
local consumablesByZone = {
["Blade's Edge Mountains"] = {
["hp"] = 32910, -- Red Ogre Brew Special
["mana"] = 32909 -- Blue Ogre Brew Special
},
["Serpentshrine Cavern"] = sscConsumables,
["The Slave Pens"] = sscConsumables,
["The Underbog"] = sscConsumables,
["The Steamvault"] = sscConsumables,
["Tempest Keep"] = tkConsumables,
["The Botanica"] = tkConsumables,
["The Mechanar"] = tkConsumables,
["The Arcatraz"] = tkConsumables,
["default"] = defaultConsumables
};
local function InitMacros()
if (GetMacroBody("AutoConsHP") == nil) then
CreateMacro("AutoConsHP", "INV_MISC_QUESTIONMARK", "")
end
if (GetMacroBody("AutoConsMana") == nil) then
CreateMacro("AutoConsMana", "INV_MISC_QUESTIONMARK", "")
end
if (GetMacroBody("AutoConsHS") == nil) then
CreateMacro("AutoConsHS", "INV_MISC_QUESTIONMARK", "")
end
if (GetMacroBody("AutoConsFood") == nil) then
CreateMacro("AutoConsFood", "INV_MISC_QUESTIONMARK", "")
end
if (GetMacroBody("AutoConsWater") == nil) then
CreateMacro("AutoConsWater", "INV_MISC_QUESTIONMARK", "")
end
if (GetMacroBody("AutoConsSpellPowerFood") == nil) then
CreateMacro("AutoConsSpellPowerFood", "INV_MISC_QUESTIONMARK", "")
end
end
local function UpdatePotionMacros(zone)
local consumablesForZone = consumablesByZone[zone] or consumablesByZone["default"]
local hpCount = GetItemCount(consumablesForZone["hp"])
local manaCount = GetItemCount(consumablesForZone["mana"])
local hpId = hpCount > 0 and consumablesForZone["hp"] or defaultConsumables["hp"]
local manaId = manaCount > 0 and consumablesForZone["mana"] or defaultConsumables["mana"]
EditMacro("AutoConsHP", nil, nil, "#showtooltip\n/cast item:" .. hpId)
EditMacro("AutoConsMana", nil, nil, "#showtooltip\n/cast item:" .. manaId)
end
local largeHsId = 22105
local mediumHsId = 22104
local smallHsId = 22103
local function UpdateHealthstoneMacro()
local largeCount = GetItemCount(largeHsId)
local mediumCount = GetItemCount(mediumHsId)
local hsId = largeCount > 0 and largeHsId or mediumCount > 0 and mediumHsId or smallHsId
EditMacro("AutoConsHS", nil, nil, "#showtooltip item:" .. hsId .. "\n/cast item:" .. largeHsId .. "\n/cast item:" .. mediumHsId .. "\n/cast item:" .. smallHsId)
end
local function UpdateFoodMacros()
local conjuredCount = GetItemCount(34062)
local foodId = conjuredCount > 0 and 34062 or 29448
local waterId = conjuredCount > 0 and 34062 or 27860
EditMacro("AutoConsFood", nil, nil, "#showtooltip\n/cast item:" .. foodId)
EditMacro("AutoConsWater", nil, nil, "#showtooltip\n/cast item:" .. waterId)
end
local buffFoods = {
{
id = 27657, -- blackened basilisk
count = 0
},
{
id = 31673, -- crunchy serpent
count = 0
},
{
id = 27665, -- poached bluefish
count = 0
}
}
local function UpdateBuffFoodMacro()
for i,v in ipairs(buffFoods) do
buffFoods[i]["count"] = GetItemCount(buffFoods[i]["id"])
end
table.sort(buffFoods, function(a, b)
return a["count"] < b["count"]
end)
local foodId = buffFoods[1]["id"]
for i,v in ipairs(buffFoods) do
if (buffFoods[i]["count"] > 0) then
foodId = buffFoods[i]["id"]
break;
end
end
EditMacro("AutoConsSpellPowerFood", nil, nil, "#showtooltip\n/cast item:" .. foodId)
end
AutoConsumableMacros = AutoConsumableMacros or {}
AutoConsumableMacros.frame = CreateFrame("Frame", "AutoConsumableMacros", UIParent)
AutoConsumableMacros.frame:SetFrameStrata("BACKGROUND")
AutoConsumableMacros.frame:RegisterEvent("PLAYER_LOGIN")
AutoConsumableMacros.frame:RegisterEvent("ZONE_CHANGED_NEW_AREA")
AutoConsumableMacros.frame:RegisterEvent("UNIT_INVENTORY_CHANGED")
AutoConsumableMacros.frame:SetScript("OnEvent", function(self, event, ...)
if (event == "PLAYER_LOGIN") then
InitMacros()
end
if (event == "PLAYER_LOGIN" or event == "ZONE_CHANGED_NEW_AREA" or event == "UNIT_INVENTORY_CHANGED") then
local zone = GetZoneText()
UpdatePotionMacros(zone)
UpdateFoodMacros()
end
if (event == "PLAYER_LOGIN" or event == "UNIT_INVENTORY_CHANGED") then
UpdateHealthstoneMacro()
UpdateFoodMacros()
UpdateBuffFoodMacro()
end
end)
print("AutoConsumableMacros loaded")