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()