Skip to content

Commit

Permalink
Merge pull request #1 from Diclah/master
Browse files Browse the repository at this point in the history
Use cast sequence if possible.
  • Loading branch information
ollidiemaus authored Apr 24, 2019
2 parents 6827763 + e709c36 commit da0741f
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 8 deletions.
2 changes: 1 addition & 1 deletion HealthstoneAutoMacro.toc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Interface: 80100
## Version: 0.1.0-alpha
## Version: 0.3.0-alpha
## Title: Healthstone Auto Macro
## Author: ollidiemaus
## Notes: Updates the Macro HAMHealthPot to use either Healthstone or Coastal Healing Potion
Expand Down
93 changes: 86 additions & 7 deletions code.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,93 @@
-- This file is loaded from "HealthstoneAutoMacro.toc"

-- #showtooltip
-- /castsequence reset=combat Healthstone, Coastal Healing Potion
do

local HealPotMacroIcon = CreateFrame("Frame")
HealPotMacroIcon:RegisterEvent("BAG_UPDATE")
HealPotMacroIcon:RegisterEvent("PLAYER_LOGIN")
local HSId = 5512;
local SilasPotId = 156634;
local NormalPotId = 152494;
local EmeraldId = 166799; -- Emerald of Vigor

function getPotNames()
SilasPotName = GetItemInfo(SilasPotId);
NormalPotName = GetItemInfo(NormalPotId);
EmeraldName = GetItemInfo(EmeraldId);

-- fall back on connect sometimes GetItem fail
if SilasPotName==nil then
SilasPotName = "Silas' Vial of Continuous Curing"
end
if NormalPotName==nil then
NormalPotName = "Coastal Healing Potion"
end
if EmeraldName==nil then
EmeraldName = "Emerald of Vigor"
end
return SilasPotName, NormalPotName, EmeraldName
end

function getPots()
SilasPotName, NormalPotName, EmeraldName = getPotNames()
SilasNbr = GetItemCount(SilasPotId, false, false);
return {
{SilasPotName, SilasNbr},
{EmeraldName, GetItemCount(EmeraldId, false, false)},
{NormalPotName, GetItemCount(NormalPotId, false, false)}
}
end
function getHs()
HSName = GetItemInfo(HSId);
if HSName==nil then
HSName = "Healthstone"
end
return HSName, GetItemCount(HSId, false, false);
end

local onCombat = true;
local HealPotMacroIcon = CreateFrame("Frame");
HealPotMacroIcon:RegisterEvent("BAG_UPDATE");
HealPotMacroIcon:RegisterEvent("PLAYER_LOGIN");
HealPotMacroIcon:RegisterEvent("PLAYER_REGEN_ENABLED");
HealPotMacroIcon:RegisterEvent("PLAYER_REGEN_DISABLED");
HealPotMacroIcon:SetScript("OnEvent",function(self,event,...)
pot = GetItemCount("Healthstone")==0 and "Coastal Healing Potion" or "Healthstone"
item = GetItemCount("Silas' Vial of Continuous Curing")==0 and pot or "Silas' Vial of Continuous Curing"
EditMacro("HAMHealthPot", "HAMHealthPot", nil, "#showtooltip \n/use " .. item, 1, nil)
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
local Pot = getPots()
local HsName, HsNbr = getHs()
local macroStr, potName, found;

found = false;
for i,v in ipairs(Pot) do
if v[2] > 0 then
found = true;
potName = v[1]
break;
end
end

if HsNbr > 0 then
if found==true then
macroStr = "#showtooltip \n/castsequence reset=combat " .. HSName .. ", " .. potName;
else
macroStr = "#showtooltip \n/use " .. HSName;
end
elseif found==true then
macroStr = "#showtooltip \n/use " .. potName;
else
macroStr = "#showtooltip"
end
EditMacro("HAMHealthPot", "HAMHealthPot", nil, macroStr, 1, nil)
end
end)

end

0 comments on commit da0741f

Please sign in to comment.