--[[ Ѩ: [ε][][][  һָ][][][][][˪][][][޾]
ؼ:
  2 1 1Ч
  2Ч 2
  2 2Ч
  1 1 2Ч
ˮ  3 1

ûǰĿһֱѡboss
--]]


--
local v = {}
v["¼Ϣ"] = true

--
local f = {}

--ѭ
function Main()
	--Զݼ1ҷҡ, עǿݼ趨Ŀݼ1ָİǼϵ1
	if keydown(1) then
		fcast("ҡֱ")
	end

	--¼
	if casting("") and castleft() < 0.13 then
		settimer("")
	end

	--ʼ
	v[""] = charinfo("")
	v["Ŀ"] = f["ȡĿ"]()
	v["ĿѪ"] = xlife(v["Ŀ"])
	v["Ӱ"] = 0
	for i = 3, 8 do
		if buff("999"..i) then
			v["Ӱ"] = v["Ӱ"] + 1
		end
	end

	---------------------------------------------
	
	--лѩ
	if nobuff("9320") then
		cast("ѩ")
	end
	
	--ĿӰ
	if v["Ӱ"] < 6 and fight() and rela("ж") and cn("Ӱб") > 2 then
		cast("Ӱб")
	end

	--ɢ
	v["Ҫɢ"] = party("û״̬:", "<20", "߿ɴ", "buffʱ:ԲЧ|ԪԲЧ|ԲЧ|ԲЧ>1")
	if v["Ҫɢ"] ~= 0  then
		xcast("һָ", v["Ҫɢ"], true)
	end

	--Ƿж
	local bBreak = false
	if casting("") then
		v["Ŀ"] = casttarget()
		if v["Ŀ"] ~= v["Ŀ"] or xlife(v["Ŀ"]) > 0.98 then	--Ŀ겻Ѫٶ  ѾѪ
			bBreak = true
		end
	end

	--
	if fight() and v["ĿѪ"] < 0.7 then
		CastX("", bBreak)
	end

	--
	if v["ĿѪ"] < 0.9 and gettimer("") > 0.5 and xbufftime("", v["Ŀ"], id()) < 2 then
		CastX("", bBreak)
	end

	--
	if v["ĿѪ"] < 0.9 then
		CastX("", bBreak)
	end

	-- 
	if v["ĿѪ"] < 0.95 then
		if xbufftime("", v["Ŀ"], id()) < -1 then
			CastX("", bBreak)
		end
		if xbufftime("", v["Ŀ"], id()) < -1 then
			CastX("", bBreak)
		end
	end

	--ĿĿ
	if fight() and rela("ж") then
		v["ĿĿ"] = ttid()
		if v["ĿĿ"] ~= 0 then
			--
			if gettimer("") > 0.5 and xbufftime("", v["ĿĿ"], id()) < 2 then
				xcast("", v["ĿĿ"], bBreak)
			end
			--hot
			if xbufftime("", v["ĿĿ"], id()) < -1 then
				xcast("", v["ĿĿ"], bBreak)
			end
			if xbufftime("", v["ĿĿ"], id()) < -1 then
				xcast("", v["ĿĿ"], bBreak)
			end
		end
	end

	--ս
	if casting("辡Ӱ") and castleft() < 0.13 then
		settimer("辡")
	end
	if nofight() and gettimer("辡") > 1 then
		xcast("辡Ӱ", party("״̬:", "<20", "߿ɴ"))
	end

	--Thot
	xcast("", party("û״̬:", "<20", "ڹ:ϴ辭|||", "߿ɴ", "ҵbuffʱ:<-1"))
	xcast("", party("û״̬:", "<20", "ڹ:ϴ辭|||", "߿ɴ", "ҵbuffʱ:<-1"))

	--hot
	xcast("", party("û״̬:", "<20", "߿ɴ", "ҵbuffʱ:<-1"))
	xcast("", party("û״̬:", "<20", "߿ɴ", "ҵbuffʱ:<-1"))
end

-------------------------------------------------------------------------------

f["ȡĿ"] = function()
	local targetID = id()	--ĿΪԼ, ڶŶʱ party  0
	local partyID = party("û״̬:", "Լ", "<20", "߿ɴ", "ûؾ", "Ѫ")	--ȡѪٶ
	if partyID ~= 0 and partyID ~= targetID and xlife(partyID) < life() then	--ѪٶұԼѪ
		targetID = partyID	--ָΪĿ
	end
	return targetID
end

--¼Ϣ
function PrintInfo(s)
	local t = {}
	if s then t[#t+1] = s end
	t[#t+1] = "Ŀ:"..v["Ŀ"]
	t[#t+1] = "ĿѪ:"..format("%0.2f", v["ĿѪ"])
	print(table.concat(t, ", "))
end

--Ŀʹü
function CastX(szSkill, bf)
	if xcast(szSkill, v["Ŀ"], bf) then
		if v["¼Ϣ"] then PrintInfo() end
		return true
	end
	return false
end
