--[[ Ѩ: [ָ  ][ϼ  Ϣ][  »  ][  ָ][΢][][][  ][  ĩ][][ң][޻]
ؼ:
¥  2Ϣ 1 1
  2 1Ч 1ī
  1 1 2Ч
  1 3

ѨؼֻƼҲ̫棬Լŵ
Ҫϵ[ָ], ѡеĴ
ûǰĿһֱѡboss
--]]

--ѡ
addopt("", false)

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

--
local f = {}

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

	--
	if fight() and life() < 0.5 then
		cast("¥Ӱ")
	end

	--
	if getopt("") and tbuffstate("ɴ") then
		cast("ָ")
	end

	--ʼ
	v["ī"] = rage()
	v[""] = charinfo("")	--뾫ȷƣ * ϵ = ʵʼѪ
	v["Ŀ"] = f["ȡĿ"]()
	v["ĿѪ"] = xlife(v["Ŀ"])
	v["ĿT"] = xmount("ϴ辭|||", v["Ŀ"])

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

	--
	if fight() and v["ĿѪ"] < 0.4 and life() > 0.8 then
		CastX("紵ѩ")
	end

	--
	if v["ĿѪ"] < 0.75 then
		--ˮ
		if fight() and v["ī"] < 20 then
			cast("ˮ޼")
		end

		if buff("412|722|932|3458|6266") then	--˲
			CastX("")
		end
	end

	--

	--
	if v["ĿѪ"] < 0.9 then		--Ѫ
		CastX("")
	end
	if v["ī"] < 30 then				--ˢī
		CastX("")
	end

	--
	if rela("ж") and ttid() ~= 0 and xrela("Լ|Ѻ|", ttid()) then	--ĿĿ bossĿʾһҪ̵
		if xbufftime("", ttid(), id()) < 3 then
			xcast("", ttid())
		end
	end

	--ˮ
	if fight() and mana() < 0.45 then
		cast("ˮ", true)
	end

	--
	if fight() and target("boss") and face() < 80 and qixue("") and tbufftime("") < 3 then
		cast("ָ")
	end

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

	--ս
	if casting("") and castleft() < 0.13 then
		settimer("")
	end
	if nofight() and gettimer("") > 0.5 then
		xcast("", party("״̬:", "<20", "߿ɴ"))
	end
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] = "Ŀ:"..v["Ŀ"]
	t[#t+1] = "ĿѪ:"..format("%0.2f", v["ĿѪ"])
	print(table.concat(t, ", "))
end

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