x020035_g_scriptId=020035

x020035_g_BeginLevel = 0
x020035_g_IdPuTong={}
x020035_g_IdPuTong[1]={{202001,202002,202003,202004,202005,202006,202007,202008,202009,202010,202011,202012,202013,202014,202015,202016,202017,202018,202019,202020},{202001,202002,202003,202004,202005,202006,202007,202008,202009,202010,202011,202012,202013,202014,202015,202016,202017,202018,202019,202020},{202001,202002,202003,202004,202005,202006,202007,202008,202009,202010,202011,202012,202013,202014,202015,202016,202017,202018,202019,202020},{202001,202002,202003,202004,202005,202006,202007,202008,202009,202010,202011,202012,202013,202014,202015,202016,202017,202018,202019,202020},{202001,202002,202003,202004,202005,202006,202007,202008,202009,202010,202011,202012,202013,202014,202015,202016,202017,202018,202019,202020},{202001,202002,202003,202004,202005,202006,202007,202008,202009,202010,202011,202012,202013,202014,202015,202016,202017,202018,202019,202020},{202001,202002,202003,202004,202005,202006,202007,202008,202009,202010,202011,202012,202013,202014,202015,202016,202017,202018,202019,202020},{202001,202002,202003,202004,202005,202006,202007,202008,202009,202010,202011,202012,202013,202014,202015,202016,202017,202018,202019,202020},{202001,202002,202003,202004,202005,202006,202007,202008,202009,202010,202011,202012,202013,202014,202015,202016,202017,202018,202019,202020}}    -- 小怪的编号
x020035_g_AdaptLvlNum = 20

x020035_g_IdBoss ={}
x020035_g_IdBoss[1] = {{203001,203002,203003,203004,203005,203006,203007,203008,203009,203010,203011,203012,203013,203014,203015,203016,203017,203018,203019,203020}}

x020035_g_MonsterPosList={}     
x020035_g_MonsterPosList[1]={{60,60,1.26}}		    --   Boss坐标
x020035_g_MonsterPosList[2]={{60,60,1.26},{60,60,1.26},{60,60,1.26},{60,60,1.26},{60,60,1.26},{60,60,1.26},{60,60,1.26},{60,60,1.26},{60,60,1.26}}			-- 	 召唤小怪坐标

x020035_g_ResurrectionPosList = {}
x020035_g_ResurrectionPosList[1]={{363.5,199.3,3.14}}                      -- 复活点坐标


						    
x020035_g_BossTips = 10309       --  Boss召怪喊话	
x020035_g_BossFakeObjId = 60605

x020035_g_CSParamIdxCurStage=0                     -- 场景切换波数
x020035_g_CSParamIdxCurSubStage=1				   -- 同一场景中的时间点		
x020035_g_CSParamIdxrandtime=2					   -- 隐藏BOSS随机数  副本开始到BOSS总时间戳			
x020035_g_CSParamIdxcurNum = 3					   -- 总的杀怪个数	  
x020035_g_CSParamIdBoss = 4                        
x020035_g_CSParamBossroleId = 5 

x020035_g_CounterId = 8504

