--任务副本1
--进入副本→刷第一波小怪→击杀第一波小怪→刷第二波小怪→击杀第二波小怪→刷BOSS→击杀BOSS→副本完成→传出副本

x020185_g_scriptId = 020185

--副本参数
x020185_g_CSParamIdxCurStage = 0			  --大阶段	
x020185_g_CSParamIdxCurSubStage = 1           --小阶段
x020185_g_KillMonsterNum = 2				  -- 记录杀了多少怪

x020185_g_chooseFinish = 4 					  -- 副本选择完成记录
x020185_g_PositionOne = 5   				  -- 事件位置 1标记
x020185_g_PositionTwo = 6 					  -- 事件位置 2标记
x020185_g_PortalDisappearsOne = 11    		      -- 传送门消失 标识
x020185_g_PortalDisappearsTwo = 12				 -- 传送门消失 标识

x020185_g_CSParamIdxBoxHpAward = 13 -- 该次副本血量奖励索引

x020185_g_ExtendTime = 10 -- 延迟时间
x020185_g_CopyEndMark = 17 -- 副本结束标识
x020185_g_BossDieMark = 18 
x020185_g_NotickMark = 19
x020185_g_AdapteLvl = 60  --   每个怪物的自适应等级套数  必须随适应等级的变化而改变

x020185_g_chooseTime = 30

x020185_g_MonstorList={}
x020185_g_MonstorList[1]={12001001, 12001001, 12001001, 12001001, 12001001, 12001001, 12001001,12001001, 12001077, 12001153, 12001153, 12001153, 12001153, 12001229, 12001229}  --小怪
x020185_g_MonstorList[2]={12001001, 12001001, 12001001, 12001001, 12001001, 12001001, 12001001,12001001, 12001077, 12001305, 12001305, 12001305, 12001305, 12001381, 12001381}  --小怪                            
x020185_g_MonstorList[3]={12001609}       --BOSS

x020185_g_MonstorPosList={}
x020185_g_MonstorPosList[1]={{14.3,14.3,-1.57},{14.3,16.5,-1.57},{16.5,16.5,-1.57},{18.7,16.5,-1.57},{14.3,18.7,-1.57},{16.5,18.7,-1.57},{18.7,18.7,-1.57},{18.7,14.3,-1.57},{16.5,14.3,-1.57},{21.68,29.9,3.14},{25,29.9,3.14},{21.68,23.3,3.14},{25,23.3,3.14},{21.57,25.8,3.14},{21.57,27.68,3.14}} --小怪坐标
x020185_g_MonstorPosList[2]={{18.54,49.77,-1.57},{14.14,49.77,-1.57},{16.33,47.57,-1.57},{14.14,45.37,-1.57},{18.54,45.41,-1.57},{16.33,49.77,-1.57},{18.54,47.57,-1.57},{14.14,47.57,-1.57},{16.33,45.41,-1.57},{16.19,58.58,-1.57},{9.61,58.58,-1.57},{16.19,61.08,-1.57},{9.6,61.08,-1.57},{13.7,58.58,-1.57},{11.85,58.58,-1.57}} --小怪坐标
x020185_g_MonstorPosList[3]={{56.32,54.16,3.14}}


x020185_g_JarList={} -- 罐子id
x020185_g_JarList[1]={12001686, 12001686, 12001687} 
x020185_g_JarList[2]={12001685, 12001686, 12001687, 12001687} 
x020185_g_JarList[3]={12001685, 12001686,12001686} 
x020185_g_JarList[4]={12001687, 12001687} 
x020185_g_JarList[5]={12001685, 12001686, 12001687} 
x020185_g_JarList[6]={12001685, 12001687} 

x020185_g_JarPosList={} -- 罐子坐标
x020185_g_JarPosList[1]={{25.32,14.62,1.57},{25.22,16.21,1.57},{27.05,16.18,1.57}}
x020185_g_JarPosList[2]={{7.8,29.71,1.57},{7.29,27.79,1.57},{10,29.52,1.57},{8.67,28.56,1.57}}
x020185_g_JarPosList[3]={{9.26,46.25,1.57},{9.63,44.93,1.57},{8.08,45.94,1.57}}
x020185_g_JarPosList[4]={{23.22,60.86,1.57},{21.99,61.81,1.57}}
x020185_g_JarPosList[5]={{47.48,43.63,1.57},{49.19,43.73,1.57},{47.64,45.56,1.57}}
x020185_g_JarPosList[6]={{55.04,64.86,1.57},{56.68,64.85,1.57}}

