x020004_g_scriptId=020004

x020004_g_BeginLevel = 20

x020004_g_IdPuTong={}
x020004_g_IdPuTong[1]={100001,100013,100025,100037,100049,100061,100073,100085,100097,100109,100121,100133,100145,100157,100169,100181,100193}
x020004_g_IdPuTong[2]={100004,100016,100028,100040,100052,100064,100076,100088,100100,100112,100124,100136,100148,100160,100172,100184,100196}
x020004_g_IdPuTong[3]={100007,100019,100031,100043,100055,100067,100079,100091,100103,100115,100127,100139,100151,100163,100175,100187,100199}

x020004_g_IdJingYing={}
x020004_g_IdJingYing[1]={100002,100014,100026,100038,100050,100062,100074,100086,100098,100110,100122,100134,100146,100158,100170,100182,100194}
x020004_g_IdJingYing[2]={100005,100017,100029,100041,100053,100065,100077,100089,100101,100113,100125,100137,100149,100161,100173,100185,100197}
x020004_g_IdJingYing[3]={100008,100020,100032,100044,100056,100068,100080,100092,100104,100116,100128,100140,100152,100164,100176,100188,100200}

x020004_g_IdBoss={}
x020004_g_IdBoss[1]={100003,100015,100027,100039,100051,100063,100075,100087,100099,100111,100123,100135,100147,100159,100171,100183,100195}
x020004_g_IdBoss[2]={100006,100018,100030,100042,100054,100066,100078,100090,100102,100114,100126,100138,100150,100162,100174,100186,100198}
x020004_g_IdBoss[3]={100009,100021,100033,100045,100057,100069,100081,100093,100105,100117,100129,100141,100153,100165,100177,100189,100201}

x020004_g_IdBossLuck={}
x020004_g_IdBossLuck[1]={100010,100022,100034,100046,100058,100070,100082,100094,100106,100118,100130,100142,100154,100166,100178,100190,100202}
x020004_g_IdBossLuck[2]={100011,100023,100035,100047,100059,100071,100083,100095,100107,100119,100131,100143,100155,100167,100179,100191,100203}
x020004_g_IdBossLuck[3]={100012,100024,100036,100048,100060,100072,100084,100096,100108,100120,100132,100144,100156,100168,100180,100192,100204}

x020004_g_Pos={}
x020004_g_Pos[1]={{54,21,2.9},{43,23,3.3},{50,28,4.2},{43,19,2.9},{47,26,3.7},{53,24,3.5}}
x020004_g_Pos[2]={{85,29,2.7},{86,35,3.3},{84,37,4.2},{85,32,3.6},{82,34,3.8},{92,32,3.1}}
x020004_g_Pos[3]={{44,68,5.4},{36,68,5.9},{43,62,3.8},{50,65,3.6},{48,70,4.2},{46,63,0},{41,67,0.8},{41,71,5.9}}
x020004_g_Pos[4]={{33,102,6.5},{28,92,5.7},{35,92,5},{31,96,5.1},{33,97,5.8},{25,100,6},{30,102,5.9},{28,96,3.3},{38,98,0.4},{23,97,5.9}}
x020004_g_Pos[5]={{71,84,4},{68,81,5.3},{69,95,0.8},{66,98,6.1},{64,95,4.4},{65,91,4.2},{72,80,4.2},{72,91,1.8},{66,85,1.7},{71,96,3.7}}
x020004_g_Pos[6]={{83,77,2.6}}
x020004_g_Pos[7]={{104,97,4}}


x020004_g_BossLuckDropPack = 110075

x020004_g_PutongFakeObjID = {}
x020004_g_PutongFakeObjID[1] = {100003, 100006, 100009}

x020004_g_PutongStrId = {}
x020004_g_PutongStrId[1] = {41012, 41014, 41016}

x020004_g_BossLuckFakeObjID = {}
x020004_g_BossLuckFakeObjID[1] = {100010, 100011, 100012}

x020004_g_BossLuckStrId = {}
x020004_g_BossLuckStrId[1] = {41013, 41015, 41017}

x020004_g_CSParamType=0
x020004_g_CSParamStage=1
x020004_g_CSParamBossroleid = 2
x020004_g_CSParamBossPaoPao = 3
x020004_g_CSParamLuckBossPaoPao = 4
x020004_g_CSParamBossId = 5
x020004_g_CSParamLuckBossId = 6
x020004_g_CSParamLuckBossroleid = 7


