ezsc_UseAction = nil;

function SelfCast_OnLoad()
	ezsc_UseAction = UseAction;
	UseAction = ezSelfCast_UseAction;
	this:RegisterEvent("VARIABLES_LOADED");
end

function SelfCast_OnEvent(event)
	if( event == "VARIABLES_LOADED" ) then
		if( not SelfCast_Solo ) then
			SelfCast_Solo = 1;
		end
		if( not SelfCast_Alt ) then
			SelfCast_Alt = 1;
		end
		-- SelfCast_Register();
	end
end


function SelfCast_Toggle_Enabled(toggle)
	SelfCast_Solo = toggle;
end
function SelfCast_Toggle_Alt(toggle)
	SelfCast_Alt = toggle;
end

-- function SelfCast_Register()
-- 	gLim_RegisterButton (
-- 		"Self Cast",
-- 		"自身施法",
-- 		"Interface\\AddOns\\SelfCast\\Icon", 
-- 		function()
-- 			gLimModSecBookShowConfig("gLimSelfCast");
-- 		end,
-- 		2,
-- 		4
-- 		);

--   gLim_RegisterConfigClass(
-- 	"gLimSelfCast",
-- 	"Self Cast",
-- 	"CraZy aPpLe"
-- 	);
--   gLim_RegisterConfigSection(
-- 	"gLimSelfCastSection",
-- 	"自身施法",
-- 	"自身施法",
-- 	"CraZy aPpLe",
-- 	"gLimSelfCast"
-- 	);
--   gLim_RegisterConfigCheckBox(
-- 	"gLim_SelfCast_ENABLED",
-- 	"开启Solo模式",
-- 	"当玩家没有目标时对自己施法",
-- 	SelfCast_Solo,
-- 	SelfCast_Toggle_Enabled,
-- 	"gLimSelfCast"
-- 	);
--   gLim_RegisterConfigCheckBox(
-- 	"gLim_SelfCast_ALT_KEY",
-- 	"开启Alt模式",
-- 	"当Alt键按下时对自己施法",
-- 	SelfCast_Alt,
-- 	SelfCast_Toggle_Alt,
-- 	"gLimSelfCast"
-- 	);
-- end

function ezSelfCast_UseAction(id, number, onSelf)	
	if(SelfCast_Alt == 1 and IsAltKeyDown()) then
		ezsc_UseAction(id, number, 1);
		return;
	end
	ezsc_UseAction(id, number, onSelf);
	if(SelfCast_Solo == 1) then
		if (UnitExists("target")) then
			if (not UnitIsFriend("player", "target")) then
				SpellTargetUnit("player");
			end
		else
			SpellTargetUnit("player");
		end
	end
end