x020185_g_JinBiList={} -- 金币堆
x020185_g_JinBiList[1]={12001457} 
x020185_g_JinBiPosList={}
x020185_g_JinBiPosList[1]={{24.75,26.62,0}}

x020185_g_BaoShiList={} -- 宝石堆
x020185_g_BaoShiList[1]={12001533} 
x020185_g_BaoShiPosList={}
x020185_g_BaoShiPosList[1]={{12.8,61.02,1.57}}

x020185_g_Person_1 = {16.67,36.17,5} -- 玩家第一次触发坐标(X坐标 Z坐标 半径)
x020185_g_Person_2 = {42.18,54.11,5} -- 玩家第二次触发坐标(X坐标 Z坐标 半径)

x020185_g_MonstorEventOneList={}  -- 事件 1 触发怪物
x020185_g_MonstorEventOneList[1]={12001688, 12001764, 12001764} 

x020185_g_MonstorEventOnePostList={}
x020185_g_MonstorEventOnePostList[1]={{9.26,46.25,1.57},{9.63,44.93,1.57},{8.08,45.94,1.57}}

x020185_g_MonstorEventTwoList={}  -- 事件 2 触发怪物
x020185_g_MonstorEventTwoList[1]={12001840, 12001916, 12001916} 
x020185_g_MonstorEventTwoPostList={}
x020185_g_MonstorEventTwoPostList[1]={{47.48,43.63,1.57},{49.19,43.73,1.57},{47.64,45.56,1.57}}

x020185_g_MoveListId={}    -- 怪物 寻路id
x020185_g_MoveListId[1]={40101} 
x020185_g_MoveListId[2]={40103} 

x020185_g_RandomLimit = 5000  -- 随机概率 
x020185_g_RandomTotal = 10000

--传送门ID
x020185_g_TransmitIdList={1001,1005}

--传送门坐标
x020185_g_TransmitPos={}
x020185_g_TransmitPos[1]={22.3,61,-2.35}
x020185_g_TransmitPos[2]={54.34,64.26,3.14}

x020185_g_BossDrop1 = 201411  -- Boss 掉落

x020185_g_DropHp = {}   -- 宝箱掉落百分比血量，注意单调，由高到底，填写大于0的数 不包括0
x020185_g_DropHp[1] = { 80, 60, 40, 20}

--死亡impact罐子
x020185_g_DieImpact = 77101 
-- 出生特效 罐子
x020185_g_LiveImpact = 77103
-- 死亡特效 金币
x020185_g_GoldDieImpact = 77104

x020185_g_BossImpact = 77106 -- Boss 特效

x020185_g_PickImpact = 100002 -- 拾取buff 金币本专用

function x020185_OnObjEnter(scene, objId)
	--CopySceneNPC(scene,1001101,51001,6,201,1,"XXX")--场景、角色ID、CharModel表ID、势力、出现的场景SceneID、等级、名称
	SynCsStageData(scene, objId, true)
	SendImpactToUnit(scene, objId, x020185_g_PickImpact)
end

function x020185_OnCopySceneOpen(scene)
	local nUserCount = GetSceneUserCount(scene)
	for j=0,nUserCount-1 do
		local nUserObjId = GetUserObjIdByIdx(scene,j)
		SetHpFull(scene, nUserObjId)
	end	
	SetCopySceneParam(scene, x020185_g_chooseFinish, 0)
	SetCopySceneParam(scene, x020185_g_CSParamIdxCurStage, 0)
	SetCopySceneParam(scene, x020185_g_PositionOne, 0)
	SetCopySceneParam(scene, x020185_g_PositionTwo, 0)
	SetCopySceneParam(scene, x020185_g_PortalDisappearsOne, 0)
	SetCopySceneParam(scene, x020185_g_PortalDisappearsTwo, 0)
	SetCopySceneParam(scene, x020185_g_KillMonsterNum, 0)
	SetCopySceneParam(scene, x020185_g_CopyEndMark, 0)
	SetCopySceneParam(scene, x020185_g_ExtendTime, 0)
	SetCopySceneParam(scene, x020185_g_BossDieMark, 0)
	SetCopySceneParam(scene, x020185_g_NotickMark, 0)
	
