wx020051_g_scriptId=020051


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

x020051_g_YuansuId = {}
x020051_g_YuansuId[1] = {461000,461010,461020,461030,461040,461050,461060,461070,461080,461090,461100,461110,461120,461130,461140,461150,461160,461170,461180,461190,461200,461210,461220,461230,461240,461250,461260,461270,461280,461290,461300,	461310,	461320,	461330,	461340,	461350,	461360,	461370,	461380,	461390,	461400,	461410,	461420,	461430,	461440,	461450,	461460,	461470,	461480,	461490,	461500,	461510,	461520,	461530,	461540,	461550,	461560,	461570,	461580,	461590} -- 第1种怪物的Id
x020051_g_YuansuId[2] = {462000,462010,	462020,	462030,	462040,	462050,	462060,	462070,	462080,	462090,	462100,	462110,	462120,	462130,	462140,	462150,	462160,	462170,	462180,	462190,	462200,	462210,	462220,	462230,	462240,	462250,	462260,	462270,	462280,	462290,	462300,	462310,	462320,	462330,	462340,	462350,	462360,	462370,	462380,	462390,	462400,	462410,	462420,	462430,	462440,	462450,	462460,	462470,	462480,	462490,	462500,	462510,	462520,	462530,	462540,	462550,	462560,	462570,	462580,	462590} -- 第2种怪物的Id
x020051_g_YuansuId[3] = {463000,463010,	463020,	463030,	463040,	463050,	463060,	463070,	463080,	463090,	463100,	463110,	463120,	463130,	463140,	463150,	463160,	463170,	463180,	463190,	463200,	463210,	463220,	463230,	463240,	463250,	463260,	463270,	463280,	463290,	463300,	463310,	463320,	463330,	463340,	463350,	463360,	463370,	463380,	463390,	463400,	463410,	463420,	463430,	463440,	463450,	463460,	463470,	463480,	463490,	463500,	463510,	463520,	463530,	463540,	463550,	463560,	463570,	463580,	463590} -- 第3种怪物的Id

x020051_g_YuansuPosList={}
x020051_g_YuansuPosList[1] = {{54.33,60.22,-1.57},{68.08,65.98,-1.57},{67.37,54.29,-1.57}} 	      -- 坐标控制数量，多少个坐标一次刷多少个  第一波的第一种怪物坐标
x020051_g_YuansuPosList[2] = {{61.08,69.98,-1.57},{53.36,65.9,-1.57},{54.26,54.87,-1.57}} 		--第一波的第2种
x020051_g_YuansuPosList[3] = {{61.08,65.29,-1.57},{69.2,60.15,-1.57},{60.97,60.21,-1.57}} 		--第一波的第3种
x020051_g_YuansuPosList[4] = {{60.84,53.08,-1.57},{68.27,59.36,-1.57},{66.4,66.59,-1.57}} --第2波的第1种
x020051_g_YuansuPosList[5] = {{61,67.18,-1.57},{53.89,60.74,-1.57},{65.87,54.91,-1.57}} --第2波的第2种
x020051_g_YuansuPosList[6] = {{60.92,59.77,-1.57},{55.87,66.43,-1.57},{54.76,55.55,-1.57}} --第2波的第3种
x020051_g_YuansuPosList[7] = {{60.84,53.08,-1.57},{68.27,59.36,-1.57},{66.4,66.59,-1.57}} --第3波的第1种
x020051_g_YuansuPosList[8] = {{61,67.18,-1.57},{53.89,60.74,-1.57},{65.87,54.91,-1.57}} --第3波的第2种
x020051_g_YuansuPosList[9] = {{60.92,59.77,-1.57},{55.87,66.43,-1.57},{54.76,55.55,-1.57}} --第3波的第3种


x020051_g_TotalTargetNum = 27	--  通关击杀总数
x020051_g_CreateTime = 5 -- 刷怪物时间间隔

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

x020051_g_BossId = {}
x020051_g_BossId[1] = {20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20}	-- Boss编号   表示Boss的自适应等级套数   
x020051_g_BossPosList={}
x020051_g_BossPosList[1]={{106,85,3.21}}    --  Boss 坐标

