ShowMessage("幸运快活三任务脚本 $Rev: 192 $")

--[[
[author]
descript="每天可以做1次"
]]--
perday_max=1
script_name="幸运快活三"

local g_szMission = "幸运快活三"

local g_NpcInfo = {
	[0] = {szNpcName="柳月虹", fX=230, fY=350}
}

while true do

	if Player:GetData("LEVEL") < 20 then
		ShowMessage("幸运快活三：玩家等级小于20级。")
		break 
	end

	if UI:IsWindowShow("XingYun") == false then
		MoveToNPC(g_NpcInfo[0].fX, g_NpcInfo[0].fY, 1, g_NpcInfo[0].szNpcName)
		QuestFrameOptionClicked(g_szMission, CMP_PART_MATCH)
		System:Sleep(1000)
		local strType,_,_,_,szText = DataPool:GetNPCEventList_Item(0);
		
		if strType == "text" then
			if string.find(szText, "已经参加") then 
				System:UpdateRecord( script_name )
				break
			elseif string.find(szText, "再等60分钟") then
				break
			end
		end
	else
		local i = Get_XParam_INT(1999986, 0)

		if i == 3 then
			DoLuaString("XingYun_Env", "XingYun_Close()")
			System:Sleep(1000)

			local lastNum = DataPool:UserBag_CountItemByName("愿灵泉")

			while true do
				if lastNum < DataPool:UserBag_CountItemByName("愿灵泉") then
					UI:WindowHide("XingYun")
					break
				end

				QuestFrameSpeak(0, g_NpcInfo[0].szNpcName)
				QuestFrameOptionClicked("领取幸运", CMP_PART_MATCH)
				local strType,_,_,_,szText = DataPool:GetNPCEventList_Item(0);

				if strType == "text" then
					if string.find(szText, "没有奖励") then break end
				end
				System:Sleep(1000)
			end
		else
			DoLuaString("XingYun_Env", string.format("Play_Ani(%d)", i+1))
			System:Sleep(2000)
		end
	end

	System:Sleep(1000)
end