ShowMessage("新手任务1-10级 $Rev: 199 $")

-- 缘起无量
function OnMission_890251()

	local strMission = "缘起无量"

	local index, idMission, idScript = DataPool:GetPlayerMission(strMission)

	if index ~= -1 then
	
		DbgPrintf("%d %d %d", index, idMission, idScript)
		MoveToNPC(187, 205, DataBase:GetSceneID("无量山"), "受伤的山民")
		QuestFrameOptionClicked(strMission, CMP_PART_MATCH)
		QuestFrameMissionComplete()
		QuestFrameAcceptClicked()
		return true
	end
	return false
end

-- 路见不平
function OnMission_890252()
	
	local strMission = "路见不平"

	if DataPool:IsMissionOutline(strMission) then
		MoveToNPC(187, 205, DataBase:GetSceneID("无量山"), "受伤的山民")
		QuestFrameOptionClicked(strMission, CMP_PART_MATCH)
		QuestFrameAcceptClicked()
		return true
	end

	local index, idMission, idScript = DataPool:GetPlayerMission(strMission)

	if index ~= -1 then

		DbgPrintf("%d %d %d", index, idMission, idScript)

		if DataPool:IsMissionCanCommit(idMission) then
			MoveToNPC(194, 174, DataBase:GetSceneID("无量山"), "遇险的钟灵")
			QuestFrameOptionClicked(strMission, CMP_PART_MATCH)
			QuestFrameMissionContinue()	-- 继续
			QuestFrameMissionComplete()	-- 完成
			QuestFrameAcceptClicked()
		else
			MoveTo(159, 180, DataBase:GetSceneID("无量山"))
			-- 设置AI为杀怪
			AI:SetAI("杀怪")
			-- 设置采集对象名称
			AI:SetParameter("目标", "添加", "神农帮喽啰")
			-- 开始AI
			AI:Start(false)
			while DataPool:IsMissionCanCommit(idMission) == false do
				System:Sleep(200)
			end
			AI:Stop()
		end
		return true
	end
	return false
end

-- 武功招式
function OnMission_890254()

	local strMission = "武功招式"

	if DataPool:IsMissionOutline(strMission) then
		MoveToNPC(194, 174, DataBase:GetSceneID("无量山"), "遇险的钟灵")
		QuestFrameOptionClicked(strMission, CMP_PART_MATCH)
		QuestFrameAcceptClicked()
		return true
	end

	local index, idMission, idScript = DataPool:GetPlayerMission(strMission)

	if index ~= -1 then
		DbgPrintf("%d %d %d", index, idMission, idScript)

		if DataPool:IsMissionCanCommit(idMission) then
			MoveToNPC(238, 133, DataBase:GetSceneID("无量山"), "剑湖宫的钟灵")
			QuestFrameOptionClicked(strMission, CMP_PART_MATCH)
			QuestFrameMissionContinue()	-- 继续
			QuestFrameMissionComplete()	-- 完成
			QuestFrameAcceptClicked()
		else
			MoveTo(227, 156, DataBase:GetSceneID("无量山"))
			-- 设置AI为杀怪
			AI:SetAI("杀怪")
			-- 设置采集对象名称
			AI:SetParameter("目标", "添加", "神农帮精英")
			-- 开始AI
			AI:Start(false)
			while DataPool:IsMissionCanCommit(idMission) == false do
				System:Sleep(200)
			end
			AI:Stop()
		end
		return true
	end
	return false
end

-- 并肩作战
function OnMission_890255()
	
	local strMission = "并肩作战"

	if DataPool:IsMissionOutline(strMission) then
		MoveToNPC(238, 133, DataBase:GetSceneID("无量山"), "剑湖宫的钟灵")
		QuestFrameOptionClicked(strMission, CMP_PART_MATCH)
		QuestFrameAcceptClicked()
		return true
	end

	local index, idMission, idScript = DataPool:GetPlayerMission(strMission)

	if index ~= -1 then

		DbgPrintf("%d %d %d", index, idMission, idScript)

		if DataPool:IsMissionCanCommit(idMission) then
			MoveToNPC(238, 133, DataBase:GetSceneID("无量山"), "剑湖宫的钟灵")
			QuestFrameOptionClicked(strMission, CMP_PART_MATCH)
			QuestFrameMissionContinue()	-- 继续
			QuestFrameMissionComplete()	-- 完成
			QuestFrameAcceptClicked()
		else
			Pet:Go_Fight(0)	-- 宠物出战，此时只有一个宠物，直接写0
			MoveTo(255, 149, DataBase:GetSceneID("无量山"))
			-- 设置AI为杀怪
			AI:SetAI("杀怪")
			-- 设置采集对象名称
			AI:SetParameter("目标", "添加", "神农帮堂主")
			-- 开始AI
			AI:Start(false)
			while DataPool:IsMissionCanCommit(idMission) == false do
				System:Sleep(200)
			end
			AI:Stop()
		end
		return true
	end
	return false
