wx020078_g_scriptId=020078


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

x020078_g_BossId = {}
x020078_g_BossId[1] = {551000}
x020078_g_BossPosList={}
x020078_g_BossPosList[1]={{18.9,26.29,0.01}}    --  Boss 坐标

x020078_g_Movparm = 10

x020078_g_BossDrop1 = 218001  -- 小
x020078_g_BossDrop2 = 218003	-- 大

x020078_g_BossDrop3 = 218002	-- 中

x020078_g_BossDrop1Per = 5
x020078_g_BossDrop3Per = 20

x020078_g_BossIdTips = {}
x020078_g_BossIdTips[1] = {120203}


x020078_g_CSParamIdxCurStage=0                     -- 场景切换波数
x020078_g_CSParamIdxCurSubStage=1				   -- 同一场景中的时间点		
x020078_g_CSParamIdxrandtime=2					   -- 记录击杀了几个第一只怪

x020078_g_CSParamIdLastHpPec = 11    -- 记录上一次tick时 怪物血量  用于计算每秒的boss掉落

function x020078_OnObjEnter(scene, objId)
	SynCsStageData(scene, objId, true)
	--AutoCombat(scene,objId,true)
end
function x020078_OnCopySceneOpen(scene, objId)
	--SynCsStageData(scene, objId, true)
	--AutoCombat(scene,objId,true)
	--StoryAnimation(scene, 7002)
	SetCopySceneParam(scene, x020078_g_CSParamIdLastHpPec, 100)