x020004_g_IdPaoPaoBoss=41012
x020004_g_IdPaoPaoLuckBoss=41013

x020004_g_TotalNum = 9999

x020004_g_IdCSItemBox={10001,10002,10003,10004,10005,10006,10007,10008,10009,10010}
x020004_g_IdCSItemBoxXiayi=11001

function x020004_OnCopySceneOpen( scene )
	AddCSMission(scene,60021)
	AddCSMission(scene,60022)
	AddCSMission(scene,60023)
	AddCSMission(scene,60024)
	AddCSMission(scene,60025)
	AddCSMission(scene,60026)
	AddCSMission(scene,60027)
end

function x020004_OnCopySceneTick(scene,tickCount)	
	if( tickCount == 0) then
		math.randomseed(os.time())
		local nRand = math.random(1,3)
		SetCopySceneParam(scene,x020004_g_CSParamType,nRand)
		SetCopySceneParam(scene,x020004_g_CSParamStage,1)
		local nAdaptedLvl = math.floor((GetAdaptLvl(scene)-x020004_g_BeginLevel)/5)+1
		x020004_CreateMonster(scene,1,nAdaptedLvl,nRand)
	end			
	--SetCopySceneParam(scene, x020004_g_CSParamStage, 4)
	local nStage = GetCopySceneParam(scene,x020004_g_CSParamStage)+1
	if nStage == 7 and GetCopySceneParam(scene, x020004_g_CSParamBossPaoPao) ~= 0	then
		local nbossStag = GetCopySceneParam(scene, x020004_g_CSParamBossPaoPao)
		if nbossStag > 0 and nbossStag < 2 then
			if nbossStag == 1 then
				NpcPaoPaoByRBId(scene,GetCopySceneParam(scene, x020004_g_CSParamBossroleid),x020004_g_IdPaoPaoBoss)
			end
			SetCopySceneParam(scene, x020004_g_CSParamBossPaoPao, nbossStag+1)
		elseif nbossStag == 2 then

			SetNpcCampByObjId(scene,GetCopySceneParam(scene, x020004_g_CSParamBossId),3)
			SetCopySceneParam(scene, x020004_g_CSParamBossPaoPao, 0)
		end
	end
	if nStage == 8 and GetCopySceneParam(scene, x020004_g_CSParamLuckBossPaoPao) ~= 0	then
		local nbossStag = GetCopySceneParam(scene, x020004_g_CSParamLuckBossPaoPao)
		if nbossStag > 0 and nbossStag < 2 then
			if nbossStag == 1 then
				NpcPaoPaoByRBId(scene,GetCopySceneParam(scene, x020004_g_CSParamLuckBossroleid),x020004_g_IdPaoPaoLuckBoss)
			end
			SetCopySceneParam(scene, x020004_g_CSParamLuckBossPaoPao, nbossStag+1)
		elseif nbossStag == 2 then

			SetNpcCampByObjId(scene,GetCopySceneParam(scene, x020004_g_CSParamLuckBossId),3)
			SetCopySceneParam(scene, x020004_g_CSParamLuckBossPaoPao, 0)
		end
	end
end

