x020006_g_scriptId=020006

x020006_g_BeginLevel = 20
x020006_g_IdPuTong={}
x020006_g_IdPuTong[1]={110001, 110012, 110023, 110034, 110045, 110056, 110067, 110078, 110089, 110100, 110111, 110122, 110133, 110144, 110155, 110166, 110177, 110177, 110177, 110177}
x020006_g_IdPuTong[2]={110002, 110013, 110024, 110035, 110046, 110057, 110068, 110079, 110090, 110101, 110112, 110123, 110134, 110145, 110156, 110167, 110178, 110178, 110178, 110178}
x020006_g_IdPuTong[3]={110003, 110014, 110025, 110036, 110047, 110058, 110069, 110080, 110091, 110102, 110113, 110124, 110135, 110146, 110157, 110168, 110179, 110179, 110179, 110179}
x020006_g_IdPuTong[4]={110004, 110015, 110026, 110037, 110048, 110059, 110070, 110081, 110092, 110103, 110114, 110125, 110136, 110147, 110158, 110169, 110180, 110180, 110180, 110180}
x020006_g_IdPuTong[5]={110005, 110016, 110027, 110038, 110049, 110060, 110071, 110082, 110093, 110104, 110115, 110126, 110137, 110148, 110159, 110170, 110181, 110181, 110181, 110181}
x020006_g_IdPuTong[6]={110006, 110017, 110028, 110039, 110050, 110061, 110072, 110083, 110094, 110105, 110116, 110127, 110138, 110149, 110160, 110171, 110182, 110182, 110182, 110182}


x020006_g_IdJingYing={}
x020006_g_IdJingYing[1]={110007, 110018, 110029, 110040, 110051, 110062, 110073, 110084, 110095, 110106, 110117, 110128,110139,110150,110161,110172,110183,110183,110183,110183,110183}
x020006_g_IdJingYing[2]={110008, 110019, 110030, 110041, 110052, 110063, 110074, 110085, 110096, 110107, 110118, 110129,110140,110151,110162,110173,110184,110184,110184,110184,110184}
x020006_g_IdJingYing[3]={110009, 110020, 110031, 110042, 110053, 110064, 110075, 110086, 110097, 110108, 110119, 110130,110141,110152,110163,110174,110185,110185,110185,110185,110185}



x020006_g_JingYingBuff={}
x020006_g_JingYingBuff[1] = {-1,-1, -1,-1, -1,-1}            -- Buff 编号


x020006_g_IdBoss={}
x020006_g_IdBoss[1]={110010, 110021, 110032, 110043, 110054, 110065, 110076, 110087, 110098, 110109, 110120, 110131, 110142, 110153, 110164, 110175, 110186, 110186, 110186, 110186, 110186}


x020006_g_IdBossLuck={}
x020006_g_IdBossLuck[1]={110011, 110022, 110033, 110044, 110055, 110066, 110077, 110088, 110099, 110110, 110121, 110132, 110143, 110154, 110165, 110176, 110187, 110187, 110187, 110187}         
x020006_g_IdBossLuck[2]={110011, 110022, 110033, 110044, 110055, 110066, 110077, 110088, 110099, 110110, 110121, 110132, 110143, 110154, 110165, 110176, 110187, 110187, 110187, 110187}      
x020006_g_IdBossLuck[3]={110011, 110022, 110033, 110044, 110055, 110066, 110077, 110088, 110099, 110110, 110121, 110132, 110143, 110154, 110165, 110176, 110187, 110187, 110187, 110187}      
x020006_g_IdBossLuck[4]={110011, 110022, 110033, 110044, 110055, 110066, 110077, 110088, 110099, 110110, 110121, 110132, 110143, 110154, 110165, 110176, 110187, 110187, 110187, 110187}       

