x020193_g_scriptId=020193

x020193_g_MonsterRoundMax = 3		--小怪最大波数
x020193_g_MonsterNum = 10			--每波小怪数量

x020193_g_CSParamIdRound = 2		--小怪波数记录
x020193_g_CSParamIdKillNum = 4		--击杀怪物数目

x020193_g_MonsterRoleIdStart = 21000000
x020193_g_BossRoleIdStart = 20000000

x020193_g_MonsterBornPosList={}
x020193_g_MonsterBornPosList[1]={{44.88,66.81,180},{47.77,67.63,180},{50.54,66.71,180},{50.72,68.26,180},{51.8,69.86,180},{48.3,70.11,180},{45.75,69.2,180},{51.34,71.82,180},{45.62,71.5,180},{47.9,73,180}}
x020193_g_MonsterBornPosList[2]={{37.38,111.1,180},{40.27,111.92,180},{43.04,111,180},{43.22,112.5,180},{44.3,114.15,180},{40.8,114.4,180},{40.8,114.4,180},{43.84,116.11,180},{40.45,117.28,180},{38.12,115.8,180}}
x020193_g_MonsterBornPosList[3]={{57.58,140.5,180},{60.47,141.32,180},{63.24,140.4,180},{63.42,141.95,180},{61,143.8,180},{64.04,145.51,180},{60.67,146.68,180},{58.32,145.25,180},{58.45,142.89,180},{60.47,139.01,180}}

x020193_g_BigBossPos = { 114.3,146.41,-90 }
							
function x020193_OnObjEnter(scene,objId)
	--AutoCombat(scene,objId,true)
	SynCsStageData(scene, objId)
end

function x020193_OnCopySceneOpen(scene)

end

--副本Tick
function x020193_OnCopySceneTick(scene,tickCount)
	local stage = GetCopySceneParam(scene,7)
	local monsterLv = GetCopySceneEnterParam(scene,1)
	local MonsterRoleId = x020193_g_MonsterRoleIdStart + monsterLv
	if stage == 0 then
		local numMonster = GetAliveMonsterCount(scene, MonsterRoleId)
		local roundNum = GetCopySceneParam(scene,x020193_g_CSParamIdRound)

		if numMonster == 0 and roundNum < x020193_g_MonsterRoundMax  then 
			for i = 1,x020193_g_MonsterNum do
				local idx = RandomMon(1,#x020193_g_MonsterBornPosList[roundNum+1])
				local nMonObjId = CreateMonster(scene,  MonsterRoleId, x020193_g_MonsterBornPosList[roundNum+1][idx][3], x020193_g_MonsterBornPosList[roundNum+1][idx][1],x020193_g_MonsterBornPosList[roundNum+1][idx][2])
			end
			
			local nUserCount = GetSceneUserCount(scene)
			for i=0,nUserCount-1 do   
				local nUserObjId = GetUserObjIdByIdx(scene,i)
				SynCsStageData(scene, nUserObjId)
			end
			SetCopySceneParam(scene,x020193_g_CSParamIdRound,roundNum+1)
		elseif numMonster == 0 and roundNum == x020193_g_MonsterRoundMax  then 
			local nUserCount = GetSceneUserCount(scene)
			for i=0,nUserCount-1 do   
				local nUserObjId = GetUserObjIdByIdx(scene,i)
				SynCsStageData(scene, nUserObjId)
			end
			SetCopySceneParam(scene,7,1)
		end
	elseif stage == 1 then
		local BossRoleId = x020193_g_BossRoleIdStart + monsterLv
		local objId = CreateStarCraftBoss(scene, 1, BossRoleId, x020193_g_BigBossPos[3], x020193_g_BigBossPos[1], x020193_g_BigBossPos[2])
		print("CreateStarCraftBoss objId=" .. objId)
		local nUserCount = GetSceneUserCount(scene)
		for i=0,nUserCount-1 do   
			local nUserObjId = GetUserObjIdByIdx(scene,i)
			SynCsStageData(scene, nUserObjId)
		end
		SetCopySceneParam(scene,7,2)
		
	end	
	
end	

function  x020193_OnObjDie(scene,objId,rolebaseId,killerId)
	local monsterLv = GetCopySceneEnterParam(scene,1)
	local MonsterRoleId = x020193_g_MonsterRoleIdStart + monsterLv
	if rolebaseId == MonsterRoleId then
		local Cur = GetCopySceneParam(scene, x020193_g_CSParamIdKillNum)
		SetCopySceneParam(scene, x020193_g_CSParamIdKillNum, Cur+1)	
	end
end

function x020193_OnCopySceneTimeOut(scene)
	SetCopySceneParam(scene,7,3)
	DeleAllMonster(scene)
	StarCraftCopyEnd(scene,true)
	SetCopySceneSuccess(scene)	
end

function  x020193_OnCopySceneQuit(scene)
	local stage = GetCopySceneParam(scene,7)
	if stage == 3 then
		return
	end

	SetCopySceneParam(scene,7,3)
	DeleAllMonster(scene)
	StarCraftCopyEnd(scene,true)
	SetCopySceneSuccess(scene)	
end