end

-- 寡不敌众
function OnMission_890256()

	local strMission = "寡不敌众"
	local nSceneID = DataBase:GetSceneID("无量山")

	if DataPool:IsMissionOutline(strMission) then
		MoveToNPC(238, 133, nSceneID, "剑湖宫的钟灵")
		QuestFrameOptionClicked(strMission, CMP_PART_MATCH)
		QuestFrameAcceptClicked()
		return true
	end

	local index, idMission, idScript = DataPool:GetPlayerMission(strMission)

	if index ~= -1 then

		DbgPrintf("%d %d %d", index, idMission, idScript)

		if DataPool:IsMissionCanCommit(idMission) then
			MoveToNPC(276, 94, nSceneID, "木婉清")
			QuestFrameOptionClicked(strMission, CMP_PART_MATCH)
			QuestFrameMissionContinue()	-- 继续
			QuestFrameMissionComplete()	-- 完成
			QuestFrameAcceptClicked()
		else
			MoveTo(275, 98, nSceneID)
		end
		return true
	end
	return false
end

-- 无量玉壁
function OnMission_890257()

	local strMission = "无量玉壁"

	if DataPool:IsMissionOutline(strMission) then
		MoveToNPC(276, 94, DataBase:GetSceneID("无量山"), "木婉清")
		QuestFrameOptionClicked(strMission, CMP_PART_MATCH)
		QuestFrameAcceptClicked()
		return true
	end

	local index, idMission, idScript = DataPool:GetPlayerMission(strMission)

	if index ~= -1 then
		DbgPrintf("%d %d %d", index, idMission, idScript)

		if DataPool:IsMissionCanCommit(idMission) then
			MoveToNPC(276, 94, DataBase:GetSceneID("无量山"), "木婉清")
			QuestFrameOptionClicked(strMission, CMP_PART_MATCH)
			QuestFrameMissionContinue()	-- 继续
			QuestFrameMissionComplete()	-- 完成
			QuestFrameAcceptClicked()
		else
			MoveTo(204, 59, DataBase:GetSceneID("无量山"))
			Dismount()
			Player_UseSkill_Collect(3, "不起眼的土堆")
		end
		return true
	end
	return false
end

-- 尔虞我诈
function OnMission_890258()

	local strMission = "尔虞我诈"

	if DataPool:IsMissionOutline(strMission) then
		MoveToNPC(276, 94, DataBase:GetSceneID("无量山"), "木婉清")
		QuestFrameOptionClicked(strMission, CMP_PART_MATCH)
		QuestFrameAcceptClicked()
		return true
	end

	local index, idMission, idScript = DataPool:GetPlayerMission(strMission)

	if index ~= -1 then
		DbgPrintf("%d %d %d", index, idMission, idScript)

		if DataPool:IsMissionCanCommit(idMission) then
			MoveToNPC(209, 106, DataBase:GetSceneID("无量山"), "被俘的段誉")
			QuestFrameOptionClicked(strMission, CMP_FULL_MATCH)
			QuestFrameMissionComplete()	-- 完成
			QuestFrameAcceptClicked()
		else
			Dismount()
			UseItem("灵鹫圣使的衣帽", "")
			MoveToNPC(200, 104, DataBase:GetSceneID("无量山"), "司空玄")
			QuestFrameOptionClicked("索取解毒药", CMP_FULL_MATCH)
		end
		return true
	end
	return false
end