end


--死亡回调
function x020185_OnObjDie( scene,objId,rolebaseId,killerId )
	local nCurStage = GetCopySceneParam(scene,x020185_g_CSParamIdxCurStage)
	local nAdaptedLvl = math.floor(GetAdaptLvl(scene)/10) - 25
	if nAdaptedLvl > x020185_g_AdapteLvl then
		nAdaptedLvl = x020185_g_AdapteLvl
	end	
	x020185_CheckDoorDel(scene, rolebaseId, nAdaptedLvl)
	if(rolebaseId == x020185_g_MonstorList[3][1] + (nAdaptedLvl)) then
		SetCopySceneParam(scene, x020185_g_BossDieMark, 1)
		x020185_HpCountDown1(scene)
	end	
	local MonCount = GetHostileMonsterCountForGoldFuben(scene, 12001686, 12001685, 12001687, 12001457 + nAdaptedLvl, 12001533 + nAdaptedLvl, 12001688 + nAdaptedLvl, 12001764 + nAdaptedLvl)
	if  rolebaseId == 12001686  or rolebaseId == 12001685 or rolebaseId == 12001687  or rolebaseId == 12001457 + nAdaptedLvl  or rolebaseId == 12001533 + nAdaptedLvl or rolebaseId == 12001688 + nAdaptedLvl  or rolebaseId == 12001764 + nAdaptedLvl then
		return
	end	
	local OldValue = GetCopySceneParam(scene, x020185_g_KillMonsterNum)
	if OldValue < #x020185_g_MonstorList[nCurStage+1] and rolebaseId > 100 then
    	SetCopySceneParam(scene, x020185_g_KillMonsterNum, OldValue + 1)
    end
    local nUserCount = GetSceneUserCount(scene)
    for i = 0, nUserCount - 1 do
        local nUserObjId = GetUserObjIdByIdx(scene, i)
        SynCsStageData(scene, nUserObjId)
    end
	if MonCount == 0 then
		SetCopySceneParam(scene,x020185_g_CSParamIdxCurStage,nCurStage+1)
		SetCopySceneParam(scene,x020185_g_CSParamIdxCurSubStage,0)	
		SetCopySceneParam(scene, x020185_g_KillMonsterNum, 0)
	end
end