x020006_g_MonsterPosList={}     
x020006_g_MonsterPosList[1]={{36.99,41.55,4.14},{33.36,43.87,4.14},{29.68,45.72,4.14},{30.83,47.52,4.14},{34.51,45.67,4.14},{38.14,43.35,4.14}}
x020006_g_MonsterPosList[2]={{39.24,53.11,4.14},{31.74,49.63,4.14},{35.73,47.59,4.14},{39.29,45.32,4.14},{38.4,48.98,4.14},{35.03,50.63,4.14}}
x020006_g_MonsterPosList[3]={{50.46,81.99,4.09},{54.16,79.96,4.09},{57.91,77.87,4.09},{59.11,80.23,4.09},{55.48,82.55,4.09},{51.8,84.4,4.09}}
x020006_g_MonsterPosList[4]={{63.29,92.47,3.96},{57.24,91.64,3.96},{60.1,88.96,3.96},{62.49,86.44,3.96},{62.56,89.35,3.96},{59.99,91.92,3.96}}
x020006_g_MonsterPosList[5]={{97.67,96.03,3.16},{97.46,100.26,3.16},{96.85,104.9,3.16},{100.34,105.13,3.16},{100.52,100.38,3.16},{100.78,95.66,3.16}}
x020006_g_MonsterPosList[6]={{104,94,3.11},{103.38,96,3.11},{102,92,3.11},{102,98,3.11},{101,94,3.11},{101,91,3.11}}
x020006_g_MonsterPosList[7]={{108.95,44.75,1.98}}
x020006_g_MonsterPosList[8]={{87.13,20.41,0.85}}
		

x020006_g_BossReward={}
x020006_g_BossReward[1] = {100109,100109,100109,100109,100109,100109,100109,100109,100109, 100109, 100109, 100109, 100109, 100109, 100109, 100109, 100109, 100109, 100109, 100109}		   --  Boss 奖励包

x020006_g_luckyBossReward={}
x020006_g_luckyBossReward[1] = {100109,100109,100109,100109,100109,100109,100109,100109,100109, 100109, 100109, 100109, 100109, 100109, 100109, 100109, 100109, 100109, 100109, 100109}

x020006_g_ResurrectionPosList = {}
x020006_g_ResurrectionPosList[1]={{18,18,0.97}}                      -- 复活点坐标

x020006_g_TotalNum = 36							   -- 总的怪物数量	 
x020006_g_CurNum = 0

x020006_g_BossPaoPao = 5019
x020006_g_Bossid = 60003							   --  Boss对话	形象
x020006_g_LuckBossid = 60004					   --  隐藏boss喊话的形象ID
x020006_g_BossTips = 5018

x020006_g_BossLuckPaoPao = 5021					   --  隐藏Boss 对话
x020006_g_BossLuckid = 2
x020006_g_BossLuckTips = 5020

x020006_g_CSParamIdxCurStage=0                     -- 场景切换波数
x020006_g_CSParamIdxCurSubStage=1				   -- 同一场景中的时间点		
x020006_g_CSParamIdxrandtime=2					   -- 隐藏BOSS随机数  副本开始到BOSS总时间戳			
x020006_g_CSParamIdxcurNum = 3					   -- 总的杀怪个数	  
x020006_g_CSParamIdxCamera = 4
x020006_g_CSParamIdxbossStory = 5                  -- boss动画播放结束时间
x020006_g_CSParamIdxluckbossStory = 6 			   -- 隐藏boss动画播放结束时间

x020006_g_CounterId = 8504

x020006_g_BossNumEnumId = 56
x020006_g_luckyBossNumEnumId = 55
x020006_g_AdaptLvlNum = 20
x020006_g_JingYingObjId = 0
x020006_g_JingYingImage = {60000,60001,60002}
x020006_g_JingYingTips = {5022,5023,5024}

