x020019_g_scriptId=020019

x020019_g_IdPuTong={}
x020019_g_IdPuTong[0]={{130001,130002,130003,130004,130005,130006,130007,130008,130009,130010,130011,130012,130013,130014,130015,130016,130017,130018,130019,130020},
{130001,130002,130003,130004,130005,130006,130007,130008,130009,130010,130011,130012,130013,130014,130015,130016,130017,130018,130019,130020}}
x020019_g_IdPuTong[1]={{130001,130002,130003,130004,130005,130006,130007,130008,130009,130010,130011,130012,130013,130014,130015,130016,130017,130018,130019,130020},
{130001,130002,130003,130004,130005,130006,130007,130008,130009,130010,130011,130012,130013,130014,130015,130016,130017,130018,130019,130020},
{130001,130002,130003,130004,130005,130006,130007,130008,130009,130010,130011,130012,130013,130014,130015,130016,130017,130018,130019,130020},
{131001,131002,131003,131004,131005,131006,131007,131008,131009,131010,131011,131012,131013,131014,131015,131016,131017,131018,131019,131020}}
x020019_g_IdPuTong[2]={{130001,130002,130003,130004,130005,130006,130007,130008,130009,130010,130011,130012,130013,130014,130015,130016,130017,130018,130019,130020},
{130001,130002,130003,130004,130005,130006,130007,130008,130009,130010,130011,130012,130013,130014,130015,130016,130017,130018,130019,130020},
{130001,130002,130003,130004,130005,130006,130007,130008,130009,130010,130011,130012,130013,130014,130015,130016,130017,130018,130019,130020},
{131001,131002,131003,131004,131005,131006,131007,131008,131009,131010,131011,131012,131013,131014,131015,131016,131017,131018,131019,131020}}
x020019_g_IdPuTong[4]={{132001,132002,132003,132004,132005,132006,132007,132008,132009,132010,132011,132012,132013,132014,132015,132016,132017,132018,132019,132020},
{132001,132002,132003,132004,132005,132006,132007,132008,132009,132010,132011,132012,132013,132014,132015,132016,132017,132018,132019,132020},
{133001,133002,133003,133004,133005,133006,133007,133008,133009,133010,133011,133012,133013,133014,133015,133016,133017,133018,133019,133020}}
x020019_g_IdPuTong[5]={{134001,134002,134003,134004,134005,134006,134007,134008,134009,134010,134011,134012,134013,134014,134015,134016,134017,134018,134019,134020}}
x020019_g_AdapteLvl = 20    --   每个怪物的自适应等级套数  必须随适应等级的变化而改变
--以上为波次刷怪的波次适应等级  编号1代表第一波怪的自适应等级    编号1里第一个中括号表示第一波第一个怪物的自适应等级套数  依次类推

x020019_g_BossId = 100204
--x020019_g_MonsterPosList={}
--x020019_g_MonsterPosList[1]={{363.5,199.3,3.14}}

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


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


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


x020019_g_User_ParamIdOfOne = 1                   -- 三环本第一环钥匙
x020019_g_User_ParamIdOfTwo = 2 				  -- 三环本第二换钥匙

x020019_g_CounterId = 8504
x020019_g_BosskuangbaoTips = 50007
x020019_g_BossFakeObjId = 801

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

x020019_g_BossNumEnumId = 55
x020019_g_luckyBossNumEnumId = 56	

x020019_g_TimeForReply = 30
x020019_g_BuffId = 20106
x020019_g_IdCSItemBox = 10101       -- 宝箱奖励ID
x020019_g_IdCSItemxiayi = 10111

x020019_g_IdSkillBuff = 1002

function x020019_OnCopySceneOpen(scene)
	AddCSMission(scene,63011)
	AddCSMission(scene,63012)
	AddCSMission(scene,63013)
	AddCSMission(scene,63014)
	AddCSMission(scene,63015)
	AddCSMission(scene,63016)
end
function x020019_OnObjLeave(scene, objId)
	RemoveTmpSkill(scene, objId, 600002)
