awx020025_g_scriptId=020025

x020025_g_IdPuTong={}
--  x020025_g_IdPuTong [1] = {{怪物1的自适应ID}， ｛怪物2的自适应ID｝ ， ｛怪物3的自适应ID｝}    有几个怪物加几组   后面对应
x020025_g_IdPuTong[1] ={{340001,340002,340003,340004,340005,340006,340007,340008,340009,340010,340011,340012,340013,340014,340015,340016,340017,340018,340019,340020},{341001,341002,341003,341004,341005,341006,341007,341008,341009,341010,341011,341012,341013,341014,341015,341016,341017,341018,341019,341020},{340001,340002,340003,340004,340005,340006,340007,340008,340009,340010,340011,340012,340013,340014,340015,340016,340017,340018,340019,340020}}    --  位置2第一波一个精英 2个小怪   小怪的Debuff AI配置在怪物身上
x020025_g_IdPuTong[2] ={{342001,342002,342003,342004,342005,342006,342007,342008,342009,342010,342011,342012,342013,342014,342015,342016,342017,342018,342019,342020},{342001,342002,342003,342004,342005,342006,342007,342008,342009,342010,342011,342012,342013,342014,342015,342016,342017,342018,342019,342020}} --  位置3第二波五个小怪
x020025_g_IdPuTong[3] ={{342001,342002,342003,342004,342005,342006,342007,342008,342009,342010,342011,342012,342013,342014,342015,342016,342017,342018,342019,342020},{342001,342002,342003,342004,342005,342006,342007,342008,342009,342010,342011,342012,342013,342014,342015,342016,342017,342018,342019,342020}}   --  位置4  击杀五个巡逻小怪
x020025_g_IdPuTong[4] ={{343001,343002,343003,343004,343005,343006,343007,343008,343009,343010,343011,343012,343013,343014,343015,343016,343017,343018,343019,343020},{344001,344002,344003,344004,344005,344006,344007,344008,344009,344010,344011,344012,344013,344014,344015,344016,344017,344018,344019,344020},{343001,343002,343003,343004,343005,343006,343007,343008,343009,343010,343011,343012,343013,343014,343015,343016,343017,343018,343019,343020}}    --  位置6  第二波精英怪  + 两个小怪  位置5  AI配置在怪物身上
x020025_g_IdPuTong[5] ={{342001,342002,342003,342004,342005,342006,342007,342008,342009,342010,342011,342012,342013,342014,342015,342016,342017,342018,342019,342020},{342001,342002,342003,342004,342005,342006,342007,342008,342009,342010,342011,342012,342013,342014,342015,342016,342017,342018,342019,342020}}           --  位置7 一波巡逻小怪  
x020025_g_IdPuTong[6] ={{345001,345002,345003,345004,345005,345006,345007,345008,345009,345010,345011,345012,345013,345014,345015,345016,345017,345018,345019,345020},{346001,346002,346003,346004,346005,346006,346007,346008,346009,346010,346011,346012,346013,346014,346015,346016,346017,346018,346019,346020},{345001,345002,345003,345004,345005,345006,345007,345008,345009,345010,345011,345012,345013,345014,345015,345016,345017,345018,345019,345020}}    --  位置8 第三波精英怪  同上 
x020025_g_IdPuTong[7] ={{342001,342002,342003,342004,342005,342006,342007,342008,342009,342010,342011,342012,342013,342014,342015,342016,342017,342018,342019,342020}}      --  位置9 一波巡逻小怪
x020025_g_IdPuTong[8] ={{347001,347002,347003,347004,347005,347006,347007,347008,347009,347010,347011,347012,347013,347014,347015,347016,347017,347018,347019,347020}}    --  位置11   Boss ID
x020025_g_IdPuTong[9] ={{340101,340102,340103,340104,340105,340106,340107,340108,340109,340110,340111,340112,340113,340114,340115,340116,340117,340118,340119,340120},{343101,343102,343103,343104,343105,343106,343107,343108,343109,343110,343111,343112,343113,343114,343115,343116,343117,343118,343119,343120}, {345101,345102,345103,345104,345105,345106,345107,345108,345109,345110,345111,345112,345113,345114,345115,345116,345117,345118,345119,345120}}      -- 40血的元素怪Id   AI不用配置技能  手动释放
x020025_g_IdPuTong[10]={{341101,341102,341103,341104,341105,341106,341107,341108,341109,341110,341111,341112,341113,341114,341115,341116,341117,341118,341119,341120},{344101,344102,344103,344104,344105,344106,344107,344108,344109,344110,344111,344112,344113,344114,344115,344116,344117,344118,344119,344120}, {346101,346102,346103,346104,346105,346106,346107,346108,346109,346110,346111,346112,346113,346114,346115,346116,346117,346118,346119,346120}}     -- 80血的精英怪Id       
-- 每个组次的元素怪物的roleId不能相同
x020025_g_AdaptLvl = 20

