wx020024_g_scriptId=020024

x020024_g_IdPuTong={}
x020024_g_IdPuTong[1]={{330001,	330002,	330003,	330004,	330005,	330006,	330007,	330008,	330009,	330010,	330011,	330012,	330013,	330014,	330015,	330016,	330017,	330018,	330019,	330020},{330001,	330002,	330003,	330004,	330005,	330006,	330007,	330008,	330009,	330010,	330011,	330012,	330013,	330014,	330015,	330016,	330017,	330018,	330019,	330020},{330001,	330002,	330003,	330004,	330005,	330006,	330007,	330008,	330009,	330010,	330011,	330012,	330013,	330014,	330015,	330016,	330017,	330018,	330019,	330020},{330001,	330002,	330003,	330004,	330005,	330006,	330007,	330008,	330009,	330010,	330011,	330012,	330013,	330014,	330015,	330016,	330017,	330018,	330019,	330020},{330001,	330002,	330003,	330004,	330005,	330006,	330007,	330008,	330009,	330010,	330011,	330012,	330013,	330014,	330015,	330016,	330017,	330018,	330019,	330020}}    -- 位置1：五个小怪的编号
x020024_g_IdPuTong[2]={{331001,	331002,	331003,	331004,	331005,	331006,	331007,	331008,	331009,	331010,	331011,	331012,	331013,	331014,	331015,	331016,	331017,	331018,	331019,	331020},{331001,	331002,	331003,	331004,	331005,	331006,	331007,	331008,	331009,	331010,	331011,	331012,	331013,	331014,	331015,	331016,	331017,	331018,	331019,	331020}}		  -- 位置2：石化怪物解除石化
x020024_g_IdPuTong[3]={{335001,	335002,	335003,	335004,	335005,	335006,	335007,	335008,	335009,	335010,	335011,	335012,	335013,	335014,	335015,	335016,	335017,	335018,	335019,	335020},{335001,	335002,	335003,	335004,	335005,	335006,	335007,	335008,	335009,	335010,	335011,	335012,	335013,	335014,	335015,	335016,	335017,	335018,	335019,	335020}}		  -- 位置3：石化怪物解除石化
x020024_g_IdPuTong[4]={{332001,	332002,	332003,	332004,	332005,	332006,	332007,	332008,	332009,	332010,	332011,	332012,	332013,	332014,	332015,	332016,	332017,	332018,	332019,	332020},{332001,	332002,	332003,	332004,	332005,	332006,	332007,	332008,	332009,	332010,	332011,	332012,	332013,	332014,	332015,	332016,	332017,	332018,	332019,	332020},{332001,	332002,	332003,	332004,	332005,	332006,	332007,	332008,	332009,	332010,	332011,	332012,	332013,	332014,	332015,	332016,	332017,	332018,	332019,	332020}}	  -- 位置4：四波精英怪物   添加数量的话直接在里面添加，下方需要添加对应的坐标
x020024_g_IdPuTong[5]={{331001,	331002,	331003,	331004,	331005,	331006,	331007,	331008,	331009,	331010,	331011,	331012,	331013,	331014,	331015,	331016,	331017,	331018,	331019,	331020}}    -- boss左侧召唤小蛇   添加数量的话直接在里面添加，下方需要添加对应的坐标  所有召唤物的rolebaseId 注意相同
x020024_g_IdPuTong[6]={{331001,	331002,	331003,	331004,	331005,	331006,	331007,	331008,	331009,	331010,	331011,	331012,	331013,	331014,	331015,	331016,	331017,	331018,	331019,	331020}}	  -- boss右侧召唤小蛇   添加数量的话直接在里面添加，下方需要添加对应的坐标  所有召唤物的rolebaseId 注意相同
x020024_g_IdPuTong[7]={{334001,	334002,	334003,	334004,	334005,	334006,	334007,	334008,	334009,	334010,	334011,	334012,	334013,	334014,	334015,	334016,	334017,	334018,	334019,	334020}}    --  左侧蛇蛋召唤物
x020024_g_IdPuTong[8]={{334001,	334002,	334003,	334004,	334005,	334006,	334007,	334008,	334009,	334010,	334011,	334012,	334013,	334014,	334015,	334016,	334017,	334018,	334019,	334020}}    -- 右侧蛇蛋召唤物

