ShowMessage("上缴战魂玉 $Rev: 214 $")

--[[
[author]
class=3
descript="每周可上缴20个"
]]--
perday_max=1
script_name="上缴战魂玉"

function OnMission()

	while true do 
		
		System:Sleep(500)

		if CityToGuild() == false then
			ShowMessage("没有帮派城市！")
			return
		end
			
		MoveToNPC( 101, 58,-1, "赵明启" )

		local nCount = DataPool:UserBag_CountItemByName("战魂玉")
		if nCount < 1 then
			ShowMessage("战魂玉数量不足，脚本结束！")
			return
		end	

		if nCount > 10 then
			QuestFrameOptionClicked("上缴10个战魂玉", CMP_PART_MATCH)
			ShowMessage("上缴10个战魂玉！")
		elseif nCount > 5  then
			QuestFrameOptionClicked("上缴5个战魂玉", CMP_PART_MATCH)
			ShowMessage("上缴15战魂玉！")
		else
			QuestFrameOptionClicked("上缴1个战魂玉", CMP_PART_MATCH)
			ShowMessage("上缴1个战魂玉！")
		end

		System:Sleep(1500)
		
		local isNext,szMsg = GetDebugMessage()
		while isNext == 1 do

			if string.find(szMsg, "你本周已上缴20个战魂玉") then
				ShowMessage("已经缴纳足够数量的战魂玉，脚本结束！")
				System:UpdateRecord( script_name )
				return
			elseif string.find(szMsg, "你没有未加锁的战魂玉") then
				ShowMessage("战魂玉数量不足，脚本结束！")
				System:UpdateRecord( script_name )
				return
			end

			isNext,szMsg = GetDebugMessage()
		end

		if UI:IsWindowShow("LoginSelectServerQuest") then
			DoLuaString("LoginSelectServerQuest_Env" , "SelectServerQuest_Bn2Click()")
			DoLuaString("LoginSelectServerQuest_Env" , "SelectServerQuest_Frame_OnHiden()")
			ShowMessage("已经缴纳足够数量的战魂玉，脚本结束！")
			System:UpdateRecord( script_name )
			return
		end
	end

end

function _SMain(...)

	local nCount = DataPool:UserBag_CountItemByName("战魂玉")
	if nCount <= 0 then
		ShowMessage("身上没有战魂玉，停止执行脚本")
		return 
	end

	OnMission()

	GuildToCity(0)

end

_SMain()

