--[[ Ѩ: [][ѩ][][][][Ԩ][][лת][ٽ][][][ɽ]
ؼ:
Ǵ	1 3˺
	2 2˺
ź	3˺
	2Ϣ 2˺
	1 3˺
Ѫ	2Ϣ 2
ڤ	2˺ 2Ļ11
--]]

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

--ѡ
addopt("", false)

--
local v = {}
v["Ϣ"] = true
v["Ź"] = false

--ѭ
function Main(g_player)
	if casting("ź") and castleft() < 0.13 then
		settimer("źĶ")
	end
	if casting("") and castleft() < 0.13 then
		settimer("Ƕ")
	end

	--ʼ
	v["CD"] = scdtime("")
	v["źĳʱ"] = cntime("ź", true)
	v["źĳܴ"] = cn("ź")
	v["CD"] = scdtime("")
	v["⹳CD"] = scdtime("⹳")
	v["CD"] = scdtime("͹")
	v["CD"] = scdtime("лת")
	v["ɽCD"] = scdtime("ɽ")
	v["ʱ"] = bufftime("͹")	--ĻЧ15%, 4
	v["ʱ"] = bufftime("24244")	-- 5
	v["ǲ"] = buffsn("26215")
	v["ʱ"] = bufftime("26215")		--8
	v["ٽڲ"] = buffsn("ٽ")			--ʵЧ 15927 15928 15929
	v["ٽʱ"] = bufftime("ٽ")		--5
	v["ʱ"] = bufftime("")		--10
	v["ʱ"] = bufftime("")		--10
	v[""] = buff("15524")
	v["˫"] = buff("15565")
	v["˫"] = nobuff("15524|15565")
	local tSpeedXY, tSpeedZ = speed(tid())
	v["Ŀ꾲ֹ"] = rela("ж") and tSpeedXY <= 0 and tSpeedZ <= 0
	v["źĶʱ"] = casttime("ź")

	--Ŀ겻ǵж, 
	if not rela("ж") then return end
	-- ûս ѡ, 
	if getopt("") and dungeon() and nofight() then return end

	--ȴ״̬ͬ
	if gettimer("ȴ") < 0.3 then print("--------------------ȴ") return end
	if gettimer("ȴ") < 0.3 then print("--------------------ȴ") return end
	if gettimer("źĶ") < 0.3 then
		--print("----------ȴźͷ")
		return
	end

	--Ʒ
	v[""] = npc("ϵ:Լ", "ģID:107305", "<12")
	if v[""] ~= 0 then
		aCastX("", 0, v[""])
	end

	--⹳
	if dis() < 5 and v["ʱ"] > 9 then
		if aCastX("⹳") then
			settimer("⹳")
		end
	end

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

	if v["˫"] then
		--
		if dis() > 6 and dis() < 12 and face() < 60 and v["CD"] > 20 then
			 if v["ٽڲ"] >= 3 and v["ٽʱ"] > 0 and v["ʱ"] > 0 and v["ʱ"] > 0 then
				CastX("")
			 end
		end

		--
		if dis() < 12 and v["źĳʱ"] > 4.5  and v["CD"] > 8 and v["ʱ"] > 8 then
			if CastX("͹") then
				settimer("͹")
			end
		end

		--
		v[""] = false

		if v["ʱ"] < 2 then
			v[""] = ", ʱ쵽"
		elseif v["ٽڲ"] < 3 and v["ʱ"] < 3 then
			v[""] = ", û3ٽʱС3"
		elseif v["Ź"] then
			v[""] = ", Ź"
		end

		if v[""] then
			if CastX("ѪȪ") then
				settimer("ȴ")
				print(v[""])
				return
			end
		end

		--
		if dis() < 12 and gettimer("⹳") > 0.3 and v["ʱ"] > 7 then
			CastX("лת")
		end

		--ź
		if v["ٽڲ"] < 3 or v["ٽʱ"] < 2.5 or v["ʱ"] > 3 then
			if CastX("ź") then
				settimer("ź")	--п
			end
		end

		--
		if dis() < 12 and face() < 60 then
			if v["ٽڲ"] >= 3 or v["ʱ"] > 1 then
				if aCastX("") then
					settimer("")
				end
			end
		end
	end

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

	if v[""] then
		--
		local nTime = (v["źĶʱ"] + 0.0625) * 2 + 0.25
		if v["CD"] < 1 then
			nTime = nTime + cdinterval(16)
		end

		v[""] = false
		if dis() < 5 and v["źĳʱ"] <= nTime then	--ܴ3
			v[""] = ",  * 3 + "
			cbuff("ٽ")
		elseif dis() > 6 and dis() < 12 and v["Ŀ꾲ֹ"] and v["CD"] < 0.1 and v["źĳܴ"] >= 1 and v["źĳʱ"] > 5 and v["CD"] > 8.5 then
			v[""] = ",  +  + "
		end

		if v[""] then
			if CastX("ڤ") then
				settimer("ȴ")
				print(v[""])
				return
			end
		end

		--CastX("")
		
		--
		CastX("")

		--ɽ
		if v["Ŀ꾲ֹ"] and v["CD"] > 0 then
			CastX("ɽ")
		end
		
		--Ǵ
		if v["CD"] > 0 and dis() < 6 and face() < 90 then
			CastX("ǴƽҰ")
		end
	end

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

	if fight() and rela("ж") and dis() < 12 and face() < 60 and cdleft(16) <= 0 and castleft() <= 0  and gettimer("ź") > 0.3 and gettimer("") > 0.3 and state("վ|·|ܲ|Ծ") then
		PrintInfo("----------û, ")
	end
