x020075_g_scriptId = 020075

x020075_g_MonsterId = {} -- 每波怪物的Id
x020075_g_MonsterId[1] = {502100,502100,502100,502100}

x020075_g_BossId = 502000
x020075_g_BossPos = {}
x020075_g_BossPos[1] ={{101.17,42.24,1.57}}

x020075_g_MonsterPos = {} -- 每波怪物的出生位置
x020075_g_MonsterPos[1] = {{111.11,37,1.57},{104.96,37,1.57},{97.06,37,1.57},{90.48,37,1.57}}

x020075_g_BossFakeObjId = 30019
x020075_g_BossTipsId = 120102

x020075_g_Stage = 7
x020075_g_SubStage = 5
x020075_g_Role_1 = 2
x020075_g_Role_2 = 3
x020075_g_Role_3 = 4
x020075_g_Time = 1
x020075_g_Stage_2 = 0

x020075_g_MonsterRoleBaseId = {}
x020075_g_MonsterRoleBaseId[1] = {502000,502100}
x020075_g_MonsterRoleBaseId[2] = {502100}

x020075_g_AdapteLvl = 60

function x020075_OnCopySceneOpen(scene)
	SetCopySceneParam(scene,x020075_g_Stage,0)
	SetCopySceneParam(scene,x020075_g_SubStage,0)
	SetCopySceneParam(scene,x020075_g_Stage_2,1)
    x020075_g_Init(scene)
end
function x020075_g_Init(scene)
	local nUserCount = GetSceneUserCount(scene)
	for j=0,nUserCount-1 do   
		local nUserObjId = GetUserObjIdByIdx(scene,j)   
		SynCsStageData(scene, nUserObjId)
	end
end
function x020075_OnCopySceneTick(scene,tickCount)
	local nCurStage = GetCopySceneParam(scene,x020075_g_Stage)+1
	local nCurSubStage = GetCopySceneParam(scene,x020075_g_SubStage)+1
	SetCopySceneParam(scene,x020075_g_SubStage,nCurSubStage)

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

    			if MonsterLevelId > x020075_g_AdapteLvl then
    				MonsterLevelId = x020075_g_AdapteLvl
    			end
    			
				local nCountMonsterId = #x020075_g_MonsterId[nCurStage+1]
				--4个小怪
				for i=1,nCountMonsterId do
					CreateMonster(scene,x020075_g_MonsterId[nCurStage+1][i]+MonsterLevelId,x020075_g_MonsterPos[nCurStage+1][i][3],x020075_g_MonsterPos[nCurStage+1][i][1],x020075_g_MonsterPos[nCurStage+1][i][2])
				end
				--boss
				CreateMonster(scene,x020075_g_BossId+MonsterLevelId,x020075_g_BossPos[1][1][3],x020075_g_BossPos[1][1][1],x020075_g_BossPos[1][1][2])
				for i=0,nUserCount-1 do
					local nUserObjId = GetUserObjIdByIdx(scene,i)
					ShowBossTips(scene, nUserObjId, x020075_g_BossFakeObjId, x020075_g_BossTipsId)
				end
			end
		end
	end
end

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

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

function x020075_OnObjDie(scene,objId,rolebaseId,killerId)
	local MonCount = GetHostileMonsterCount(scene)
	RecordExp(scene,rolebaseId)
	
	local MonsterLevelId = math.floor(GetAdaptLvl(scene)/10)
	if MonsterLevelId > x020075_g_AdapteLvl then
    	MonsterLevelId = x020075_g_AdapteLvl
    end

	local nCurStage = GetCopySceneParam(scene,x020075_g_Stage)+1
	local nMonsterCount = #x020075_g_MonsterRoleBaseId[nCurStage]
	for i = 1,nMonsterCount do
		if (rolebaseId == x020075_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)
			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,x020075_g_Stage,nCurStage)
		SetCopySceneParam(scene,x020075_g_SubStage,0)

		for i=0,nUserCount-1 do
			local nUserObjId = GetUserObjIdByIdx(scene,i)
			HuanTianShenDianStage(scene,nUserObjId)
		end
	end
end