x020053_g_scriptId=020053


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

x020053_g_YuansuId = {}
x020053_g_YuansuId[1] = {464000,464010,	464020,	464030,	464040,	464050,	464060,	464070,	464080,	464090,	464100,	464110,	464120,	464130,	464140,	464150,	464160,	464170,	464180,	464190,	464200,	464210,	464220,	464230,	464240,	464250,	464260,	464270,	464280,	464290,	464300,	464310,	464320,	464330,	464340,	464350,	464360,	464370,	464380,	464390,	464400,	464410,	464420,	464430,	464440,	464450,	464460,	464470,	464480,	464490,	464500,	464510,	464520,	464530,	464540,	464550,	464560,	464570,	464580,	464590}
x020053_g_YuansuId[2] = {465000,465010,	465020,	465030,	465040,	465050,	465060,	465070,	465080,	465090,	465100,	465110,	465120,	465130,	465140,	465150,	465160,	465170,	465180,	465190,	465200,	465210,	465220,	465230,	465240,	465250,	465260,	465270,	465280,	465290,	465300,	465310,	465320,	465330,	465340,	465350,	465360,	465370,	465380,	465390,	465400,	465410,	465420,	465430,	465440,	465450,	465460,	465470,	465480,	465490,	465500,	465510,	465520,	465530,	465540,	465550,	465560,	465570,	465580,	465590}
x020053_g_YuansuId[3] = {466000,466010,	466020,	466030,	466040,	466050,	466060,	466070,	466080,	466090,	466100,	466110,	466120,	466130,	466140,	466150,	466160,	466170,	466180,	466190,	466200,	466210,	466220,	466230,	466240,	466250,	466260,	466270,	466280,	466290,	466300,	466310,	466320,	466330,	466340,	466350,	466360,	466370,	466380,	466390,	466400,	466410,	466420,	466430,	466440,	466450,	466460,	466470,	466480,	466490,	466500,	466510,	466520,	466530,	466540,	466550,	466560,	466570,	466580,	466590}
x020053_g_YuansuId[4] = {467000,467010,	467020,	467030,	467040,	467050,	467060,	467070,	467080,	467090,	467100,	467110,	467120,	467130,	467140,	467150,	467160,	467170,	467180,	467190,	467200,	467210,	467220,	467230,	467240,	467250,	467260,	467270,	467280,	467290,	467300,	467310,	467320,	467330,	467340,	467350,	467360,	467370,	467380,	467390,	467400,	467410,	467420,	467430,	467440,	467450,	467460,	467470,	467480,	467490,	467500,	467510,	467520,	467530,	467540,	467550,	467560,	467570,	467580,	467590}
x020053_g_YuansuPosList={}
x020053_g_YuansuPosList[1] = {{67.02,33.82,0.52},{63.12,40.56,0.52}} 
x020053_g_YuansuPosList[2] = {{64.99,27.73,0.52},{56.74,42.02,0.52}} 
x020053_g_YuansuPosList[3] = {{61.75,26.94,0.52},{54.72,39.11,0.52}} 
x020053_g_YuansuPosList[4] = {{57.3,27.51,0.52},{53.2,34.72,0.52}} 

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

x020053_g_BossId = {}
x020053_g_BossId[1] = {468000,468010,468020,468030,	468040,	468050,	468060,	468070,	468080,	468090,	468100,	468110,	468120,	468130,	468140,	468150,	468160,	468170,	468180,	468190,	468200,	468210,	468220,	468230,	468240,	468250,	468260,	468270,	468280,	468290,	468300,	468310,	468320,	468330,	468340,	468350,	468360,	468370,	468380,	468390,	468400,	468410,	468420,	468430,	468440,	468450,	468460,	468470,	468480,	468490,	468500,	468510,	468520,	468530,	468540,	468550,	468560,	468570,	468580,	468590}	-- Boss编号   表示Boss的自适应等级套数   
x020053_g_BossPosList={}
x020053_g_BossPosList[1]={{62.67,35.34,0.52}}    --  Boss 坐标

