--[[ Ѩ:[â][][аħ][ҵ][][ͬ][ҵ][û޶][岻η][][][]
ؼ:
	1 3˺
ն	1 2˺ 1ֹĿ˺
	2˺ 2
ħ	1 2˺ 120»()
	2 2˺
ն	3 1Ŀ˺ Ҫ5»
	3CD 1Ѫ(ɢ) Ҫ
ҹ	2˺ 2()

˫100, սʱԶ鵽˫100
--]]

--رԶ
setglobal("Զ", false)

--ѡ
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 and nobuff("̰ħ") then
		cast("̰ħ")
	end

	--ʼ
	v[""] = sun()
	v["»"] = moon()
	v[""] = sun_power()
	v[""] = moon_power()

	v["GCD"] = cdinterval(503)
	v["նCD"] = scdtime("ն")
	v["նCD"] = scdtime("ն")
	v["CD"] = scdtime("")
	v["CD"] = scdtime("ɢ")
	v["CD"] = scdtime("")

	v["Ŀʱ"] = tbufftime("")
	v["Ŀʱ"] = tbufftime("ն")
	v[""] = bufftime("25758")		--պ, ¼ӹ, 1, ʱɾ
	v[""] = bufftime("25759")		--º, ռӻ, 1, ʱɾ
	v[""] = buffsn("")
	v["ʱ"] = bufftime("")	--20
	v["ͬԲ"] = buffsn("ͬ")		--35 3
	v["ͬʱ"] = bufftime("ͬ")
	v["ʱ"] = bufftime("25731")
	v[""] = buffsn("25716")
	v["ʱ"] = bufftime("25716")
	v["ȼ"] = bufflv("25721")		--ȼ1 ˺+5%, ȼ2 ˺+15%, ȼ3 ˺+30%,  20/60/100
	v["ʱ"] = bufftime("25721")
	
	v["ĿѪ϶"] = rela("ж") and tlifevalue() > lifemax() * 10		--Ŀ굱ǰѪԼѪ10, Сֲ뿪ϵ

	-------------------------------------------------------
	
	--ûս
	if gettimer("") < 0.75 and v[""] < 100 and v["»"] < 100 then
		--print("---------- ȴ")
		return
	end

	if nofight() and nobuff("ɢ|4908|11547|12492") then
		--
		if (v[""] < 100 or v["»"] < 100) and cdleft(503) <= 0 then
			if CastX("ɢ") then
				settimer("")
				return
			end
		end
		--ҹ
		if rela("ж") and dis() < 20 then
			CastX("ɢ")
		end
	end

	--
	if getopt("") and dungeon() and nofight() then return end

	--˺
	if buff("") then
		f["׶"]()
	else
		f["ѭ"]()
	end

	--ûܼ¼Ϣ
	if fight() and rela("ж") and dis() < 4 and cdleft(503) <= 0 and nobuff("̰ħ") and state("վ") then
		PrintInfo("----------û")
	end
end

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

f["׶"] = function()
	CastX("")

	if buff("аħ") then
		CastX("аħ")	--12, 
	end
	
	if v[""] < 100 and v["»"] < 100 then
		if v["»"] < 60 then
			CastX("ҹϳ")
		end
		CastX("ն")
	end

	if bufftime("аħ") < 0 then
		CastX("ħ")
	end

	if CastX("") then		--Ӧò, Ϸֹ׶
		print("------------------------------ д")
	end
end

