--[[ Ѩ: [][¼][Ⱦ][ʱ][][][][Ʈ][][ͬ][][ì]
ؼ:
  2 1Ч 1Ч
  2Ϣ 1Ч 1Ч
  1 1Ч 2Ч
  2Ϣ 2Ч
  2 2Ч
ľ  3Ϣ 1Ч(Ѫ)
  3Ϣ 1Ч(Ѫ)

ְҵ, д, սû, ǰĿѡboss (ʵѡ˭ν, ѡbossΪĿҪĿλ÷ന)
--]]

--ѡ
addopt("ֶƺ", false)
addopt("ֶന", false)

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

--
local f = {}

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

	--ʼ
	v[""] = charinfo("")
	v["ҩ"] = yaoxing()
	v["Ŀ"] = f["ȡĿ"]()
	v["ĿѪ"] = xlife(v["Ŀ"])
	local tSpeedXY, tSpeedZ = speed(tid())
	v["Ŀ꾲ֹ"] = rela("ж") and tSpeedXY <= 0 and tSpeedZ <= 0


	--ƺ
	if not getopt("ֶƺ") and fight() and v["Ŀ꾲ֹ"] and target("boss") and dis() < 10 then
		v["ƺ"] = npc("ģID:106623")
		if v["ƺ"] == 0 then
			_, v["ûƶ"] = party("û״̬:", "ƽ<10", "buffʱ:<-1")
			if v["ûƶ"] >= 4 then
				cast("ƺ")
			end
		end
	end

	--ന
	if not getopt("ֶന") and fight() and v["Ŀ꾲ֹ"] and target("boss") then
		cast("ന")
	end

	--ѩ
	if v["ĿѪ"] < 0.7 and xdis(v["Ŀ"]) < 6 and xxface(id(), v["Ŀ"]) < 130 then
		cast("ѩ")
	end
	
	---------------------------------------------

	--Կ
	if fight() and v["ĿѪ"] < 0.4 then
		CastX("Կ")
	end

	--ͺ
	if fight() and v["ĿѪ"] < 0.6 then
		CastX("ͺ")
	end

	--
	if v["ĿѪ"] < 0.8 then
		CastX("")
	end

	--ֺ
	if v["ĿѪ"] < 0.95 then
		CastX("ֺ")
	end

	--ƺ
	if v["ĿѪ"] < 0.95 then
		CastX("ƺ")
	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 CastX(szSkill)
	if xcast(szSkill, v["Ŀ"]) then
		if v["¼Ϣ"] then PrintInfo() end
		return true
	end
	return false
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 OnFight(bFight)
	if bFight then
		print("--------------------ս")
	else
		print("--------------------뿪ս")
	end
end
