ShowMessage("鹊桥相会脚本 $Rev: 100 $")


--[[
[author]
class=3
perday_max=1
descript="请留意背包空格，保证有足够位置可以让脚本顺利执行。"
]]--
script_name="鹊桥相会"

local g_NpcName = "灵鹊仙子"			-- NPC名称
local g_Npc_X = 222
local g_Npc_Y = 137
local g_Npc_Map = 30

local quest_is_done = false

function _SMain(...)

	local nIndex = 0
	local idMission = -1 
	local idScript = 0 

	while true do

		nIndex, idMission, idScript = DataPool:GetPlayerMission( script_name )

		if nIndex ~= -1 then

			--DbgPrintf("%s Index:%d MissionID:%d ScriptID:%d", script_name, nIndex, idMission, idScript)

			if DataPool:IsMissionCanCommit(idMission) then

				local nEmptySlot = PlayerPackage:GetEmptySlot(0)
				if  nEmptySlot < 1 then 
					ShowMessage("背包需要至少1个空格才能提交任务。")
					return 
				end

				quest_is_done = true 

				-- 完成任务
				DbgPrintf("任务已完成")
				MoveToNPC( 245, 124, 0xa4 , "牛郎" )
				QuestFrameOptionClicked(script_name, CMP_FULL_MATCH)	-- 选择选项
				QuestFrameMissionContinue()	-- 继续
				QuestFrameMissionComplete()	-- 完成
				
			else
				if Player:IsHaveBuff(0xcdd) then 
					local dwFlags = CHA_RELATION_FRIEND|CHA_TYPE_NPC|CHA_OWNER_FREE|CHA_OCCUPANT_FREE|CHA_OCCUPANT_MYSELF|CHA_OCCUPANT_TEAM|CHA_STATE_ALIVE
					local Id = LockNearestTarget("灵鹊", dwFlags, CMP_FULL_MATCH , 1 )
					if Id ~= INVALID_ID then
						Player_UseSkill_Collect(0x0cde, Id)

						System:Sleep(200)
					else
						MoveTo( 210 , 79 , 30 )
					end
				else
					MoveToNPC( g_Npc_X, g_Npc_Y, g_Npc_Map , g_NpcName )
					Dismount()
					QuestFrameOptionClicked( "学习捕捉灵鹊技能", CMP_FULL_MATCH)	-- 选择选项
					System:Sleep(1000)
				end
			end
		else
			-------------------------------------------------------------------------------------
			-- 领取任务

			if quest_is_done == true then
				ShowMessage( "鹊桥相会脚本已完成" )
				System:UpdateRecord( script_name )
				return
			end

			local nLevel = Player:GetData("LEVEL")

			if nLevel < 30 then 
				ShowMessage("等级不够30级，不能接鹊桥相会任务。")
				return
			end

			MoveToNPC( g_Npc_X, g_Npc_Y, g_Npc_Map , g_NpcName )
			Dismount()
			QuestFrameOptionClicked(script_name, CMP_FULL_MATCH)	-- 选择选项
			QuestFrameAcceptClicked()

			System:Sleep(1000)

			local isNext,szMsg = GetDebugMessage()
			while isNext == 1 do
				if string.find(szMsg, "今日已参加鹊桥相会活动") then
					ShowMessage("完成鹊桥相会脚本。") 
					System:UpdateRecord( script_name )
					return
				end
				isNext,szMsg = GetDebugMessage()
			end
		end

		System:Sleep(500)
	end

end

_SMain()