ShowMessage("劳动奖章大作战 $Rev: 100 $")


--[[
[author]
class=3
perday_max=1
descript="请保持材料背包空格大于1，否者脚本会自动跳过。"
]]--
script_name="劳动奖章大作战"

local g_NpcInfo = {
	[0] = {szNpcName="朝廷军需官" , fX=255 , fY=250 , CheckID=0x962 },
	[1] = {szNpcName="雷横" , fX=352 , fY=279 , CheckID=0x02626c46 },
	[2] = {szNpcName="关胜" , fX=252 , fY=379 , CheckID=0x02626c45 },
	[3] = {szNpcName="朱仝" , fX=160 , fY=270 , CheckID=0x02626c44 }
}

function GetMissionNPC()
	local nResult = 0
	for i=1,3 do
		if DataPool:UserBag_CountItemByIDTable( g_NpcInfo[i].CheckID ) > 0 then 
			nResult = i
		end
	end
	return nResult
end

function _SMain(...)

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

	while true do

		local nNpcIndex = GetMissionNPC()

		if nNpcIndex > 0 then 
			MoveToNPC( g_NpcInfo[nNpcIndex].fX, g_NpcInfo[nNpcIndex].fY, 0 , g_NpcInfo[nNpcIndex].szNpcName )
			QuestFrameOptionClicked( "上交城防物资" , CMP_FULL_MATCH)	-- 选择选项
			System:Sleep(1000)
		else
			MoveToNPC( g_NpcInfo[0].fX, g_NpcInfo[0].fY, 0 , g_NpcInfo[0].szNpcName )
			Dismount()
			nIndex, idMission, idScript = DataPool:GetPlayerMission( script_name )
			if Player:IsHaveBuff( g_NpcInfo[0].CheckID ) and nIndex ~= -1 then
				--接道具
				QuestFrameOptionClicked( "领取城防物资" , CMP_FULL_MATCH)	-- 选择选项
				System:Sleep(1000)

				local isNext,szMsg = GetDebugMessage()
				while isNext == 1 do
					if string.find(szMsg, "无法领取货物") then
						ShowMessage("取消劳动奖章脚本。") 
						return
					end
					isNext,szMsg = GetDebugMessage()
				end
			else
				if nIndex ~= -1 then
					QuestFrameOptionClicked( script_name , CMP_FULL_MATCH)	-- 选择选项
					QuestFrameMissionComplete()	-- 完成
					System:Sleep(1000)
				else
					if PlayerPackage:GetEmptySlot(1) < 1 then 
						ShowMessage("材料栏已满无法接取任务,自动跳过。")
						return 
					end

					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
			end
		end
	end
end

_SMain()