wx020049_g_scriptId=020049


x020049_g_AdapteLvl = 60  --   每个怪物的自适应等级套数  必须随适应等级的变化而改变
--以上为波次刷怪的波次适应等级  编号1代表第一波怪的自适应等级    编号1里第一个中括号表示第一波第一个怪物的自适应等级套数  依次类推

x020049_g_YuansuId = {}
x020049_g_YuansuId[1] = {483000,483010,483020,483030,	483040,	483050,	483060,	483070,	483080,	483090,	483100,	483110,	483120,	483130,	483140,	483150,	483160,	483170,	483180,	483190,	483200,	483210,	483220,	483230,	483240,	483250,	483260,	483270,	483280,	483290,	483300,	483310,	483320,	483330,	483340,	483350,	483360,	483370,	483380,	483390,	483400,	483410,	483420,	483430,	483440,	483450,	483460,	483470,	483480,	483490,	483500,	483510,	483520,	483530,	483540,	483550,	483560,	483570,	483580,	483590}

x020049_g_YuansuPosList={}
x020049_g_YuansuPosList[1] = {{41.93,77.64,-1.57},{41.93,77.64,-1.57},{41.93,77.64,-1.57},{41.93,77.64,-1.57}} 	-- 坐标控制数量，多少个坐标一次刷多少个

x020049_g_TotalTargetNum = 30	--  通关击杀总数
x020049_g_CreateTime = 5-- 刷怪物时间间隔
x020049_g_StageCreateTime = 1 -- 每几个怪中间的时间间隔

x020049_g_YuansuBuffId={}
x020049_g_YuansuBuffId[1] = {-1,-1, -1,-1, -1,-1}   

x020049_g_BossId = {}
x020049_g_BossId[1] = {483000,483010,483020,483030,	483040,	483050,	483060,	483070,	483080,	483090,	483100,	483110,	483120,	483130,	483140,	483150,	483160,	483170,	483180,	483190,	483200,	483210,	483220,	483230,	483240,	483250,	483260,	483270,	483280,	483290,	483300,	483310,	483320,	483330,	483340,	483350,	483360,	483370,	483380,	483390,	483400,	483410,	483420,	483430,	483440,	483450,	483460,	483470,	483480,	483490,	483500,	483510,	483520,	483530,	483540,	483550,	483560,	483570,	483580,	483590}	-- Boss编号   表示Boss的自适应等级套数   
x020049_g_BossPosList={}
x020049_g_BossPosList[1]={{42,60, 1.57}}    --  Boss 坐标

x020049_g_TpPosList = {}
x020049_g_TpPosList[1] = {{41.93,77.64,1.57}, {41.59, 37, -1.57}}
x020049_g_CSParamIdxCurStage=0                     -- 场景切换波数
x020049_g_CSParamIdxCurSubStage=1				   -- 同一场景中的时间点		
x020049_g_CSParamIdxrandtime=2					   -- 记录击杀了几个第一只怪
x020049_g_CSParamIdxrandtime2= 3				   -- 记录击杀了几个元素小怪

x020049_g_Movparm = 10

function x020049_OnObjEnter(scene, objId)
	--CopySceneNPC(scene,1001101,51001,6,203,1,"XXX")--场景、角色ID、CharModel表ID、势力、出现的场景SceneID、等级、名称
	SynCsStageData(scene, objId, true)
	--AutoCombat(scene,objId,true)
end
function x020049_OnCopySceneOpen(scene, objId)
	--SynCsStageData(scene, objId, true)
	--AutoCombat(scene,objId,true)
	StoryAnimation(scene, 2203)
