local Ret = 0
local g_szMission = {
	[0] = {xxName = "#{SXPY_130826_3}", TaskName = "#{SXPY_130826_32}"},--"学习对诗", 
	[1] = {xxName = "#{SXPY_130826_4}", TaskName = "#{SXPY_130826_78}"},--学习作画", 
	[2] = {xxName = "#{SXPY_130826_5}", TaskName = "#{SXPY_130826_108}"},--"学习礼仪",
	[3] = {xxName = "#{SXPY_130826_6}", TaskName = "#{SXPY_130826_144}"},--"切磋音律", 
	[4] = {xxName = "#{SXPY_130826_7}", TaskName = "#{SXPY_130826_188}"},--"学习射箭"
}

local g_MannerSkill1 =
{
	[0] = "称赞",
	[1] = "点头",
	[2] = "摇头",
}

local g_MannerSkill2 =
{
	[0] = "鞠躬",
	[1] = "鼓掌",
	[2] = "抱拳",
	[3] = "招手",
}

local g_MannerSkill3 =
{
	[0] = "奉茶",
	[1] = "作揖",
	[2] = "拜礼",
	[3] = "拱手",
	[4] = "执手",
}
local g_NpcInfo = {
	[0] = {szNpcName = "木子姐姐", fX = 151, fY=187, nSceneID=0},
	[1] = {szNpcName = "蔡丙臣", fX=220, fY=236, nSceneID=0},
	[2] = {szNpcName = "全小颜", fX=118, fY=138, nSceneID=0},
	[3] = {szNpcName = "张伯智", fX=162, fY=266, nSceneID=0},
}
local xInfant_DrawPos = {
    [1] = {
        [1] = {SceneID = 0, SceneName = "洛阳", PosX = 153, PosZ = 158},
        [2] = {SceneID = 0, SceneName = "洛阳", PosX = 295, PosZ = 260},
        [3] = {SceneID = 0, SceneName = "洛阳", PosX = 226, PosZ = 419},
        [4] = {SceneID = 1, SceneName = "苏州", PosX = 367, PosZ = 171},
        [5] = {SceneID = 1, SceneName = "苏州", PosX = 278, PosZ = 326},
        [6] = {SceneID = 1, SceneName = "苏州", PosX = 181, PosZ = 355},
    },
    [2] = {
        [1] = {SceneID = 2,SceneName = "大理", PosX = 70, PosZ = 49},
        [2] = {SceneID = 2,SceneName = "大理", PosX = 293, PosZ = 46},
        [3] = {SceneID = 2,SceneName = "大理", PosX = 69, PosZ = 235},
        [4] = {SceneID = 18,SceneName = "雁南", PosX = 156, PosZ = 277},
        [5] = {SceneID = 18,SceneName = "雁南", PosX = 250, PosZ = 82},
        [6] = {SceneID = 18,SceneName = "雁南", PosX = 138, PosZ = 242},
    },
    [3] = {
        [1] = {SceneID = 4,SceneName = "太湖", PosX = 168, PosZ = 189},
        [2] = {SceneID = 4,SceneName = "太湖", PosX = 62, PosZ = 74},
        [3] = {SceneID = 4,SceneName = "太湖", PosX = 100, PosZ = 175},
        [4] = {SceneID = 30,SceneName = "西湖", PosX = 124, PosZ = 50},
        [5] = {SceneID = 30,SceneName = "西湖", PosX = 246, PosZ = 193},
        [6] = {SceneID = 30,SceneName = "西湖", PosX = 154, PosZ = 132},
    },
}
local xMannerNPCTable =  
{
	[1] = {NPCName = "全小颜", PosX = 118,PosZ = 138, nSceneID=0},
	[2] = {NPCName = "曹小明", PosX = 118,PosZ = 132, nSceneID=0},
	[3] = {NPCName = "陆小祺", PosX = 127,PosZ = 132, nSceneID=0},
}
function 学习对诗()
	--打印信息("开始执行我要作诗任务..")
	local 任务进度 = 取任务进度(g_szMission[0].TaskName)
	if 任务进度 == -1 then
		召唤坐骑(1)
		ID_寻路(g_NpcInfo[0].fX,g_NpcInfo[0].fY,g_NpcInfo[0].nSceneID)
		延迟(500)
		对话npc(g_NpcInfo[0].szNpcName)
		延迟(500)
		对话选项("#{SXPY_130826_1}")
		延迟(500)
		对话选项(g_szMission[0].xxName)
		if 取对话栏内容() == "#{SXPY_130826_26}" then return end
		if 取对话栏内容() == "#{SXPY_130826_374}" then 打印信息("子女：孩子健康为0,脚本结束") Ret = 1 return end
		接受任务()
		return 学习对诗()
	end
	
	if 任务进度 == 1 then
		召唤坐骑(1)
		ID_寻路(g_NpcInfo[0].fX,g_NpcInfo[0].fY,g_NpcInfo[0].nSceneID)
		延迟(500)
		对话npc(g_NpcInfo[0].szNpcName)
		对话选项("#{SXPY_130826_1}")
		延迟(500)
		对话选项(g_szMission[0].xxName)
		延迟(500)
		完成任务()
		return 学习对诗()
	end
	
	if 任务进度 == 0 then
		召唤坐骑(1)
		ID_寻路(g_NpcInfo[1].fX,g_NpcInfo[1].fY,g_NpcInfo[1].nSceneID)
		对话npc(g_NpcInfo[1].szNpcName)
		延迟(500)
		对话选项("#{SXPY_130826_9}")
		延迟(500)
		while 取任务参数(g_szMission[0].TaskName,0) ~= 1 do
			strType = 取任务参数(g_szMission[0].TaskName,2)
			for j = 1,4 do
				GetNPCEventList_Item(j + 1)
				延迟(500)
				if strType ~= 取任务参数(g_szMission[0].TaskName,2) then
					break
				end
			end
		end
		return 学习对诗()
	end
