local Bloodboil = DBM:NewBossMod("Bloodboil", DBM_BLOODBOIL_NAME, DBM_BLOODBOIL_DESCRIPTION, DBM_BLACK_TEMPLE, DBM_BT_TAB, 5);

Bloodboil.Version	= "1.0";
Bloodboil.Author	= "Tandanu";

local boilCounter = 0;

Bloodboil:RegisterCombat("YELL", DBM_BLOODBOIL_YELL_PULL);

Bloodboil:RegisterEvents(
	"SPELL_AURA_APPLIED",
	"SPELL_AURA_REMOVED"
);

Bloodboil:AddOption("WarnSmash", false, DBM_BLOODBOIL_OPTION_SMASH);

Bloodboil:AddBarOption("Enrage")
Bloodboil:AddBarOption("Bloodboil")
Bloodboil:AddBarOption("Fel Rage")
Bloodboil:AddBarOption("Normal Phase")
Bloodboil:AddBarOption("Arcing Smash")


function Bloodboil:OnCombatStart(delay)
	boilCounter = 0;
	self:StartStatusBarTimer(480, "Enrage", "Interface\\Icons\\Spell_Shadow_UnholyFrenzy");
	self:StartStatusBarTimer(60, "Fel Rage", "Interface\\Icons\\Spell_Fire_ElementalDevastation");
	self:ScheduleSelf(55, "FelRageWarn");
	self:StartStatusBarTimer(11, "First Bloodboil", "Interface\\Icons\\Spell_Shadow_BloodBoil");
	self:ScheduleSelf(11, "BloodboilWarn");
end


function Bloodboil:OnEvent(event, arg1)
	if event == "SPELL_AURA_APPLIED" then
		if arg1.spellId == 40604 then
			self:SendSync("FelRage"..tostring(arg1.destName));
		elseif arg1.spellId == 40599 then
			self:SendSync("ArcingSmash"..tostring(arg1.destName));
		end
	elseif event == "SPELL_AURA_REMOVED" then
		if arg1.spellId == 40594 then
			boilCounter = 0;
			self:StartStatusBarTimer(11, "First Bloodboil", "Interface\\Icons\\Spell_Shadow_BloodBoil");
			self:ScheduleSelf(11, "BloodboilWarn");
			self:Announce(DBM_BLOODBOIL_WARN_NORMALPHASE, 3)
			self:ScheduleSelf(55, "FelRageWarn");
			self:StartStatusBarTimer(60, "Fel Rage", "Interface\\Icons\\Spell_Fire_ElementalDevastation");
		end
	elseif event == "FelRageWarn" then
		self:Announce(DBM_BLOODBOIL_WARN_FELRAGE_SOON, 2);
	elseif event == "NormalWarn" then
		self:Announce(DBM_BLOODBOIL_WARN_NORMAL_SOON, 2);
	elseif event == "SmashWarn" then
		self:Announce(DBM_BLOODBOIL_WARN_SMASH_SOON, 2);
	elseif event == "BloodboilWarn" then
		self:SendSync("Bloodboil");
	end
end

function Bloodboil:OnSync(msg)
	if msg == "Bloodboil" then
		boilCounter = boilCounter + 1;
		if boilCounter > 0 then
			self:Announce(DBM_BLOODBOIL_WARN_BLOODBOIL:format(boilCounter), 1);
		end
		if boilCounter < 5 then
			self:ScheduleSelf(10, "BloodboilWarn");
			self:StartStatusBarTimer(10, "Next Bloodboil", "Interface\\Icons\\Spell_Shadow_BloodBoil");
		end	
	elseif msg:sub(0, 7) == "FelRage" then
		msg = msg:sub(8);
		self:StartStatusBarTimer(28, "Normal Phase", "Interface\\Icons\\Spell_Nature_WispSplode");
		self:ScheduleSelf(23, "NormalWarn");
		self:Announce(DBM_BLOODBOIL_WARN_FELRAGE:format(msg), 4);
	elseif msg:sub(0, 11) == "ArcingSmash" then
		msg = msg:sub(12);
		self:StartStatusBarTimer(4, "Arcing Smash", "Interface\\Icons\\Ability_Warrior_Cleave");
		if self.Options.WarnSmash then
			self:ScheduleSelf(3, "SmashWarn");		
			self:Announce(DBM_BLOODBOIL_WARN_SMASH, 4);
		end
	end
end