--
--  La Vendetta BossMod for Patchwerk v1.2
--
--  v1.0 Based on Tandanus Enraged Timer
--  v1.1 Modivied version with HFS Announce
--  v1.2 Modivied version by Nitram with InfoFrame Support for HFS
--

LVBM.AddOns.Patchwerk = {
	["Name"] = LVBM_PW_NAME,
	["Abbreviation1"] = "pw",
	["Version"] = "1.2",
	["Author"] = "La Vendetta|Nitram",
	["Description"] = LVBM_PW_DESCRIPTION,
	["Instance"] = LVBM_NAXX,
	["GUITab"] = LVBMGUI_TAB_NAXX,
	["Sort"] = 41,
	["Options"] = {
		["Enabled"] = true,
		["Announce"] = false,
		["HatefulStrike"] = true,
--		["InfoFrame"] = false,
	},
	["DropdownMenu"] = {
		[1] = {
			["variable"] = "LVBM.AddOns.Patchwerk.Options.HatefulStrike",
			["text"] = LVBM_PW_OPTION1,
			["func"] = function() LVBM.AddOns.Patchwerk.Options.HatefulStrike = not LVBM.AddOns.Patchwerk.Options.HatefulStrike; end,
		},
--[[	[2] = {
			["variable"] = "LVBM.AddOns.Patchwerk.Options.InfoFrame",
			["text"] = LVBM_PW_OPTION2.."(funktioniert nicht)",
			["func"] = function() 
				LVBM.AddOns.Patchwerk.Options.InfoFrame = not LVBM.AddOns.Patchwerk.Options.InfoFrame; 
				if( not LVBM.AddOns.Patchwerk.Options.InfoFrame ) then
					LVBMGui.InfoFrameHide("Patchwerk")
				end
			end,
		},]]
	},
	["Events"] = {
		["CHAT_MSG_MONSTER_YELL"] = true,
		["CHAT_MSG_SPELL_CREATURE_VS_SELF_DAMAGE"] = true,
		["CHAT_MSG_SPELL_CREATURE_VS_CREATURE_DAMAGE"] = true,
		["CHAT_MSG_SPELL_CREATURE_VS_PARTY_DAMAGE"] = true,
	},
--[[["ShowInfoFrame"] = function(mshow)			-- LVBM.AddOns.Patchwerk.ShowInfoFrame(true);
		if( LVBM.AddOns.Patchwerk.Options.InfoFrame ) then
			if( not LVBMGui.InfoFrameCheck("Patchwerk") and mshow ) then
				LVBMGui.InfoFrameCreate("Patchwerk", "Patchwerk Damage", "Shows the Damage and\nHatefull Strike Tanks");
				for i=1, 3, 1 do
					LVBMGui.InfoFrameCreateStatusbar("Patchwerk", "MT"..i, 0, 1, 1, "");
					LVBMGui.InfoFrameCreateTextField("Patchwerk", "MT"..i.."Dmg1", "");
					LVBMGui.InfoFrameCreateTextField("Patchwerk", "MT"..i.."Dmg2", "");
					LVBMGui.InfoFrameCreateTextField("Patchwerk", "MT"..i.."Dmg3", "");
				end
			else
				if( mshow ) then	LVBMGui.InfoFrameShow("Patchwerk");
				else			LVBMGui.InfoFrameHide("Patchwerk");
				end
			end
		else	LVBMGui.InfoFrameHide("Patchwerk");
		end
	end,
	["UpdateInfoFrame"] = function()
		if( LVBM.AddOns.Patchwerk.Options.InfoFrame ) then
			i=1;
			for index, value in LVBM.AddOns.Patchwerk.HSDmgTab do
				LVBMGui.InfoFrameSetStatusBarTitle("Patchwerk", "MT"..i, index.." ("..(time()-value.lasthit).."s)");
				LVBMGui.InfoFrameSetTextField("Patchwerk", "MT"..i.."Dmg1", value[1]);
				LVBMGui.InfoFrameSetTextField("Patchwerk", "MT"..i.."Dmg2", value[2]);
				LVBMGui.InfoFrameSetTextField("Patchwerk", "MT"..i.."Dmg3", value[3]);
				i=i+1;
			end
			for i=i, 3, 1 do		-- clear last
				LVBMGui.InfoFrameSetStatusBarTitle("Patchwerk", "MT"..i, "");
				LVBMGui.InfoFrameSetTextField("Patchwerk", "MT"..i.."Dmg1", "");
				LVBMGui.InfoFrameSetTextField("Patchwerk", "MT"..i.."Dmg2", "");
				LVBMGui.InfoFrameSetTextField("Patchwerk", "MT"..i.."Dmg3", "");
			end
		end
	end,
	["HSDmgTab"] = {
--		["Stormy"] = {
--			["lasthit"] = time("] = time(),),
--			[1] = 8391,
--			[2] = 8452,
--			[3] = "dodge",
--		},
--		["Axomta"] = ....
	},
	["InfoFrameAddHFS"] = function(mt, dmg)
		if( LVBM.AddOns.Patchwerk.Options.InfoFrame ) then
			if( LVBM.AddOns.Patchwerk.HSDmgTab[mt] == nil ) then
				LVBM.AddOns.Patchwerk.HSDmgTab[mt] = { 
					["lasthit"] = time(), 
					[1] = dmg, 
					[2] = "-", 
					[3] = "-", 
				};
			else
				LVBM.AddOns.Patchwerk.HSDmgTab[mt].lasthit = time();
				LVBM.AddOns.Patchwerk.HSDmgTab[mt][1] = LVBM.AddOns.Patchwerk.HSDmgTab[mt][2];
				LVBM.AddOns.Patchwerk.HSDmgTab[mt][2] = LVBM.AddOns.Patchwerk.HSDmgTab[mt][3];
				LVBM.AddOns.Patchwerk.HSDmgTab[mt][3] = dmg;
				LVBM.AddOns.Patchwerk.UpdateInfoFrame();
			end
		end
	end,]]
	["OnEvent"] = function(event, arg1)
		if (event == "CHAT_MSG_MONSTER_YELL") then
			if (arg1 == LVBM_PW_YELL_1) or (arg1 == LVBM_PW_YELL_2) then
				LVBM.Announce("*** Enrage in 7 minutes ***");
				LVBM.Schedule(120, "LVBM.AddOns.Patchwerk.OnEvent", "EnrageWarning", 300);
				LVBM.Schedule(240, "LVBM.AddOns.Patchwerk.OnEvent", "EnrageWarning", 180);
				LVBM.Schedule(360, "LVBM.AddOns.Patchwerk.OnEvent", "EnrageWarning", 60);
				LVBM.Schedule(390, "LVBM.AddOns.Patchwerk.OnEvent", "EnrageWarning", 30);
				LVBM.Schedule(405, "LVBM.AddOns.Patchwerk.OnEvent", "EnrageWarning", 15);
				LVBM.Schedule(420, "LVBM.AddOns.Patchwerk.OnEvent", "EnrageWarning", 0);				
				LVBM.StartStatusBarTimer(420, "Enrage");
				LVBM.AddOns.Patchwerk.InCombat = true;

--				LVBM.AddOns.Patchwerk.ShowInfoFrame(true);
			end

		elseif (event == "EnrageWarning") then
			if arg1 == 300 then
				LVBM.Announce(string.format(LVBM_PW_ENRAGE_WARNING, 5, LVBM_MINUTES));
			elseif arg1 == 180 then
				LVBM.Announce(string.format(LVBM_PW_ENRAGE_WARNING, 3, LVBM_MINUTES));
			elseif arg1 == 60 then
				LVBM.Announce(string.format(LVBM_PW_ENRAGE_WARNING, 1, LVBM_MINUTE));
			elseif arg1 == 30 then
				LVBM.Announce(string.format(LVBM_PW_ENRAGE_WARNING, 30, LVBM_SECONDS));
			elseif arg1 == 15 then
				LVBM.Announce(string.format(LVBM_PW_ENRAGE_WARNING, 15, LVBM_SECONDS));
			end

		elseif (event == "ConfirmCombatEnd") then
			if (not UnitAffectingCombat("player")) and (not UnitIsDeadOrGhost("player")) then			
				LVBM.UnSchedule("LVBM.AddOns.Patchwerk.OnEvent");
				LVBM.EndStatusBarTimer("Enrage");
				LVBM.AddOns.Patchwerk.InCombat = false;

--				LVBM.AddOns.Patchwerk.ShowInfoFrame(false);
			end

		elseif (event == "CHAT_MSG_SPELL_CREATURE_VS_SELF_DAMAGE") 
		    or (event == "CHAT_MSG_SPELL_CREATURE_VS_CREATURE_DAMAGE") 
		    or (event == "CHAT_MSG_SPELL_CREATURE_VS_PARTY_DAMAGE") then

			if LVBM.AddOns.Patchwerk.Options.HatefulStrike and LVBM.AddOns.Patchwerk.Options.Announce and LVBM.Rank >= 1 then
				local _, _, target, damage;
				if string.find(arg1, LVBM_PW_HS_YOU_HIT) then
					_, _, damage = string.find(arg1, LVBM_PW_HS_YOU_HIT);
					SendChatMessage(string.format(LVBM_PW_HS_ANNOUNCE, UnitName("player"), damage), "RAID");
--					LVBM.AddOns.Patchwerk.InfoFrameAddHFS(UnitName("player"), damage);

				elseif string.find(arg1, LVBM_PW_HS_YOU_MISS) then
					SendChatMessage(string.format(LVBM_PW_HS_ANNOUNCE, UnitName("player"), LVBM_MISS), "RAID");
--					LVBM.AddOns.Patchwerk.InfoFrameAddHFS(UnitName("player"), LVBM_MISS);

				elseif string.find(arg1, LVBM_PW_HS_YOU_DODGE) then
					SendChatMessage(string.format(LVBM_PW_HS_ANNOUNCE, UnitName("player"), LVBM_DODGE), "RAID");
--					LVBM.AddOns.Patchwerk.InfoFrameAddHFS(UnitName("player"), LVBM_DODGE);

				elseif string.find(arg1, LVBM_PW_HS_YOU_PARRY) then
					SendChatMessage(string.format(LVBM_PW_HS_ANNOUNCE, UnitName("player"), LVBM_PARRY), "RAID");
					LVBM.AddOns.Patchwerk.InfoFrameAddHFS(UnitName("player"), LVBM_PARRY);

				elseif string.find(arg1, LVBM_PW_HS_PARTY_HIT) then
					_, _, target, damage = string.find(arg1, LVBM_PW_HS_PARTY_HIT);
					SendChatMessage(string.format(LVBM_PW_HS_ANNOUNCE, target, damage), "RAID");
--					LVBM.AddOns.Patchwerk.InfoFrameAddHFS(target, damage);

				elseif string.find(arg1, LVBM_PW_HS_PARTY_MISS) then
					_, _, target = string.find(arg1, LVBM_PW_HS_PARTY_MISS);
					SendChatMessage(string.format(LVBM_PW_HS_ANNOUNCE, target, LVBM_MISS), "RAID");
--					LVBM.AddOns.Patchwerk.InfoFrameAddHFS(target, LVBM_MISS);

				elseif string.find(arg1, LVBM_PW_HS_PARTY_DODGE) then
					_, _, target = string.find(arg1, LVBM_PW_HS_PARTY_DODGE);
					SendChatMessage(string.format(LVBM_PW_HS_ANNOUNCE, target, LVBM_DODGE), "RAID");
--					LVBM.AddOns.Patchwerk.InfoFrameAddHFS(target, LVBM_DODGE);

				elseif string.find(arg1, LVBM_PW_HS_PARTY_PARRY) then
					_, _, target = string.find(arg1, LVBM_PW_HS_PARTY_PARRY);
					SendChatMessage(string.format(LVBM_PW_HS_ANNOUNCE, target, LVBM_PARRY), "RAID");
--					LVBM.AddOns.Patchwerk.InfoFrameAddHFS(target, LVBM_PARRY);

				end				
			end
		end
	end,
	
	["OnUpdate"] = function(elapsed) 
		if (LVBM.AddOns.Patchwerk.InCombat) 
		and (not UnitAffectingCombat("player")) 
		and (not UnitIsDeadOrGhost("player")) 
		and (not LVBM.GetScheduleTimeLeft("LVBM.AddOns.Patchwerk.OnEvent", "ConfirmCombatEnd")) then

			LVBM.Schedule(10, "LVBM.AddOns.Patchwerk.OnEvent", "ConfirmCombatEnd");

		end
		if(LVBM.AddOns.Patchwerk.InCombat) then
--			LVBM.AddOns.Patchwerk.UpdateInfoFrame();
		end
	end,
	["UpdateInterval"] = 3,	
};