--副本Tick
function x020185_OnCopySceneTick(scene,tickCount)
	local curStage = GetCopySceneParam(scene,x020185_g_CSParamIdxCurStage)
	local curSubStage = GetCopySceneParam(scene,x020185_g_CSParamIdxCurSubStage)
	SetCopySceneParam(scene, x020185_g_CSParamIdxCurSubStage, curSubStage+1)
	local is_finish =  GetCopySceneParam(scene,x020185_g_chooseFinish)
	local is_EndMark =  GetCopySceneParam(scene,x020185_g_CopyEndMark)
	local nUserCount = GetSceneUserCount(scene)	
	local ExtendTime = GetCopySceneParam(scene, x020185_g_ExtendTime)
	local NotickMark = GetCopySceneParam(scene, x020185_g_NotickMark)
	local nAdaptedLvl = math.floor(GetAdaptLvl(scene)/10) - 25
	if nAdaptedLvl > x020185_g_AdapteLvl then
		nAdaptedLvl = x020185_g_AdapteLvl
	end	
	local nBossMark =  GetCopySceneParam(scene, x020185_g_BossDieMark)
	if ExtendTime == 0 and is_finish == 1 then
		SetCopySceneParam(scene, x020185_g_ExtendTime, tickCount)
	end	
	if curStage == 0 then
		x020185_Stage_1(scene, curStage, curSubStage, nAdaptedLvl, tickCount)
		x020185_StageControl(scene, curStage)
	elseif curStage == 1 then
		x020185_ChenkUserPosOne(scene, x020185_g_Person_1[1], x020185_g_Person_1[2], x020185_g_Person_1[3], nAdaptedLvl) -- 位置 1 检测
		
		x020185_Stage_2(scene, curStage, curSubStage, nAdaptedLvl, tickCount)
		x020185_StageControl(scene, curStage)
	elseif curStage == 2 then	
		x020185_ChenkUserPosTwo(scene, x020185_g_Person_2[1], x020185_g_Person_2[2], x020185_g_Person_2[3], nAdaptedLvl) -- 位置 2 检测			
		x020185_Stage_3(scene, curStage, curSubStage, nAdaptedLvl)
		x020185_HpCountDown1(scene)  -- boss 阶段
		x020185_StageControl(scene, curStage)
	elseif curStage == 3 and nBossMark == 1 and tickCount <= 240 and is_finish == 0 and NotickMark == 0 then -- 通知翻牌
		NoticGoldFuben(scene)
		SetCopySceneParam(scene, x020185_g_NotickMark, 1)
	elseif curStage == 3 and is_finish == 1 and tickCount - ExtendTime == 2 and is_EndMark == 0 then -- 翻牌 (延时3秒)
		SetCopySceneSuccess(scene)
		GoldFuBenEnd(scene, true, true)
		SetCopySceneParam(scene, x020185_g_CopyEndMark, 1)
	elseif curStage == 3 and tickCount > 240 and is_finish == 0 and is_EndMark == 0 and nBossMark == 1 then  -- 不翻牌 评级A	
		SetCopySceneSuccess(scene)
		GoldFuBenEnd(scene, true, false)
		SetCopySceneParam(scene, x020185_g_CopyEndMark, 1)
	end
end

-- 玩家位置1检测 事件1触发
function x020185_ChenkUserPosOne(scene ,posX, posZ, range, nlv)
	local PosMark = GetCopySceneParam(scene,x020185_g_PositionOne)
	local nCount = GetUserCountInRange(scene, posX, posZ, range)
	if PosMark == 0 then
		if nCount == 1 then
			local randPos = math.random(1, x020185_g_RandomTotal) 
			if(randPos >= x020185_g_RandomLimit) then
			-- if(randPos >= 1) then
				x020185_CreateEventMonsterOne(scene, nlv)
			end
			SetCopySceneParam(scene, x020185_g_PositionOne, 1)  -- 已经到达过位置 1
		end
	end
end

-- 事件1 触发 创建传送门与怪
function x020185_CreateEventMonsterOne(scene, nlv)
	local count = #x020185_g_MonstorEventOneList[1] -- 小怪
	SetSceneBuff(scene,x020185_g_TransmitIdList[1],x020185_g_TransmitPos[1][1],x020185_g_TransmitPos[1][2],x020185_g_TransmitPos[1][3])  -- 创建传送门
	for i = 1, count do
		local MonId = CreateMonster(scene, x020185_g_MonstorEventOneList[1][i] + nlv, x020185_g_MonstorEventOnePostList[1][i][3], x020185_g_MonstorEventOnePostList[1][i][1], x020185_g_MonstorEventOnePostList[1][i][2])
		NpcStartPatrol(scene, MonId, x020185_g_MoveListId[1][1])--怪物寻路
	end
end


-- 玩家位置2检测 事件2触发
function x020185_ChenkUserPosTwo(scene ,posX, posZ, range, nlv)
	local PosMark = GetCopySceneParam(scene,x020185_g_PositionTwo)
	local nCount = GetUserCountInRange(scene, posX, posZ, range)
	if PosMark == 0 then
		if nCount == 1 then
			local randPos = math.random(1, x020185_g_RandomTotal) 
			if(randPos >= x020185_g_RandomLimit) then
				x020185_CreateEventMonsterTwo(scene, nlv)
			end
			SetCopySceneParam(scene, x020185_g_PositionTwo, 1)  -- 已经到达过位置 2
		end
	end
end