x020035_g_BossNumEnumId = 55
x020035_g_luckyBossNumEnumId = 56
function x020035_OnCopySceneTick(scene,tickCount)					--副本阶段
	local curStage = GetCopySceneParam(scene,x020035_g_CSParamIdxCurStage) +1
	local curSubStage = GetCopySceneParam(scene,x020035_g_CSParamIdxCurSubStage) +1
	local rand = GetCopySceneParam(scene,x020035_g_CSParamIdxrandtime) + 1

	SetCopySceneParam(scene,x020035_g_CSParamIdxrandtime,rand)
	SetCopySceneParam(scene,x020035_g_CSParamIdxCurSubStage,curSubStage)
  	
	local nAdaptedLvl = math.floor(GetAdaptLvl(scene)/5)		
	if(nAdaptedLvl > x020035_g_AdaptLvlNum) then
		nAdaptedLvl = x020035_g_AdaptLvlNum
	end

	if(tickCount == 0)  then
		local nUserCount = GetSceneUserCount(scene)	
    	for i=0,nUserCount-1 do
			local nUserObjId = GetUserObjIdByIdx(scene,i)
			if GetUserCsParm(scene, 0, nUserObjId) ~= 0   then
				local BossId = GetUserCsParm(scene, 0, nUserObjId)
				SetUserCsParm(scene, nUserObjId, 0, 0)
				SetCopySceneParam(scene, x020035_g_CSParamBossroleId, BossId)
			end
		end		
	end	

	local BossId = GetObjIdByRoleBase(scene, x020035_g_IdBoss[1][1][nAdaptedLvl])		
	if curStage == 1 then
		x020035_Stage_1(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 2 then
		SetCopySceneSuccess(scene)
	end		
			
	if (0 == tickCount%30 and 0 ~= GetCopySceneParam(scene, x020035_g_CSParamIdBoss) and tickCount ~= 0 and MonIsBattle(scene, x020035_g_IdBoss[1][1][nAdaptedLvl]) )  then
		local nUserCount = GetSceneUserCount(scene)		
		for i=0,nUserCount-1 do
			local nUserObjId = GetUserObjIdByIdx(scene,i)
			ShowBossTips(scene, nUserObjId, x020035_g_BossFakeObjId, x020035_g_BossTips, x020035_g_IdBoss[1][1][nAdaptedLvl])
		end		
		local MonNum = #x020035_g_IdPuTong[1]
		local index =  (tickCount/30)%MonNum
		local MonId = CreateMonster(scene, x020035_g_IdPuTong[1][index][nAdaptedLvl], x020035_g_MonsterPosList[2][index][3],x020035_g_MonsterPosList[2][index][1],x020035_g_MonsterPosList[2][index][2])
	end
end

function  x020035_OnObjDie(scene,objId,rolebaseId,killerId)			
	local MonCount = GetHostileMonsterCount(scene)
	local nCurStage = GetCopySceneParam(scene, x020035_g_CSParamIdxCurStage)
	local BossId = GetCopySceneParam(scene, x020035_g_CSParamIdBoss)

	if nCurStage == 0 and MonCount == 0 then
		SetCopySceneParam(scene,x020035_g_CSParamIdxCurStage,nCurStage+1)
		SetCopySceneParam(scene,x020035_g_CSParamIdxCurSubStage,0)
		SetCopySceneParam(scene,x020035_g_CSParamIdBoss, 0)
		AccoutByCopyScene(scene)
		ShowWinPanel(scene)
		local nUserCount = GetSceneUserCount(scene)
		for i=0,nUserCount-1 do		
			local nUserObjId = GetUserObjIdByIdx(scene,i)
			x020035_CheckMissionMD(scene, nUserObjId, 59)

			local oldTime = GetMissionMD(scene, nUserObjId, 4, 59)
			SetMissionMD(scene, nUserObjId, 4, 59, oldTime+1)


			if(GetMissionMD(scene,nUserObjId,4,59)%100 <= 2) then
				CreatDropBox(scene,nUserObjId, 9999,objId)
			end
		end
	end
end

function x020035_CheckMissionMD(scene ,objId, type)
	local nLastData = GetMissionMD(scene, objId, 3, type)
	local nNewData = CheckRefreshTime(scene, nLastData, objId, 0)       -- 参数为0代表每天更新
	if math.floor(nLastData/100) ~= nNewData then
		SetMissionMD(scene, objId, 3, type, nNewData*100)
	end
end

function x020035_CreateMonster( scene,idx,camp, nlv)					--刷怪（
	local objId = CreateMonster(scene, x020035_g_IdBoss[1][1][nlv],x020035_g_MonsterPosList[idx][1][3],x020035_g_MonsterPosList[idx][1][1],x020035_g_MonsterPosList[idx][1][2])
	SetNpcCampByObjId(scene,objId,camp)
	return objId
end

function x020035_Stage_1(scene ,stage,substage, nlv)  
	                  
	if substage == 1 then
		local BossObjId = x020035_CreateMonster(scene,stage,3,nlv)
	--	StartClientStory(scene,5006)
	--	SetNpcCampByObjId(scene,BossObjId,3)
		SetCopySceneParam(scene, x020035_g_CSParamIdBoss, BossObjId)
	end
end

function x020035_OnObjresurrectionEnd(scene ,objId)
		SetPos(scene,objId,363.5,199.3)
end

