x020042_g_scriptId=020042

x020042_g_BeginLevel = 0
x020042_g_IdPuTong={}
x020042_g_IdPuTong[1]={111001,111001,111001,111001,111001,111001,111001,111001,111001,111001,111001,111001,111001,111001,111001,111001,111001,111001,111001,111001}
x020042_g_IdPuTong[2]={111002,111002,111002,111002,111002,111002,111002,111002,111002,111002,111002,111002,111002,111002,111002,111002,111002,111002,111002,111002}
x020042_g_IdPuTong[3]={111003,111003,111003,111003,111003,111003,111003,111003,111003,111003,111003,111003,111003,111003,111003,111003,111003,111003,111003,111003}
x020042_g_IdPuTong[4]={111004,111004,111004,111004,111004,111004,111004,111004,111004,111004,111004,111004,111004,111004,111004,111004,111004,111004,111004,111004}
x020042_g_IdPuTong[5]={111005,111005,111005,111005,111005,111005,111005,111005,111005,111005,111005,111005,111005,111005,111005,111005,111005,111005,111005,111005}
x020042_g_IdPuTong[6]={111006,111006,111006,111006,111006,111006,111006,111006,111006,111006,111006,111006,111006,111006,111006,111006,111006,111006,111006,111006}

x020042_g_IdJingYing={}
x020042_g_IdJingYing[1]={111007,111007,111007,111007,111007,111007,111007,111007,111007,111007,111007,111007,111007,111007,111007,111007,111007,111007,111007,111007}
x020042_g_IdJingYing[2]={111008,111008,111008,111008,111008,111008,111008,111008,111008,111008,111008,111008,111008,111008,111008,111008,111008,111008,111008,111008}
x020042_g_IdJingYing[3]={111009,111009,111009,111009,111009,111009,111009,111009,111009,111009,111009,111009,111009,111009,111009,111009,111009,111009,111009,111009}


x020042_g_JingYingBuff={}
x020042_g_JingYingBuff[1] = {-1,-1, -1,-1, -1,-1}            -- Buff 编号


x020042_g_IdBoss={}
x020042_g_IdBoss[1]={111010,111010,111010,111010,111010,111010,111010,111010,111010,111010,111010,111010,111010,111010,111010,111010,111010,111010,111010,111010}
    

x020042_g_MonsterPosList={}     
x020042_g_MonsterPosList[1]={{36.99,41.55,4.14},{33.36,43.87,4.14},{29.68,45.72,4.14},{30.83,47.52,4.14},{34.51,45.67,4.14},{38.14,43.35,4.14}}
x020042_g_MonsterPosList[2]={{39.24,53.11,4.14},{31.74,49.63,4.14},{35.73,47.59,4.14},{39.29,45.32,4.14},{38.4,48.98,4.14},{35.03,50.63,4.14}}
x020042_g_MonsterPosList[3]={{50.46,81.99,4.09},{54.16,79.96,4.09},{57.91,77.87,4.09},{59.11,80.23,4.09},{55.48,82.55,4.09},{51.8,84.4,4.09}}
x020042_g_MonsterPosList[4]={{63.29,92.47,3.96},{57.24,91.64,3.96},{60.1,88.96,3.96},{62.49,86.44,3.96},{62.56,89.35,3.96},{59.99,91.92,3.96}}
x020042_g_MonsterPosList[5]={{97.67,96.03,3.16},{97.46,100.26,3.16},{96.85,104.9,3.16},{100.34,105.13,3.16},{100.52,100.38,3.16},{100.78,95.66,3.16}}
x020042_g_MonsterPosList[6]={{104,94,3.11},{103.38,96,3.11},{102,92,3.11},{102,98,3.11},{101,94,3.11},{101,91,3.11}}
x020042_g_MonsterPosList[7]={{108.95,44.75,1.98}}

x020042_g_ResurrectionPosList = {}
x020042_g_ResurrectionPosList[1]={{18,18,0.97}}                      -- 复活点坐标

x020042_g_TotalNum = 35							   -- 总的怪物数量	 
x020042_g_CurNum = 0

