sx020029_g_scriptId=020029

x020029_g_IdPuTong={}
x020029_g_IdPuTong[0]={{160001,160002,160003,160004,160005,160006,160007,160008,160009,160010,160011,160012,160013,160014,160015,160016,160017,160018,160019,160020},
{160001,160002,160003,160004,160005,160006,160007,160008,160009,160010,160011,160012,160013,160014,160015,160016,160017,160018,160019,160020}}
x020029_g_IdPuTong[1]={{160001,160002,160003,160004,160005,160006,160007,160008,160009,160010,160011,160012,160013,160014,160015,160016,160017,160018,160019,160020},
{160001,160002,160003,160004,160005,160006,160007,160008,160009,160010,160011,160012,160013,160014,160015,160016,160017,160018,160019,160020},
{160001,160002,160003,160004,160005,160006,160007,160008,160009,160010,160011,160012,160013,160014,160015,160016,160017,160018,160019,160020},
{161001,161002,161003,161004,161005,161006,161007,161008,161009,161010,161011,161012,161013,161014,161015,161016,161017,161018,161019,161020}}
x020029_g_IdPuTong[2]={{160001,160002,160003,160004,160005,160006,160007,160008,160009,160010,160011,160012,160013,160014,160015,160016,160017,160018,160019,160020},
{160001,160002,160003,160004,160005,160006,160007,160008,160009,160010,160011,160012,160013,160014,160015,160016,160017,160018,160019,160020},
{160001,160002,160003,160004,160005,160006,160007,160008,160009,160010,160011,160012,160013,160014,160015,160016,160017,160018,160019,160020},
{161001,161002,161003,161004,161005,161006,161007,161008,161009,161010,161011,161012,161013,161014,161015,161016,161017,161018,161019,161020}}
x020029_g_IdPuTong[4]={{162001,162002,162003,162004,162005,162006,162007,162008,162009,162010,162011,162012,162013,162014,162015,162016,162017,162018,162019,162020},
{162001,162002,162003,162004,162005,162006,162007,162008,162009,162010,162011,162012,162013,162014,162015,162016,162017,162018,162019,162020},
{163001,163002,163003,163004,163005,163006,163007,163008,163009,163010,163011,163012,163013,163014,163015,163016,163017,163018,163019,163020}}
x020029_g_IdPuTong[5]={{164001,164002,164003,164004,164005,164006,164007,164008,164009,164010,164011,164012,164013,164014,164015,164016,164017,164018,164019,164020}}
x020029_g_AdapteLvl = 20    --   每个怪物的自适应等级套数  必须随适应等级的变化而改变
--以上为波次刷怪的波次适应等级  编号1代表第一波怪的自适应等级    编号1里第一个中括号表示第一波第一个怪物的自适应等级套数  依次类推

x020029_g_BossId = 100204
--x020029_g_MonsterPosList={}
--x020029_g_MonsterPosList[1]={{363.5,199.3,3.14}}

x020029_g_MonsterPosList={}     
x020029_g_MonsterPosList[0]={{145,93,-0.75}, {148,95,-1.12}}			
x020029_g_MonsterPosList[1]={{141,96,-0.488}, {142,98,-0.488}, {144,102,-0.488}, {140,99,-0.488}}		--  小怪坐标
x020029_g_MonsterPosList[2]={{130,100,-0.488}, {131,102,-0.488}, {133,106,-0.488}, {127,104,-0.488}}
x020029_g_MonsterPosList[4]={{92,121,-1.41}, {90,121,-1.41}, {95,121,-1.41}}	   -- Boss坐标  
x020029_g_MonsterPosList[5]={{102,144,3.92}}


x020029_g_ResurrectionPosList = {}
x020029_g_ResurrectionPosList[1]={{167,74,2.40}}                      -- 复活点坐标