end

--Ϣ
function PrintInfo(s)
	local szinfo = "CD:"..v["CD"]..", źCD:"..v["źĳܴ"]..", "..v["źĳʱ"]..", CD:"..v["CD"]..", ⹳CD:"..v["⹳CD"]..", CD:"..v["CD"]..", CD:"..v["CD"]..", ɽCD:"..v["ɽCD"]..", :"..v["ǲ"]..", "..v["ʱ"]..", ٽ:"..v["ٽڲ"]..", "..v["ٽʱ"]..", :"..v["ʱ"]..", :"..v["ʱ"]..", :" ..v["ʱ"]..", "..v["ʱ"]
	if s then
		szinfo = s..szinfo
	end
	print(szinfo)
end

--ʹüܲϢ
function CastX(szSkill)
	if cast(szSkill) then
		if v["Ϣ"] then PrintInfo() end
		return true
	end
	return false
end

function aCastX(szSkill)
	if acast(szSkill) then
		if v["Ϣ"] then PrintInfo() end
		return true
	end
	return false
end

--ͷ
function OnCast(CasterID, SkillName, SkillID, SkillLevel, TargetType, TargetID, PosY, PosZ, StartFrame, FrameCount)
	if CasterID == id() then
		if SkillID == 22327 then	--ź
			deltimer("źĶ")
			return
		end
		if SkillID == 22361 then	--ڤ
			v["Ź"] = false
			return
		end
		if SkillID == 22320 then	--
			v["Ź"] = true
			return
		end
	end
end

--buff
function OnBuff(CharacterID, BuffName, BuffID, BuffLevel, StackNum, SkillSrcID, StartFrame, EndFrame, FrameCount)
	if CharacterID == id() then
		if BuffID == 15524 then	--
			if StackNum  > 0 then
				deltimer("ȴ")
			else
				deltimer("ȴ")
			end
		end
	end
end

--ûãϢ
function OnFight(bFight)
	if gettimer("սս") > 5 then
		settimer("սս")
		if bFight then
			print("--------------------ս")
		else
			print("--------------------뿪ս")
		end
	end
end
