x020072_g_scriptId = 020072

x020072_g_MonsterId = {} -- 每波怪物的Id
x020072_g_MonsterId[1] = {500200,500200,500200,500200,500200,500200,500200,500200}
x020072_g_MonsterId[2] = {500300,500300,500300,500300,500300,500300,500300,500300}
x020072_g_MonsterId[3] = {500500}
x020072_g_MonsterId[4] = {500600,500600,500600}


x020072_g_MonsterPos = {} -- 每波怪物的出生位置
x020072_g_MonsterPos[1] = {{62.38,26.92,-1.57},{58.39,27.46,-1.57},{66.54,27.38,-1.57},{71.38,26.83,-1.57},{71.85,31.69,-1.57},{66.56,32.04,-1.57},{61.92,32.21,-1.57},{58.06,32.03,-1.57}}
x020072_g_MonsterPos[2] = {{57.64,36.24,-1.57},{62.35,35.61,-1.57},{66.36,35.83,-1.57},{71.19,35.53,-1.57},{71.3,39,-1.57},{66.47,39.3,-1.57},{62.46,39.08,-1.57},{57.75,39.71,-1.57}}
x020072_g_MonsterPos[3] = {{66.59,70.85,-1.57}}
x020072_g_MonsterPos[4] = {{74.92,76.64,0.53},{67.5,81.68,1.51},{59.61,77.99,-0.72}}
x020072_g_BossFakeObjId = 60010
x020072_g_BossTipsId = 120002
x020072_g_Stage = 7

x020072_g_Role_1 = 2
x020072_g_Role_2 = 3
x020072_g_Role_3 = 4
x020072_g_Time = 1
x020072_g_Stage_2 = 0
x020072_g_MonsterRoleBaseId = {}
x020072_g_MonsterRoleBaseId[1] = {500200}
x020072_g_MonsterRoleBaseId[2] = {500300}
x020072_g_MonsterRoleBaseId[3] = {500500}
x020072_g_MonsterRoleBaseId[4] = {500600}

function x020072_OnCopySceneOpen(scene)
	SetCopySceneParam(scene,x020072_g_Stage,0)
	SetCopySceneParam(scene,x020072_g_Stage_2,1)
    x020072_g_Init(scene)
end
function x020072_g_Init(scene)
	local nUserCount = GetSceneUserCount(scene)
	for j=0,nUserCount-1 do   
		local nUserObjId = GetUserObjIdByIdx(scene,j)   
		SynCsStageData(scene, nUserObjId)
	end
end
function x020072_OnCopySceneTick(scene,tickCount)
	local nCurStage = GetCopySceneParam(scene,x020072_g_Stage)+1
	if(nCurStage == 5) then
		SetCopySceneParam(scene,x020072_g_Stage,nCurStage+1)
		local nUserCount = GetSceneUserCount(scene)
		for i=0,nUserCount-1 do
			local nUserObjId = GetUserObjIdByIdx(scene,i)
			HuanTianShenDianEnd(scene,nUserObjId,true)
			SetCopySceneSuccess(scene)
		end
	end
		local nCurStage = GetCopySceneParam(scene,x020072_g_Stage)
	local xCurStage = GetCopySceneParam(scene,x020072_g_Stage_2)
	if nCurStage == 0 then
		if( xCurStage == 1) then
		SetCopySceneParam(scene,x020072_g_Stage_2,0)
		local nCurStage = GetCopySceneParam(scene,x020072_g_Stage)
		local nUserCount = GetSceneUserCount(scene)
    	local MonsterLevelId = math.floor(GetAdaptLvl(scene)/10)
    	if MonsterLevelId > 60 then
    		MonsterLevelId = 60
    	end
		local nCountMonsterId = #x020072_g_MonsterId[nCurStage+1]
		for i=1,nCountMonsterId do
			CreateMonster(scene,x020072_g_MonsterId[nCurStage+1][i]+MonsterLevelId,x020072_g_MonsterPos[nCurStage+1][i][3],x020072_g_MonsterPos[nCurStage+1][i][1],x020072_g_MonsterPos[nCurStage+1][i][2])
		end
	end
end
end

function x020072_OnObjEnter(scene,objId)
	AutoCombat(scene,objId,true)
end

function x020072_OnCopySceneTimeOut(scene)
	local nUserCount = GetSceneUserCount(scene)
	for i=0,nUserCount-1 do
		local nUserObjId = GetUserObjIdByIdx(scene,i)
		HuanTianShenDianEnd(scene,nUserObjId,false)
	end
	SetCopySceneFail(scene)
end

function x020072_OnObjDie(scene,objId,rolebaseId,killerId)
	local MonCount = GetHostileMonsterCount(scene)
	RecordExp(scene,rolebaseId)
    local MonsterLevelId = math.floor(GetAdaptLvl(scene)/10)
    if MonsterLevelId > 60 then
   		MonsterLevelId = 60
   	end
	local nCurStage = GetCopySceneParam(scene,x020072_g_Stage)+1
	local nMonsterCount = #x020072_g_MonsterRoleBaseId[nCurStage]
	for i = 1,nMonsterCount do
		if (rolebaseId == x020072_g_MonsterRoleBaseId[nCurStage][i]+MonsterLevelId) then
			local OldNum = GetCopySceneParam(scene,i+1)
			SetCopySceneParam(scene,i+1,OldNum+1)
		end	
	end
	local nUserCount = GetSceneUserCount(scene)
	for j=0,nUserCount-1 do   
		local nUserObjId = GetUserObjIdByIdx(scene,j)   
		SynCsStageData(scene, nUserObjId)
	end


	if(MonCount == 0) then
		SetCopySceneParam(scene,x020072_g_Stage,nCurStage)

		for i=0,nUserCount-1 do
			local nUserObjId = GetUserObjIdByIdx(scene,i)
				HuanTianShenDianStage(scene,nUserObjId)
		end
		if(nCurStage < 4) then
			SetCopySceneParam(scene,x020072_g_Role_1,0)
			SetCopySceneParam(scene,x020072_g_Role_2,0)
			SetCopySceneParam(scene,x020072_g_Role_3,0)
			for j=0,nUserCount-1 do   
				local nUserObjId = GetUserObjIdByIdx(scene,j)   
				SynCsStageData(scene, nUserObjId)
			end
			local nCountMonsterId = #x020072_g_MonsterId[nCurStage+1]
			for i=1,nCountMonsterId do
				CreateMonster(scene,x020072_g_MonsterId[nCurStage+1][i]+MonsterLevelId,x020072_g_MonsterPos[nCurStage+1][i][3],x020072_g_MonsterPos[nCurStage+1][i][1],x020072_g_MonsterPos[nCurStage+1][i][2])
			end
			if(nCurStage == 2) then
			
				--local nUserCount = GetSceneUserCount(scene)
				for i=0,nUserCount-1 do
				    local nUserObjId = GetUserObjIdByIdx(scene,i)
				    ShowBossTips(scene, nUserObjId, x020072_g_BossFakeObjId, x020072_g_BossTipsId)
				end
			end
		end
	end
end