wx020050_g_scriptId=020050


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

x020050_g_YuansuId = {}
x020050_g_YuansuId[1] = {485000,485010,	485020,	485030,	485040,	485050,	485060,	485070,	485080,	485090,	485100,	485110,	485120,	485130,	485140,	485150,	485160,	485170,	485180,	485190,	485200,	485210,	485220,	485230,	485240,	485250,	485260,	485270,	485280,	485290,	485300,	485310,	485320,	485330,	485340,	485350,	485360,	485370,	485380,	485390,	485400,	485410,	485420,	485430,	485440,	485450,	485460,	485470,	485480,	485490,	485500,	485510,	485520,	485530,	485540,	485550,	485560,	485570,	485580,	485590} -- 第1种怪物的Id
x020050_g_YuansuId[2] = {485600,485601,	485602,	485603,	485604,	485605,	485606,	485607,	485608,	485609,	485610,	485611,	485612,	485613,	485614,	485615,	485616,	485617,	485618,	485619,	485620,	485621,	485622,	485623,	485624,	485625,	485626,	485627,	485628,	485629,	485630,	485631,	485632,	485633,	485634,	485635,	485636,	485637,	485638,	485639,	485640,	485641,	485642,	485643,	485644,	485645,	485646,	485647,	485648,	485649,	485650,	485651,	485652,	485653,	485654,	485655,	485656,	485657,	485658,	485659} -- 第2种怪物的Id


x020050_g_ZhSkillId = 1100000		-- 召唤技能初始ID  只需配置一连串的ID  提供给程序一个初始就可以

x020050_g_DingShengBuffId = 72033		-- 50血之前给会召唤的怪物上的定身buff

x020050_g_ZhaoHunaTime = 18		-- 召唤的周期

x020050_g_YuansuPosList={}
x020050_g_YuansuPosList[1] = {{57.16,88.79,1.25}} 	      -- 坐标控制数量，多少个坐标一次刷多少个  第一波的第一种怪物坐标
x020050_g_YuansuPosList[2] = {{67.69,89.15,4.53}} 		--第一波的第2种


x020050_g_TotalTargetNum = {}	--  通关击杀总分数
x020050_g_TotalTargetNum[1] = {1,2} -- 通关需要达到的怪物击杀数量  第一个1表示一个boss  第二个2表示2个小弟

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

x020050_g_BossId = {}
x020050_g_BossId[1] = {484000,484010,484020,484030,	484040,	484050,	484060,	484070,	484080,	484090,	484100,	484110,	484120,	484130,	484140,	484150,	484160,	484170,	484180,	484190,	484200,	484210,	484220,	484230,	484240,	484250,	484260,	484270,	484280,	484290,	484300,	484310,	484320,	484330,	484340,	484350,	484360,	484370,	484380,	484390,	484400,	484410,	484420,	484430,	484440,	484450,	484460,	484470,	484480,	484490,	484500,	484510,	484520,	484530,	484540,	484550,	484560,	484570,	484580,	484590}	-- Boss编号   表示Boss的自适应等级套数
x020050_g_BossPosList={}
x020050_g_BossPosList[1]={{62.43,80.33,-1.57}}    --  Boss 坐标

x020050_g_TpPosList = {}
x020050_g_TpPosList[1] = {{57.16,88.79,1.25}, {67.69,89.15,4.53}}
x020050_g_CSParamIdxCurStage=0                     -- 场景切换波数
x020050_g_CSParamIdxCurSubStage=1				   -- 同一场景中的时间点
x020050_g_CSParamIdxrandtime=2					   -- 记录击杀了boss
x020050_g_CSParamIdxrandtime2 = 3				   -- 记录杀了几个小弟
x020050_g_CSParamIdSkill1 = 4
x020050_g_CSParamIdSkill2 = 5

x020050_g_Movparm = 10

function x020050_OnObjEnter(scene, objId)
	SynCsStageData(scene, objId, true)
	--AutoCombat(scene,objId,true)
end
function x020050_OnCopySceneOpen(scene, objId)
	--SynCsStageData(scene, objId, true)
	--AutoCombat(scene,objId,true)
	StoryAnimation(scene, 2204)
end

