ShowMessage("每日聚宝盆活动脚本 $Rev: 1 $")

local g_szJuBaoPen = ""
local g_Position = {
{52,89},{100,147},{147,90}
}

--开采宝石
--投入宝石

function GetJuBaoPenName()
	local Id,szName = LockNearestTarget("聚宝盆",CHA_TYPE_NPC|CHA_RELATION_FRIEND ,CMP_PART_MATCH)
	
	if Id == -1 then
		return ""
	end
	return szName
end

function OnProcedure()
	
	-- 判断是否挖到翡翠
	if Player_GetBuff("运送翡翠原石") ~= -1 then
		MoveTo(100, 79, -1, "", 3, false)

		if g_szJuBaoPen == "" then
			MoveTo(100, 79, -1)
			g_szJuBaoPen = GetJuBaoPenName()
			return true
		end

		local Id = FindCharacterByName(g_szJuBaoPen)
		Player_UseSkill_Collect(3107, Id)
		return true
	end

	-- 判断是否变身
	if Player_GetBuff("矿工") == -1 then

		if g_szJuBaoPen == "" then

			MoveTo(100, 79, -1)
			g_szJuBaoPen = GetJuBaoPenName()

		else

			Dismount()
			MoveToNPC(100, 79, -1, g_szJuBaoPen)

			if Player_GetBuff("运送翡翠原石") ~= -1 or Player_GetBuff("矿工") ~= -1 then
				return true
			end

			if FindQuestFrameOption("我要变身矿工", CMP_FULL_MATCH) then
				
				if Guild:GetGuildContri() < 50 then
					ShowMessage("帮会贡献度少于50！")
					return false
				end

				QuestFrameOptionClicked("我要变身矿工", CMP_FULL_MATCH)
				QuestFrameOptionClicked("首次变身矿工", CMP_FULL_MATCH)
				--System:Sleep(1000)
				return ture

			elseif FindQuestFrameOption("再次变身矿工", CMP_FULL_MATCH) == false then

				QuestFrameOptionClicked("领取翡翠心精", CMP_FULL_MATCH)
				QuestFrameOptionClicked("直接领取翡翠心精", CMP_FULL_MATCH)
				System:Sleep(1500)

				local isNext,szMsg = GetDebugMessage()
				while isNext == 1 do
					if string.find(szMsg, "您已领取过翡翠心精") then
						return false
					end
					isNext,szMsg = GetDebugMessage()
				end

				return ture
			end

			QuestFrameOptionClicked("再次变身矿工", CMP_FULL_MATCH)
			--System:Sleep(1000)
		end

		return ture
	end

	-- 挖翡翠原石
	--[[
	math.randomseed(os.time())
	local idx = math.random(1, 3)

	if g_Position[idx] == nil then
		ShowMessage("数据错误！")
		return false
	end
	]]--
	
	MoveTo(g_Position[2][1], g_Position[2][2], -1, "", 4, false)
	Player_UseSkill_Collect(3106)

end

function _SMain(...)

	while true do

		-- 进入帮派城市
		if CityToGuild() == false then
			ShowMessage("没有帮派城市！")
			break 
		end

		if OnProcedure() == false then
			break
		end

		System:Sleep(500)
	end

	GuildToCity(0)
end

_SMain()