end
function x020078_OnCopySceneTick(scene,tickCount)					--副本阶段

	x060000_HpCountDown1(scene)
	--print(GetBindMoney(scene))
	local curStage = GetCopySceneParam(scene,x020078_g_CSParamIdxCurStage)
	local curSubStage = GetCopySceneParam(scene,x020078_g_CSParamIdxCurSubStage) +1
	SetCopySceneParam(scene,x020078_g_CSParamIdxCurSubStage,curSubStage)

	local nAdaptedLvl = math.floor(GetAdaptLvl(scene)/10)
	if nAdaptedLvl > x020078_g_AdapteLvl then
		nAdaptedLvl = x020078_g_AdapteLvl
	end

	if curStage == 0 then
		x020078_Stage_1(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 1 then
		x020078_Stage_2(scene, curStage, curSubStage)
	
		
	end			
end
function x060000_HpCountDown1(scene)
--	print("階段是")
--	print(stage)l
		local BindMoney = GetCopySceneBindMoney(scene)
	SetCopySceneParam(scene, 3, BindMoney)

				local nUserCount = GetSceneUserCount(scene)
				for i=0,nUserCount-1 do   
					local nUserObjId = GetUserObjIdByIdx(scene,i)   
					SynCsStageData(scene, nUserObjId)
				end   
	 local nAdaptedLvl = math.floor(GetAdaptLvl(scene)/10)
	if nAdaptedLvl > x020078_g_AdapteLvl then
		nAdaptedLvl = x020078_g_AdapteLvl
	end
	local OldHp = math.ceil(GetCopySceneParam(scene, x020078_g_CSParamIdLastHpPec))
	local ZhobjId2 = GetObjIdByRoleBase(scene, x020078_g_BossId[1][1] + (nAdaptedLvl))
	local NewHp = math.ceil(CalculatePercenHp(scene, ZhobjId2))

	if NewHp <= 0 or NewHp >= OldHp then
		return
	end
	
	local dropNum = math.ceil(OldHp / x020078_g_BossDrop1Per) - math.ceil(NewHp / x020078_g_BossDrop1Per)
	local nUserCount = GetSceneUserCount(scene)
	print("掉落小掉落包的數量")
	print(dropNum)
	MoneyDropEff(scene, ZhobjId2)	
	SetCopySceneParam(scene, x020078_g_CSParamIdLastHpPec, NewHp)
	for i = 1, dropNum do
		for k = 0,nUserCount-1 do		
			local nUserObjId = GetUserObjIdByIdx(scene,k)
	
			CreatDropBox(scene, nUserObjId, x020078_g_BossDrop1, ZhobjId2)
		end
	end

	local dropNum3 = math.ceil(OldHp / x020078_g_BossDrop3Per) - math.ceil(NewHp / x020078_g_BossDrop3Per)

	local nUserCount = GetSceneUserCount(scene)
	print("掉落中的掉落包的數量")
	print(dropNum3)
	--SetCopySceneParam(scene, x020078_g_CSParamIdLastHpPec, NewHp)
	for i = 1, dropNum3 do
		for k = 0,nUserCount-1 do		
			local nUserObjId = GetUserObjIdByIdx(scene,k)
	
			CreatDropBox(scene, nUserObjId, x020078_g_BossDrop3, ZhobjId2)
		end
	end

		local BindMoney = GetCopySceneBindMoney(scene)
	SetCopySceneParam(scene, 3, BindMoney)
				local nUserCount = GetSceneUserCount(scene)
				for i=0,nUserCount-1 do   
					local nUserObjId = GetUserObjIdByIdx(scene,i)   
					SynCsStageData(scene, nUserObjId)
				end   
end
function x020078_ClearAllMonster(scene)
 	local nAdaptedLvl = math.floor(GetAdaptLvl(scene)/10)
	if nAdaptedLvl > x020078_g_AdapteLvl then
		nAdaptedLvl = x020078_g_AdapteLvl
	end
	--    for i = 1, 3 do
    --	DeleMonsterByRoleId(scene, x020078_g_YuansuId[i][nAdaptedLvl])
    --end
    DeleMonsterByRoleId(scene, x020078_g_BossId[1][1] + (nAdaptedLvl))

end
function x020078_Stage_2(scene,curStage,curSubStage)
	-- body
			local nCurStage = GetCopySceneParam(scene, x020078_g_CSParamIdxCurStage)
	SetCopySceneParam(scene,x020078_g_CSParamIdxCurStage,nCurStage+1)
	SetCopySceneParam(scene,x020078_g_CSParamIdxCurSubStage,0)
	ShowBindMoneyCsEnd(scene, true)
	x020078_Success(scene)
end
function x020078_Success(scene)
	AccoutByCopyScene(scene)	
	local nUserCount = GetSceneUserCount(scene)
	for i=0,nUserCount-1 do
		local nUserObjId = GetUserObjIdByIdx(scene,i)
	--	AwardCSItemBox(scene,nUserObjId,x020078_g_IdCSxiayiBox, x020078_g_IdCSItemBox)
	end
	SetCopySceneSuccess(scene)
end


function  x020078_OnObjDie(scene,objId,rolebaseId,killerId)			
	local MonCount = GetHostileMonsterCount(scene)
	local nCurStage = GetCopySceneParam(scene, x020078_g_CSParamIdxCurStage)
	local nAdaptedLvl = math.floor(GetAdaptLvl(scene)/10)
	if nAdaptedLvl > x020078_g_AdapteLvl then
		nAdaptedLvl = x020078_g_AdapteLvl
	end
	if rolebaseId == x020078_g_BossId[1][1] +  (nAdaptedLvl) then
		SetCopySceneParam(scene, x020078_g_CSParamIdxrandtime, 1)
		MoneyDropEff(scene, objId)
		local nUserCount = GetSceneUserCount(scene)
				for k = 0,nUserCount-1 do		
					local nUserObjId = GetUserObjIdByIdx(scene,k)
				--	print("獲得掉落")
				--	print(x020068_g_DropId[1][i])
				print("boss死後大掉落")
					CreatDropBox(scene, nUserObjId, x020078_g_BossDrop2, objId)
				end

				local DropNum = GetCopySceneParam(scene, x020078_g_CSParamIdLastHpPec)
				local dropNum1 = math.ceil(DropNum / x020078_g_BossDrop1Per)-1
				print("boss死後彌補小掉落數量")
				print(dropNum1)
				for j = 1, dropNum1 do
					for k1 = 0,nUserCount-1 do		
							local nUserObjId = GetUserObjIdByIdx(scene,k1)
							CreatDropBox(scene, nUserObjId, x020078_g_BossDrop1, objId)
						end
				end


				local dropNum3 = math.ceil(DropNum / x020078_g_BossDrop3Per)-1
				print("boss死後彌補中掉落數量")
				print(dropNum3)
				for j = 1, dropNum3 do
					for k1 = 0,nUserCount-1 do		
							local nUserObjId = GetUserObjIdByIdx(scene,k1)
							CreatDropBox(scene, nUserObjId, x020078_g_BossDrop3, objId)
						end
				end
			
	end
	--x020078_OnDieCountDown1(scene, rolebaseId, nAdaptedLvl)


	if(MonCount == 0) then

		SetCopySceneParam(scene,x020078_g_CSParamIdxCurStage,nCurStage+1)
		SetCopySceneParam(scene,x020078_g_CSParamIdxCurSubStage,0)
	end
end
function x020078_OnDieCountDown1(scene, rolebaseId, nlv)
	local TargetId = x020078_g_BossId[1][1] +  (nlv)
	if(TargetId == rolebaseId) then
		local OldValue = GetCopySceneParam(scene, x020078_g_CSParamIdxrandtime)
		SetCopySceneParam(scene, x020078_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 x020078_CreateMonster( scene,idx,camp, nlv)					--刷怪（
	local count = #x020078_g_MonsterPosList[idx]
	for i = 1, count  do
		CreateMonster(scene,  x020078_g_IdPuTong[idx][i][nlv], x020078_g_MonsterPosList[idx][i][3], x020078_g_MonsterPosList[idx][i][1],x020078_g_MonsterPosList[idx][i][2])
	end
end

function x020078_Stage_1(scene ,stage,substage, nlv)                      
	if substage == 1 then
		
		BroadCastBossTips(scene, 30100, x020078_g_BossIdTips[1][1], 551000)
		print("刷怪了")
		print(x020078_g_BossId[1][1] +  (nlv))
						local nUserCount = GetSceneUserCount(scene)				
				for i=0,nUserCount-1 do   
					local nUserObjId = GetUserObjIdByIdx(scene,i)   
					AutoCombat(scene,nUserObjId,true)
				end    
		local objid = CreateMonster(scene, x020078_g_BossId[1][1] +  (nlv), x020078_g_BossPosList[1][1][3], x020078_g_BossPosList[1][1][1],x020078_g_BossPosList[1][1][2])
		--SetNpcCampByObjId(scene,objid,1)
	end
end

function x020078_OnCopySceneTimeOut(scene)
	DeleHostileMonster(scene)
	
	ShowBindMoneyCsEnd(scene, false)

end