x020051_g_TpPosList = {}
x020051_g_TpPosList[1] = {{106,85,3.21}, {89, 79, 3.21}}
x020051_g_CSParamIdxCurStage=0                     -- 场景切换波数
x020051_g_CSParamIdxCurSubStage=1				   -- 同一场景中的时间点		
x020051_g_CSParamIdxrandtime=2					   -- 记录击杀了几个第1只怪
x020051_g_CSParamIdxrandtime=3					   -- 记录击杀了几个第2只怪
x020051_g_CSParamIdxrandtime=4					   -- 记录击杀了几个第3只怪

x020051_g_Movparm = 10

function x020051_OnObjEnter(scene, objId)
	--CopySceneNPC(scene,1001101,51001,6,206,1,"XXX")--场景、角色ID、CharModel表ID、势力、出现的场景SceneID、等级、名称
	SynCsStageData(scene, objId, true)
	AutoCombat(scene,objId,true)
end
function x020051_OnCopySceneOpen(scene, objId)
	--SynCsStageData(scene, objId, true)
	--AutoCombat(scene,objId,true)
	StoryAnimation(scene, 2205)
end
function x020051_OnCopySceneTick(scene,tickCount)					--副本阶段
		if tickCount == 0 then
			--StoryAnimation(scene, 7005)
		CaluCSRound(scene)
	end
	local curStage = GetCopySceneParam(scene,x020051_g_CSParamIdxCurStage) 

	local curSubStage = GetCopySceneParam(scene,x020051_g_CSParamIdxCurSubStage) +1
	SetCopySceneParam(scene,x020051_g_CSParamIdxCurSubStage,curSubStage)
	if GetCopySceneStatus(scene) == 4 and curStage < 3 then
		curStage = 4
		x020051_ClearAllMonster(scene)
		SetCopySceneParam(scene, x020051_g_CSParamIdxCurStage, 4)
		ShowSJCSEnd(scene, false)
	end
	local nAdaptedLvl = math.floor(GetAdaptLvl(scene)/10)
	if nAdaptedLvl > x020051_g_AdapteLvl then
		nAdaptedLvl = x020051_g_AdapteLvl
	end
	if(tickCount == 20) then
		ChangeAllMonsterCamp(scene,3)
	end
	if curStage == 0 then
		x020051_Stage_0(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage < 3 and curStage > 0 then
		x020051_CreateMonster(scene,curStage,3,nAdaptedLvl, curSubStage)
	elseif curStage == 3 then
		x020051_Stage_2(scene, curStage, curSubStage)
	end		
end
function x020051_Stage_0(scene ,stage,substage, nlv)  
	--	print(x020051_g_Movparm) 
	--	print((substage == x020051_g_MovCdTime and GetCopySceneParam(scene,13) == 0))        
	if ((substage == x020051_g_Movparm and GetCopySceneParam(scene,13) == 0) or GetCopySceneParam(scene,13) == 1) then
		SetCopySceneParam(scene, 13, 2)	
		local nCurStage = GetCopySceneParam(scene, x020051_g_CSParamIdxCurStage)
		SetCopySceneParam(scene,x020051_g_CSParamIdxCurStage,1)
		SetCopySceneParam(scene,x020051_g_CSParamIdxCurSubStage,0)
	end
end

function x020051_OnStoryEventEnd(scene,nStoryId,nAnimationId)
	local OldValue =  GetCopySceneParam(scene,13)
	--print("播放完MOV")
	--print(OldValue)
	if OldValue == 0 then

		SetCopySceneParam(scene, 13,1)
	end
end
function x020051_ClearAllMonster(scene)
 	local nAdaptedLvl = math.floor(GetAdaptLvl(scene)/10)
	if nAdaptedLvl > x020051_g_AdapteLvl then
		nAdaptedLvl = x020051_g_AdapteLvl
	end
	    for i = 1, 3 do
    	DeleMonsterByRoleId(scene, x020051_g_YuansuId[i][nAdaptedLvl])
    end
  --  DeleMonsterByRoleId(scene, x020051_g_BossId[1][nAdaptedLvl])

end
function x020051_CreateYuansuBuff(scene, idx, nlv)
	SendImpactToAllByRBID(scene, x020051_g_YuansuId[idx][nlv], x020051_g_YuansuBuffId[1][idx])
end
function x020051_Stage_2(scene,curStage,curSubStage)
	-- body
				local nCurStage = GetCopySceneParam(scene, x020051_g_CSParamIdxCurStage)
	SetCopySceneParam(scene,x020051_g_CSParamIdxCurStage,nCurStage+1)
	SetCopySceneParam(scene,x020051_g_CSParamIdxCurSubStage,0)
	ShowSJCSEnd(scene, true)
	x020051_Success(scene)
end
function x020051_Success(scene)
	AccoutByCopyScene(scene)	
	local nUserCount = GetSceneUserCount(scene)
	for i=0,nUserCount-1 do
		local nUserObjId = GetUserObjIdByIdx(scene,i)
	--	AwardCSItemBox(scene,nUserObjId,x020051_g_IdCSxiayiBox, x020051_g_IdCSItemBox)
	end
	SetCopySceneSuccess(scene)
end


function  x020051_OnObjDie(scene,objId,rolebaseId,killerId)			
	local MonCount = GetHostileMonsterCount(scene)
	local nCurStage = GetCopySceneParam(scene, x020051_g_CSParamIdxCurStage)
	local nAdaptedLvl = math.floor(GetAdaptLvl(scene)/10)
	if nAdaptedLvl > x020051_g_AdapteLvl then
		nAdaptedLvl = x020051_g_AdapteLvl
	end
	x020051_OnDieCountDown2(scene, rolebaseId, nAdaptedLvl)
	--local OldValue = GetCopySceneParam(scene, x020051_g_CSParamIdxrandtime)
	if(MonCount == 0) then

		SetCopySceneParam(scene,x020051_g_CSParamIdxCurStage,nCurStage+1)
		SetCopySceneParam(scene,x020051_g_CSParamIdxCurSubStage,0)
	end
end
function x020051_OnDieCountDown1(scene, rolebaseId, nlv)
	local TargetId = x020051_g_YuansuId[1][nlv]
	if(TargetId == rolebaseId) then
		local OldValue = GetCopySceneParam(scene, x020051_g_CSParamIdxrandtime)
		SetCopySceneParam(scene, x020051_g_CSParamIdxrandtime, OldValue+1)
		local nUserCount = GetSceneUserCount(scene)
		for i=0,nUserCount-1 do   
			local nUserObjId = GetUserObjIdByIdx(scene,i)   
			SynCsStageData(scene, nUserObjId)
		end    
	end
end
function x020051_OnDieCountDown2(scene, rolebaseId, nlv)
	for i = 1, 3 do
		local TargetId = x020051_g_YuansuId[i][nlv]
		if(TargetId == rolebaseId) then
			local OldValue = GetCopySceneParam(scene, 1+i)
			SetCopySceneParam(scene, 1+i, OldValue+1)
			local nUserCount = GetSceneUserCount(scene)
			for j=0,nUserCount-1 do   
				local nUserObjId = GetUserObjIdByIdx(scene,j)   
				SynCsStageData(scene, nUserObjId)
			end  
			--print("i = ")
			--print(i+1)  
			break
		end

	end
end


function x020051_CreateMonster( scene,idx,camp, nlv, substage)	
	if substage == 1 then				--刷怪（

		--print("CreateMonster")
		if idx == 1 then
			
		end
		for i = 1, 3 do
			local index = (idx-1)*3 + i
			local count = #x020051_g_YuansuPosList[index]
			for j = 1, count  do
				local ObjId = CreateMonster(scene,  x020051_g_YuansuId[i][nlv], x020051_g_YuansuPosList[index][j][3], x020051_g_YuansuPosList[index][j][1],x020051_g_YuansuPosList[index][j][2])

			end
		end
	end
	--local count = #x020051_g_YuansuPosList[idx]
--	for i = 1, count  do
--		CreateMonster(scene,  x020051_g_YuansuId[idx][nlv], x020051_g_YuansuPosList[idx][i][3], x020051_g_YuansuPosList[idx][i][1],x020051_g_YuansuPosList[idx][i][2])
--	end
end

function x020051_Stage_1(scene ,stage,substage, nlv)                      
	if substage == 1 then
						local nUserCount = GetSceneUserCount(scene)				
				for i=0,nUserCount-1 do   
					local nUserObjId = GetUserObjIdByIdx(scene,i)   
					AutoCombat(scene,nUserObjId,true)
				end    
		CreateMonster(scene, x020051_g_BossId[1][nlv], x020051_g_BossPosList[1][1][3], x020051_g_BossPosList[1][1][1],x020051_g_BossPosList[1][1][2])
		for i = 1, 4 do
			x020051_CreateMonster(scene, i, 3, nlv)
		end
	end
end