-- 事件2 触发 创建传送门与怪
function x020185_CreateEventMonsterTwo(scene, nlv)
	local count = #x020185_g_MonstorEventTwoList[1] -- 小怪
	SetSceneBuff(scene,x020185_g_TransmitIdList[2],x020185_g_TransmitPos[2][1],x020185_g_TransmitPos[2][2],x020185_g_TransmitPos[2][3])  -- 创建传送门
	for i = 1, count do
		local MonId = CreateMonster(scene, x020185_g_MonstorEventTwoList[1][i] + nlv, x020185_g_MonstorEventTwoPostList[1][i][3], x020185_g_MonstorEventTwoPostList[1][i][1], x020185_g_MonstorEventTwoPostList[1][i][2])
		NpcStartPatrol(scene, MonId, x020185_g_MoveListId[2][1])--怪物寻路
	end
end


--第1阶段 刷小怪
function x020185_Stage_1(scene ,stage,substage, nlv, tickCount)
	if substage == 1 then		
		for i = 1, 9 do
			CreateMonster(scene, x020185_g_MonstorList[1][i] + nlv, x020185_g_MonstorPosList[1][i][3], x020185_g_MonstorPosList[1][i][1], x020185_g_MonstorPosList[1][i][2])
		end
	end
	if substage == 2 then
		local count_1 = #x020185_g_MonstorList[1] -- 小怪
		for i = 10, count_1 do
			CreateMonster(scene, x020185_g_MonstorList[1][i] + nlv, x020185_g_MonstorPosList[1][i][3], x020185_g_MonstorPosList[1][i][1], x020185_g_MonstorPosList[1][i][2])
		end
		local count_2 = #x020185_g_JarList[1]   -- 罐子
		for i = 1, count_2 do
			local guanzi_1 = CreateMonster(scene, x020185_g_JarList[1][i], x020185_g_JarPosList[1][i][3], x020185_g_JarPosList[1][i][1], x020185_g_JarPosList[1][i][2])
			SendImpactToUnit(scene, guanzi_1, x020185_g_DieImpact)
			SendImpactToUnit(scene, guanzi_1, x020185_g_LiveImpact)		
		end
		local count_3 = #x020185_g_JarList[2]   -- 罐子
		for i = 1, count_3 do
			local guanzi_2 = CreateMonster(scene, x020185_g_JarList[2][i], x020185_g_JarPosList[2][i][3], x020185_g_JarPosList[2][i][1], x020185_g_JarPosList[2][i][2])
			SendImpactToUnit(scene, guanzi_2, x020185_g_DieImpact)
			SendImpactToUnit(scene, guanzi_2, x020185_g_LiveImpact)
		end
		local count_4 = #x020185_g_JinBiList[1]   -- 金币
		for i = 1, count_4 do
			local jinbi = CreateMonster(scene, x020185_g_JinBiList[1][i] + nlv, x020185_g_JinBiPosList[1][i][3], x020185_g_JinBiPosList[1][i][1], x020185_g_JinBiPosList[1][i][2])
			SendImpactToUnit(scene, jinbi, x020185_g_GoldDieImpact)	
		end
		TellPlayerAutoCombat(scene, true)		
	end
end

