wx020038_g_scriptId=020038																																																																																															
																																																																																															
x020038_g_IdPuTong={}																																																																																															
x020038_g_IdPuTong[1]={{360001,	360002,	360003,	360004,	360005,	360006,	360007,	360008,	360009,	360010,	360011,	360012,	360013,	360014,	360015,	360016,	360017,	360018,	360019,	360020},{360001,	360002,	360003,	360004,	360005,	360006,	360007,	360008,	360009,	360010,	360011,	360012,	360013,	360014,	360015,	360016,	360017,	360018,	360019,	360020},{360001,	360002,	360003,	360004,	360005,	360006,	360007,	360008,	360009,	360010,	360011,	360012,	360013,	360014,	360015,	360016,	360017,	360018,	360019,	360020},{360001,	360002,	360003,	360004,	360005,	360006,	360007,	360008,	360009,	360010,	360011,	360012,	360013,	360014,	360015,	360016,	360017,	360018,	360019,	360020},{360001,	360002,	360003,	360004,	360005,	360006,	360007,	360008,	360009,	360010,	360011,	360012,	360013,	360014,	360015,	360016,	360017,	360018,	360019,	360020}}    -- 位置1：五个小怪的编号
x020038_g_IdPuTong[2]={{361001,	361002,	361003,	361004,	361005,	361006,	361007,	361008,	361009,	361010,	361011,	361012,	361013,	361014,	361015,	361016,	361017,	361018,	361019,	361020},{361001,	361002,	361003,	361004,	361005,	361006,	361007,	361008,	361009,	361010,	361011,	361012,	361013,	361014,	361015,	361016,	361017,	361018,	361019,	361020}}		  -- 位置2：石化怪物解除石化																																																							
x020038_g_IdPuTong[3]={{365001,	365002,	365003,	365004,	365005,	365006,	365007,	365008,	365009,	365010,	365011,	365012,	365013,	365014,	365015,	365016,	365017,	365018,	365019,	365020},{365001,	365002,	365003,	365004,	365005,	365006,	365007,	365008,	365009,	365010,	365011,	365012,	365013,	365014,	365015,	365016,	365017,	365018,	365019,	365020}}		  -- 位置3：石化怪物解除石化																																																							
x020038_g_IdPuTong[4]={{362001,	362002,	362003,	362004,	362005,	362006,	362007,	362008,	362009,	362010,	362011,	362012,	362013,	362014,	362015,	362016,	362017,	362018,	362019,	362020},{362001,	362002,	362003,	362004,	362005,	362006,	362007,	362008,	362009,	362010,	362011,	362012,	362013,	362014,	362015,	362016,	362017,	362018,	362019,	362020},{362001,	362002,	362003,	362004,	362005,	362006,	362007,	362008,	362009,	362010,	362011,	362012,	362013,	362014,	362015,	362016,	362017,	362018,	362019,	362020}}	  -- 位置4：四波精英怪物   添加数量的话直接在里面添加，下方需要添加对应的坐标																																					
x020038_g_IdPuTong[5]={{361001,	361002,	361003,	361004,	361005,	361006,	361007,	361008,	361009,	361010,	361011,	361012,	361013,	361014,	361015,	361016,	361017,	361018,	361019,	361020}}    -- boss左侧召唤小蛇   添加数量的话直接在里面添加，下方需要添加对应的坐标  所有召唤物的rolebaseId 注意相同																																																																												
x020038_g_IdPuTong[6]={{361001,	361002,	361003,	361004,	361005,	361006,	361007,	361008,	361009,	361010,	361011,	361012,	361013,	361014,	361015,	361016,	361017,	361018,	361019,	361020}}	  -- boss右侧召唤小蛇   添加数量的话直接在里面添加，下方需要添加对应的坐标  所有召唤物的rolebaseId 注意相同																																																																											
x020038_g_IdPuTong[7]={{364001,	364002,	364003,	364004,	364005,	364006,	364007,	364008,	364009,	364010,	364011,	364012,	364013,	364014,	364015,	364016,	364017,	364018,	364019,	364020}}    --  左侧蛇蛋召唤物																																																																												
x020038_g_IdPuTong[8]={{364001,	364002,	364003,	364004,	364005,	364006,	364007,	364008,	364009,	364010,	364011,	364012,	364013,	364014,	364015,	364016,	364017,	364018,	364019,	364020}}    -- 右侧蛇蛋召唤物																																																																												