x020029_g_CSParamIdxCurStage=0                     -- 场景切换波数
x020029_g_CSParamIdxCurSubStage=1				   -- 同一场景中的时间点		
x020029_g_CSParamIdxrandtime=2					   -- 隐藏BOSS随机数  副本开始到BOSS总时间戳			
x020029_g_CSParamIdxcurNum = 3					   -- 总的杀怪个数	  
x020029_g_CSParamIdxBossId = 4 					   -- Boss模型来源
x020029_g_CSParamTPobjId = 5                       -- 是否释放低血量既能
x020029_g_CSParamTemskill = 7      				   -- 拿到临时技能的用户Id


x020029_g_User_ParamIdOfOne = 1                   -- 三环本第一环钥匙
x020029_g_User_ParamIdOfTwo = 2 				  -- 三环本第二换钥匙

x020029_g_CounterId = 8504
x020029_g_BossKuangbaoTips = 50007   --  狂暴时喊话字典号
x020029_g_BossFakeObjId = 801     --  狂暴时喊话的boss形象

x020029_g_Tips={}
x020029_g_Tips[1]="#{50005}*"			 --  回血提示 
									
x020029_g_BuffPos={}
x020029_g_BuffPos[1]={361.36,192}

x020029_g_BossNumEnumId = 55
x020029_g_luckyBossNumEnumId = 56	

x020029_g_TimeForReply = 30
x020029_g_BuffId = 20106
x020029_g_IdCSItemBox = 10201      -- 宝箱奖励ID
x020029_g_IdCSItemxiayi = 10211
x020029_g_IdSkillBuff = 1002

function x020029_OnCopySceneOpen(scene)
	AddCSMission(scene,65011)
	AddCSMission(scene,65012)
	AddCSMission(scene,65013)
	AddCSMission(scene,65014)
	AddCSMission(scene,65015)
	AddCSMission(scene,65016)
end
function x020029_OnObjLeave(scene, objId)
	RemoveTmpSkill(scene, objId, 600002)
end
function x020029_OnCopySceneTick(scene,tickCount)					--副本阶段
	local curStage = GetCopySceneParam(scene,x020029_g_CSParamIdxCurStage)
	local curSubStage = GetCopySceneParam(scene,x020029_g_CSParamIdxCurSubStage) +1
	SetCopySceneParam(scene,x020029_g_CSParamIdxCurSubStage,curSubStage)
	  
	local nAdaptedLvl = math.floor(GetAdaptLvl(scene)/5)
	if nAdaptedLvl > x020029_g_AdapteLvl then
		nAdaptedLvl = x020029_g_AdapteLvl
	end
	--print(nAdaptedLvl)
	local objid = GetObjIdByRoleBase(scene, x020029_g_IdPuTong[5][1][nAdaptedLvl])
	if CalculatePercenHp(scene, objid) < 20 and  CalculatePercenHp(scene, objid) ~= -1 and CalculatePercenHp(scene, objid) ~= 0 and GetCopySceneParam(scene, x020029_g_CSParamTPobjId)  == 0 then
			local nUserCount = GetSceneUserCount(scene)
			for i=0,nUserCount-1 do                                                                                        --  帮助奖励（当所有BOSS奖励触发后开始触发）
				local nUserObjId = GetUserObjIdByIdx(scene,i)
				ShowBossTips(scene, nUserObjId, x020029_g_BossFakeObjId, x020029_g_BossKuangbaoTips, x020029_g_IdPuTong[5][1][nAdaptedLvl])                                 -- 狂暴提示
			end
			SendImpactToUnit(scene, objid, x020029_g_BuffId)
			SetCopySceneParam(scene, x020029_g_CSParamTPobjId, 1)
	end
		 														 --   打断提醒
	if IsAlive(scene, objid) and tickCount%(x020029_g_TimeForReply-5) == 0 and CalculatePercenHp(scene, objid) ~= 100 then
		SendAllPlayerServerTips(scene, x020029_g_Tips[1])
	end			 														 --   打断提醒
	if IsAlive(scene, objid) and tickCount%(x020029_g_TimeForReply) == 0 and CalculatePercenHp(scene, objid) ~= 100 then

	end		
	
	if curStage == 0 then
		x020029_CreateMonster(scene, curStage,curSubStage, nAdaptedLvl)
	elseif curStage == 1 then
		x020029_CreateMonster(scene, curStage,curSubStage, nAdaptedLvl)
	elseif curStage == 2 then
		x020029_CreateMonster(scene, curStage,curSubStage, nAdaptedLvl)
	elseif curStage == 3 then
		if curSubStage == 1 then
			OnCSMissionStage(scene,curStage)
			SetSceneBuff(scene,x020029_g_IdSkillBuff,x020029_g_BuffPos[1][1],x020029_g_BuffPos[1][2],0)
		end
	elseif curStage == 4 then 
		x020029_CreateMonster(scene, curStage,curSubStage, nAdaptedLvl)
	elseif curStage == 5 then
		x020029_CreateMonster(scene, curStage,curSubStage, nAdaptedLvl)
	end