-- 城外相会
function OnMission_890261()

	local strMission = "城外相会"

	if DataPool:IsMissionOutline(strMission) then
		MoveToNPC(209, 106, DataBase:GetSceneID("无量山"), "被俘的段誉")
		QuestFrameOptionClicked(strMission, CMP_FULL_MATCH)
		QuestFrameAcceptClicked()
		return true
	end

	local index, idMission, idScript = DataPool:GetPlayerMission(strMission)

	if index ~= -1 then
		DbgPrintf("%d %d %d", index, idMission, idScript)

		if DataPool:IsMissionCanCommit(idMission) then
			MoveToNPC(63, 172, DataBase:GetSceneID("无量山"), "城外的段誉")
			QuestFrameOptionClicked(strMission, CMP_FULL_MATCH)
			QuestFrameMissionComplete()	-- 完成
			QuestFrameAcceptClicked()
		end
		return true
	end
	return false
end

-- 珍兽商店
function OnMission_890262()

	local strMission = "珍兽商店"

	if DataPool:IsMissionOutline(strMission) then
		MoveToNPC(63, 172, DataBase:GetSceneID("无量山"), "城外的段誉")
		QuestFrameOptionClicked(strMission, CMP_PART_MATCH)
		QuestFrameAcceptClicked()
		return true
	end

	local index, idMission, idScript = DataPool:GetPlayerMission(strMission)

	if index ~= -1 then

		DbgPrintf("%d %d %d", index, idMission, idScript)

		MissionMoveToNPC("云飘飘")
		QuestFrameOptionClicked(strMission, CMP_PART_MATCH)
		QuestFrameMissionComplete()
		QuestFrameAcceptClicked()
		System:Sleep(2000)	-- 这里接任务会骑鸟
		return true
	end
	return false
end

-- 武器商店
function OnMission_890263()

	local strMission = "武器商店"

	if DataPool:IsMissionOutline(strMission) then
		MissionMoveToNPC("云飘飘")
		QuestFrameOptionClicked(strMission, CMP_PART_MATCH)
		QuestFrameAcceptClicked()
		return true
	end

	local index, idMission, idScript = DataPool:GetPlayerMission(strMission)

	if index ~= -1 then

		DbgPrintf("%d %d %d", index, idMission, idScript)

		MissionMoveToNPC("蒲良")
		QuestFrameOptionClicked(strMission, CMP_PART_MATCH)
		QuestFrameMissionComplete()
		QuestFrameAcceptClicked()
		return true
	end

	return false
end

-- 防具商店
function OnMission_890264()

	local strMission = "防具商店"

	if DataPool:IsMissionOutline(strMission) then
		DbgPrintf("@@")
		MissionMoveToNPC("蒲良")
		QuestFrameOptionClicked(strMission, CMP_PART_MATCH)
		QuestFrameAcceptClicked()
		return true
	end

	local index, idMission, idScript = DataPool:GetPlayerMission(strMission)

	if index ~= -1 then
		DbgPrintf("%d %d %d", index, idMission, idScript)
		MissionMoveToNPC("黄公道")
		QuestFrameOptionClicked(strMission, CMP_PART_MATCH)
		QuestFrameMissionComplete()
		QuestFrameAcceptClicked()
		System:Sleep(1000)
		return true
	end
	return false
end

-- 拜访天师
function OnMission_890265()
	
	local strMission = "拜访天师"

	if DataPool:IsMissionOutline(strMission) then
		MissionMoveToNPC("黄公道")
		QuestFrameOptionClicked(strMission, CMP_PART_MATCH)
		QuestFrameAcceptClicked()
		System:Sleep(1000)
		return true
	end

	local index, idMission, idScript = DataPool:GetPlayerMission(strMission)

	if index ~= -1 then

		DbgPrintf("%d %d %d", index, idMission, idScript)

		MissionMoveToNPC("赵天师")
		QuestFrameOptionClicked(strMission, CMP_PART_MATCH)
		QuestFrameMissionComplete()
		QuestFrameAcceptClicked()
		return true
	end
	return false
end

-- 加入门派
function OnMission_890278()
	
	local strMission = "加入门派"

	if DataPool:IsMissionOutline(strMission) then
		MissionMoveToNPC("赵天师")
		QuestFrameOptionClicked(strMission, CMP_PART_MATCH)
		QuestFrameAcceptClicked()
		return true
	end

	return false
end

function _SMain(...)

	if Player:GetData("LEVEL") > 10 then return end

	local nCheckTick = 0 
