wx020052_g_scriptId=020052


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

x020052_g_YuansuId = {}
x020052_g_YuansuId[1] = {487000,487010,	487020,	487030,	487040,	487050,	487060,	487070,	487080,	487090,	487100,	487110,	487120,	487130,	487140,	487150,	487160,	487170,	487180,	487190,	487200,	487210,	487220,	487230,	487240,	487250,	487260,	487270,	487280,	487290,	487300,	487310,	487320,	487330,	487340,	487350,	487360,	487370,	487380,	487390,	487400,	487410,	487420,	487430,	487440,	487450,	487460,	487470,	487480,	487490,	487500,	487510,	487520,	487530,	487540,	487550,	487560,	487570,	487580,	487590} -- 第1种怪物的Id
x020052_g_YuansuId[2] = {488000,488010,	488020,	488030,	488040,	488050,	488060,	488070,	488080,	488090,	488100,	488110,	488120,	488130,	488140,	488150,	488160,	488170,	488180,	488190,	488200,	488210,	488220,	488230,	488240,	488250,	488260,	488270,	488280,	488290,	488300,	488310,	488320,	488330,	488340,	488350,	488360,	488370,	488380,	488390,	488400,	488410,	488420,	488430,	488440,	488450,	488460,	488470,	488480,	488490,	488500,	488510,	488520,	488530,	488540,	488550,	488560,	488570,	488580,	488590} -- 第2种怪物的Id
x020052_g_YuansuId[3] = {489000,489010,	489020,	489030,	489040,	489050,	489060,	489070,	489080,	489090,	489100,	489110,	489120,	489130,	489140,	489150,	489160,	489170,	489180,	489190,	489200,	489210,	489220,	489230,	489240,	489250,	489260,	489270,	489280,	489290,	489300,	489310,	489320,	489330,	489340,	489350,	489360,	489370,	489380,	489390,	489400,	489410,	489420,	489430,	489440,	489450,	489460,	489470,	489480,	489490,	489500,	489510,	489520,	489530,	489540,	489550,	489560,	489570,	489580,	489590} -- 第3种怪物的Id

x020052_g_YuansuPosList={}
x020052_g_YuansuPosList[1] = {{55.1,49.13,-1.57},{62.23,47.42,-1.57},{70.5,48.95,-1.57}} 	      -- 坐标控制数量，多少个坐标一次刷多少个  第一波的第一种怪物坐标
x020052_g_YuansuPosList[2] = {{50.97,56.78,-1.57},{70.65,57.05,-1.57},{56.42,64.75,-1.57}} 		--第一波的第2种
x020052_g_YuansuPosList[3] = {{62.36,51.11,-1.57},{68.9,64.58,-1.57}} 		--第一波的第3种

x020052_g_RandPosList = {}
x020052_g_RandPosList[1] = {{58.24,52.5,-1.57},{66.56,52.03,-1.57},{62.57,61.65,-1.57},{50.9,62.79,-1.57},{74.21,62.88,-1.57},{62.89,67.94,-1.57},{56.66,59.89,-1.57},{68.54,59.89,-1.57}}

x020052_g_YuansuValue = {}
x020052_g_YuansuValue[1] = {10, 50, 300}    -- 三种怪物的分数 ，依次和前面的ID对应，不要改变顺序

x020052_g_TotalTargetNum = 1500	--  通关击杀总分数
x020052_g_CreateTime = 5 -- 刷怪物时间间隔

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

x020052_g_BossId = {}
x020052_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的自适应等级套数   
x020052_g_BossPosList={}
x020052_g_BossPosList[1]={{106,85,3.21}}    --  Boss 坐标

x020052_g_TpPosList = {}
x020052_g_TpPosList[1] = {{106,85,3.21}, {89, 79, 3.21}}
x020052_g_CSParamIdxCurStage=0                     -- 场景切换波数
x020052_g_CSParamIdxCurSubStage=1				   -- 同一场景中的时间点		
x020052_g_CSParamIdxrandtime=2					   -- 记录击杀了多少分

x020052_g_Movparm = 10

x020052_g_CampTick = 7 -- 怪物出生时间导致的客户端准备好了 怪还没刷出来的Tick