x020053_g_Movparm = 10
x020053_g_CSParamIdxCurStage=0                     -- 场景切换波数
x020053_g_CSParamIdxCurSubStage=1				   -- 同一场景中的时间点		
x020053_g_CSParamIdxrandtime=2					   -- 记录击杀了几个第一只怪
x020053_g_CSParamIdxrandtime2= 3				   -- 记录击杀了几个元素小怪
function x020053_OnObjEnter(scene, objId)
	--CopySceneNPC(scene,1001101,51001,6,200,1,"XXX")--场景、角色ID、CharModel表ID、势力、出现的场景SceneID、等级、名称
	SynCsStageData(scene, objId, true)
	--AutoCombat(scene,objId,true)
end
function x020053_OnCopySceneOpen(scene, objId)
	--SynCsStageData(scene, objId, true)
	--AutoCombat(scene,objId,true)
	StoryAnimation(scene, 2200)
end
function x020053_OnCopySceneTick(scene,tickCount)					--副本阶段

		if tickCount == 0 then
		CaluCSRound(scene)
		--StoryAnimation(scene, 7001)
	end
	local curStage = GetCopySceneParam(scene,x020053_g_CSParamIdxCurStage)
	local curSubStage = GetCopySceneParam(scene,x020053_g_CSParamIdxCurSubStage) +1
	SetCopySceneParam(scene,x020053_g_CSParamIdxCurSubStage,curSubStage)
	if GetCopySceneStatus(scene) == 4 and curStage == 1 then
		curStage = 3
		x020053_ClearAllMonster(scene)
		SetCopySceneParam(scene, x020053_g_CSParamIdxCurStage, 3)
		ShowSJCSEnd(scene, false)
	end
	local nAdaptedLvl = math.floor(GetAdaptLvl(scene)/10)
	if nAdaptedLvl > x020053_g_AdapteLvl then
		nAdaptedLvl = x020053_g_AdapteLvl
	end
	if(tickCount == 20) then
		ChangeAllMonsterCamp(scene,3)
	end
	if curStage == 0 then
		x020053_Stage_0(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 1 then
		x020053_Stage_1(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 2 then
		x020053_Stage_2(scene, curStage, curSubStage)
	end		
		local Hp = CalculatePercenHp(scene, GetObjIdByRoleBase(scene, x020053_g_BossId[1][nAdaptedLvl]))
		if Hp > 0 then
			if ((tickCount % 10) == 0 and (tickCount ~= 0)) then
				local Count = (tickCount/10)%4
			--	print("上buff了")
			--	print(Count)
				x020053_CreateYuansuBuff(scene, Count+1, nAdaptedLvl)
			end
		end
end
function x020053_Stage_0(scene ,stage,substage, nlv)  
	--	print(x020053_g_Movparm) 
	--	print((substage == x020053_g_MovCdTime and GetCopySceneParam(scene,13) == 0))        
	if ((substage == x020053_g_Movparm and GetCopySceneParam(scene,13) == 0) or GetCopySceneParam(scene,13) == 1) then
		SetCopySceneParam(scene, 13, 2)	
		local nCurStage = GetCopySceneParam(scene, x020053_g_CSParamIdxCurStage)
		SetCopySceneParam(scene,x020053_g_CSParamIdxCurStage,1)
		SetCopySceneParam(scene,x020053_g_CSParamIdxCurSubStage,0)
	end
end

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

		SetCopySceneParam(scene, 13,1)
	end
end
function x020053_CopyScenePause(scene)
 	local nAdaptedLvl = math.floor(GetAdaptLvl(scene)/10)
	if nAdaptedLvl > x020053_g_AdapteLvl then
		nAdaptedLvl = x020053_g_AdapteLvl
	end
	local nUserCount = GetSceneUserCount(scene)
	for i=0,nUserCount-1 do
		local nUserObjId = GetUserObjIdByIdx(scene,i)
	--	AwardCSItemBox(scene,nUserObjId,x020053_g_IdCSxiayiBox, x020053_g_IdCSItemBox)
		AutoCombat(scene,nUserObjId,false)
	end
	--AutoCombat(scene,objId,false)
    for i = 1, 4 do
    	SetNpcCampByRBId(scene, x020053_g_YuansuId[i][nAdaptedLvl], 1)
    end
    SetNpcCampByRBId(scene, x020053_g_BossId[1][nAdaptedLvl], 1)

end
function x020053_ClearAllMonster(scene)
 	local nAdaptedLvl = math.floor(GetAdaptLvl(scene)/10)
	if nAdaptedLvl > x020053_g_AdapteLvl then
		nAdaptedLvl = x020053_g_AdapteLvl
	end
    for i = 1, 4 do
    	DeleMonsterByRoleId(scene, x020053_g_YuansuId[i][nAdaptedLvl])
    end
    DeleMonsterByRoleId(scene, x020053_g_BossId[1][nAdaptedLvl])

end
function x020053_CreateYuansuBuff(scene, idx, nlv)
	SendImpactToAllByRBID(scene, x020053_g_YuansuId[idx][nlv], x020053_g_YuansuBuffId[1][idx])
end
function x020053_Stage_2(scene,curStage,curSubStage)
	-- body
		-- body
	local nCurStage = GetCopySceneParam(scene, x020053_g_CSParamIdxCurStage)
	SetCopySceneParam(scene,x020053_g_CSParamIdxCurStage,nCurStage+1)
	SetCopySceneParam(scene,x020053_g_CSParamIdxCurSubStage,0)
	ShowSJCSEnd(scene, true)
	x020053_Success(scene)
end
function x020053_Success(scene)
	AccoutByCopyScene(scene)	
	local nUserCount = GetSceneUserCount(scene)
	for i=0,nUserCount-1 do
		local nUserObjId = GetUserObjIdByIdx(scene,i)
	--	AwardCSItemBox(scene,nUserObjId,x020053_g_IdCSxiayiBox, x020053_g_IdCSItemBox)
	end
	SetCopySceneSuccess(scene)
end


function  x020053_OnObjDie(scene,objId,rolebaseId,killerId)			
	local MonCount = GetHostileMonsterCount(scene)
	local nCurStage = GetCopySceneParam(scene, x020053_g_CSParamIdxCurStage)
	local nAdaptedLvl = math.floor(GetAdaptLvl(scene)/10)
	if nAdaptedLvl > x020053_g_AdapteLvl then
		nAdaptedLvl = x020053_g_AdapteLvl
	end
	x020053_OnDieCountDown1(scene, rolebaseId, nAdaptedLvl)
	x020053_OnDieCountDown2(scene, rolebaseId, nAdaptedLvl)
	if(MonCount == 0) then

		SetCopySceneParam(scene,x020053_g_CSParamIdxCurStage,nCurStage+1)
		SetCopySceneParam(scene,x020053_g_CSParamIdxCurSubStage,0)
	end
end
function x020053_OnDieCountDown1(scene, rolebaseId, nlv)
	local TargetId = x020053_g_BossId[1][nlv]
	if(TargetId == rolebaseId) then
		BroadCastTips(scene, 94030)
		local OldValue = GetCopySceneParam(scene, x020053_g_CSParamIdxrandtime)
		SetCopySceneParam(scene, x020053_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 x020053_OnDieCountDown2(scene, rolebaseId, nlv)
	for i = 1, 4 do
		local TargetId = x020053_g_YuansuId[i][nlv]
		if(TargetId == rolebaseId) then
			local OldValue = GetCopySceneParam(scene, x020053_g_CSParamIdxrandtime2)
			SetCopySceneParam(scene, x020053_g_CSParamIdxrandtime2, OldValue+1)
			local nUserCount = GetSceneUserCount(scene)
			for j=0,nUserCount-1 do   
				local nUserObjId = GetUserObjIdByIdx(scene,j)   
				SynCsStageData(scene, nUserObjId)
			end  
			--print(OldValue)  
			break
		end

	end
end

function x020053_CreateMonster( scene,idx,camp, nlv)					--刷怪（
	local count = #x020053_g_YuansuPosList[idx]
	for i = 1, count  do
		local ObjId = CreateMonster(scene,  x020053_g_YuansuId[idx][nlv], x020053_g_YuansuPosList[idx][i][3], x020053_g_YuansuPosList[idx][i][1],x020053_g_YuansuPosList[idx][i][2])
	--	SetNpcCampByObjId(scene,ObjId,1)
	end
end

function x020053_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    
		local a = CreateMonster(scene, x020053_g_BossId[1][nlv], x020053_g_BossPosList[1][1][3], x020053_g_BossPosList[1][1][1],x020053_g_BossPosList[1][1][2])
	--	SetNpcCampByObjId(scene,a,1)
		for i = 1, 4 do
			x020053_CreateMonster(scene, i, 3, nlv)

		end
    	SendImpactToAllByRBID(scene, x020053_g_BossId[1][nlv], 71041)
	end
end