end
function x020049_OnCopySceneTick(scene,tickCount)					--副本阶段

		if tickCount == 0 then
		CaluCSRound(scene)
		--StoryAnimation(scene, 7000)
	end
	local curStage = GetCopySceneParam(scene,x020049_g_CSParamIdxCurStage)
	local curSubStage = GetCopySceneParam(scene,x020049_g_CSParamIdxCurSubStage) +1
	SetCopySceneParam(scene,x020049_g_CSParamIdxCurSubStage,curSubStage)

	if(tickCount == 0) then
		SetSceneBuff(scene,4700,x020049_g_TpPosList[1][1][1],x020049_g_TpPosList[1][1][2],x020049_g_TpPosList[1][1][3])
		SetSceneBuff(scene,4701,x020049_g_TpPosList[1][2][1],x020049_g_TpPosList[1][2][2],x020049_g_TpPosList[1][2][3])
	end
	--x020049_OpenAutoCombat(scene)
	if GetCopySceneStatus(scene) == 4 and curStage == 1 then
		curStage = 3
		x020049_ClearAllMonster(scene)
		SetCopySceneParam(scene, x020049_g_CSParamIdxCurStage,3)
		ShowSJCSEnd(scene, false)
	end
	local nAdaptedLvl = math.floor(GetAdaptLvl(scene)/10)
	if nAdaptedLvl > x020049_g_AdapteLvl then
		nAdaptedLvl = x020049_g_AdapteLvl
	end
	if curStage == 0 then
		x020049_Stage_0(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 1 then
		x020049_CreateMonster(scene,1,3,nAdaptedLvl, tickCount)
	elseif curStage == 2 then
		x020049_Stage_2(scene, curStage, curSubStage)
	end		
end
function x020049_Stage_0(scene ,stage,substage, nlv)  
	--	print(x020049_g_Movparm) 
	--	print((substage == x020049_g_MovCdTime and GetCopySceneParam(scene,13) == 0))        
	if ((substage == x020049_g_Movparm and GetCopySceneParam(scene,13) == 0) or GetCopySceneParam(scene,13) == 1) then
		SetCopySceneParam(scene, 13, 2)	
						local nUserCount = GetSceneUserCount(scene)				
				for i=0,nUserCount-1 do   
					local nUserObjId = GetUserObjIdByIdx(scene,i)   
					AutoCombat(scene,nUserObjId,true)
				end   
		local nCurStage = GetCopySceneParam(scene, x020049_g_CSParamIdxCurStage)
		SetCopySceneParam(scene,x020049_g_CSParamIdxCurStage,1)
		SetCopySceneParam(scene,x020049_g_CSParamIdxCurSubStage,0)
	end
end

function x020049_OnStoryEventEnd(scene,nStoryId,nAnimationId)
	local OldValue =  GetCopySceneParam(scene,13)
	--print("播放完MOV")
	--print(OldValue)
	if OldValue == 0 then
				local nUserCount = GetSceneUserCount(scene)				
				for i=0,nUserCount-1 do   
					local nUserObjId = GetUserObjIdByIdx(scene,i)   
					AutoCombat(scene,nUserObjId,true)
				end   
		SetCopySceneParam(scene, 13,1)
	end
end
function x020049_ClearAllMonster(scene)
 	local nAdaptedLvl = math.floor(GetAdaptLvl(scene)/10)
	if nAdaptedLvl > x020049_g_AdapteLvl then
		nAdaptedLvl = x020049_g_AdapteLvl
	end
   	DeleMonsterByRoleId(scene, x020049_g_YuansuId[1][nAdaptedLvl])
    DeleMonsterByRoleId(scene, x020049_g_BossId[1][nAdaptedLvl])

end
function x020049_CreateYuansuBuff(scene, idx, nlv)
	SendImpactToAllByRBID(scene, x020049_g_YuansuId[idx][nlv], x020049_g_YuansuBuffId[1][idx])
end
function x020049_Stage_2(scene,curStage,curSubStage)
	-- body
		local nCurStage = GetCopySceneParam(scene, x020049_g_CSParamIdxCurStage)
	SetCopySceneParam(scene,x020049_g_CSParamIdxCurStage,nCurStage+1)
	SetCopySceneParam(scene,x020049_g_CSParamIdxCurSubStage,0)
	ShowSJCSEnd(scene, true)
	x020049_Success(scene)
end
function x020049_Success(scene)
	--print("結束了")
	AccoutByCopyScene(scene)	
	local nUserCount = GetSceneUserCount(scene)
	for i=0,nUserCount-1 do
		local nUserObjId = GetUserObjIdByIdx(scene,i)
	--	AwardCSItemBox(scene,nUserObjId,x020049_g_IdCSxiayiBox, x020049_g_IdCSItemBox)
	end
	SetCopySceneSuccess(scene)
end


function  x020049_OnObjDie(scene,objId,rolebaseId,killerId)			
	local MonCount = GetHostileMonsterCount(scene)
	local nCurStage = GetCopySceneParam(scene, x020049_g_CSParamIdxCurStage)
	local nAdaptedLvl = math.floor(GetAdaptLvl(scene)/10)
	if nAdaptedLvl > x020049_g_AdapteLvl then
		nAdaptedLvl = x020049_g_AdapteLvl
	end
	x020049_OnDieCountDown1(scene, rolebaseId, nAdaptedLvl)
	local OldValue = GetCopySceneParam(scene, x020049_g_CSParamIdxrandtime)
	if(OldValue >= x020049_g_TotalTargetNum) then
		x020049_ClearAllMonster(scene)
		SetCopySceneParam(scene,x020049_g_CSParamIdxCurStage,2)
		SetCopySceneParam(scene,x020049_g_CSParamIdxCurSubStage,0)
	end
end
function x020049_OnDieCountDown1(scene, rolebaseId, nlv)
	local TargetId = x020049_g_YuansuId[1][nlv]
	if(TargetId == rolebaseId) then
		local OldValue = GetCopySceneParam(scene, x020049_g_CSParamIdxrandtime)
		OldValue = OldValue + 1
		if OldValue >= x020049_g_TotalTargetNum then
			OldValue = x020049_g_TotalTargetNum
		end
		SetCopySceneParam(scene, x020049_g_CSParamIdxrandtime, OldValue)
		local nUserCount = GetSceneUserCount(scene)
		for i=0,nUserCount-1 do   
			local nUserObjId = GetUserObjIdByIdx(scene,i)   
			SynCsStageData(scene, nUserObjId)
		end    
	end
end
function x020049_OnDieCountDown2(scene, rolebaseId, nlv)
	for i = 1, 4 do
		local TargetId = x020049_g_YuansuId[1][nlv]
		if(TargetId == rolebaseId) then
			local OldValue = GetCopySceneParam(scene, x020049_g_CSParamIdxrandtime2)
			SetCopySceneParam(scene, x020049_g_CSParamIdxrandtime2, OldValue+1)
			local nUserCount = GetSceneUserCount(scene)
			for i=0,nUserCount-1 do   
				local nUserObjId = GetUserObjIdByIdx(scene,i)   
				SynCsStageData(scene, nUserObjId)
			end  
			--print(OldValue)  
			break
		end

	end
end

function x020049_CreateMonster( scene,idx,camp, nlv, tickCount)					--刷怪（

	local count = #x020049_g_YuansuPosList[idx]
	for i = 1, count  do
		if((tickCount % x020049_g_CreateTime) ==  i*x020049_g_StageCreateTime) then
	
			local objId = CreateMonster(scene,  x020049_g_YuansuId[idx][nlv], x020049_g_YuansuPosList[idx][i][3], x020049_g_YuansuPosList[idx][i][1],x020049_g_YuansuPosList[idx][i][2])
			NpcStartPatrol(scene, objId, 200)
		end
	end
end

function x020049_Stage_1(scene ,stage,substage, nlv)                      
	if substage == 1 then

		CreateMonster(scene, x020049_g_BossId[1][nlv], x020049_g_BossPosList[1][1][3], x020049_g_BossPosList[1][1][1],x020049_g_BossPosList[1][1][2])
		for i = 1, 4 do
			x020049_CreateMonster(scene, i, 3, nlv)

		end
	end
end

function x020049_OnObjPatrolEnd(scene, objId)
	-- body
	DeleMonsterByObjId(scene, objId)
end