x020042_g_BossPaoPao = 5019
x020042_g_Bossid = 60003							   --  Boss对话	形象
x020042_g_BossTips = 5018

x020042_g_initialAp = 80	-- 初始百分比怒气


x020042_g_CSParamIdxCurStage=0                     -- 场景切换波数
x020042_g_CSParamIdxCurSubStage=1				   -- 同一场景中的时间点					
x020042_g_CSParamIdxcurNum = 3					   -- 总的杀怪个数	
x020042_g_CSParamIdxbossStory = 4 				   -- 普通boss动画播放完毕时间戳

x020042_g_BossNumEnumId = 55
x020042_g_AdaptLvlNum = 20
x020042_g_JingYingObjId = 0
x020042_g_JingYingImage = {60000,60001,60002}
x020042_g_JingYingTips = {5022,5023,5024}
--x020042_g_Trees_roleId = 
--x020042_g_Trees_ModelId = 					   -- 果树模型
function x020042_OnCopySceneTick(scene,tickCount)					--副本阶段
	local curStage = GetCopySceneParam(scene,x020042_g_CSParamIdxCurStage) +1
	local curSubStage = GetCopySceneParam(scene,x020042_g_CSParamIdxCurSubStage) +1
	SetCopySceneParam(scene,x020042_g_CSParamIdxCurSubStage,curSubStage)
	nAdaptedLvl = x020042_g_AdaptLvlNum
	  	
	if(tickCount == 0)  then
		local nUserCount = GetSceneUserCount(scene)
		for i=0,nUserCount-1 do
			local nUserObjId = GetUserObjIdByIdx(scene,i)
			SetPerAp(scene, nUserObjId, x020042_g_initialAp)
		end
	end
	if curStage == 1 then
		OnCSMissionStage(scene,curStage-1)
		x020042_Stage_1(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 2 then
		OnCSMissionStage(scene,curStage-1)
		x020042_Stage_2(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 3 then
		OnCSMissionStage(scene,curStage-1)
		x020042_Stage_3(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 4 then
		OnCSMissionStage(scene,curStage-1)
		x020042_Stage_4(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 5 then
		OnCSMissionStage(scene,curStage-1)
		x020042_Stage_5(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 6 then
		OnCSMissionStage(scene,curStage-1)
		x020042_Stage_6(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 7 then
		OnCSMissionStage(scene,curStage-1)
		x020042_Stage_7(scene,curStage,curSubStage,nAdaptedLvl, tickCount)
	elseif curStage == 8 then
		OnCSMissionStage(scene,curStage-1)
		x020042_Stage_8(scene,curStage,curSubStage,nAdaptedLvl, rand)
	elseif curStage >= 9 then
		SetCopySceneSuccess(scene)
	end									
end

function x020042_OnCopySceneOpen(scene)
	 AddCSMission(scene,60001)
	 AddCSMission(scene,60002)
	 AddCSMission(scene,60003)
	 AddCSMission(scene,60004)
	 AddCSMission(scene,60005)
	 AddCSMission(scene,60006)
	 AddCSMission(scene,60007)
end


function  x020042_OnObjDie(scene,objId,rolebaseId,killerId)			
	local MonCount = GetHostileMonsterCount(scene)
	local OldNum = GetCopySceneParam(scene, x020042_g_CSParamIdxcurNum)
	if(0 ~= GetObjType(scene, objId)) then
	SetCopySceneParam(scene, x020042_g_CSParamIdxcurNum, OldNum+1) 
	end
	if(MonCount == 0) then
		local nCurStage = GetCopySceneParam(scene,x020042_g_CSParamIdxCurStage)
		if(nCurStage == 6)    then		
			--OnCSMissionStage(scene,nCurStage-1)
			print(11)													-- BOSS奖励次数的限制
			local nUserCount = GetSceneUserCount(scene)		
			for i=0,nUserCount-1 do
				local nUserObjId = GetUserObjIdByIdx(scene,i)
				local nLvl = GetLevel(scene,nUserObjId)
				local nIdx = math.floor(nLvl/10) + 1
				--x020042_CheckMissionMD(scene, nUserObjId, x020042_g_BossNumEnumId)

				local oldTime = GetMissionMD(scene, nUserObjId, 4, x020042_g_BossNumEnumId)
				SetMissionMD(scene, nUserObjId, 4, x020042_g_BossNumEnumId, oldTime+1)

				--if(GetMissionMD(scene,nUserObjId,4,x020042_g_BossNumEnumId)%100 <= 2) then
					--CreatDropBox(scene,nUserObjId, x020042_g_BossReward[1][nIdx])
				--end
			--	AddActivtyNum(scene, nUserObjId , 1)                                        --活动活跃度
			end
		end
		if(nCurStage == 7)    then															-- 隐藏BOSS奖励次数限制
			local nUserCount = GetSceneUserCount(scene)
			
			for i=0,nUserCount-1 do		
				local nUserObjId = GetUserObjIdByIdx(scene,i)
				local nLvl = GetLevel(scene,nUserObjId)
				local nIdx = math.floor(nLvl/10) + 1
			end
			SendAllPlayerServerTips(scene, "#{20034}*")
			x020042_Success(scene)
		end
		SetCopySceneParam(scene,x020042_g_CSParamIdxCurStage,nCurStage+1)
		SetCopySceneParam(scene,x020042_g_CSParamIdxCurSubStage,0)

	end
end
function x020042_CreateJingYingBuff( scene, idx, nlv)	--刷怪（
		local nUserCount = GetSceneUserCount(scene)				
		if idx == 2 then
			
			for i=0,nUserCount-1 do
				local nUserObjId = GetUserObjIdByIdx(scene,i)
				SendImpactToUnit(scene, nUserObjId, x020042_g_JingYingBuff[1][idx])
				SendImpactToUnit(scene, nUserObjId, x020042_g_JingYingBuff[1][idx-1])
			end
		elseif idx > 2  then
			local n = 800
			function sleep(n)
   				if n > 0 then os.execute("ping -n " .. tonumber(n + 1) .. " localhost > NUL") end
			end
			SendImpactToAllByRBID(scene, x020042_g_IdJingYing[idx/2][nlv], x020042_g_JingYingBuff[1][idx-1])
		end
end
function x020042_CreateMonster( scene,idx,camp, nlv)					--刷怪（
	if idx <= #x020042_g_IdPuTong then
		if(0 == idx%2)  then
			CreateMonster(scene,x020042_g_IdJingYing[idx/2][nlv], x020042_g_MonsterPosList[idx][1][3],x020042_g_MonsterPosList[idx][1][1],x020042_g_MonsterPosList[idx][1][2])
			local nUserCount = GetSceneUserCount(scene)
			for i=0,nUserCount-1 do
				local nUserObjId = GetUserObjIdByIdx(scene,i)
				ShowBossTips(scene, nUserObjId, x020042_g_JingYingImage[idx/2], x020042_g_JingYingTips[idx/2],x020042_g_IdJingYing[idx/2][nlv])--喊话
			end
		end
		local nCount = #x020042_g_MonsterPosList[idx]
		for i=((idx+1)%2)+1,nCount do
			local objId = CreateMonster(scene,x020042_g_IdPuTong[idx][nlv],x020042_g_MonsterPosList[idx][i][3],x020042_g_MonsterPosList[idx][i][1],x020042_g_MonsterPosList[idx][i][2])
		end
		
	end
end
function x020042_CheckMissionMD(scene ,objId, type)
	local nLastData = GetMissionMD(scene, objId, 4, type)
	local nNewData = CheckRefreshTime(scene, nLastData, objId, 0)
	if math.floor(nLastData/100) ~= nNewData then
		SetMissionMD(scene, objId, 4, type, nNewData*100)
	end
end
function x020042_Success(scene)									-- 带小号奖励结算
	ShowWinPanel(scene)
	AccoutByCopyScene(scene)	
end
function x020042_Stage_1(scene ,stage,substage, nlv)                      
	if substage == 1 then
		x020042_CreateMonster(scene,stage,3,nlv)
	end
end
function x020042_Stage_2(scene ,stage,substage, nlv)                        
	if(substage == 1) then
		x020042_CreateMonster(scene,stage,3,nlv)
	elseif substage == 2 then
		x020042_CreateJingYingBuff(scene, stage, nlv)
	end
end
function x020042_Stage_3(scene ,stage,substage,nlv)                      
	if substage == 1 then
		x020042_CreateMonster(scene,stage,3,nlv)		
	end
end
function x020042_Stage_4(scene ,stage,substage,nlv)						
	if substage == 1 then
		x020042_CreateMonster(scene,stage,3,nlv)	
	elseif substage == 2 then
		x020042_CreateJingYingBuff(scene, stage, nlv)
	end
end
function x020042_Stage_5(scene ,stage,substage,nlv)					
	if substage == 1 then
		x020042_CreateMonster(scene,stage,3,nlv)	
	end
end
function x020042_Stage_6(scene ,stage,substage,nlv)							
	if substage == 1 then
		x020042_CreateMonster(scene,stage,3,nlv)	
	elseif substage == 2 then
		x020042_CreateJingYingBuff(scene, stage, nlv)
	end
end
function x020042_Stage_7(scene ,stage,substage,nlv,tickcount)		
	local tick = GetCopySceneParam(scene, x020042_g_CSParamIdxbossStory)
	if substage == 1 then
		StoryAnimation(scene, 6020)
		SetCopySceneParam(scene, x020042_g_CSParamIdxbossStory,tickcount + 10)

	elseif tick ~= 0 and tickcount == tick + 1 then
		local nUserCount = GetSceneUserCount(scene)
		for i=0,nUserCount-1 do
			local nUserObjId = GetUserObjIdByIdx(scene,i)
			ShowBossTips(scene, nUserObjId, x020042_g_Bossid, x020042_g_BossTips, x020042_g_IdBoss[1][nlv])
		end
	elseif tick ~= 0 and tickcount == tick + 2 then
		local nObjId = CreateMonster(scene,x020042_g_IdBoss[1][math.ceil((GetAdaptLvl(scene)-x020042_g_BeginLevel)/5)],x020042_g_MonsterPosList[7][1][3], x020042_g_MonsterPosList[7][1][1],x020042_g_MonsterPosList[7][1][2])
		SetNpcCampByObjId(scene,nObjId,1)
	elseif tick ~= 0 and tickcount == tick + 3 then
		NpcPaoPaoByRBId(scene,x020042_g_IdBoss[1][math.ceil((GetAdaptLvl(scene)-x020042_g_BeginLevel)/5)],x020042_g_BossPaoPao)
	elseif tick ~= 0 and tickcount == tick + 4 then
		SetNpcCampByRBId(scene,x020042_g_IdBoss[1][math.ceil((GetAdaptLvl(scene)-x020042_g_BeginLevel)/5)],3)
	end
end
function x020042_Stage_8(scene ,stage,substage,nlv, rand)						
	x020042_Success(scene)
	local nUserCount = GetSceneUserCount(scene)
	local nCurStage = GetCopySceneParam(scene,x020042_g_CSParamIdxCurStage)
	for i=0,nUserCount-1 do
		local nUserObjId = GetUserObjIdByIdx(scene,i)
	end	
	SendAllPlayerServerTips(scene, "#{20035}*")
	SetCopySceneParam(scene,x020042_g_CSParamIdxCurStage,nCurStage+1)
	SetCopySceneParam(scene,x020042_g_CSParamIdxCurSubStage,0)
end


function x020042_OnObjresurrectionEnd(scene ,objId)
		SetPos(scene,objId,115,9, 0)
end
function x020042_OnStoryEventEnd(scene,nStoryId,nAnimationId)
		if nAnimationId == 6020 then
			local tick = GetCopySceneParam(scene, 9)
			local originaltick = GetCopySceneParam(scene, x020042_g_CSParamIdxbossStory)
			if tick < originaltick  then
				SetCopySceneParam(scene, x020042_g_CSParamIdxbossStory, tick)
			end
		end
end
