local ShroomHelper = {};
function ShroomHelper_OnLoad(self)
self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED");
self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED");
self:RegisterEvent("PLAYER_ENTERING_WORLD");
self:RegisterEvent("PLAYER_TOTEM_UPDATE");
self:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED");
self:SetScript("OnEvent",function(self, event, ...)ShroomHelper[event](self, ...)end);
ShroomHelper["CurrentOverheal"] = 0;
ShroomHelper["MaxOverheal"] = 0;
ShroomHelper["BloomPercent"] = 0;
ShroomHelper["CurrentNumShrooms"] = 0;
ShroomHelper["ShortestTime"] = 300;
ShroomHelper["trackingTime"] = false;
ShroomHelper_MainText:SetText("0%");
ShroomHelper["AreShroomsDown"] = false;
--ShroomHelper:Reset(self);
if ( ShroomHelper_Settings == nil ) then
ShroomHelper_Settings = {};
end
end
function ShroomHelper:COMBAT_LOG_EVENT_UNFILTERED(timestamp, event, hideCaster, sourceGUID, sourceName, sourceFlags, sourceFlags2, destGUID, destName, destFlags, destFlags2, ...)
if ( sourceGUID == ShroomHelper.GUID ) then
if ( event == "SPELL_PERIODIC_HEAL" ) then
local spellID, spellName, spellSchool, amount, overhealing, absorbed, critical = select(1, ...);
if ( spellID == 774 and ShroomHelper.AreShroomsDown) then -- Rejuvenation
if ( ShroomHelper.CurrentOverheal < ShroomHelper.MaxOverheal ) then
ShroomHelper.CurrentOverheal = ShroomHelper.CurrentOverheal + overhealing;
if ( ShroomHelper.CurrentOverheal >= ShroomHelper.MaxOverheal ) then
ShroomHelper.CurrentOverheal = ShroomHelper.MaxOverheal;
ActionButton_ShowOverlayGlow(_G[self:GetName().."Button2"]);
end
ShroomHelper.BloomPercent = (ShroomHelper.CurrentOverheal / ShroomHelper.MaxOverheal) * 100;
ShroomHelper:UpdatePercentage(ShroomHelper.BloomPercent);
--print("Current Overhealing: "..ShroomHelper.CurrentOverhealing);
end
end
end
end
end
function ShroomHelper:UNIT_SPELLCAST_SUCCEEDED(unitID, spellName, spellRank, lineID, spellID)
if ( unitID == "player" ) then
if ( spellID == 145205 ) then -- Wild Mushroom
ShroomHelper.MaxOverheal = UnitHealthMax("player") * 2;
ShroomHelper:AddShroom(self);
--ShroomHelper:ResetOverheal();
--ActionButton_HideOverlayGlow(_G[self:GetName().."Button2"]);
elseif ( spellID == 102791) then --Wild Mushroom: Bloom
ShroomHelper:Reset(self);
end
end
end
function ShroomHelper:PLAYER_ENTERING_WORLD()
ShroomHelper["GUID"] = UnitGUID("player");
SLASH_SHROOMHELPER1 = "/sh";
SlashCmdList["SHROOMHELPER"] = function(message, editbox) ShroomHelper:SlashCmd(message, editbox) end;
_G[self:GetName().."Button1ShroomCount"]:SetText(ShroomHelper.CurrentNumShrooms);
if ( ShroomHelper_Settings.IsLocked ) then
self:RegisterForDrag();
else
self:RegisterForDrag("LeftButton");
end
ShroomHelper:ChangeScale(ShroomHelper_Settings.FrameScale);
if ( ShroomHelper:HasBloom() ) then
ShroomHelper_Main:Show();
else
ShroomHelper:Reset(ShroomHelper_Main);
ShroomHelper_Main:Hide();
end
end
function ShroomHelper:PLAYER_TOTEM_UPDATE(shroomID)
ShroomHelper.ShortestTime = ShroomHelper:GetShortestTime();
if ( ShroomHelper.ShortestTime > 0 ) then
ShroomHelper.trackingTime = true;
ShroomHelper:SetTimer(ShroomHelper.ShortestTime)
--print(ShroomHelper.ShortestTime);
else
ShroomHelper:Reset(ShroomHelper_Main);
end
end
function ShroomHelper:ACTIVE_TALENT_GROUP_CHANGED(talentIndex)
if ( ShroomHelper:HasBloom() ) then
ShroomHelper_Main:Show();
else
ShroomHelper:Reset(ShroomHelper_Main);
ShroomHelper_Main:Hide();
end
end
function ShroomHelperButton_OnEvent(self, event, ...)
local cooldown = _G[self:GetName().."Cooldown"];
local start, duration, enabled = GetSpellCooldown(self.spellID);
cooldown:SetCooldown(start,duration);
end
function ShroomHelper:UpdatePercentage(percentage)
ShroomHelper_MainText:SetText(math.floor(percentage) .. "%");
end
function ShroomHelper:SlashCmd(message, editBox)
local command, rest = message:match("^(%S*)%s*(.-)$");
if ( command == "lock") then
if ( ShroomHelper_Settings.IsLocked ) then
ShroomHelper_Main:RegisterForDrag("LeftButton");
print("ShroomHelper: Frame unlocked.");
ShroomHelper_Settings.IsLocked = false;
else
ShroomHelper_Main:RegisterForDrag();
print("ShroomHelper: Frame locked.");
ShroomHelper_Settings.IsLocked = true;
end
elseif ( command == "scale" and tonumber(rest) > 0 ) then
ShroomHelper:ChangeScale(rest);
print("ShroomHelper: Setting frame scale to ["..rest.."].");
end
end
function ShroomHelper:Reset(self)
ShroomHelper.AreShroomsDown = false;
ShroomHelper.CurrentNumShrooms = 0;
ShroomHelper:ResetOverheal();
ShroomHelper.trackingTime = false;
ShroomHelper_MainTimerCounter:Hide();
_G[self:GetName().."Button1ShroomCount"]:SetText(ShroomHelper.CurrentNumShrooms);
ActionButton_HideOverlayGlow(_G[self:GetName().."Button2"]);
end
function ShroomHelper:ResetOverheal()
ShroomHelper_MainText:SetText("0%");
ShroomHelper.CurrentOverheal = 0;
end
function ShroomHelper:GetShortestTime()
local times={};
local short = 0;
for index=1,3 do
local currentTime = GetTotemTimeLeft(index);
if ( currentTime ~= 0 ) then
times[index-1] = currentTime;
else
times[index-1] = 300;
end
end
if ( times[0] < times[1] and times[0] < times[2] ) then
short = times[0];
elseif ( times[1] < times[0] and times[1] < times[2] ) then
short = times[1];
else
short = times[2];
end
return short;
end
function ShroomHelper:SetTimer(setTime)
ShroomHelper_MainTimerCounter:SetWidth((setTime/300) * 135);
end
function ShroomHelper_TimerUpdate(self, elapsed)
if ( ShroomHelper.AreShroomsDown and ShroomHelper.trackingTime ) then
if ( elapsed <= ShroomHelper.ShortestTime ) then
ShroomHelper.ShortestTime = ShroomHelper.ShortestTime - elapsed
ShroomHelper:SetTimer(ShroomHelper.ShortestTime);
else
ShroomHelper:SetTimer(0);
ShroomHelper:MinusShroom(ShroomHelper_MainButton1ShroomCount);
ShroomHelper.trackingTime = false;
end
end
end
function ShroomHelper:AddShroom()
ShroomHelper.AreShroomsDown = true;
ShroomHelper.trackingTime = true;
if ( ShroomHelper.CurrentNumShrooms == 0 ) then
ShroomHelper.CurrentNumShrooms = 1; --ShroomHelper.CurrentNumShrooms + 1;
end
ShroomHelper_MainButton1ShroomCount:SetText(ShroomHelper.CurrentNumShrooms);
ShroomHelper_MainTimerCounter:Show();
--DEFAULT_CHAT_FRAME:AddMessage("Current: " .. ShroomHelper.CurrentNumShrooms);
--DEFAULT_CHAT_FRAME:AddMessage(ShroomHelper_MainButton1ShroomCount:GetText())
end
function ShroomHelper:MinusShroom(frame)
if ( ShroomHelper.CurrentNumShrooms > 0 ) then
ShroomHelper.CurrentNumShrooms = ShroomHelper.CurrentNumShrooms - 1;
if ( ShroomHelper.CurrentNumShrooms == 0 ) then
ShroomHelper:Reset(ShroomHelper_Main);
end
end
ShroomHelper_MainButton1ShroomCount:SetText(ShroomHelper.CurrentNumShrooms);
end
function ShroomHelper:ChangeScale(scale)
ShroomHelper_Settings.FrameScale = scale or 1;
ShroomHelper_Main:SetScale(ShroomHelper_Settings.FrameScale);
end
function ShroomHelper:HasBloom()
local spellName = GetSpellInfo(145205)
local _, spellId = GetSpellBookItemInfo(spellName);
if ( spellId ) then
return true;
end
return false;
end