end

function 学习作画()
	--打印信息("开始执行我要作画任务..")
	local 任务进度 = 取任务进度(g_szMission[1].TaskName)
	if 任务进度 == -1 then
		召唤坐骑(1)
		ID_寻路(g_NpcInfo[0].fX,g_NpcInfo[0].fY,g_NpcInfo[0].nSceneID)
		延迟(500)
		对话npc(g_NpcInfo[0].szNpcName)
		延迟(500)
		对话选项("#{SXPY_130826_1}")
		延迟(500)
		对话选项(g_szMission[1].xxName)
		if 取对话栏内容() == "#{SXPY_130826_532}" then return end
		if 取对话栏内容() == "#{SXPY_130826_374}" then 打印信息("子女：孩子健康为0,脚本结束") Ret = 1 return end
		接受任务()
		return 学习作画()
	end
	
	if 任务进度 == 1 then
		召唤坐骑(1)
		ID_寻路(g_NpcInfo[0].fX,g_NpcInfo[0].fY,g_NpcInfo[0].nSceneID)
		延迟(500)
		对话npc(g_NpcInfo[0].szNpcName)
		延迟(500)
		对话选项("#{SXPY_130826_1}")
		延迟(500)
		对话选项(g_szMission[1].xxName)
		延迟(500)
		完成任务()
		return 学习作画()
	end
	
	if 任务进度 == 0 then
		local level = 取任务参数(g_szMission[1].TaskName,1)
		local pos = 取任务参数(g_szMission[1].TaskName,9)
		--打印信息("level = "..level.." pos = "..pos)
		召唤坐骑(1)
		ID_寻路(xInfant_DrawPos[level][pos].PosX, xInfant_DrawPos[level][pos].PosZ, xInfant_DrawPos[level][pos].SceneID)
		召唤坐骑(0)
		while 取任务参数(g_szMission[1].TaskName,0) ~= 1 do
			使用物品("文房四宝")
			延迟(7000)
		end
		return 学习作画()
	end
end

function 学习礼仪()
	--打印信息("开始执行我要礼仪任务..")
	local 任务进度 = 取任务进度(g_szMission[2].TaskName)
	if 任务进度 == -1 then
		召唤坐骑(1)
		ID_寻路(g_NpcInfo[0].fX,g_NpcInfo[0].fY,g_NpcInfo[0].nSceneID)
		对话npc(g_NpcInfo[0].szNpcName)
		延迟(500)
		对话选项("#{SXPY_130826_1}")
		延迟(500)
		对话选项(g_szMission[2].xxName)
		if 取对话栏内容() == "#{SXPY_130826_534}" then return end
		if 取对话栏内容() == "#{SXPY_130826_374}" then 打印信息("子女：孩子健康为0,脚本结束") Ret = 1 return end
		接受任务()
		return 学习礼仪()
	end
	
	if 任务进度 == 1 then
		召唤坐骑(1)
		ID_寻路(g_NpcInfo[0].fX,g_NpcInfo[0].fY,g_NpcInfo[0].nSceneID)
		延迟(500)
		对话npc(g_NpcInfo[0].szNpcName)
		对话选项("#{SXPY_130826_1}")
		延迟(500)
		对话选项(g_szMission[2].xxName)
		完成任务()
		return 学习礼仪()
	end
	
	if 任务进度 == 0 then
		level = 取任务参数(g_szMission[2].TaskName,1)
		--打印信息("level = " ..level)
		if 取距离(xMannerNPCTable[level].PosX,xMannerNPCTable[level].PosZ) >= 20 then 召唤坐骑(1) end
		ID_寻路(xMannerNPCTable[level].PosX,xMannerNPCTable[level].PosZ,xMannerNPCTable[level].nSceneID)
		召唤坐骑(0)
		对话npc(xMannerNPCTable[level].NPCName)
		延迟(500)
		对话选项("#{SXPY_130826_12}")
		延迟(500)
		while 取任务参数(g_szMission[2].TaskName,0) ~= 1 do
			if level == 1 then
				for i=0, 2 do
					使用技能(g_MannerSkill1[i],-1)
					延迟(500)
				end
			elseif level == 2 then
				for i=0, 3 do
					使用技能(g_MannerSkill2[i],-1)
					延迟(500)
				end
			elseif level == 3 then
				for i=0, 4 do
					使用技能(g_MannerSkill3[i],-1)
					延迟(500)
				end
			end
		end
		return 学习礼仪()
	end
