x020074_g_scriptId = 020074

x020074_g_MonsterId = {} -- 每波怪物的Id
x020074_g_MonsterId[1] = {2000000,2000000,2000000,2000000,2000000,2000000,2000000,2000000}
x020074_g_MonsterId[2] = {2010000,2010000,2010000,2010000,2010000,2010000,2010000,2010000}
x020074_g_MonsterId[3] = {2020000}
x020074_g_MonsterId[4] = {2030000,2030000,2030000}


x020074_g_MonsterPos = {} -- 每波怪物的出生位置
x020074_g_MonsterPos[1] = {{118.24,288.44,-0.998},{118.6,293.43,-0.998},{114.56,293.43,-0.998},{114.72,297.25,-0.998},{117.02,298.79,-0.998},{113.67,301.28,-0.998},{117.02,302.01,-0.998},{114.65,303.84,-0.998}}
x020074_g_MonsterPos[2] = {{114.88,309.46,-1.075},{111.73,309.4559,-1.075},{111.73,313.53,-1.075},{114.66,314.42,-1.075},{113.05,317.91,-1.075},{110.85,320.09,-1.075},{112.52,326.34,-1.075},{110.02,326.67,-1.075}}
x020074_g_MonsterPos[3] = {{109.11,341.85,-1.268}}
x020074_g_MonsterPos[4] = {{108.26,346.82,-1.7323},{104.41,341.34,-1.7323},{113.33,341.95,-1.7323}}
x020074_g_BossFakeObjId = 220001
x020074_g_BossTipsId = 122001
x020074_g_Stage = 7
x020074_g_SubStage = 5

x020074_g_Role_1 = 2
x020074_g_Role_2 = 3
x020074_g_Role_3 = 4
x020074_g_Time = 1
x020074_g_Stage_2 = 0
x020074_g_MonsterRoleBaseId = {}
x020074_g_MonsterRoleBaseId[1] = {2000000}
x020074_g_MonsterRoleBaseId[2] = {2010000}
x020074_g_MonsterRoleBaseId[3] = {2020000}
x020074_g_MonsterRoleBaseId[4] = {2030000}

x020074_g_AdapteLvl = 60

x020074_g_DropId = {}
x020074_g_DropId[1] = {290031, 290032, 290033, 290034}

function x020074_OnCopySceneOpen(scene)
	SetCopySceneParam(scene,x020074_g_Stage,0)
	SetCopySceneParam(scene,x020074_g_SubStage,0)
	SetCopySceneParam(scene,x020074_g_Stage_2,1)
    x020074_g_Init(scene)
end
function x020074_g_Init(scene)
	local nUserCount = GetSceneUserCount(scene)
	for j=0,nUserCount-1 do   
		local nUserObjId = GetUserObjIdByIdx(scene,j)   
		SynCsStageData(scene, nUserObjId)
	end
end
function x020074_OnCopySceneTick(scene,tickCount)

	local nCurStage = GetCopySceneParam(scene,x020074_g_Stage)+1
	local nCurSubStage = GetCopySceneParam(scene,x020074_g_SubStage) + 1
	SetCopySceneParam(scene,x020074_g_SubStage,nCurSubStage)

	if(nCurStage == 5) then
		SetCopySceneParam(scene,x020074_g_Stage,nCurStage+1)
		local nUserCount = GetSceneUserCount(scene)
		for i=0,nUserCount-1 do
			local nUserObjId = GetUserObjIdByIdx(scene,i)
			GuDiMiJingEnd(scene,nUserObjId,true)
			SetCopySceneSuccess(scene)
		end
	end
	local nCurStage = GetCopySceneParam(scene,x020074_g_Stage)
	local xCurStage = GetCopySceneParam(scene,x020074_g_Stage_2)
	if nCurStage == 0 then
		if nCurSubStage == 1 then
			if( xCurStage == 1) then
				SetCopySceneParam(scene,x020074_g_Stage_2,0)
				local nCurStage = GetCopySceneParam(scene,x020074_g_Stage)
				local nUserCount = GetSceneUserCount(scene)
    			local MonsterLevelId = math.floor(GetAdaptLvl(scene)/10)

    			if MonsterLevelId > x020074_g_AdapteLvl then
    				MonsterLevelId = x020074_g_AdapteLvl
    			end

				local nCountMonsterId = #x020074_g_MonsterId[nCurStage+1]
				for i=1,nCountMonsterId do
					--print("MonsterId", x020074_g_MonsterId[nCurStage+1][i]+MonsterLevelId)
					CreateMonster(scene,x020074_g_MonsterId[nCurStage+1][i]+MonsterLevelId,x020074_g_MonsterPos[nCurStage+1][i][3],x020074_g_MonsterPos[nCurStage+1][i][1],x020074_g_MonsterPos[nCurStage+1][i][2])
				end
			end
		end
	end
end

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

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

function x020074_OnObjDie(scene,objId,rolebaseId,killerId)
	local MonCount = GetHostileMonsterCount(scene)
	RecordExp(scene,rolebaseId)

	local MonsterLevelId = math.floor(GetAdaptLvl(scene)/10)
	if MonsterLevelId > x020074_g_AdapteLvl then
    	MonsterLevelId = x020074_g_AdapteLvl
    end

	local nCurStage = GetCopySceneParam(scene,x020074_g_Stage)+1
	local nMonsterCount = #x020074_g_MonsterRoleBaseId[nCurStage]
	for i = 1,nMonsterCount do
		if (rolebaseId == x020074_g_MonsterRoleBaseId[nCurStage][i]+MonsterLevelId) then
			local OldNum = GetCopySceneParam(scene,i+1)
			SetCopySceneParam(scene,i+1,OldNum+1)
			local nUserCount = GetSceneUserCount(scene)
			for k = 0,nUserCount-1 do		
				local nUserObjId = GetUserObjIdByIdx(scene,k)
				--print("DropID : ", x020074_g_DropId[1][nCurStage], "rolebaseId : ", rolebaseId, " nCurStage :", nCurStage)
				CreatDropBox(scene, nUserObjId, x020074_g_DropId[1][nCurStage], objId)
			end

		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,x020074_g_Stage,nCurStage)
		SetCopySceneParam(scene,x020074_g_SubStage,0)

		for i=0,nUserCount-1 do
			local nUserObjId = GetUserObjIdByIdx(scene,i)
				HuanTianShenDianStage(scene,nUserObjId)
		end
		if(nCurStage < 4) then
			SetCopySceneParam(scene,x020074_g_Role_1,0)
			SetCopySceneParam(scene,x020074_g_Role_2,0)
			SetCopySceneParam(scene,x020074_g_Role_3,0)
			for j=0,nUserCount-1 do   
				local nUserObjId = GetUserObjIdByIdx(scene,j)   
				SynCsStageData(scene, nUserObjId)
			end

			

			local nCountMonsterId = #x020074_g_MonsterId[nCurStage+1]
			for i=1,nCountMonsterId do
				--print("MonsterId", x020074_g_MonsterId[nCurStage+1][i]+MonsterLevelId)
				CreateMonster(scene,x020074_g_MonsterId[nCurStage+1][i]+MonsterLevelId,x020074_g_MonsterPos[nCurStage+1][i][3],x020074_g_MonsterPos[nCurStage+1][i][1],x020074_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, x020074_g_BossFakeObjId, x020074_g_BossTipsId)
				end
			end
		end
	end
end