local _,ns = ...

ns.tips("自动设置误导嫁祸宏(需要有个宏的名字叫嫁祸或者叫误导)")
local WD =CreateFrame("frame")
WD:RegisterEvent('GROUP_ROSTER_UPDATE')
WD:RegisterEvent('PLAYER_ENTERING_WORLD')
WD:RegisterEvent('PLAYER_REGEN_ENABLED') 
WD:SetScript("OnEvent",function(self,event)
	if event == 'GROUP_ROSTER_UPDATE' or event == 'PLAYER_ENTERING_WORLD' then
		if InCombatLockdown() then
			WD.InCombat = true
		else
			WD:UpdateMacroTarget()
		end
	end
	if event == 'PLAYER_REGEN_ENABLED' and WD.InCombat then
		WD:UpdateMacroTarget()
		WD.InCombat = nil
	end
end)
function WD:UpdateMacroTarget()
	if IsInRaid() then
		for i = 1,40 do
			if UnitGroupRolesAssigned("raid"..i) == "TANK" then
				WD.NewName = UnitName("raid"..i)
				break;
			end
		end
	elseif IsInGroup() then
		for i = 1,4 do
			if UnitGroupRolesAssigned("party"..i) == "TANK" then
				WD.NewName = UnitName("party"..i)
				break;
			end
		end
	end
	if WD.NewName == WD.OldName then return end
	local _,playerclass = UnitClass("player")
	if WD.NewName and GetMacroInfo("误导") and  playerclass == "HUNTER" then
		EditMacro("误导", nil , nil, "#showtooltip\n/cast [@target,help,exists][@"..WD.NewName..",exists][@pet][]误导")
		UIErrorsFrame:AddExternalWarningMessage("设置误导目标\:  "..WD.NewName)
		ADCTEXT("已将误导宏的目标改为:  "..WD.NewName)
		local gameHour, gameMinute = GetGameTime()
		print("|cff00FF00"..string.format("%02d:%02d", gameHour, gameMinute).."|r|cffFF0000已将误导宏的目标改为:  |r"..WD.NewName)
		WD.OldName = WD.NewName
	end
	if WD.NewName and GetMacroInfo("嫁祸") and  playerclass == "ROGUE" then
		EditMacro("嫁祸", nil , nil, "#showtooltip\n/cast [@target,help,exists][@"..WD.NewName..",exists][]嫁祸诀窍")
		UIErrorsFrame:AddExternalWarningMessage("设置嫁祸目标\:  "..WD.NewName)
		ADCTEXT("已将嫁祸宏的目标改为:  "..WD.NewName)
		local gameHour, gameMinute = GetGameTime()
		print("|cff00FF00"..string.format("%02d:%02d", gameHour, gameMinute).."|r|cffFF0000已将嫁祸宏的目标改为:  |r"..WD.NewName)
		WD.OldName = WD.NewName
	end
end