f["ѭ"] = function()
	if v["ĿѪ϶"] then

	--
	if v[""] and v["»"] >= 80 then
		if v["ʱ"] > 0 and v["ȼ"] == 1 then
			if (v["ʱ"] > 0 and v[""] >= 2)  or v["ͬʱ"] > (v["GCD"] + 0.25) * 3 then
				if v["CD"] < v["GCD"] and v["CD"] < v["GCD"] then
					if rela("ж") and dis() < 4 and face() < 80 then
						if cdtime("") <= 0 and cdtime("ɢ") <= 0 then
							CastX("ɢ")
							CastX("")
						end
					end
					return	--룬, ȿ
				end
			end
		end
	end

	--ֽ
	if v["ȼ"] == 1 and v["ʱ"] > v["GCD"] + 0.5 then
		if (v["ʱ"] > v["GCD"] + 0.5 and v[""] >= 2) or v["ͬʱ"] > (v["GCD"] + 0.25) * 4 then
			if v[""] == 60 and v["»"] == 80 and v["CD"] <= v["GCD"] then
				CastX("ն")
			end
		end
	end

	--׼, ﲻǺ, Ӧÿ֮жϽ, пٸ
	if v[""] < 0 and v[""] < 100 and v["»"] < 100 and v["CD"] < v["GCD"] * 2 then
		if v["ȼ"] == 1 and v["ʱ"] > v["GCD"] * 2 + 0.5 then
			if (v["ʱ"] > v["GCD"] * 2 + 0.5 and v[""] >= 2) or v["ͬʱ"] > (v["GCD"] + 0.25) * 4 then
				if rela("ж") and dis() < 4 and cdleft(503) <= 0 then
					print("--------------------")
				end

				if v["»"] <= 20 then
					f["ҹ"]()
					if v["ͬԲ"] >= 2 then
						CastX("ҹϳ")
					end
				end

				if v[""] < 60 or v["»"] == 80 then
					CastX("ն")
				end

				if v["»"] <= 40 then
					CastX("ն")
				end

				if v[""] < 60 or v["»"] == 80 then
					CastX("")
				end

				if v["»"] < 80 then
					CastX("")
				end

				return
			end
		end
	end

	end

	--ն
	if v[""] < 100 and v["»"] < 100 then

		if v[""] < 40 and v["»"] < 40 then	--ҹ
			f["ҹ"]()
		end

		if v[""] > 0 then			--ȴ
			if v["»"] <= 60 then
				CastX("ն")
			end
			if v[""] < 60 then
				CastX("ն")
			end
			if v["ͬԲ"] >= 3 then
				if v[""] <= 20 and v["»"] <= 60 and v["CD"] > 4 then
					CastX("ҹϳ")
				end
			end
		else							--ûȴ
			if v[""] <= 60 then
				CastX("ն")
			end
			if v["»"] < 60 then
				CastX("ն")
			end
			if v["ͬԲ"] >= 3 then
				if v["»"] <= 20 and v[""] <= 60 and v["CD"] > 4 then
					CastX("ҹϳ")
				end
			end
		end
	end

	--аħ
	if buff("аħ") then
		CastX("аħ")
	end

	--
	if  v["ʱ"] > 0 and v["ȼ"] >= 3 then	--
		if rela("ж") and dis() < range("") and cdtime("") <= 0 then
			CastX("")
		end
		CastX("")
	end
	
	if buff("顤|ꡤ") and v["CD"] > 13 then	--ħ
		CastX("")
	end

	--ħ
	if v[""] and cdtime("ħ") <= 0 and rela("ж") and dis() < 15 then	
		if v["CD"] < 8 then		--ʱд
			if cbuff("⡤Ҽ") then
				print("---------- ȡһ")
			end
		end
	end
	CastX("ħ")

	--
	if v[""] < 100 and v["»"] < 100 then
		if v[""] > 0 then		--
			if v["»"] < 60 or v["»"] >= 80  then
				CastX("")
			end
			if v[""] < 60 then
				CastX("")
			end
			CastX("")
		else						--û
			if v[""] < 60 or v[""] >= 80 then
				CastX("")
			end
			if v["»"] < 60 then
				CastX("")
			end
			CastX("")
		end
	end
end

f["ҹ"] = function()
	if buff("12850") and nobuff("ͬ") then
		CastX("ҹϳ")
	end
end

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

--¼Ϣ
function PrintInfo(s)
	local t = {}
	if s then t[#t+1] = s end
	t[#t+1] = ":"..(v[""] and "true" or "false")
	t[#t+1] = ":"..(v[""] and "true" or "false")
	t[#t+1] = ":"..v[""]
	t[#t+1] = "»:"..v["»"]
	t[#t+1] = ":"..format("%0.1f", dis())
	
	t[#t+1] = "նCD:"..v["նCD"]
	t[#t+1] = "նCD:"..v["նCD"]
	t[#t+1] = "CD:"..v["CD"]
	t[#t+1] = "CD:"..v["CD"]
	t[#t+1] = "CD:"..v["CD"]

	--t[#t+1] = "Ŀ:"..v["Ŀʱ"]
	--t[#t+1] = "Ŀ:"..v["Ŀʱ"]
	t[#t+1] = ":"..v[""]
	t[#t+1] = ":"..v[""]
	t[#t+1] = ":"..v[""]..", "..v["ʱ"]
	t[#t+1] = "ͬ:"..v["ͬԲ"]..", "..v["ͬʱ"]
	t[#t+1] = ":"..v["ʱ"]
	t[#t+1] = ":"..v[""]..", "..v["ʱ"]
	t[#t+1] = ":"..v["ȼ"]..", "..v["ʱ"]
	
	print(table.concat(t, ", "))
end

--ʹüܲ¼Ϣ
function CastX(szSkill, bSelf)
	if cast(szSkill, bSelf) then
		settimer(szSkill)
		if v["¼Ϣ"] then
			PrintInfo()
			if szSkill == "ħ" then
				if v[""] then
					print("-------------------- ")
				else
					print("-------------------- ")
				end
				if cdtime("ɢ") <= 0 then
					print("---------------------------------------- ȴ")
				end
			end
			if szSkill == "" then
				if v[""] then
					print("-------------------- ս")
				else
					print("-------------------- ½")
				end
			end
			if szSkill == "" then
				if v[""] then
					print("-------------------- ")
				else
					print("-------------------- ")
				end
			end
		end
		return true
	end
	return false
end

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

--¼ս״̬ı
function OnFight(bFight)
	if bFight then
		print("--------------------ս")
	else
		print("--------------------뿪ս")
	end
end

--[[ --------- 
ͬʱ100 100 ȸ
[] ػĶdotЧ
[] dotЧ
[] Bug, Ҫbuff 25758(¼˺) ²Ÿbuff 25759(ռӻ), û 25758 ² 25759
[岻η] ˺, жĿʱ˭ϵĶ, նҪԼϵĲЧ, ûʲӰ췴նҪ
[] 3, 1ħ buff 25928, 2 buff 25929, 3 buff 25930, бʾû
--]]