--[[
[7352] _______  当前显示窗口 ______
[7352] [0x32e8b7b8] ChatFrame
[7352] [0x2ad8b610] DebugListBox
[7352] [0x3057c388] FreshManMission_JLYH
[7352] [0x2ad97268] FreshmanWatch
[7352] [0x2ad98960] Friend_IMWindowMin
[7352] [0x32e8fb50] FunctionBarRight
[7352] [0x372069d0] JBZFMessageBall
[7352] [0x32e8c4d8] MainMenuBar
[7352] [0x32e90b10] MainMenuBar_2
[7352] [0x32e8e5a8] MiniMap
[7352] [0x2ad91dc0] NewMessageBall
[7352] [0x2ad91fb8] NewMessageBall2
[7352] [0x32e8ccb8] PlayerFrame
[7352] [0x32e811b0] PlayerImpactFrame
[7352] [0x30580918] PlayerQuicklyEnter
[7352] [0x32e8f2c8] Quest
[7352] [0x3057e110] XianShiHuoDongTiShi1

[7352] this:FreshManMission_JLYH_OK_Clicked(); pre:setmetatable(_G, {__index = FreshManMission_JLYH_Env});

[7352] _______  当前显示窗口 ______
[7352] [0x32e8b7b8] ChatFrame
[7352] [0x2ad8b610] DebugListBox
[7352] [0x2ad97268] FreshmanWatch
[7352] [0x2ad98960] Friend_IMWindowMin
[7352] [0x32e8fb50] FunctionBarRight
[7352] [0x372069d0] JBZFMessageBall
[7352] [0x32e8c4d8] MainMenuBar
[7352] [0x32e90b10] MainMenuBar_2
[7352] [0x32e8e5a8] MiniMap
[7352] [0x2ad91dc0] NewMessageBall
[7352] [0x2ad91fb8] NewMessageBall2
[7352] [0x32e8ccb8] PlayerFrame
[7352] [0x32e811b0] PlayerImpactFrame
[7352] [0x30580918] PlayerQuicklyEnter
[7352] [0x32e8f2c8] Quest
[7352] [0x3057e110] XianShiHuoDongTiShi1

[7352] this:FreshmanWatch_Bn2Click(); pre:setmetatable(_G, {__index = FreshmanWatch_Env});

]]--
	local nLastLevel = 0

	while true do

		local nCurLevel = Player:GetData("LEVEL")
		local nCurExperience = Player:GetData("EXP");
		local nRequireExperience = Player:GetData("NEEDEXP");

		if nCurLevel > nLastLevel and nCurLevel < 30 then
			
			for i=1, 30 do
				if PlayerPackage:IsPresent(i-1) then
					if PlayerPackage:GetItemClass(i-1) == ITEM_CLASS.ICLASS_EQUIP then
						if nCurLevel > PlayerPackage:GetNeedLevel(i-1) + 1 then
							DiscardItem(2,i-1)
							System:Sleep(1000)
						end
					end
				end
			end
			
			nLastLevel = nCurLevel

			System:Sleep(1000)
		end
		
		if UI:IsWindowShow("FreshmanWatch") == true then
			DoLuaString("FreshmanWatch_Env" , "FreshmanWatch_Bn2Click()")
			System:Sleep(1000)
		end		

		if UI:IsWindowShow("FreshManMission_JLYH") == true then
			DoLuaString("FreshManMission_JLYH_Env" , "FreshManMission_JLYH_OK_Clicked()")
			System:Sleep(1000)
		end

		DataPool:GetMissionOutline()

		if OnMission_890251() then
		elseif OnMission_890252() then
		elseif OnMission_890254() then
		elseif OnMission_890255() then
		elseif OnMission_890256() then
		elseif OnMission_890257() then
		elseif OnMission_890258() then
		elseif OnMission_890261() then
		elseif OnMission_890262() then
		elseif OnMission_890263() then
		elseif OnMission_890264() then
		elseif OnMission_890265() then
		elseif OnMission_890278() then
		elseif DataPool:GetPlayerMission("加入门派") ~= -1 then
			break
		else
			nCheckTick = nCheckTick + 1
			if nCheckTick > 5 then 
				break
			else
				System:Sleep(1000)
				continue
			end
		end

		System:Sleep(200)
	end
end


_SMain()