x020024_g_AdaptLvlNum = 20

x020024_g_BossroleId = {}
x020024_g_BossroleId[1] = {333001,	333002,	333003,	333004,	333005,	333006,	333007,	333008,	333009,	333010,	333011,	333012,	333013,	333014,	333015,	333016,	333017,	333018,	333019,	333020}		--  Boss 编号
x020024_g_EndBossPosList={}
x020024_g_EndBossPosList[1]={{90.56,33.65,3.30}}	  --最终的boss坐标

x020024_g_MonsterPosList={}     
x020024_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}}		
x020024_g_MonsterPosList[2]={{64.18,103.88,3.30},{60.89,86.7,3.30}}		--  小怪坐	```标
x020024_g_MonsterPosList[3]={{78.67,103.78,3.30},{74.48,81.81,3.30}}  
x020024_g_MonsterPosList[4]={{21.97,31.12,3.30},{23.11,12.95,3.30},{31.90,22.98,3.30}}	   
x020024_g_MonsterPosList[5]={{89.37,35.40,3.30}}		-- 召唤物左侧坐标
x020024_g_MonsterPosList[6]={{89.37,35.40,3.30}}		-- 右侧召唤物坐标  增加数量直接在这添加
x020024_g_MonsterPosList[7]={{75.78,43.53,0}}         -- 左侧蛇蛋召唤坐标
x020024_g_MonsterPosList[8]={{85.12,19.13,0}}         -- 右侧蛇蛋召唤坐标

x020024_g_RefreshMonTime = 10		-- 刷新时间间隔

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

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

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


x020024_g_CSParamIdxCurStage=0                     -- 场景切换波数
x020024_g_CSParamIdxCurSubStage=1				   -- 同一场景中的时间点		
x020024_g_CSParamIdxrandtime=2					   -- 70血以下是否释放		
x020024_g_CSParamIdxcurNum = 3					   -- 30血以下是否释放
x020024_g_CSParamIdx70 = 4                   
x020024_g_CSParamIdx30 = 5  


x020024_g_ShoutBossId = 801    					-- 喊话展示BossFakeobjid
x020024_g_ShoutStrId = 50010					-- 喊话字典号

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

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

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


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

x020024_g_TpId = {}	  -- 传送点ID
x020024_g_TpId[1] = {1021, 1022}
x020024_g_TpPos={}
x020024_g_TpPos[1]={93.46,95.07}   
x020024_g_TpPos[2]={36.93,23.42}-- 传送点坐标

x020024_g_IdCSItemxiayiBox = 10400
x020024_g_IdCSItemBox = 10300   -- 奖品箱子ID

function x020024_OnCopySceneOpen( scene )
	AddCSMission(scene,64001)
	AddCSMission(scene,64002)
	AddCSMission(scene,64003)
	AddCSMission(scene,64004)
	AddCSMission(scene,64005)
	AddCSMission(scene,64006)
	AddCSMission(scene,64007)
end
--任务完成回调
function x020024_OnMissionComplete(scene, nObjId, nMissionId)
	print(nMissionId)
	if nMissionId == 64004 then
		OnCSMissionStage(scene,4)
	end
	if nMissionId == 64006 then
		OnCSMissionStage(scene, 6)
	end
end
--副本Tick
function x020024_OnCopySceneTick(scene,tickCount)					--副本阶段
	local curStage = GetCopySceneParam(scene,x020024_g_CSParamIdxCurStage) +1
	local curSubStage = GetCopySceneParam(scene,x020024_g_CSParamIdxCurSubStage) +1
	SetCopySceneParam(scene,x020024_g_CSParamIdxCurSubStage,curSubStage)

	local nAdaptedLvl = math.floor(GetAdaptLvl(scene)/5)		
	if(x020024_g_AdaptLvlNum < nAdaptedLvl)  then
		nAdaptedLvl = x020024_g_AdaptLvlNum
	end
	if curStage == 1 then
		x020024_Stage_1(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 2 then
		x020024_Stage_2(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 3 then
		x020024_Stage_3(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 4 then
		x020024_Stage_4(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 5 then
		x020024_Stage_5(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 6 then
		x020024_Stage_6(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 7 then
		x020024_Stage_7(scene,curStage,curSubStage,nAdaptedLvl)
	elseif curStage == 8 then
		x020024_Stage_8(scene,curStage,curSubStage,nAdaptedLvl)
		--70%左侧蛇
		if ((CalculatePercenHp(scene, GetObjIdByRoleBase(scene, x020024_g_BossroleId[1][nAdaptedLvl])) <= x020024_g_PerHp1) and (CalculatePercenHp(scene, GetObjIdByRoleBase(scene, x020024_g_BossroleId[1][nAdaptedLvl])) ~= -1) and (CalculatePercenHp(scene, GetObjIdByRoleBase(scene, x020024_g_BossroleId[1][nAdaptedLvl])) ~= 0) and GetCopySceneParam(scene, x020024_g_CSParamIdxrandtime) == 0)then
			SetCopySceneParam(scene, x020024_g_CSParamIdxrandtime, tickCount)
			local nUserCount = GetSceneUserCount(scene)
				for i=0,nUserCount-1 do
					local nUserObjId = GetUserObjIdByIdx(scene,i)
					ShowBossTips(scene, nUserObjId, x020024_g_ShoutBossId, x020024_g_ShoutStrId, x020024_g_BossroleId[1][nAdaptedLvl])
				end
			--print("70% Snake")
			x020024_CreateMonster(scene, 5, 3, nAdaptedLvl)
			SetCopySceneParam(scene, x020024_g_CSParamIdx70, tickCount)
			--SetCopySceneParam(scene,x020024_g_CSParamIdxCurSubStage, 10)
		end
		--30%左侧蛇
		if ((CalculatePercenHp(scene, GetObjIdByRoleBase(scene, x020024_g_BossroleId[1][nAdaptedLvl])) <= x020024_g_PerHp2) and (CalculatePercenHp(scene, GetObjIdByRoleBase(scene, x020024_g_BossroleId[1][nAdaptedLvl])) ~= -1) and (CalculatePercenHp(scene, GetObjIdByRoleBase(scene, x020024_g_BossroleId[1][nAdaptedLvl])) ~= 0) and GetCopySceneParam(scene, x020024_g_CSParamIdxcurNum) == 0)then
			SetCopySceneParam(scene, x020024_g_CSParamIdxcurNum, tickCount)
			local nUserCount = GetSceneUserCount(scene)
				for i=0,nUserCount-1 do
					local nUserObjId = GetUserObjIdByIdx(scene,i)
					ShowBossTips(scene, nUserObjId, x020024_g_ShoutBossId, x020024_g_ShoutStrId, x020024_g_BossroleId[1][nAdaptedLvl])
				end
			--print("30% Snake")
			x020024_CreateMonster(scene, 6, 3, nAdaptedLvl)
			SetCopySceneParam(scene, x020024_g_CSParamIdx30, tickCount)
			--SetCopySceneParam(scene,x020024_g_CSParamIdxCurSubStage, 10)
		end

		--左侧蛋蛇
		if (GetAliveByRoleBaseNum(scene, x020024_g_IdPuTong[5][1][nAdaptedLvl]) > 0 and  GetCopySceneParam(scene, x020024_g_CSParamIdxrandtime) > 0 and GetCopySceneParam(scene, x020024_g_CSParamIdx70) ~= 0 and tickCount == GetCopySceneParam(scene, x020024_g_CSParamIdx70) + x020024_g_RefreshMonTime) then
			--print("70% Egg Snake")
			x020024_CreateMonster(scene, 7, 3, nAdaptedLvl)
			SetCopySceneParam(scene, x020024_g_CSParamIdx70, tickCount)
		end
		--右侧蛋蛇
		if (GetAliveByRoleBaseNum(scene, x020024_g_IdPuTong[6][1][nAdaptedLvl]) > 0 and GetCopySceneParam(scene, x020024_g_CSParamIdxcurNum) > 0  and GetCopySceneParam(scene, x020024_g_CSParamIdx30) ~= 0 and tickCount == GetCopySceneParam(scene, x020024_g_CSParamIdx30) + x020024_g_RefreshMonTime) then
			--print("30% Egg Snake")
			x020024_CreateMonster(scene, 8, 3, nAdaptedLvl)
			SetCopySceneParam(scene, x020024_g_CSParamIdx30, tickCount)
		end

		--失去仇恨回满血后恢复技能冷却删除召唤物
		local Hp = CalculatePercenHp(scene, GetObjIdByRoleBase(scene, x020024_g_BossroleId[1][nAdaptedLvl]))
		--if(CalculatePercenHp(scene, GetObjIdByRoleBase(scene, x020024_g_BossroleId[1][nAdaptedLvl])) == 100) then     
		if(not MonIsBattle(scene, x020024_g_BossroleId[1][nAdaptedLvl]) and Hp > 0) then 
			SetCopySceneParam(scene, x020024_g_CSParamIdxrandtime, 0)
			SetCopySceneParam(scene, x020024_g_CSParamIdxcurNum, 0)
			SetCopySceneParam(scene, x020024_g_CSParamIdx70, 0)
			SetCopySceneParam(scene, x020024_g_CSParamIdx30, 0)
			DeleMonsterByRoleId(scene, x020024_g_IdPuTong[5][1][nAdaptedLvl])
			DeleMonsterByRoleId(scene, x020024_g_IdPuTong[6][1][nAdaptedLvl])
			DeleMonsterByRoleId(scene, x020024_g_IdPuTong[7][1][nAdaptedLvl])
			DeleMonsterByRoleId(scene, x020024_g_IdPuTong[8][1][nAdaptedLvl])
		end
		if(GetCopySceneParam(scene, x020024_g_CSParamIdx70) ~= 0 and CalculatePercenHp(scene, GetObjIdByRoleBase(scene, x020024_g_BossroleId[1][nAdaptedLvl])) > 0 ) then
			if(tickCount == GetCopySceneParam(scene, x020024_g_CSParamIdx70) + x020024_g_time)  then
				SendAllPlayerServerTips(scene, x020024_g_Tips[1])
			end
		end
		if(GetCopySceneParam(scnee, x020024_g_CSParamIdx30) ~= 0 and CalculatePercenHp(scene, GetObjIdByRoleBase(scene, x020024_g_BossroleId[1][nAdaptedLvl])) > 0 ) then
			if(tickCount == GetCopySceneParam(scnee, x020024_g_CSParamIdx30) + x020024_g_time)  then
				SendAllPlayerServerTips(scene, x020024_g_Tips[1])
			end
		end
	elseif curStage == 9 then
		x020024_Stage_End(scene, curSubStage)
	end	
end

--结算
function x020024_Success(scene)
	local nUserCount = GetSceneUserCount(scene)
	for i=0,nUserCount-1 do
		local nUserObjId = GetUserObjIdByIdx(scene,i)
	--	AwardCSItemBox(scene,nUserObjId,x020024_g_IdCSItemxiayiBox,x020024_g_IdCSItemBox)
		AddActivtyNum(scene, nUserObjId, 19)
	end

	SetCopySceneSuccess(scene)
end

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

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

	local count = #x020024_g_MonsterPosList[idx]
	--print(count)
	for i = 1, count  do
		local nMonObjId = CreateMonster(scene,  x020024_g_IdPuTong[idx][i][nlv], x020024_g_MonsterPosList[idx][i][3], x020024_g_MonsterPosList[idx][i][1],x020024_g_MonsterPosList[idx][i][2])
		SetNpcCampByObjId(scene, nMonObjId, camp)
		if idx == 5 then
			CommandMoveTo(scene, nMonObjId, x020024_g_MonsterTargetPos[1][1], x020024_g_MonsterTargetPos[1][2])
			--SendAllPlayerServerTips(scene, x020024_g_Tips[1])
		end
		if idx == 6 then
			CommandMoveTo(scene, nMonObjId, x020024_g_MonsterTargetPos[2][1], x020024_g_MonsterTargetPos[2][2])
			--SendAllPlayerServerTips(scene, x020024_g_Tips[1])
		end
		if(idx == 2 or idx == 3 ) then
			local buffcount = #x020024_g_BossShihuabuffId[1]

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

function x020024_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 x020024_Stage_1(scene ,stage,substage, nlv)                      
	if substage == 1 then
		OnCSMissionStage(scene,0)
		--print("stage",stage)
		x020024_CreateMonster(scene,1,3,nlv)
		x020024_CreateMonster(scene,2,1,nlv)
		x020024_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 x020024_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, x020024_g_ShoutBossId1, x020024_g_ShoutStrId1, x020024_g_BossroleId[1][nlv])
		end
	elseif(substage == 2) then
		--print("stage",stage)
		OnCSMissionStage(scene,1)
		local countleft =  #x020024_g_MonsterPosList[2]
		for i = 1, countleft do
			local MonObjs = GetAllObjIdByRoleBase(scene, x020024_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 = #x020024_g_BossShihuabuffId[1]
				for k = 1, buffcount do
					RemoveImpactByStrId(scene, nId, x020024_g_BossShihuabuffId[1][k])
				end
			
			end
		end
	end
end

--阶段3
function x020024_Stage_3(scene ,stage,substage,nlv)                      
	if substage == 1 then
		OnCSMissionStage(scene,2)
		--print("stage",stage)
		local countright =  #x020024_g_MonsterPosList[3]
		for i = 1, countright do
			local MonObjs = GetAllObjIdByRoleBase(scene, x020024_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 = #x020024_g_BossShihuabuffId[1]
				for k = 1, buffcount do
					RemoveImpactByStrId(scene, nId, x020024_g_BossShihuabuffId[1][k])
				end
			
			end
		end	
	end
end

--阶段4
function x020024_Stage_4(scene ,stage,substage,nlv)		
	if substage == 1 then
		OnCSMissionStage(scene,3)
		--print("stage",stage)
		SetSceneBuff(scene, x020024_g_TpId[1][1], x020024_g_TpPos[1][1], x020024_g_TpPos[1][2], 0)	
	elseif substage == 2 then
		x020024_CreateMonster(scene,4,3,nlv)
	end	
end

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

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

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

--阶段8
function x020024_Stage_8(scene ,stage,substage,nlv)						
	if substage == 1 then
		OnCSMissionStage(scene,5)
		--print("stage",stage)
		local Monobj = CreateMonster(scene, x020024_g_BossroleId[1][nlv], x020024_g_EndBossPosList[1][1][3], x020024_g_EndBossPosList[1][1][1],x020024_g_EndBossPosList[1][1][2])
	elseif substage == 2 then 
		SetSceneBuff(scene, x020024_g_TpId[1][2], x020024_g_TpPos[2][1], x020024_g_TpPos[2][2], 0)	
	end
end

function x020024_Stage_End(scene, substage)
	if substage == 1 then
		x020024_Success(scene)
	end
end