end

function 切磋音律()
	--打印信息("开始执行我要音律任务..")
	local 任务进度 = 取任务进度(g_szMission[3].TaskName)
	if 任务进度 == -1 then
		召唤坐骑(1)
		ID_寻路(g_NpcInfo[0].fX,g_NpcInfo[0].fY,g_NpcInfo[0].nSceneID)
		延迟(500)
		对话npc(g_NpcInfo[0].szNpcName)
		延迟(500)
		对话选项("#{SXPY_130826_1}")
		延迟(500)
		对话选项(g_szMission[3].xxName)
		延迟(500)
		if 取对话栏内容() == "#{SXPY_130826_536}" then return end
		if 取对话栏内容() == "#{SXPY_130826_374}" then 打印信息("子女：孩子健康为0,脚本结束") Ret = 1 return end
		接受任务()
		return 切磋音律()
	end
	
	if 任务进度 == 1 then
		召唤坐骑(1)
		ID_寻路(g_NpcInfo[0].fX,g_NpcInfo[0].fY,g_NpcInfo[0].nSceneID)
		延迟(500)
		对话npc(g_NpcInfo[0].szNpcName)
		对话选项("#{SXPY_130826_1}")
		延迟(500)
		对话选项(g_szMission[3].xxName)
		延迟(500)
		完成任务()
		return 切磋音律()
	end

	if 任务进度 == 0 then
		if 取距离(g_NpcInfo[3].fX,g_NpcInfo[3].fY) >= 20 then 召唤坐骑(1) end
		ID_寻路(g_NpcInfo[3].fX,g_NpcInfo[3].fY,g_NpcInfo[3].nSceneID)
		对话npc(g_NpcInfo[3].szNpcName)
		延迟(500)
		对话选项("#{SXPY_130826_15}")
		延迟(500)
		while 取任务参数(g_szMission[3].TaskName,0) ~= 1 do
			strType = 取任务参数(g_szMission[3].TaskName,2)
			for j = 1,4 do
				GetNPCEventList_Item(j + 1)
				延迟(500)
				if strType ~= 取任务参数(g_szMission[3].TaskName,2) then
					break
				end
			end
			延迟(500)
		end
		return 切磋音律()
	end
end

function 学习射箭()
	--打印信息("开始执行我要射箭任务..")
	local 任务进度 = 取任务进度(g_szMission[4].TaskName)
	--打印信息("任务进度 = "..任务进度)
	if 任务进度 == -1 then
		召唤坐骑(1)
		ID_寻路(g_NpcInfo[0].fX,g_NpcInfo[0].fY,g_NpcInfo[0].nSceneID)
		对话npc(g_NpcInfo[0].szNpcName)
		延迟(500)
		对话选项("#{SXPY_130826_1}")
		延迟(500)
		对话选项(g_szMission[4].xxName)
		if 取对话栏内容() == "#{SXPY_130826_538}" then return end
		if 取对话栏内容() == "#{SXPY_130826_374}" then 打印信息("子女：孩子健康为0,脚本结束") Ret = 1 return end
		接受任务()
		return 学习射箭()
	end
	
	if 任务进度 == 1 then
		召唤坐骑(1)
		ID_寻路(g_NpcInfo[0].fX,g_NpcInfo[0].fY,g_NpcInfo[0].nSceneID)
		对话npc(g_NpcInfo[0].szNpcName)
		延迟(500)
		对话选项("#{SXPY_130826_1}")
		延迟(500)
		对话选项(g_szMission[4].xxName)
		延迟(500)
		完成任务()
		return 学习射箭()
	end
	
	if 任务进度 == 0 then
		if 取距离(176,150) >= 20 then 召唤坐骑(1) end
		ID_寻路(176,150,0)
		召唤坐骑(0)
		local Id1,Id2,Id3 = FindTarget("靶子")			
		local array = {
		   [1] = Id1, 
		   [2] = Id2, 
		   [3] = Id3,
		}
		--打印信息("ID = "..array[1].."   "..array[2].."  "..array[3])
		while 取任务参数(g_szMission[4].TaskName,0) ~= 1 do
			for i = 1, 3 do
				if GetBuffNumber(array[i]) == 1 then
					--打印信息("开始使用弓箭")
					使用物品Ex("弓箭",array[i])
					延迟(500) 
					break				
				end			
			end	
		end
		return 学习射箭()
	end
end

if Ret ~= 1 then
打印信息("子女：学习对诗!!")
学习对诗()
end
if Ret ~= 1 then
打印信息("子女：学习作画!!")
学习作画()
end
if Ret ~= 1 then
打印信息("子女：学习礼仪!!")
学习礼仪()
end 
if Ret ~= 1 then
打印信息("子女：切磋音律!!")
切磋音律()
end
if Ret ~= 1 then
打印信息("子女：学习射箭!!")
学习射箭()
end
打印信息("子女：能力五项执行完毕!!")