x020038_g_AdaptLvlNum = 20

x020038_g_BossroleId = {}
x020038_g_BossroleId[1] = {363001,	363002,	363003,	363004,	363005,	363006,	363007,	363008,	363009,	363010,	363011,	363012,	363013,	363014,	363015,	363016,	363017,	363018,	363019,	363020}		--  Boss 编号
x020038_g_EndBossPosList={}
x020038_g_EndBossPosList[1]={{90.56,33.65,3.30}}	  --最终的boss坐标

x020038_g_MonsterPosList={}     
x020038_g_MonsterPosList[1]={{52.44,105.46,3.30},{51.92,103.06,3.30},{48.48,101.26,3.30},{50.97,98.73,3.30},{50.21,95.99,3.30}}		
x020038_g_MonsterPosList[2]={{64.18,103.88,3.30},{60.89,86.7,3.30}}		--  小怪坐	```标
x020038_g_MonsterPosList[3]={{78.67,103.78,3.30},{74.48,81.81,3.30}}  
x020038_g_MonsterPosList[4]={{21.97,31.12,3.30},{23.11,12.95,3.30},{31.90,22.98,3.30}}	   
x020038_g_MonsterPosList[5]={{89.37,35.40,3.30}}		-- 召唤物左侧坐标
x020038_g_MonsterPosList[6]={{89.37,35.40,3.30}}		-- 右侧召唤物坐标  增加数量直接在这添加
x020038_g_MonsterPosList[7]={{75.78,43.53,0}}         -- 左侧蛇蛋召唤坐标
x020038_g_MonsterPosList[8]={{85.12,19.13,0}}         -- 右侧蛇蛋召唤坐标

x020038_g_RefreshMonTime = 10		-- 刷新时间间隔

x020038_g_MonsterTargetPos={}
x020038_g_MonsterTargetPos[1]={75.78,43.53,0}  		--  左侧蛇蛋坐标
x020038_g_MonsterTargetPos[2]={85.12,19.13,0}  		-- 右侧蛇蛋坐标

x020038_g_BossShihuabuffId = {}    				-- 石化特效buff
x020038_g_BossShihuabuffId[1] = {10019, 10020}

x020038_g_ResurrectionPosList = {}
x020038_g_ResurrectionPosList[1]={20.70,87.95,0.84}                      -- 复活点坐标w


x020038_g_CSParamIdxCurStage=0                     -- 场景切换波数
x020038_g_CSParamIdxCurSubStage=1				   -- 同一场景中的时间点		
x020038_g_CSParamIdxrandtime=2					   -- 70血以下是否释放		
x020038_g_CSParamIdxcurNum = 3					   -- 30血以下是否释放
x020038_g_CSParamIdx70 = 4                   
x020038_g_CSParamIdx30 = 5  


x020038_g_ShoutBossId = 801    					-- 喊话展示BossFakeobjid
x020038_g_ShoutStrId = 50010						-- 喊话字典号

x020038_g_ShoutStrId1 = 50011  					-- 狐狸之后第一次boss喊话id
x020038_g_ShoutBossId1 = 21						-- 狐狸之后第一次boss形象id（FakeobjId）

x020038_g_time = 5    -- boss 喊话和系统提示的时间差

x020038_g_Tips={}
x020038_g_Tips[1]="#{50014}*"       --  召唤怪物系统提示

x020038_g_PerHp1 = 70		-- 第一次释放召唤技能的血量百分比
x020038_g_PerHp2 = 30	-- 第二次释放召唤技能的血量百分比

x020038_g_TpId = {}	  -- 传送点ID
x020038_g_TpId[1] = {1032, 1033}
x020038_g_TpPos={}
x020038_g_TpPos[1]={93.46,95.07}   
x020038_g_TpPos[2]={36.93,23.42}-- 传送点坐标

x020038_g_IdCSItemxiayiBox = 10600
x020038_g_IdCSItemBox = 10500   -- 奖品箱子ID

function x020038_OnCopySceneOpen( scene )
	AddCSMission(scene,66001)
	AddCSMission(scene,66002)
	AddCSMission(scene,66003)
	AddCSMission(scene,66004)
	AddCSMission(scene,66005)
	AddCSMission(scene,66006)
	AddCSMission(scene,66007)
end
function x020038_OnMissionComplete(scene, nObjId, nMissionId)
	print(nMissionId)
	if nMissionId == 66004 then
		OnCSMissionStage(scene,4)
	end
	if nMissionId == 66006 then
		OnCSMissionStage(scene, 6)
	end
end
--副本Tick
function x020038_OnCopySceneTick(scene,tickCount)					--副本阶段
	local curStage = GetCopySceneParam(scene,x020038_g_CSParamIdxCurStage) +1
	local curSubStage = GetCopySceneParam(scene,x020038_g_CSParamIdxCurSubStage) +1
	SetCopySceneParam(scene,x020038_g_CSParamIdxCurSubStage,curSubStage)

	local nAdaptedLvl = math.floor(GetAdaptLvl(scene)/5)		
	if(x020038_g_AdaptLvlNum < nAdaptedLvl)  then
		nAdaptedLvl = x020038_g_AdaptLvlNum
	end
	if curStage == 1 then
		x020038_Stage_1(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 2 then
		x020038_Stage_2(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 3 then
		x020038_Stage_3(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 4 then
		x020038_Stage_4(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 5 then
		x020038_Stage_5(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 6 then
		x020038_Stage_6(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 7 then
		x020038_Stage_7(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 8 then
		x020038_Stage_8(scene,curStage,curSubStage,nAdaptedLvl)
		--70%左侧蛇
		if ((CalculatePercenHp(scene, GetObjIdByRoleBase(scene, x020038_g_BossroleId[1][nAdaptedLvl])) <= x020038_g_PerHp1) and (CalculatePercenHp(scene, GetObjIdByRoleBase(scene, x020038_g_BossroleId[1][nAdaptedLvl])) ~= -1) and (CalculatePercenHp(scene, GetObjIdByRoleBase(scene, x020038_g_BossroleId[1][nAdaptedLvl])) ~= 0) and GetCopySceneParam(scene, x020038_g_CSParamIdxrandtime) == 0)then
			SetCopySceneParam(scene, x020038_g_CSParamIdxrandtime, tickCount)
			local nUserCount = GetSceneUserCount(scene)
				for i=0,nUserCount-1 do
					local nUserObjId = GetUserObjIdByIdx(scene,i)
					ShowBossTips(scene, nUserObjId, x020038_g_ShoutBossId, x020038_g_ShoutStrId, x020038_g_BossroleId[1][nAdaptedLvl])
				end
			--print("70% Snake")
			x020038_CreateMonster(scene, 5, 3, nAdaptedLvl)
			SetCopySceneParam(scene, x020038_g_CSParamIdx70, tickCount)
			--SetCopySceneParam(scene,x020038_g_CSParamIdxCurSubStage, 10)
		end
		--30%左侧蛇
		if ((CalculatePercenHp(scene, GetObjIdByRoleBase(scene, x020038_g_BossroleId[1][nAdaptedLvl])) <= x020038_g_PerHp2) and (CalculatePercenHp(scene, GetObjIdByRoleBase(scene, x020038_g_BossroleId[1][nAdaptedLvl])) ~= -1) and (CalculatePercenHp(scene, GetObjIdByRoleBase(scene, x020038_g_BossroleId[1][nAdaptedLvl])) ~= 0) and GetCopySceneParam(scene, x020038_g_CSParamIdxcurNum) == 0)then
			SetCopySceneParam(scene, x020038_g_CSParamIdxcurNum, tickCount)
			local nUserCount = GetSceneUserCount(scene)
				for i=0,nUserCount-1 do
					local nUserObjId = GetUserObjIdByIdx(scene,i)
					ShowBossTips(scene, nUserObjId, x020038_g_ShoutBossId, x020038_g_ShoutStrId, x020038_g_BossroleId[1][nAdaptedLvl])
				end
			--print("30% Snake")
			x020038_CreateMonster(scene, 6, 3, nAdaptedLvl)
			SetCopySceneParam(scene, x020038_g_CSParamIdx70, tickCount)
			--SetCopySceneParam(scene,x020038_g_CSParamIdxCurSubStage, 10)
		end

		--左侧蛋蛇
		if (GetAliveByRoleBaseNum(scene, x020038_g_IdPuTong[5][1][nAdaptedLvl]) > 0 and  GetCopySceneParam(scene, x020038_g_CSParamIdxrandtime) > 0 and GetCopySceneParam(scene, x020038_g_CSParamIdx70) ~= 0 and tickCount == GetCopySceneParam(scene, x020038_g_CSParamIdx70) + x020038_g_RefreshMonTime) then
			--print("70% Egg Snake")
			x020038_CreateMonster(scene, 7, 3, nAdaptedLvl)
			SetCopySceneParam(scene, x020038_g_CSParamIdx70, tickCount)
		end
		--右侧蛋蛇
		if (GetAliveByRoleBaseNum(scene, x020038_g_IdPuTong[6][1][nAdaptedLvl]) > 0 and GetCopySceneParam(scene, x020038_g_CSParamIdxcurNum) > 0  and GetCopySceneParam(scene, x020038_g_CSParamIdx30) ~= 0 and tickCount == GetCopySceneParam(scene, x020038_g_CSParamIdx30) + x020038_g_RefreshMonTime) then
			--print("30% Egg Snake")
			x020038_CreateMonster(scene, 8, 3, nAdaptedLvl)
			SetCopySceneParam(scene, x020038_g_CSParamIdx30, tickCount)
		end

		--失去仇恨回满血后恢复技能冷却删除召唤物
		local Hp = CalculatePercenHp(scene, GetObjIdByRoleBase(scene, x020038_g_BossroleId[1][nAdaptedLvl]))
		--print(hp)
		--print(not MonIsBattle(scene, x020038_g_BossroleId[1][nAdaptedLvl]))
		--if(CalculatePercenHp(scene, GetObjIdByRoleBase(scene, x020038_g_BossroleId[1][nAdaptedLvl])) == 100) then    
		if(not MonIsBattle(scene, x020038_g_BossroleId[1][nAdaptedLvl]) and Hp > 0) then  
			SetCopySceneParam(scene, x020038_g_CSParamIdxrandtime, 0)
			SetCopySceneParam(scene, x020038_g_CSParamIdxcurNum, 0)
			SetCopySceneParam(scene, x020038_g_CSParamIdx70, 0)
			SetCopySceneParam(scene, x020038_g_CSParamIdx30, 0)
			DeleMonsterByRoleId(scene, x020038_g_IdPuTong[5][1][nAdaptedLvl])
			DeleMonsterByRoleId(scene, x020038_g_IdPuTong[6][1][nAdaptedLvl])
			DeleMonsterByRoleId(scene, x020038_g_IdPuTong[7][1][nAdaptedLvl])
			DeleMonsterByRoleId(scene, x020038_g_IdPuTong[8][1][nAdaptedLvl])
		end
		if(GetCopySceneParam(scene, x020038_g_CSParamIdx70) ~= 0 and CalculatePercenHp(scene, GetObjIdByRoleBase(scene, x020038_g_BossroleId[1][nAdaptedLvl])) > 0 ) then
			if(tickCount == GetCopySceneParam(scene, x020038_g_CSParamIdx70) + x020038_g_time)  then
				SendAllPlayerServerTips(scene, x020038_g_Tips[1])
			end
		end
		if(GetCopySceneParam(scnee, x020038_g_CSParamIdx30) ~= 0 and CalculatePercenHp(scene, GetObjIdByRoleBase(scene, x020038_g_BossroleId[1][nAdaptedLvl])) > 0 ) then
			if(tickCount == GetCopySceneParam(scnee, x020038_g_CSParamIdx30) + x020038_g_time)  then
				SendAllPlayerServerTips(scene, x020038_g_Tips[1])
			end
		end
	elseif curStage == 9 then
		x020038_Stage_End(scene, curSubStage)
	end	
end

--结算
function x020038_Success(scene)
	local nUserCount = GetSceneUserCount(scene)
	for i=0,nUserCount-1 do
		local nUserObjId = GetUserObjIdByIdx(scene,i)
	--	AwardCSItemBox(scene,nUserObjId,x020038_g_IdCSItemxiayiBox,x020038_g_IdCSItemBox)
		AddActivtyNum(scene, nUserObjId, 21)
	end

	SetCopySceneSuccess(scene)
end

--死亡回调
function  x020038_OnObjDie(scene,objId,rolebaseId,killerId)			
	local MonCount = GetHostileMonsterCount(scene)
	--print("MonCount",MonCount)
	local nCurStage = GetCopySceneParam(scene, x020038_g_CSParamIdxCurStage)
	if MonCount == 0 then
		--print("nCurStage",nCurStage+1)
		SetCopySceneParam(scene,x020038_g_CSParamIdxCurStage,nCurStage+1)	
		SetCopySceneParam(scene,x020038_g_CSParamIdxCurSubStage,0)
	end
end

--创建怪物
function x020038_CreateMonster( scene,idx,camp, nlv)					--刷怪（

	local count = #x020038_g_MonsterPosList[idx]
	--print(count)
	for i = 1, count  do
		local nMonObjId = CreateMonster(scene,  x020038_g_IdPuTong[idx][i][nlv], x020038_g_MonsterPosList[idx][i][3], x020038_g_MonsterPosList[idx][i][1],x020038_g_MonsterPosList[idx][i][2])
		SetNpcCampByObjId(scene, nMonObjId, camp)
		if idx == 5 then
			CommandMoveTo(scene, nMonObjId, x020038_g_MonsterTargetPos[1][1], x020038_g_MonsterTargetPos[1][2])
		end
		if idx == 6 then
			CommandMoveTo(scene, nMonObjId, x020038_g_MonsterTargetPos[2][1], x020038_g_MonsterTargetPos[2][2])
		end
		if(idx == 2 or idx == 3 ) then
			local buffcount = #x020038_g_BossShihuabuffId[1]

			for j = 1, buffcount do
			--	print( nMonObjId , "+", x020038_g_BossShihuabuffId[1][j])
				SendImpactToUnit(scene, nMonObjId, x020038_g_BossShihuabuffId[1][j])
			end
		end
	end
end

function x020038_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

--阶段1
function x020038_Stage_1(scene ,stage,substage, nlv)                      
	if substage == 1 then
		OnCSMissionStage(scene,0)
		--print("stage",stage)
		x020038_CreateMonster(scene,1,3,nlv)
		x020038_CreateMonster(scene,2,1,nlv)
		x020038_CreateMonster(scene,3,1,nlv)

	end
end

--字符串分隔
function string_split(str, split_char)
	local sub_str_tab = {}
	while (true) do
		local pos = string.find(str, split_char)
		if not pos then
			sub_str_tab[#sub_str_tab + 1] = str
			break
		end
		local sub_str = string.sub(str, 1, pos - 1)
		sub_str_tab[#sub_str_tab + 1] = sub_str
		str = string.sub(str, pos + 1, #str)
	end
	return sub_str_tab
end

--阶段2
function x020038_Stage_2(scene ,stage,substage, nlv)   
	if(substage == 1) then
		local nUserCount = GetSceneUserCount(scene)
		for i=0,nUserCount-1 do
			local nUserObjId = GetUserObjIdByIdx(scene,i)
			ShowBossTips(scene, nUserObjId, x020038_g_ShoutBossId1, x020038_g_ShoutStrId1, x020038_g_BossroleId[1][nlv])
		end
	elseif(substage == 2) then       
		OnCSMissionStage(scene,1)              
		--print("stage",stage)
		local countleft =  #x020038_g_MonsterPosList[2]
		for i = 1, countleft do
			local MonObjs = GetAllObjIdByRoleBase(scene, x020038_g_IdPuTong[2][i][nlv])
			--print("MonObjs",MonObjs)
			local nObjIds = string_split(MonObjs, ",")
			for j = 1, #nObjIds do
				--print("nObjIds",nObjIds[j])
				local nId = nObjIds[j]
				SetNpcCampByStrObjId(scene, nId, 3)
				local buffcount = #x020038_g_BossShihuabuffId[1]
				for k = 1, buffcount do
					RemoveImpactByStrId(scene, nId, x020038_g_BossShihuabuffId[1][k])
				end
			
			end
		end
	end
end

--阶段3
function x020038_Stage_3(scene ,stage,substage,nlv)                      
	if substage == 1 then
		--print("stage",stage)
		OnCSMissionStage(scene,2)
		local countright =  #x020038_g_MonsterPosList[3]
		for i = 1, countright do
			local MonObjs = GetAllObjIdByRoleBase(scene, x020038_g_IdPuTong[3][i][nlv])
			--print("MonObjs",MonObjs)
			local nObjIds = string_split(MonObjs, ",")
			for j = 1, #nObjIds do
				--print("nObjIds",nObjIds[j])
				local nId = nObjIds[j]
				SetNpcCampByStrObjId(scene, nId, 3)
				local buffcount = #x020038_g_BossShihuabuffId[1]
				for k = 1, buffcount do
					RemoveImpactByStrId(scene, nId, x020038_g_BossShihuabuffId[1][k])
				end
			
			end
		end	
	end
end

--阶段4
function x020038_Stage_4(scene ,stage,substage,nlv)		
	if substage == 1 then
		--print("stage",stage)
		SetSceneBuff(scene, x020038_g_TpId[1][1], x020038_g_TpPos[1][1], x020038_g_TpPos[1][2], 0)	
	elseif substage == 2 then
		x020038_CreateMonster(scene,4,3,nlv)
	end	
end

--阶段5
function x020038_Stage_5(scene ,stage,substage,nlv)	
	if substage == 1 then
		--print("stage",stage)
		x020038_CreateMonster(scene,4,3,nlv)
	end
end

--阶段6
function x020038_Stage_6(scene ,stage,substage,nlv)	
	if substage == 1 then
		--print("stage",stage)
		x020038_CreateMonster(scene,4,3,nlv)
	end
end

--阶段7
function x020038_Stage_7(scene ,stage,substage,nlv)	
	if substage == 1 then
		--print("stage",stage)
		x020038_CreateMonster(scene,4,3,nlv)
	end
end

--阶段8
function x020038_Stage_8(scene ,stage,substage,nlv)						
	if substage == 1 then
		OnCSMissionStage(scene,5)
		--print("stage",stage)
		local Monobj = CreateMonster(scene, x020038_g_BossroleId[1][nlv], x020038_g_EndBossPosList[1][1][3], x020038_g_EndBossPosList[1][1][1],x020038_g_EndBossPosList[1][1][2])
	elseif substage == 2 then 
		SetSceneBuff(scene, x020038_g_TpId[1][2], x020038_g_TpPos[2][1], x020038_g_TpPos[2][2], 0)	
	end
end

function x020038_Stage_End(scene, substage)
	if substage == 1 then
		x020038_Success(scene)
	end
end