-- 第2阶段 刷小怪
function x020185_Stage_2(scene ,stage,substage, nlv, tickCount)
	local ExtendTime = GetCopySceneParam(scene, x020185_g_ExtendTime)
	if substage == 1 then	
		for i = 1, 9 do
			CreateMonster(scene, x020185_g_MonstorList[2][i] + nlv, x020185_g_MonstorPosList[2][i][3], x020185_g_MonstorPosList[2][i][1], x020185_g_MonstorPosList[2][i][2])
		end
	end
	if substage == 2 then
		local count_1 = #x020185_g_MonstorList[2]
		for i = 10, count_1 do
			CreateMonster(scene, x020185_g_MonstorList[2][i] + nlv, x020185_g_MonstorPosList[2][i][3], x020185_g_MonstorPosList[2][i][1], x020185_g_MonstorPosList[2][i][2])
		end
		local count_2 = #x020185_g_JarList[3]   -- 罐子
		for i = 1, count_2 do
			local guanzi_1 = CreateMonster(scene, x020185_g_JarList[3][i], x020185_g_JarPosList[3][i][3], x020185_g_JarPosList[3][i][1], x020185_g_JarPosList[3][i][2])
			SendImpactToUnit(scene, guanzi_1, x020185_g_DieImpact)
			SendImpactToUnit(scene, guanzi_1, x020185_g_LiveImpact)	
		end
		local count_3 = #x020185_g_JarList[4]   -- 罐子
		for i = 1, count_3 do
			local guanzi_2 = CreateMonster(scene, x020185_g_JarList[4][i], x020185_g_JarPosList[4][i][3], x020185_g_JarPosList[4][i][1], x020185_g_JarPosList[4][i][2])
			SendImpactToUnit(scene, guanzi_2, x020185_g_DieImpact)
			SendImpactToUnit(scene, guanzi_2, x020185_g_LiveImpact)	
		end
		local count_4 = #x020185_g_BaoShiList[1]   -- 宝石
		for i = 1, count_4 do
			CreateMonster(scene, x020185_g_BaoShiList[1][i] + nlv, x020185_g_BaoShiPosList[1][i][3], x020185_g_BaoShiPosList[1][i][1], x020185_g_BaoShiPosList[1][i][2])
		end	
	end
end

--第3阶段 刷BOSS
function x020185_Stage_3(scene ,stage,substage, nlv)
	if substage == 2 then
		local count_1 = #x020185_g_JarList[5]   -- 罐子
		for i = 1, count_1 do
			CreateMonster(scene, x020185_g_JarList[5][i], x020185_g_JarPosList[5][i][3], x020185_g_JarPosList[5][i][1], x020185_g_JarPosList[5][i][2])
		end
		local count_2 = #x020185_g_JarList[6]   -- 罐子
		for i = 1, count_2 do
			CreateMonster(scene, x020185_g_JarList[6][i], x020185_g_JarPosList[6][i][3], x020185_g_JarPosList[6][i][1], x020185_g_JarPosList[6][i][2])
		end
		CreateMonster(scene, x020185_g_MonstorList[3][1] + nlv, x020185_g_MonstorPosList[3][1][3], x020185_g_MonstorPosList[3][1][1], x020185_g_MonstorPosList[3][1][2])
	end
end

function x020185_HpCountDown1(scene)
	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) - 25 
	if nAdaptedLvl > x020185_g_AdapteLvl then
		nAdaptedLvl = x020185_g_AdapteLvl
	end
	local nUserCount = GetSceneUserCount(scene)
	local ZhobjId2 = GetObjIdByRoleBase(scene, x020185_g_MonstorList[3][1] + (nAdaptedLvl))
    local HpCount = #x020185_g_DropHp[1]
    for i = 1, HpCount do
        if math.ceil(CalculatePercenHp(scene, ZhobjId2)) <= x020185_g_DropHp[1][i] and CalculatePercenHp(scene, ZhobjId2) >= 0 then
            local Flag = GetCopySceneParam(scene, x020185_g_CSParamIdxBoxHpAward - 1 + i)
			if Flag == 0 then
				SetCopySceneParam(scene, x020185_g_CSParamIdxBoxHpAward - 1 + i, 1)
				for k = 0,nUserCount-1 do
					local nUserObjId = GetUserObjIdByIdx(scene,k)
					CreatDropBox(scene, nUserObjId, x020185_g_BossDrop1, ZhobjId2)
					SendImpactToUnit(scene, ZhobjId2, x020185_g_BossImpact)	
					print("boss------------ 掉落")
				end
			end
		end
	end
end


function  x020185_StageControl(scene,nstage)
	SetCopySceneParam(scene, 7, nstage)
	local nUserCount = GetSceneUserCount(scene)
	for j=0,nUserCount-1 do
		local nUserObjId = GetUserObjIdByIdx(scene,j)
		SynCsStageData(scene, nUserObjId)
	end
end

function x020185_OnCopySceneTimeOut(scene)  
   	local is_EndMark =  GetCopySceneParam(scene,x020185_g_CopyEndMark)
   	if is_EndMark == 0 then
   		SetCopySceneFail(scene)
   		GoldFuBenEnd(scene, false, false)
   		SetCopySceneParam(scene, x020185_g_CopyEndMark, 1)
   	end   	