end

--任务完成回调
function x020029_OnMissionComplete(scene, nObjId, nMissionId)
	local nCurStage = GetCopySceneParam(scene,x020029_g_CSParamIdxCurStage)
	local nCount = GetCopySceneParam(scene, x020029_g_CSParamTemskill)
	if nMissionId == 65014 and nCount == 0 then
		AddTmpSkill(scene, nObjId, 600002)
		SetCopySceneParam(scene, 10, 600002)
		SetCopySceneParam(scene, x020029_g_CSParamTemskill, nCount + 1)

		SetCopySceneParam(scene,x020029_g_CSParamIdxCurStage,nCurStage+1)
		SetCopySceneParam(scene,x020029_g_CSParamIdxCurSubStage,0)
	end
end

function x020029_CreateMonster( scene,idx, flag, Lvl)					--刷怪（
	if(flag == 1)  then
		OnCSMissionStage(scene,idx)
		local count = #x020029_g_MonsterPosList[idx]
		for i = 1, count  do
			CreateMonster(scene,  x020029_g_IdPuTong[idx][i][Lvl], x020029_g_MonsterPosList[idx][i][3], x020029_g_MonsterPosList[idx][i][1],x020029_g_MonsterPosList[idx][i][2])
		end
	end
end

function  x020029_OnObjDie(scene,objId,rolebaseId,killerId)			
	local MonCount = GetHostileMonsterCount(scene)
	local nCurStage = GetCopySceneParam(scene, x020029_g_CSParamIdxCurStage)
	if(MonCount == 0) then													-- BOSS奖励次数限制
			local nUserCount = GetSceneUserCount(scene)
			for i=0,nUserCount-1 do                                                                                        --  帮助奖励（当所有BOSS奖励触发后开始触发）
					local nUserObjId = GetUserObjIdByIdx(scene,i)
					local Key1 = GetUserCsParm(scene, x020029_g_User_ParamIdOfOne, nUserObjId)
					if Key1 ~= 0   then
						SetUserCsParm(scene, nUserObjId, x020029_g_User_ParamIdOfOne, Key1-1)
						oldKey2 = GetUserCsParm(scene,  x020029_g_User_ParamIdOfTwo, nUserObjId)
						SetUserCsParm(scene, nUserObjId, x020029_g_User_ParamIdOfTwo, oldKey2+1)
					end
			end
	--		x020029_Success(scene)
	if(nCurStage == 5) then
		x020029_Success(scene)
	end
	SetCopySceneParam(scene,x020029_g_CSParamIdxCurStage,nCurStage+1)
	SetCopySceneParam(scene,x020029_g_CSParamIdxCurSubStage,0)
	end
end

function x020029_Success(scene)
	AccoutByCopyScene(scene)	
	local nUserCount = GetSceneUserCount(scene)
	for i=0,nUserCount-1 do
		local nUserObjId = GetUserObjIdByIdx(scene,i)
	--	AwardCSItemBox(scene,nUserObjId,x020029_g_IdCSItemxiayi,x020029_g_IdCSItemBox)
	end

	SetCopySceneSuccess(scene)
end

function x020029_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 x020029_OnObjresurrectionEnd(scene ,objId)
		SetPos(scene,objId,363.5,199.3)
end