function x020050_OnCopySceneTick(scene,tickCount)					--副本阶段

		if tickCount == 0 then

		CaluCSRound(scene)
	end
	local curStage = GetCopySceneParam(scene,x020050_g_CSParamIdxCurStage)
	local curSubStage = GetCopySceneParam(scene,x020050_g_CSParamIdxCurSubStage) +1
	SetCopySceneParam(scene,x020050_g_CSParamIdxCurSubStage,curSubStage)
	if GetCopySceneStatus(scene) == 4 and curStage == 1 then
		curStage = 3
		x020050_ClearAllMonster(scene)
		SetCopySceneParam(scene, x020050_g_CSParamIdxCurStage, 3)
		ShowSJCSEnd(scene, false)
	end
	local nAdaptedLvl = math.floor(GetAdaptLvl(scene)/10)
	if nAdaptedLvl > x020050_g_AdapteLvl then
		nAdaptedLvl = x020050_g_AdapteLvl
	end

	if(tickCount == 20) then
		ChangeAllMonsterCamp(scene,3)
	end
	for i = 1, 2 do
		local ZhobjId1 = GetObjIdByRoleBase(scene, x020050_g_YuansuId[1][nAdaptedLvl] )
		local ZhobjId2 = GetObjIdByRoleBase(scene, x020050_g_YuansuId[2][nAdaptedLvl] )
		if CalculatePercenHp(scene, ZhobjId1) == 100 then
			SendImpactToAllByRBID(scene, x020050_g_YuansuId[1][nAdaptedLvl], x020050_g_DingShengBuffId)
			SetCopySceneParam(scene, x020050_g_CSParamIdSkill1, 0)
			--print("刪除普攻1")
			DeleteTmpSkill(scene, ZhobjId1, 220476)
		end
		if CalculatePercenHp(scene, ZhobjId2) == 100 then
			SendImpactToAllByRBID(scene, x020050_g_YuansuId[2][nAdaptedLvl], x020050_g_DingShengBuffId)
			SetCopySceneParam(scene, x020050_g_CSParamIdSkill2, 0)
			--print("刪除普攻2")
			DeleteTmpSkill(scene, ZhobjId2, 220476)
		end
		if CalculatePercenHp(scene, ZhobjId1) <= 50 then
			RemoveImpact(scene, ZhobjId1, x020050_g_DingShengBuffId)
			DeleteTmpSkill(scene, ZhobjId1, x020050_g_ZhSkillId+nAdaptedLvl)
			--print("添加普攻1")
			MonAddSkill(scene, ZhobjId1, 220476)

		elseif tickCount % x020050_g_ZhaoHunaTime == 0  and GetCopySceneParam(scene,x020050_g_CSParamIdSkill1) == 0 then
			--print("放技能1")
			SetCopySceneParam(scene, x020050_g_CSParamIdSkill1, 1)
				ProcessSkillRequest(scene, ZhobjId1, ZhobjId1, x020050_g_ZhSkillId+nAdaptedLvl)
		end
		if CalculatePercenHp(scene, ZhobjId2) <= 50 then
			RemoveImpact(scene, ZhobjId2, x020050_g_DingShengBuffId)
			DeleteTmpSkill(scene, ZhobjId1, x020050_g_ZhSkillId+nAdaptedLvl)
			--print("添加普攻2")
			MonAddSkill(scene, ZhobjId2, 220476)
		elseif tickCount % x020050_g_ZhaoHunaTime == 0 and GetCopySceneParam(scene,x020050_g_CSParamIdSkill2) == 0 then
			--print("放技能2")
			SetCopySceneParam(scene, x020050_g_CSParamIdSkill2, 1)
				ProcessSkillRequest(scene, ZhobjId2, ZhobjId2, x020050_g_ZhSkillId+nAdaptedLvl)

		end
	end

	if curStage == 0 then
		x020050_Stage_0(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 1 then
		x020050_Stage_1(scene, curStage, curSubStage,nAdaptedLvl)
	elseif curStage == 2 then
		x020050_Stage_2(scene, curStage, curSubStage)
	end
end
function x020050_Stage_0(scene ,stage,substage, nlv)
	--	print(x020050_g_Movparm)
	--	print((substage == x020050_g_MovCdTime and GetCopySceneParam(scene,13) == 0))
	if ((substage == x020050_g_Movparm and GetCopySceneParam(scene,13) == 0) or GetCopySceneParam(scene,13) == 1) then
		SetCopySceneParam(scene, 13, 2)
		local nCurStage = GetCopySceneParam(scene, x020050_g_CSParamIdxCurStage)
		SetCopySceneParam(scene,x020050_g_CSParamIdxCurStage,1)
		SetCopySceneParam(scene,x020050_g_CSParamIdxCurSubStage,0)
	end
end

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

		SetCopySceneParam(scene, 13,1)
	end
end
function x020050_ClearAllMonster(scene)
 	local nAdaptedLvl = math.floor(GetAdaptLvl(scene)/10)
	if nAdaptedLvl > x020050_g_AdapteLvl then
		nAdaptedLvl = x020050_g_AdapteLvl
	end
    for i = 1, 2 do
    	DeleMonsterByRoleId(scene, x020050_g_YuansuId[i][nAdaptedLvl])
    end
    DeleMonsterByRoleId(scene, x020050_g_BossId[1][nAdaptedLvl])

end
function x020050_CreateYuansuBuff(scene, idx, nlv)
	SendImpactToAllByRBID(scene, x020050_g_YuansuId[idx][nlv], x020050_g_YuansuBuffId[1][idx])
end
function x020050_Stage_2(scene,curStage,curSubStage)
	-- body
	local nCurStage = GetCopySceneParam(scene, x020050_g_CSParamIdxCurStage)
	SetCopySceneParam(scene,x020050_g_CSParamIdxCurStage,nCurStage+1)
	SetCopySceneParam(scene,x020050_g_CSParamIdxCurSubStage,0)
	ShowSJCSEnd(scene, true)
	x020050_Success(scene)

end
function x020050_Success(scene)
	AccoutByCopyScene(scene)
	local nUserCount = GetSceneUserCount(scene)
	for i=0,nUserCount-1 do
		local nUserObjId = GetUserObjIdByIdx(scene,i)
	--	AwardCSItemBox(scene,nUserObjId,x020050_g_IdCSxiayiBox, x020050_g_IdCSItemBox)
	end
	SetCopySceneSuccess(scene)
end


function  x020050_OnObjDie(scene,objId,rolebaseId,killerId)
	local MonCount = GetHostileMonsterCount(scene)
	local nCurStage = GetCopySceneParam(scene, x020050_g_CSParamIdxCurStage)
	local nAdaptedLvl = math.floor(GetAdaptLvl(scene)/10)
	if nAdaptedLvl > x020050_g_AdapteLvl then
		nAdaptedLvl = x020050_g_AdapteLvl
	end

	x020050_OnDieCountDown2(scene, rolebaseId, nAdaptedLvl)
	x020050_OnDieCountDown1(scene, rolebaseId, nAdaptedLvl)
	local OldValue = GetCopySceneParam(scene, x020050_g_CSParamIdxrandtime)
	local OldValue2 = GetCopySceneParam(scene, x020050_g_CSParamIdxrandtime2)
	if(OldValue >= x020050_g_TotalTargetNum[1][1] and OldValue2 >= x020050_g_TotalTargetNum[1][2]) then

		SetCopySceneParam(scene,x020050_g_CSParamIdxCurStage,2)
		SetCopySceneParam(scene,x020050_g_CSParamIdxCurSubStage,0)
	end
end
function x020050_OnDieCountDown1(scene, rolebaseId, nlv)
	local TargetId = x020050_g_BossId[1][nlv]
	if(TargetId == rolebaseId) then
		--x020050_ClearAllMonster(scene)
		DeleHostileMonster(scene)
		local OldValue = GetCopySceneParam(scene, x020050_g_CSParamIdxrandtime)
		SetCopySceneParam(scene, x020050_g_CSParamIdxrandtime, OldValue+1)
		SetCopySceneParam(scene, x020050_g_CSParamIdxrandtime2, 2)
		local nUserCount = GetSceneUserCount(scene)
		for i=0,nUserCount-1 do
			local nUserObjId = GetUserObjIdByIdx(scene,i)
			SynCsStageData(scene, nUserObjId)
		end
	end
end
function x020050_OnDieCountDown2(scene, rolebaseId, nlv)
	for i = 1, 2 do
		local TargetId = x020050_g_YuansuId[i][nlv]
		if(TargetId == rolebaseId) then
			local OldValue = GetCopySceneParam(scene, x020050_g_CSParamIdxrandtime2)
			SetCopySceneParam(scene, x020050_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 x020050_CreateMonster( scene,idx,camp, nlv)
	--if substage == 1 then				--刷怪（
	--	print("CreateMonster")
	--	for i = 1, 3 do
	--		local index = (idx-1)*3 + i
	--		local count = #x020050_g_YuansuPosList[i]
	--		for j = 1, count  do
	--			CreateMonster(scene,  x020050_g_YuansuId[i][nlv], x020050_g_YuansuPosList[i][j][3], x020050_g_YuansuPosList[i][j][1],x020050_g_YuansuPosList[i][j][2])
	--		end
	--	end
	--end
	local count = #x020050_g_YuansuPosList[idx]
	for i = 1, count  do
		local ObjId = CreateMonster(scene,  x020050_g_YuansuId[idx][nlv], x020050_g_YuansuPosList[idx][i][3], x020050_g_YuansuPosList[idx][i][1],x020050_g_YuansuPosList[idx][i][2])
	end
end

function x020050_Stage_1(scene ,stage,substage, nlv)
	if substage == 1 then
		local objid = CreateMonster(scene, x020050_g_BossId[1][nlv], x020050_g_BossPosList[1][1][3], x020050_g_BossPosList[1][1][1],x020050_g_BossPosList[1][1][2])
	--	SetNpcCampByObjId(scene,objid,1)
	end
    if substage == 2 then
        local nUserCount = GetSceneUserCount(scene)
        for i=0,nUserCount-1 do
            local nUserObjId = GetUserObjIdByIdx(scene,i)
            AutoCombat(scene,nUserObjId,true)
        end
		for i = 1, 2 do
			x020050_CreateMonster(scene, i, 3, nlv)
		end
    end
end