x020025_g_MonsterPosList={}     
x020025_g_MonsterPosList[1]={{95.12,45.82,3.21}, {91.50,50.96,3.21}, {94.07,56.85,3.21}}		
x020025_g_MonsterPosList[2]={{81.96,65.75,-1.06}, {85.19,67.44,-1.06}}		--  小怪坐	```标
x020025_g_MonsterPosList[3]={{61.89,145.32,4.1},{65.1,143.55,4.1}}	  
x020025_g_MonsterPosList[4]={{71.13,164.87,4.1},{75.58,162.30,4.1},{80.45,159.25,4.1}}	   
x020025_g_MonsterPosList[5]={{131.14,167.41,2.10},{129.87,163.11,2.10}}		
x020025_g_MonsterPosList[6]={{154.09,161.41,2.10},{153.23,156.74,2.10},{148.83,153.83,2.10}}		-- 对应上方怪物ID  坐标
x020025_g_MonsterPosList[7]={{162.24,142.70,2.10}}          -- 这波没用了
x020025_g_MonsterPosList[8]={{115.49,107.59,1.61}}        
x020025_g_MonsterPosList[9]={{129.65,106.96,3.12}, {115.58,92.96,1.61},{100.25,107.44,-0.08}}
x020025_g_MonsterPosList[10]={{129.65,106.96,3.12}, {115.58,92.96,1.61},{100.25,107.44,-0.08}}




x020025_g_CSParamIdxCurStage=0                     -- 场景切换波数
x020025_g_CSParamIdxCurSubStage=1				   -- 同一场景中的时间点		
x020025_g_CSParamIdxrandtime=2					   -- 80血以下是否释放		
x020025_g_CSParamIdxcurNum = 3					   -- 40血以下是否释放
x020025_g_CSParamNumJYone = 4   				   -- 场面上的第1种类精英怪物数量
x020025_g_CSParamNumJYtwo = 5	  				   -- 场面上的第2种类精英怪物数量
x020025_g_CSParamNumJYthree = 6   				   -- 场面上的第3种类精英怪物数量

x020025_g_User_ParamIdOfOne = 1                   -- 三环本第一环钥匙
x020025_g_User_ParamIdOfTwo = 2 				  -- 三环本第二换钥匙


x020025_g_BuffId = 200331						-- Boss释放的加防御的buff
x020025_g_BuffJyNum = 1				  --   同时释放1个增益buff
x020025_g_BuffJyId = {}
x020025_g_BuffJyId[1] = {200331, 200331, 200331}   -- 精英怪物的三个Debuff   对应顺序为出场顺序

x020025_g_Hp2 = 60  --  第二次大招血量
x020025_g_Hp1 = 95	--  第一次

x020025_g_ShoutBossId1 = 21    -- 第一次释放召唤的时候的FakeobjId
x020025_g_ShoutBossId2 = 21	   -- 第二次释放召唤的时候的FakeobjId

x020025_g_ShoutStrId1 = 50015	-- 第一次释放召唤的时候的字典Id
x020025_g_ShoutStrId2 = 50016

x020025_g_BuffZyId = {}
x020025_g_BuffZyId[1] = {100, 100, 100}  	-- 三个临时技能的生成点grouppointID

x020025_g_BuffZyPos = {}						--  三个临时技能生成点的坐标
x020025_g_BuffZyPos[1]={{106,85,3.21}, {106,85,3.21},{88,74,0}}

x020025_g_TpId = {}
x020025_g_TpId[1] = {1023, 1024, 1025}	  -- 传送点ID
x020025_g_TpPos={}
x020025_g_TpPos[1]={75.9,80.02}   
x020025_g_TpPos[2]={89.44,183.38}-- 传送点生成坐标
x020025_g_TpPos[3]={161.66,143.38}

x020025_g_IdCSItemBoxxiayi = 10401   -- 侠义值箱子ID
x020025_g_IdCSItemBox = 10301     --  基础奖励箱子

function x020025_OnCopySceneOpen( scene )
	AddCSMission(scene,64021)
	AddCSMission(scene,64022)
	AddCSMission(scene,64023)
	AddCSMission(scene,64024)
	AddCSMission(scene,64025)
	AddCSMission(scene,64026)
	AddCSMission(scene,64027)
	AddCSMission(scene,64028)
	AddCSMission(scene,64029)
	AddCSMission(scene,64030)
end
function x020025_OnMissionComplete(scene, nObjId, nMissionId)
	--print(nMissionId)
	if nMissionId == 64023 then
		OnCSMissionStage(scene,3)
	end
	if nMissionId == 64026 then
		OnCSMissionStage(scene, 6)
	end
	if nMissionId == 64029 then
		OnCSMissionStage(scene, 9)
	end
end
function x020025_OnCopySceneTick(scene,tickCount)					--副本阶段
	local curStage = GetCopySceneParam(scene,x020025_g_CSParamIdxCurStage) +1
	local curSubStage = GetCopySceneParam(scene,x020025_g_CSParamIdxCurSubStage) +1
	SetCopySceneParam(scene,x020025_g_CSParamIdxCurSubStage,curSubStage)

	local nAdaptedLvl = math.floor(GetAdaptLvl(scene)/5)	
	if(nAdaptedLvl > x020025_g_AdaptLvl)  then
		nAdaptedLvl = x020025_g_AdaptLvl
	end	
	if curStage == 1 then
		x020025_Stage_1(scene,curStage,curSubStage,nAdaptedLvl)
	--	x020025_Success(scene)
	elseif curStage == 2 then
		x020025_Stage_2(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 3 then
		x020025_Stage_3(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 4 then
		x020025_Stage_4(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 5 then
		x020025_Stage_5(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 6 then
		x020025_Stage_6(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 7 then
		x020025_Stage_7(scene,curStage,curSubStage,nAdaptedLvl)
	--elseif curStage == 8 then
	--	x020025_Stage_8(scene,curStage,curSubStage,nAdaptedLvl)
	end		
	local Hp = CalculatePercenHp(scene, GetObjIdByRoleBase(scene, x020025_g_IdPuTong[8][1][nAdaptedLvl]))
	--if(CalculatePercenHp(scene, GetObjIdByRoleBase(scene, x020025_g_IdPuTong[8][1][nAdaptedLvl])) == 100) then
	if(not MonIsBattle(scene, x020025_g_IdPuTong[8][1][nAdaptedLvl]) and Hp > 0) then 
		SetCopySceneParam(scene, x020025_g_CSParamIdxrandtime, 0)
		SetCopySceneParam(scene, x020025_g_CSParamIdxcurNum, 0)
		DeleMonsterByRoleId(scene, x020025_g_IdPuTong[9][1][nAdaptedLvl])
		DeleMonsterByRoleId(scene, x020025_g_IdPuTong[9][2][nAdaptedLvl])
		DeleMonsterByRoleId(scene, x020025_g_IdPuTong[9][3][nAdaptedLvl])
		DeleMonsterByRoleId(scene, x020025_g_IdPuTong[10][1][nAdaptedLvl])
		DeleMonsterByRoleId(scene, x020025_g_IdPuTong[10][2][nAdaptedLvl])
		DeleMonsterByRoleId(scene, x020025_g_IdPuTong[10][3][nAdaptedLvl])
		SetCopySceneParam(scene, x020025_g_CSParamNumJYone, 0)
		SetCopySceneParam(scene, x020025_g_CSParamNumJYtwo, 0)
		SetCopySceneParam(scene, x020025_g_CSParamNumJYthree, 0)
	end
	if ((CalculatePercenHp(scene, GetObjIdByRoleBase(scene, x020025_g_IdPuTong[8][1][nAdaptedLvl])) <= x020025_g_Hp1) and (CalculatePercenHp(scene, GetObjIdByRoleBase(scene, x020025_g_IdPuTong[8][1][nAdaptedLvl])) ~= -1) and (CalculatePercenHp(scene, GetObjIdByRoleBase(scene, x020025_g_IdPuTong[8][1][nAdaptedLvl])) ~= 0) and GetCopySceneParam(scene, x020025_g_CSParamIdxrandtime) == 0)then
		SetCopySceneParam(scene, x020025_g_CSParamIdxrandtime, 1)
		local MonobjId = GetObjIdByRoleBase(scene, x020025_g_IdPuTong[8][1][nAdaptedLvl])
		SendImpactToUnit(scene, MonobjId, x020025_g_BuffId)
		x020025_CreateMonster(scene, 10, 3, nAdaptedLvl)
		local nUserCount = GetSceneUserCount(scene)
		for i=0,nUserCount-1 do
			local nUserObjId = GetUserObjIdByIdx(scene,i)
			ShowBossTips(scene, nUserObjId, x020025_g_ShoutBossId1, x020025_g_ShoutStrId1,  x020025_g_IdPuTong[8][1][nAdaptedLvl])
		end
	end
	if ((CalculatePercenHp(scene, GetObjIdByRoleBase(scene, x020025_g_IdPuTong[8][1][nAdaptedLvl])) <= x020025_g_Hp2) and (CalculatePercenHp(scene, GetObjIdByRoleBase(scene, x020025_g_IdPuTong[8][1][nAdaptedLvl])) ~= -1) and (CalculatePercenHp(scene, GetObjIdByRoleBase(scene, x020025_g_IdPuTong[8][1][nAdaptedLvl])) ~= 0) and GetCopySceneParam(scene, x020025_g_CSParamIdxcurNum) == 0)then
		SetCopySceneParam(scene, x020025_g_CSParamIdxcurNum, 1)
		SetCopySceneParam(scene, x020025_g_CSParamNumJYone, 1)
		SetCopySceneParam(scene, x020025_g_CSParamNumJYtwo, 1)
		SetCopySceneParam(scene, x020025_g_CSParamNumJYthree, 1)
		local nUserCount = GetSceneUserCount(scene)
		for i=0,nUserCount-1 do
			local nUserObjId = GetUserObjIdByIdx(scene,i)
			ShowBossTips(scene, nUserObjId, x020025_g_ShoutBossId2, x020025_g_ShoutStrId2,  x020025_g_IdPuTong[8][1][nAdaptedLvl])
		end
		x020025_CreateMonster(scene, 9, 3, nAdaptedLvl)
	end
	if(curStage == 7 and tickCount%10 == 0 and (CalculatePercenHp(scene, GetObjIdByRoleBase(scene, x020025_g_IdPuTong[8][1][nAdaptedLvl])) <= x020025_g_Hp2) and (CalculatePercenHp(scene, GetObjIdByRoleBase(scene, x020039_g_IdPuTong[8][1][nAdaptedLvl])) ~= 0)) then
		local count  = 0
		--print("!!")
		local oldNumJYone = GetCopySceneParam(scene, x020025_g_CSParamNumJYone)
		local oldnumjytow = GetCopySceneParam(scene, x020025_g_CSParamNumJYtwo)
		local oldnumjythree = GetCopySceneParam(scene, x020025_g_CSParamNumJYthree)
		--print(oldNumJYone, "+" , oldnumjytow, "+ ", oldnumjythree)
		
		for i = 1, 100 do
			local rand = RandomMon(4, 6)
			if(GetCopySceneParam(scene, rand) >= 1 and count < x020025_g_BuffJyNum) then
				count = count + 1
				local rand2 = 0
				local nUserCount = GetSceneUserCount(scene)
				if nUserCount ~= 1 then
					 rand2 = RandomMon(0, nUserCount-1)
				end
				local nUserObjId = GetUserObjIdByIdx(scene,rand2)
				--print(rand, "+", rand2)
				SendImpactToUnit(scene, nUserObjId, x020025_g_BuffJyId[1][rand-3])
				SetCopySceneParam(scene, rand, 0)
			end
		end
		SetCopySceneParam(scene, x020025_g_CSParamNumJYone, oldNumJYone)
		SetCopySceneParam(scene, x020025_g_CSParamNumJYtwo, oldnumjytow)
		SetCopySceneParam(scene, x020025_g_CSParamNumJYthree, oldnumjythree)
	end
end

function x020025_Success(scene)
	local nUserCount = GetSceneUserCount(scene)
	for i=0,nUserCount-1 do
		local nUserObjId = GetUserObjIdByIdx(scene,i)
	--	AwardCSItemBox(scene,nUserObjId,x020025_g_IdCSItemBoxxiayi,x020025_g_IdCSItemBox)
	end

	SetCopySceneSuccess(scene)
end

function  x020025_OnObjDie(scene,objId,rolebaseId,killerId)			
	local MonCount = GetHostileMonsterCount(scene)
	local nAdaptedLvl = math.floor(GetAdaptLvl(scene)/5)	
	if(nAdaptedLvl > x020025_g_AdaptLvl)  then
		nAdaptedLvl = x020025_g_AdaptLvl
	end	
	local nCurStage = GetCopySceneParam(scene, x020025_g_CSParamIdxCurStage)
	if(rolebaseId == x020025_g_IdPuTong[10][1][nAdaptedLvl]) then
			SetSceneBuff(scene, x020025_g_BuffZyId[1][1], x020025_g_BuffZyPos[1][1][1], x020025_g_BuffZyPos[1][1][2], 0)
	end
	if(rolebaseId == x020025_g_IdPuTong[10][2][nAdaptedLvl]) then
			SetSceneBuff(scene, x020025_g_BuffZyId[1][2], x020025_g_BuffZyPos[1][2][1], x020025_g_BuffZyPos[1][2][2], 0)
	end
	if(rolebaseId == x020025_g_IdPuTong[10][3][nAdaptedLvl]) then
			SetSceneBuff(scene, x020025_g_BuffZyId[1][3], x020025_g_BuffZyPos[1][3][1], x020025_g_BuffZyPos[1][3][2], 0)
	end
		--print(rolebaseId ,"!!" , x020025_g_IdPuTong[9][1][nAdaptedLvl])
	if(rolebaseId == x020025_g_IdPuTong[9][1][nAdaptedLvl]) then
			SetCopySceneParam(scene, x020025_g_CSParamNumJYone, 0)
	end
	if(rolebaseId == x020025_g_IdPuTong[9][2][nAdaptedLvl]) then
			SetCopySceneParam(scene, x020025_g_CSParamNumJYtwo, 0)
	end
	if(rolebaseId == x020025_g_IdPuTong[9][3][nAdaptedLvl]) then
			SetCopySceneParam(scene, x020025_g_CSParamNumJYthree, 0)
	end
	if(MonCount == 0) then
			SetCopySceneParam(scene,x020025_g_CSParamIdxCurStage,nCurStage+1)	
			SetCopySceneParam(scene,x020025_g_CSParamIdxCurSubStage,0)
			if(nCurStage == 6)    then															-- BOSS奖励次数限制
				x020025_Success(scene)
			end
	end
end

function x020025_CreateMonster( scene,idx,camp, nlv)					--刷怪（
	local count = #x020025_g_MonsterPosList[idx]
	for i = 1, count  do
		local nMonObjId = CreateMonster(scene,  x020025_g_IdPuTong[idx][i][nlv], x020025_g_MonsterPosList[idx][i][3], x020025_g_MonsterPosList[idx][i][1],x020025_g_MonsterPosList[idx][i][2])
		SetNpcCampByObjId(scene, nMonObjId, camp)
	end
end

function x020025_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 x020025_Stage_1(scene ,stage,substage, nlv)        -- 第一波精英                
	if substage == 1 then
		OnCSMissionStage(scene,0)
		x020025_CreateMonster(scene,stage,3,nlv)
	end
end

function x020025_Stage_2(scene ,stage,substage, nlv)                        
	if substage == 1 then
		OnCSMissionStage(scene,1)
		x020025_CreateMonster(scene,stage,3,nlv)
	end
end

function x020025_Stage_3(scene ,stage,substage,nlv)                      
	if substage == 1 then
		OnCSMissionStage(scene,2)
		SetSceneBuff(scene, x020025_g_TpId[1][1], x020025_g_TpPos[1][1], x020025_g_TpPos[1][2], 0)
	elseif substage == 2 then
		x020025_CreateMonster(scene,stage,3,nlv)
	end
end

function x020025_Stage_4(scene ,stage,substage,nlv)			-- 第二波精英			
	if substage == 1 then
		OnCSMissionStage(scene,4)
		x020025_CreateMonster(scene,stage,3,nlv)
	end
end

function x020025_Stage_5(scene ,stage,substage,nlv)		
	if substage == 1 then
		OnCSMissionStage(scene,5)
		SetSceneBuff(scene, x020025_g_TpId[1][2], x020025_g_TpPos[2][1], x020025_g_TpPos[2][2], 0)
	elseif substage == 2 then
		x020025_CreateMonster(scene,stage,3,nlv)
	end
end

function x020025_Stage_6(scene ,stage,substage,nlv)		 -- 第三波精英				
	if substage == 1 then
		OnCSMissionStage(scene,7)
		x020025_CreateMonster(scene,stage,3,nlv)
	end
end

function x020025_Stage_7(scene ,stage,substage,nlv)		-- Boss  		
	if substage == 1 then
		OnCSMissionStage(scene,8)
		SetSceneBuff(scene, x020025_g_TpId[1][3], x020025_g_TpPos[3][1], x020025_g_TpPos[3][2], 0)
	elseif substage == 2 then
		x020025_CreateMonster(scene,8,3,nlv)
	end
end