end

function x020185_OnObjLeave(scene, objId)
	-- body
	RemoveImpact(scene, objId, x020185_g_PickImpact)
end

-- 销毁传送门
function x020185_OnObjPatrolEnd(scene, objId)
	local nDoorMarkOne = GetCopySceneParam(scene,x020185_g_PortalDisappearsOne)
	local nDoorMarkTwo = GetCopySceneParam(scene,x020185_g_PortalDisappearsTwo)
	local curSubStage = GetCopySceneParam(scene,x020185_g_CSParamIdxCurStage)
	local rolebaseId = GetRbIdByObjId(scene, objId)
	local nAdaptedLvl = math.floor(GetAdaptLvl(scene)/10) - 25
	if nAdaptedLvl > x020185_g_AdapteLvl then
		nAdaptedLvl = x020185_g_AdapteLvl
	end	
	if rolebaseId == 12001688 + nAdaptedLvl or rolebaseId == 12001764 + nAdaptedLvl then
		SetCopySceneParam(scene, x020185_g_PortalDisappearsOne, nDoorMarkOne+1)
	end

	if rolebaseId == 12001840 + nAdaptedLvl or rolebaseId == 12001916 + nAdaptedLvl then
		SetCopySceneParam(scene, x020185_g_PortalDisappearsTwo, nDoorMarkTwo+1)
	end	
	local nDoorMarkOneEnd = GetCopySceneParam(scene,x020185_g_PortalDisappearsOne)
	local nDoorMarkTwoEnd= GetCopySceneParam(scene,x020185_g_PortalDisappearsTwo)
	if nDoorMarkOneEnd >= 3 then
		RemoveSceneBuffById(scene, x020185_g_TransmitIdList[1])
	end 
	if nDoorMarkTwoEnd >= 3 then
		RemoveSceneBuffById(scene, x020185_g_TransmitIdList[2])
	end
    DeleMonsterByObjId(scene, objId)
end

-- 销毁传送门
function x020185_CheckDoorDel(scene, rolebaseId, nlv)
	local nDoorMarkOne = GetCopySceneParam(scene,x020185_g_PortalDisappearsOne)
	local nDoorMarkTwo = GetCopySceneParam(scene,x020185_g_PortalDisappearsTwo)
	local curSubStage = GetCopySceneParam(scene,x020185_g_CSParamIdxCurStage)
	if rolebaseId == 12001688 + nlv or rolebaseId == 12001764 + nlv then
		SetCopySceneParam(scene, x020185_g_PortalDisappearsOne, nDoorMarkOne+1)
	end

	if rolebaseId == 12001840 + nlv or rolebaseId == 12001916 + nlv then
		SetCopySceneParam(scene, x020185_g_PortalDisappearsTwo, nDoorMarkTwo+1)
	end		

	local nDoorMarkOneEnd = GetCopySceneParam(scene,x020185_g_PortalDisappearsOne)
	local nDoorMarkTwoEnd= GetCopySceneParam(scene,x020185_g_PortalDisappearsTwo)
	if nDoorMarkOneEnd >= 3 then
		RemoveSceneBuffById(scene, x020185_g_TransmitIdList[1])
	end 
	if nDoorMarkTwoEnd >= 3 then
		RemoveSceneBuffById(scene, x020185_g_TransmitIdList[2])
	end
end



function table_fillNum(m,n)
    local j,k
    if n then
       j=m
       k=n
    else
        j=1
        k=m
    end
    local t={}
    for i=j,k do
        table.insert(t,i)
    end
    return t
end

function math_randomEx(m,n,cnt) 
    local tmp=table_fillNum(m,n)
    if cnt>n-m+1 then
        return tmp
    end
    local x=0
    local t={}math.randomseed(os.time())
    while  cnt>0 do
       x=math.random(1,n-m+1) 
       table.insert(t,tmp[x])
       table.remove(tmp,x)
       cnt=cnt-1
       m=m+1
      
    end
    return t
end