function x020004_OnObjDie( scene,objId,rolebaseId,killerId )				

	local MonCount = GetHostileMonsterCount(scene)

	if(MonCount == 0) then
		local nStage = GetCopySceneParam(scene,x020004_g_CSParamStage)+1
		local nAdaptedLvl = math.floor((GetAdaptLvl(scene)-x020004_g_BeginLevel)/5)+1
		local nType = GetCopySceneParam(scene,x020004_g_CSParamType)
		print(nStage)
		if (nStage <6) then
			OnCSMissionStage(scene,nStage-1)
			if nStage == 2 then
					local nUserCount = GetSceneUserCount(scene)
					for i=0,nUserCount-1 do
						local nUserObjId = GetUserObjIdByIdx(scene,i)
						ShowBossTips(scene, nUserObjId, x020004_g_PutongFakeObjID[1][nType], x020004_g_PutongStrId[1][nType],x020004_g_IdBoss[nType][nAdaptedLvl])
					end
			end
			

			SetCopySceneParam(scene,x020004_g_CSParamStage,nStage)			
			x020004_CreateMonster(scene,nStage,nAdaptedLvl,nType)

		elseif (nStage == 6) then

			OnCSMissionStage(scene,nStage-1)
			SetCopySceneParam(scene,x020004_g_CSParamStage,nStage)			
			local nObjId = CreateMonster(scene,x020004_g_IdBoss[nType][nAdaptedLvl],x020004_g_Pos[6][1][3],x020004_g_Pos[6][1][1],x020004_g_Pos[6][1][2])
			SetNpcCampByObjId(scene,nObjId,1)
			
			SetCopySceneParam(scene, x020004_g_CSParamBossroleid, x020004_g_IdBoss[nType][nAdaptedLvl])
			SetCopySceneParam(scene, x020004_g_CSParamBossId, nObjId)
			SetCopySceneParam(scene, x020004_g_CSParamBossPaoPao, 1)
			--NpcPaoPaoByRBId(scene,x020004_g_IdBoss[nType][nAdaptedLvl],x020004_g_IdPaoPaoBoss)

		elseif (nStage == 7) then

			math.randomseed(os.time())
			local nRand = math.random(1,10000)

			if nRand < 10000 then
				OnCSMissionStage(scene,nStage-1)
				SetCopySceneParam(scene,x020004_g_CSParamStage,nStage)			
				local nObjIdMon = CreateMonster(scene,x020004_g_IdBossLuck[nType][nAdaptedLvl],x020004_g_Pos[7][1][3],x020004_g_Pos[7][1][1],x020004_g_Pos[7][1][2])
			--	NpcPaoPaoByRBId(scene,x020004_g_IdBossLuck[nType][nAdaptedLvl],x020004_g_IdPaoPaoLuckBoss)
			--	BroadCastTips(scene,1)
				SetNpcCampByObjId(scene,nObjIdMon,1)
				SetCopySceneParam(scene, x020004_g_CSParamLuckBossroleid, x020004_g_IdBossLuck[nType][nAdaptedLvl])
				SetCopySceneParam(scene, x020004_g_CSParamLuckBossId, nObjIdMon)
				SetCopySceneParam(scene, x020004_g_CSParamLuckBossPaoPao, 1)
				local nUserCount = GetSceneUserCount(scene)
					for i=0,nUserCount-1 do
						local nUserObjId = GetUserObjIdByIdx(scene,i)
						ShowBossTips(scene, nUserObjId, x020004_g_BossLuckFakeObjID[1][nType], x020004_g_BossLuckStrId[1][nType],x020004_g_IdBossLuck[nType][nAdaptedLvl])
					end
			else
				x020004_Success(scene)
			end
		elseif (nStage == 8) then
			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
				x020004_CheckMissionMD(scene, nUserObjId, 53)

				local oldTime = GetMissionMD(scene, nUserObjId, 3, 53)
				SetMissionMD(scene, nUserObjId, 3, 53, oldTime+1)
				
				if(GetMissionMD(scene, nUserObjId, 3, 53)%100 <= 2) then
					CreatDropBox(scene,nUserObjId, x020004_g_BossLuckDropPack,objId)
				end
			end
			x020004_Success(scene) 
		end
	end

end
function x020004_CheckMissionMD(scene ,objId, type)
	local nLastData = GetMissionMD(scene, objId, 3, type)
	local nNewData = CheckRefreshTime(scene, nLastData, objId, 0)       -- 参数为0代表每天更新
	if math.floor(nLastData/100) ~= nNewData then
		SetMissionMD(scene, objId, 3, type, nNewData*100)
	end
end
function x020004_Success(scene)
	AccoutByCopyScene(scene)	
	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
		if( nil ~= x020004_g_IdCSItemBox[nIdx]) then
			AwardCSItemBox(scene,nUserObjId,x020004_g_IdCSItemBoxXiayi,x020004_g_IdCSItemBox[nIdx])
		end		
	end

	SetCopySceneSuccess(scene)
end

function x020004_CreateMonster(scene,nStage,nLvl,nType)
	if(x020004_g_Pos[nStage] ~= nil) then
		CreateMonster(scene,x020004_g_IdJingYing[nType][nLvl],x020004_g_Pos[nStage][1][3],x020004_g_Pos[nStage][1][1],x020004_g_Pos[nStage][1][2])

		local nCount = #x020004_g_Pos[nStage]
		for i=2,nCount do
			CreateMonster(scene,x020004_g_IdPuTong[nType][nLvl],x020004_g_Pos[nStage][i][3],x020004_g_Pos[nStage][i][1],x020004_g_Pos[nStage][i][2])
		end
	end
end