function x020052_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 x020052_OnCopySceneOpen(scene, objId)
	--SynCsStageData(scene, objId, true)
	--AutoCombat(scene,objId,true)
	StoryAnimation(scene, 2206)
end
function x020052_OnCopySceneTick(scene,tickCount)					--副本阶段

		if tickCount == 0 then
			--StoryAnimation(scene, 7006)
		CaluCSRound(scene)
	end
	local curStage = GetCopySceneParam(scene,x020052_g_CSParamIdxCurStage) 
	local curSubStage = GetCopySceneParam(scene,x020052_g_CSParamIdxCurSubStage) +1
	SetCopySceneParam(scene,x020052_g_CSParamIdxCurSubStage,curSubStage)
	if GetCopySceneStatus(scene) == 4 and curStage == 1 then
		curStage = 3
		x020052_ClearAllMonster(scene)
		SetCopySceneParam(scene, x020052_g_CSParamIdxCurStage, 3)
		ShowSJCSEnd(scene, false)
	end
	local nAdaptedLvl = math.floor(GetAdaptLvl(scene)/10)
	if nAdaptedLvl > x020052_g_AdapteLvl then
		nAdaptedLvl = x020052_g_AdapteLvl
	end
	if(tickCount >= x020052_g_CampTick) then
		ChangeAllMonsterCamp(scene,3)
	end
	if curStage == 0 then
		x020052_Stage_0(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 1 then
		x020052_CreateMonster(scene,curStage,3,nAdaptedLvl, curSubStage)
	elseif curStage == 2 then
		x020052_Stage_2(scene, curStage, curSubStage)
	end		
end
function x020052_Stage_0(scene ,stage,substage, nlv)  
	--	print(x020052_g_Movparm) 
	--	print((substage == x020052_g_MovCdTime and GetCopySceneParam(scene,13) == 0))        
	if ((substage == x020052_g_Movparm and GetCopySceneParam(scene,13) == 0) or GetCopySceneParam(scene,13) == 1) then
		SetCopySceneParam(scene, 13, 2)	
		local nCurStage = GetCopySceneParam(scene, x020052_g_CSParamIdxCurStage)
		SetCopySceneParam(scene,x020052_g_CSParamIdxCurStage,1)
		SetCopySceneParam(scene,x020052_g_CSParamIdxCurSubStage,0)
	end
end

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

		SetCopySceneParam(scene, 13,1)
	end
end
function x020052_ClearAllMonster(scene)
 	local nAdaptedLvl = math.floor(GetAdaptLvl(scene)/10)
	if nAdaptedLvl > x020052_g_AdapteLvl then
		nAdaptedLvl = x020052_g_AdapteLvl
	end
	    for i = 1, 3 do
    	DeleMonsterByRoleId(scene, x020052_g_YuansuId[i][nAdaptedLvl])
    end
  --  DeleMonsterByRoleId(scene, x020052_g_BossId[1][nAdaptedLvl])

end
function x020052_CreateYuansuBuff(scene, idx, nlv)
	SendImpactToAllByRBID(scene, x020052_g_YuansuId[idx][nlv], x020052_g_YuansuBuffId[1][idx])
end
function x020052_Stage_2(scene,curStage,curSubStage)
	-- body
			local nCurStage = GetCopySceneParam(scene, x020052_g_CSParamIdxCurStage)
	SetCopySceneParam(scene,x020052_g_CSParamIdxCurStage,nCurStage+1)
	SetCopySceneParam(scene,x020052_g_CSParamIdxCurSubStage,0)
	ShowSJCSEnd(scene, true)
	x020052_Success(scene)
end
function x020052_Success(scene)
	AccoutByCopyScene(scene)	
	local nUserCount = GetSceneUserCount(scene)
	for i=0,nUserCount-1 do
		local nUserObjId = GetUserObjIdByIdx(scene,i)
	--	AwardCSItemBox(scene,nUserObjId,x020052_g_IdCSxiayiBox, x020052_g_IdCSItemBox)
	end
	SetCopySceneSuccess(scene)
end


function  x020052_OnObjDie(scene,objId,rolebaseId,killerId)			
	local MonCount = GetHostileMonsterCount(scene)
	local nCurStage = GetCopySceneParam(scene, x020052_g_CSParamIdxCurStage)
	local nAdaptedLvl = math.floor(GetAdaptLvl(scene)/10)
	if nAdaptedLvl > x020052_g_AdapteLvl then
		nAdaptedLvl = x020052_g_AdapteLvl
	end
	x020052_OnDieCountDown2(scene, rolebaseId, nAdaptedLvl)
	local OldValue = GetCopySceneParam(scene, x020052_g_CSParamIdxrandtime)
	if(OldValue >= x020052_g_TotalTargetNum) then
		x020052_ClearAllMonster(scene)
		SetCopySceneParam(scene,x020052_g_CSParamIdxCurStage,2)
		SetCopySceneParam(scene,x020052_g_CSParamIdxCurSubStage,0)
	end
end
function x020052_OnDieCountDown1(scene, rolebaseId, nlv)
	local TargetId = x020052_g_YuansuId[1][nlv]
	if(TargetId == rolebaseId) then
		local OldValue = GetCopySceneParam(scene, x020052_g_CSParamIdxrandtime)
		SetCopySceneParam(scene, x020052_g_CSParamIdxrandtime, OldValue+x020052_g_YuansuValue[1][i])

		local nUserCount = GetSceneUserCount(scene)
		for i=0,nUserCount-1 do   
			local nUserObjId = GetUserObjIdByIdx(scene,i)   
			SynCsStageData(scene, nUserObjId)
		end    
	end
end
function x020052_OnDieCountDown2(scene, rolebaseId, nlv)
	for i = 1, 3 do
		local TargetId = x020052_g_YuansuId[i][nlv]
		if(TargetId == rolebaseId) then
			--BroadCastCSTips(scene, 90013)
			BroadCastTipsParam(scene, 90013, x020052_g_YuansuValue[1][i])
		--	BroadCastCSTipsParam(scene, 90013, x020052_g_YuansuValue[1][i])
			local OldValue = GetCopySceneParam(scene, x020052_g_CSParamIdxrandtime)
			OldValue = OldValue + x020052_g_YuansuValue[1][i]
			if OldValue >= x020052_g_TotalTargetNum then
				OldValue = x020052_g_TotalTargetNum
			end
			SetCopySceneParam(scene, x020052_g_CSParamIdxrandtime, OldValue)
			local count = #x020052_g_RandPosList[1]
			local RandIdex = RandomMon(1, count)
			
			CreateMonster(scene, x020052_g_YuansuId[i][nlv], x020052_g_RandPosList[1][RandIdex][3], x020052_g_RandPosList[1][RandIdex][1],x020052_g_RandPosList[1][RandIdex][2])

			local nUserCount = GetSceneUserCount(scene)
			for j=0,nUserCount-1 do   
				local nUserObjId = GetUserObjIdByIdx(scene,j)   
				SynCsStageData(scene, nUserObjId)
			end  
			break
		end

	end
end


function x020052_CreateMonster( scene,idx,camp, nlv, substage)	
	if substage == 1 then				--刷怪（
	--	print("CreateMonster")
					local nUserCount = GetSceneUserCount(scene)				
				for i=0,nUserCount-1 do   
					local nUserObjId = GetUserObjIdByIdx(scene,i)   
					AutoCombat(scene,nUserObjId,true)
				end    
		for i = 1, 3 do
			local index = (idx-1)*3 + i
			local count = #x020052_g_YuansuPosList[i]
			for j = 1, count  do
				local ObjId = CreateMonster(scene,  x020052_g_YuansuId[i][nlv], x020052_g_YuansuPosList[i][j][3], x020052_g_YuansuPosList[i][j][1],x020052_g_YuansuPosList[i][j][2])
			--	SetNpcCampByObjId(scene,ObjId,1)
			end
		end
	end
	--local count = #x020052_g_YuansuPosList[idx]
--	for i = 1, count  do
--		CreateMonster(scene,  x020052_g_YuansuId[idx][nlv], x020052_g_YuansuPosList[idx][i][3], x020052_g_YuansuPosList[idx][i][1],x020052_g_YuansuPosList[idx][i][2])
--	end
end

function x020052_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, x020052_g_BossId[1][nlv], x020052_g_BossPosList[1][1][3], x020052_g_BossPosList[1][1][1],x020052_g_BossPosList[1][1][2])
		for i = 1, 4 do
			x020052_CreateMonster(scene, i, 3, nlv)
		end
	end
end