function x020006_OnCopySceneTick(scene,tickCount)	
				--副本阶段
	
	local curStage = GetCopySceneParam(scene,x020006_g_CSParamIdxCurStage) +1
	local curSubStage = GetCopySceneParam(scene,x020006_g_CSParamIdxCurSubStage) +1
	local rand = GetCopySceneParam(scene,x020006_g_CSParamIdxrandtime) + 1
	  -- x020006_SetPos(scene, 220)
	  -- SetCopySceneParam(scene, x020006_g_CSParamIdxCamera, 1)
	SetCopySceneParam(scene,x020006_g_CSParamIdxrandtime,rand)
	SetCopySceneParam(scene,x020006_g_CSParamIdxCurSubStage,curSubStage)
	local nAdaptedLvl = math.floor((GetAdaptLvl(scene)-x020006_g_BeginLevel)/5)+1		
	if(nAdaptedLvl > x020006_g_AdaptLvlNum) then
		nAdaptedLvl = x020006_g_AdaptLvlNum
	end 
  	
	if curStage == 1 then
		OnCSMissionStage(scene,curStage-1)
		x020006_Stage_1(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 2 then
		OnCSMissionStage(scene,curStage-1)
		x020006_Stage_2(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 3 then
		OnCSMissionStage(scene,curStage-1)
		x020006_Stage_3(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 4 then
		OnCSMissionStage(scene,curStage-1)
		x020006_Stage_4(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 5 then
		OnCSMissionStage(scene,curStage-1)
		x020006_Stage_5(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 6 then
		OnCSMissionStage(scene,curStage-1)
		x020006_Stage_6(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 7 then
		OnCSMissionStage(scene,curStage-1)
		x020006_Stage_7(scene,curStage,curSubStage,nAdaptedLvl, tickCount)
	elseif curStage == 8 then
		--OnCSMissionStage(scene,curStage-1)
		x020006_Stage_8(scene,curStage,curSubStage,nAdaptedLvl, rand, tickCount)
	elseif curStage >= 9 then
		SetCopySceneSuccess(scene)
	end									
end

function x020006_OnCopySceneOpen(scene)
	 AddCSMission(scene,60001)
	 AddCSMission(scene,60002)
	 AddCSMission(scene,60003)
	 AddCSMission(scene,60004)
	 AddCSMission(scene,60005)
	 AddCSMission(scene,60006)
	 AddCSMission(scene,60007)
end


function  x020006_OnObjDie(scene,objId,rolebaseId,killerId)			
	local MonCount = GetHostileMonsterCount(scene)
	local OldNum = GetCopySceneParam(scene, x020006_g_CSParamIdxcurNum)
	if(0 ~= GetObjType(scene, objId)) then
	SetCopySceneParam(scene, x020006_g_CSParamIdxcurNum, OldNum+1) 
	end
	if(MonCount == 0) then
		local nCurStage = GetCopySceneParam(scene,x020006_g_CSParamIdxCurStage)
--[[		if(nCurStage == 6)    then		
			local nUserCount = GetSceneUserCount(scene)		
			for i=0,nUserCount-1 do
				local nUserObjId = GetUserObjIdByIdx(scene,i)
				local nLvl = GetLevel(scene,nUserObjId)
				local nIdx = math.floor(nLvl/10) + 1

				local oldTime = GetMissionMD(scene, nUserObjId, 4, x020006_g_BossNumEnumId)

				if(GetMissionMD(scene,nUserObjId,4,x020006_g_BossNumEnumId)%100 <= 2) then
					CreatDropBox(scene,nUserObjId, x020006_g_BossReward[1][nIdx])
				end
			end
		end
		]]--
		if(nCurStage == 7)    then															-- 隐藏BOSS奖励次数限制
			local nUserCount = GetSceneUserCount(scene)
			
			for i=0,nUserCount-1 do		
				local nUserObjId = GetUserObjIdByIdx(scene,i)
				local nLvl = GetLevel(scene,nUserObjId)
				local nIdx = math.floor(nLvl/10) + 1
				x020006_CheckMissionMD(scene,nUserObjId,x020006_g_luckyBossNumEnumId)
				local oldTime = GetMissionMD(scene, nUserObjId, 4, x020006_g_luckyBossNumEnumId)
				SetMissionMD(scene, nUserObjId, 4, x020006_g_luckyBossNumEnumId, oldTime+1)
				if(GetMissionMD(scene, nUserObjId, 4, x020006_g_luckyBossNumEnumId)%100 <= 2) then
					CreatDropBox(scene,nUserObjId, x020006_g_luckyBossReward[1][nIdx],objId)
					
				end
			end
			SendAllPlayerServerTips(scene, "#{20034}*")
			x020006_Success(scene)
		end
		SetCopySceneParam(scene,x020006_g_CSParamIdxCurStage,nCurStage+1)
		SetCopySceneParam(scene,x020006_g_CSParamIdxCurSubStage,0)

	end
end

function x020006_CreateJingYingBuff( scene, idx, nlv)	--刷怪（
		local nUserCount = GetSceneUserCount(scene)				
		if idx == 2 then
			
			for i=0,nUserCount-1 do
				local nUserObjId = GetUserObjIdByIdx(scene,i)
				SendImpactToUnit(scene, nUserObjId, x020006_g_JingYingBuff[1][idx])
				SendImpactToUnit(scene, nUserObjId, x020006_g_JingYingBuff[1][idx-1])
			end
		elseif idx > 2  then
			local n = 800
			function sleep(n)
   				if n > 0 then os.execute("ping -n " .. tonumber(n + 1) .. " localhost > NUL") end
			end
			SendImpactToAllByRBID(scene, x020006_g_IdJingYing[idx/2][nlv], x020006_g_JingYingBuff[1][idx-1])
		end
end

function x020006_CreateMonster( scene,idx,camp, nlv)					--刷怪（
	if idx <= #x020006_g_IdPuTong then
		if(0 == idx%2)  then
			CreateMonster(scene,x020006_g_IdJingYing[idx/2][nlv], x020006_g_MonsterPosList[idx][1][3],x020006_g_MonsterPosList[idx][1][1],x020006_g_MonsterPosList[idx][1][2])
			local nUserCount = GetSceneUserCount(scene)
			for i=0,nUserCount-1 do
				local nUserObjId = GetUserObjIdByIdx(scene,i)
				ShowBossTips(scene, nUserObjId, x020006_g_JingYingImage[idx/2], x020006_g_JingYingTips[idx/2],x020006_g_IdJingYing[idx/2][nlv])--喊话
			end
		end
		local nCount = #x020006_g_MonsterPosList[idx]
		for i=((idx+1)%2)+1,nCount do
			local objId = CreateMonster(scene,x020006_g_IdPuTong[idx][nlv],x020006_g_MonsterPosList[idx][i][3],x020006_g_MonsterPosList[idx][i][1],x020006_g_MonsterPosList[idx][i][2])
		end
		
	end
end

function x020006_CheckMissionMD(scene ,objId, type)
	local nLastData = GetMissionMD(scene, objId, 4, type)
	local nNewData = CheckRefreshTime(scene, nLastData, objId, 0)
	if math.floor(nLastData/100) ~= nNewData then
		SetMissionMD(scene, objId, 4, type, nNewData*100)
	end
end

function x020006_Success(scene)									-- 带小号奖励结算
	ShowWinPanel(scene)
	AccoutByCopyScene(scene)	
end

function x020006_Stage_1(scene ,stage,substage, nlv)                      
	if substage == 1 then
		x020006_CreateMonster(scene,stage,3,nlv)
	end
end

function x020006_Stage_2(scene ,stage,substage, nlv)                        
	if(substage == 1) then
		x020006_CreateMonster(scene,stage,3,nlv)
	elseif substage == 2 then
		x020006_CreateJingYingBuff(scene, stage, nlv)
	end
end

function x020006_Stage_3(scene ,stage,substage,nlv)                      
	if substage == 1 then
		x020006_CreateMonster(scene,stage,3,nlv)		
	end
end

function x020006_Stage_4(scene ,stage,substage,nlv)						
	if substage == 1 then
		x020006_CreateMonster(scene,stage,3,nlv)	
	elseif substage == 2 then
		x020006_CreateJingYingBuff(scene, stage, nlv)
	end
end

function x020006_Stage_5(scene ,stage,substage,nlv)					
	if substage == 1 then
		x020006_CreateMonster(scene,stage,3,nlv)	
	end
end

function x020006_Stage_6(scene ,stage,substage,nlv)							
	if substage == 1 then
		x020006_CreateMonster(scene,stage,3,nlv)	
	elseif substage == 2 then
		x020006_CreateJingYingBuff(scene, stage, nlv)
	end
end

function x020006_Stage_7(scene ,stage,substage,nlv, tickcount)	
	local tick = GetCopySceneParam(scene, x020006_g_CSParamIdxbossStory)
	if substage == 1 then
		StoryAnimation(scene, 6020)
		SetCopySceneParam(scene, x020006_g_CSParamIdxbossStory,tickcount + 10)
	--elseif substage == 2 then
--		 RecoverCamera(scene)
	elseif tick ~= 0 and tickcount == tick + 1 then
		local nUserCount = GetSceneUserCount(scene)
		for i=0,nUserCount-1 do
			local nUserObjId = GetUserObjIdByIdx(scene,i)
			ShowBossTips(scene, nUserObjId, x020006_g_Bossid, x020006_g_BossTips, x020006_g_IdBoss[1][nlv])
		end
	elseif tick ~= 0 and tickcount == tick + 2 then
		local nObjId = CreateMonster(scene,x020006_g_IdBoss[1][math.floor((GetAdaptLvl(scene)-x020006_g_BeginLevel)/5)+1],x020006_g_MonsterPosList[7][1][3], x020006_g_MonsterPosList[7][1][1],x020006_g_MonsterPosList[7][1][2])
		SetNpcCampByObjId(scene,nObjId,1)
	elseif tick ~= 0 and tickcount == tick + 3 then
		NpcPaoPaoByRBId(scene,x020006_g_IdBoss[1][math.floor((GetAdaptLvl(scene)-x020006_g_BeginLevel)/5)+1],x020006_g_BossPaoPao)
	elseif tick ~= 0 and tickcount == tick + 4 then
		SetNpcCampByRBId(scene,x020006_g_IdBoss[1][math.floor((GetAdaptLvl(scene)-x020006_g_BeginLevel)/5)+1],3)
	end
end

function x020006_Stage_8(scene ,stage,substage,nlv, rand, tickcount)	
	local tick = GetCopySceneParam(scene, x020006_g_CSParamIdxluckbossStory)					
	if substage == 1 then
		math.randomseed(rand)
		local nRand = math.random(1,10000)
		
		if nRand < 10000 then
			StoryAnimation(scene, 6021)
			SetCopySceneParam(scene, x020006_g_CSParamIdxluckbossStory,tickcount + 10)
		else 
			x020006_Success(scene)
			local nUserCount = GetSceneUserCount(scene)
			local nCurStage = GetCopySceneParam(scene,x020006_g_CSParamIdxCurStage)
			for i=0,nUserCount-1 do
				local nUserObjId = GetUserObjIdByIdx(scene,i)
			end
			SendAllPlayerServerTips(scene, "#{20035}*")
			SetCopySceneParam(scene,x020006_g_CSParamIdxCurStage,nCurStage+1)
			SetCopySceneParam(scene,x020006_g_CSParamIdxCurSubStage,0)
		end
	elseif tick ~= 0 and tickcount == tick + 1 then
		local nRand2 = math.random(1,4)
		local nObjId = CreateMonster(scene,x020006_g_IdBossLuck[nRand2][math.floor((GetAdaptLvl(scene)-x020006_g_BeginLevel)/5)+1],x020006_g_MonsterPosList[8][1][3], x020006_g_MonsterPosList[8][1][1],x020006_g_MonsterPosList[8][1][2])
		SetNpcCampByObjId(scene,nObjId,1)
		local nUserCount = GetSceneUserCount(scene)
		for i=0,nUserCount-1 do
			local nUserObjId = GetUserObjIdByIdx(scene,i)
			ShowBossTips(scene, nUserObjId, x020006_g_LuckBossid, x020006_g_BossLuckTips, x020006_g_IdBossLuck[nRand2][math.floor((GetAdaptLvl(scene)-x020006_g_BeginLevel)/5)+1])
			AcceptMission(scene,nUserObjId,60008)
		end
	elseif tick ~= 0 and tickcount == tick + 2 then
		NpcPaoPaoByRBId(scene,x020006_g_IdBossLuck[1][math.floor((GetAdaptLvl(scene)-x020006_g_BeginLevel)/5)+1],x020006_g_BossLuckPaoPao)
	elseif tick ~= 0 and tickcount == tick + 3 then
		SetNpcCampByRBId(scene,x020006_g_IdBossLuck[1][math.floor((GetAdaptLvl(scene)-x020006_g_BeginLevel)/5)+1],3)
	end
end
function x020006_OnObjresurrectionEnd(scene ,objId)
		SetPos(scene,objId,115,9, 0)
end
function x020006_OnStoryEventEnd(scene,nStoryId,nAnimationId)
		if nAnimationId == 6020 then
			local tick = GetCopySceneParam(scene, 9)
			local originaltick = GetCopySceneParam(scene, x020006_g_CSParamIdxbossStory)
			if tick < originaltick  then
				SetCopySceneParam(scene, x020006_g_CSParamIdxbossStory, tick)
			end
		end

		if nAnimationId == 6021 then
			local tick = GetCopySceneParam(scene, 9)
			local originaltick = GetCopySceneParam(scene, x020006_g_CSParamIdxluckbossStory)
			if tick < originaltick  then
				SetCopySceneParam(scene, x020006_g_CSParamIdxluckbossStory, tick)
			end
		end
end