end
function x020019_OnCopySceneTick(scene,tickCount)					--副本阶段
	local curStage = GetCopySceneParam(scene,x020019_g_CSParamIdxCurStage)
	local curSubStage = GetCopySceneParam(scene,x020019_g_CSParamIdxCurSubStage) + 1
	SetCopySceneParam(scene,x020019_g_CSParamIdxCurSubStage,curSubStage) 

	local nAdaptedLvl = math.floor(GetAdaptLvl(scene)/5)
	if nAdaptedLvl > x020019_g_AdapteLvl then
		nAdaptedLvl = x020019_g_AdapteLvl
	end
	--print(nAdaptedLvl)
	local objid = GetObjIdByRoleBase(scene, x020019_g_IdPuTong[5][1][nAdaptedLvl])
	if CalculatePercenHp(scene, objid) < 20 and CalculatePercenHp(scene, objid) ~= -1 and CalculatePercenHp(scene, objid) ~= 0  and GetCopySceneParam(scene, x020019_g_CSParamTPobjId)  == 0 then
			local nUserCount = GetSceneUserCount(scene)
			for i=0,nUserCount-1 do                                                                                        --  帮助奖励（当所有BOSS奖励触发后开始触发）
				local nUserObjId = GetUserObjIdByIdx(scene,i)
				ShowBossTips(scene, nUserObjId, x020019_g_BossFakeObjId, x020019_g_BosskuangbaoTips, x020019_g_IdPuTong[5][1][nAdaptedLvl])                                 -- 狂暴提示
			end
			SendImpactToUnit(scene, objid, x020019_g_BuffId)
			SetCopySceneParam(scene, x020019_g_CSParamTPobjId, 1)
	end
		 														 --   打断提醒
	if IsAlive(scene, objid) and tickCount%(x020019_g_TimeForReply-5) == 0 and CalculatePercenHp(scene, objid) ~= 100 then
		SendAllPlayerServerTips(scene, x020019_g_Tips[1])
	end			 														 --   打断提醒
	if IsAlive(scene, objid) and tickCount%(x020019_g_TimeForReply) == 0 and CalculatePercenHp(scene, objid) ~= 100 then

	end		
	

	if curStage == 0 then
		x020019_CreateMonster(scene, curStage,curSubStage, nAdaptedLvl)
	elseif curStage == 1 then
		x020019_CreateMonster(scene, curStage,curSubStage, nAdaptedLvl)
	elseif curStage == 2 then
		x020019_CreateMonster(scene, curStage,curSubStage, nAdaptedLvl)
	elseif curStage == 3 then
		if curSubStage == 1 then
			OnCSMissionStage(scene,curStage)
			SetSceneBuff(scene,x020019_g_IdSkillBuff,x020019_g_BuffPos[1][1],x020019_g_BuffPos[1][2],0)
		end
	elseif curStage == 4 then 
		x020019_CreateMonster(scene, curStage,curSubStage, nAdaptedLvl)
	elseif curStage == 5 then
		x020019_CreateMonster(scene, curStage,curSubStage, nAdaptedLvl)
	end

	
end

--任务完成回调
function x020019_OnMissionComplete(scene, nObjId, nMissionId)
	local nCurStage = GetCopySceneParam(scene,x020019_g_CSParamIdxCurStage)
	local nCount = GetCopySceneParam(scene, x020019_g_CSParamTemskill)
	if nMissionId == 63014 and nCount == 0 then
		AddTmpSkill(scene, nObjId, 600002)
		SetCopySceneParam(scene, 10, 600002)
		SetCopySceneParam(scene, x020019_g_CSParamTemskill, nCount + 1)

		SetCopySceneParam(scene,x020019_g_CSParamIdxCurStage,nCurStage+1)
		SetCopySceneParam(scene,x020019_g_CSParamIdxCurSubStage,0)
	end
end

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

function  x020019_OnObjDie(scene,objId,rolebaseId,killerId)			
	local MonCount = GetHostileMonsterCount(scene)
	local nCurStage = GetCopySceneParam(scene, x020019_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, x020019_g_User_ParamIdOfOne, nUserObjId)
					if Key1 ~= 0   then
						SetUserCsParm(scene, nUserObjId, x020019_g_User_ParamIdOfOne, Key1-1)
						oldKey2 = GetUserCsParm(scene,  x020019_g_User_ParamIdOfTwo, nUserObjId)
						SetUserCsParm(scene, nUserObjId, x020019_g_User_ParamIdOfTwo, oldKey2+1)
					end
			end
	--		x020019_Success(scene)
	if(nCurStage == 5) then
		x020019_Success(scene)
	end
	SetCopySceneParam(scene,x020019_g_CSParamIdxCurStage,nCurStage+1)
	SetCopySceneParam(scene,x020019_g_CSParamIdxCurSubStage,0)
	end
end

function x020019_Success(scene)
	AccoutByCopyScene(scene)	
	local nUserCount = GetSceneUserCount(scene)
	for i=0,nUserCount-1 do
		local nUserObjId = GetUserObjIdByIdx(scene,i)
	--	AwardCSItemBox(scene,nUserObjId,x020019_g_IdCSItemxiayi,x020019_g_IdCSItemBox)
	end

	SetCopySceneSuccess(scene)
end

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

