x040000_g_scriptId=040000


x040000_g_BossId = {}
x040000_g_BossId[1] = {1001109}	-- Boss编号   表示Boss的自适应等级套数   
x040000_g_BossPosList={}
x040000_g_BossPosList[1]={{77.08,64.7,-2.28}}    --  Boss 坐标


x040000_g_TargetList = {}                      --目标
x040000_g_TargetList[1]={1001109}  --第一阶段目标1

x040000_g_CSParamAnimationID = 301          --mov动画ID
x040000_g_BossDropId = -1
x040000_g_BossNumEnumId = 987  --  存储MdId  不用改
x040000_g_FirstMissionId = 1800    -- 指引之前的任务id
x040000_g_SecMissionId = 1801    -- 指引之前的任务id
x040000_g_FirstPaoPaoId = 1400001 -- 泡泡ID

x040000_g_MovTickOut = 7-- 掉线之后直接切换阶段不经过Mov

x040000_g_BloodTick = 3  -- 血脉提示留存时间
x040000_g_CSParamIdxCurStage=0                     -- 场景切换波数
x040000_g_CSParamIdxCurSubStage=1				   -- 同一场景中的时间点
x040000_g_CSParam1 = 2
x040000_g_CSParam2 = 3	
x040000_g_CommitMissionTick = 4					   -- 完成任务的tick
x040000_g_Alltick = 6				   			   -- 总tick
x040000_g_CSMonEnd = 5 							   -- Mov之后的刷怪

function x040000_OnObjEnter(scene, objId)
	--RemoveBloodSkillCDTime(scene,objId)
	SetCopySceneParam(scene, x040000_g_CSParamIdxCurStage, 0)
	SetCopySceneParam(scene, x040000_g_CSParamIdxCurSubStage, 0)
	SetCopySceneParam(scene, 2, 0)
	SetCopySceneParam(scene, 3, 0)
	x040000_ClearAllMonster(scene)
	AcceptMission(scene, objId, x040000_g_FirstMissionId)
	SetCopySceneParam(scene, 5, 0)
	SetCopySceneParam(scene, 7, 0)
	SynCsStageData(scene, objId, true)
	--SynCsStageData(scene, objId, true)
	SetCopySceneParam(scene, x040000_g_CommitMissionTick, 0)
end
function x040000_OnDieCountDown1(scene, rolebaseId,  stage)
	local TargetId = x040000_g_TargetList[stage+1][1]
	if(TargetId == rolebaseId) then
		local OldValue = GetCopySceneParam(scene, x040000_g_CSParam1)
		SetCopySceneParam(scene, x040000_g_CSParam1, OldValue+1)
		local nUserCount = GetSceneUserCount(scene)
		for i=0,nUserCount-1 do   
			local nUserObjId = GetUserObjIdByIdx(scene,i)   
			SynCsStageData(scene, nUserObjId)
		end    
	end
end
function  x040000_StageControl(scene,nstage)
	SetCopySceneParam(scene, 2, 0)
	SetCopySceneParam(scene, 3, 0)
	SetCopySceneParam(scene, 7, nstage)
	local nUserCount = GetSceneUserCount(scene)
	for j=0,nUserCount-1 do   
		local nUserObjId = GetUserObjIdByIdx(scene,j)   
		SynCsStageData(scene, nUserObjId)
	end 


end
function x040000_ClearAllMonster(scene)
	--print(count)
   -- DeleMonsterByRoleId(scene,  x040000_g_BossId[1][1])
  --  DeleMonsterByRoleId(scene,  x040000_g_TargetList[2][1])
   DeleHostileMonster(scene)
end
function x040000_OnMissionComplete(scene, nObjId, nMissionId)
	--local a = not IsBloodAwaken(scene, nObjId)
	if  not IsBloodAwaken(scene, nObjId)  then
	--	print("a = ")
	--	print(a)
		local tick = GetCopySceneParam(scene, x040000_g_Alltick)
		ShowQuestion(scene, nObjId, 316)
		RemoveBloodSkillCDTime(scene,nObjId)
		SetCopySceneParam(scene, x040000_g_CommitMissionTick, tick + x040000_g_BloodTick)
	end
end
function x040000_OnObjLeave(scene, objId)
	AbandonMissionById(scene, objId, x040000_g_FirstMissionId)
	AbandonMissionById(scene, objId, x040000_g_SecMissionId)
end
function x040000_OnStoryEventEnd(scene,nStoryId,nAnimationId)
	if nAnimationId == x040000_g_CSParamAnimationID then
		local nCurStage = GetCopySceneParam(scene,x040000_g_CSParamIdxCurStage)
		local MonCount = GetHostileMonsterCount(scene)
		SetCopySceneParam(scene,x040000_g_CSParamIdxCurStage,1)
		SetCopySceneParam(scene,x040000_g_CSParamIdxCurSubStage,0)
		x040000_Stage_1(scene,2,1)
		local nUserCount = GetSceneUserCount(scene)
			
			for i=0,nUserCount-1 do		
				local nUserObjId = GetUserObjIdByIdx(scene,i)
					AutoCombat(scene,nUserObjId,true)
				end
	end
end
function x040000_OnCopySceneBloodAwaken(scene)
--	print("paopao")
	--NpcPaoPaoByRBId(scene, x040000_g_BossId[1][1], x040000_g_FirstPaoPaoId)
	BroadCastBossTips(scene, 700062, 1400001, 1001109)
	local nUserCount = GetSceneUserCount(scene)
	for i=0,nUserCount-1 do
		local nUserObjId = GetUserObjIdByIdx(scene,i)
	--	AwardCSItemBox(scene,nUserObjId,x040008_g_IdCSxiayiBox, x040008_g_IdCSItemBox)
			AutoCombat(scene,nUserObjId,true)
			SetCopySceneParam(scene, x040000_g_CommitMissionTick, 0)
	end
end
function x040000_OnCopySceneTick(scene,tickCount)					--副本阶段
	SetCopySceneParam(scene, x040000_g_Alltick, tickCount)
	local curStage = GetCopySceneParam(scene,x040000_g_CSParamIdxCurStage) +1
	local curSubStage = GetCopySceneParam(scene,x040000_g_CSParamIdxCurSubStage) +1
	SetCopySceneParam(scene,x040000_g_CSParamIdxCurSubStage,curSubStage)
	--NpcPaoPaoByRBId(scene, 1001109, 1400001)
	local LastBlood = GetCopySceneParam(scene, x040000_g_CommitMissionTick)
	if LastBlood ~= 0 and tickCount == LastBlood  then
		local nUserCount = GetSceneUserCount(scene)
		--print("自動變身")
		for i=0,nUserCount-1 do
			local nUserObjId = GetUserObjIdByIdx(scene,i)
			
			ActiveBloodAwaken(scene, nUserObjId)
		end
	end
	if curStage == 1 then  
		x040000_Stage_0(scene, curStage, curSubStage)
		if curSubStage >= 20 then
				SetCopySceneParam(scene,x040000_g_CSParamIdxCurStage,1)
				SetCopySceneParam(scene,x040000_g_CSParamIdxCurSubStage,0)
				x040000_Stage_1(scene,2,1)
				local nUserCount = GetSceneUserCount(scene)
			
			for i=0,nUserCount-1 do		
				local nUserObjId = GetUserObjIdByIdx(scene,i)
					AutoCombat(scene,nUserObjId,true)
				end
		end 

	end			
end


function x040000_Success(scene)
	AccoutByCopyScene(scene)	
	local nUserCount = GetSceneUserCount(scene)
	for i=0,nUserCount-1 do
		local nUserObjId = GetUserObjIdByIdx(scene,i)
	--	AwardCSItemBox(scene,nUserObjId,x040000_g_IdCSxiayiBox, x040000_g_IdCSItemBox)
	end
	SetCopySceneSuccess(scene)
end

function x040000_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  x040000_OnObjDie(scene,objId,rolebaseId,killerId)			
	local MonCount = GetHostileMonsterCount(scene)
	local nCurStage = GetCopySceneParam(scene, x040000_g_CSParamIdxCurStage)
	local oldStage = GetCopySceneParam(scene, 7)
	
	if(MonCount == 0) then
		if(rolebaseId == x040000_g_BossId[1][1]) then
		BroadCastBossTips(scene, 700062, 1400004, 1001109)
		x040000_OnDieCountDown1(scene, rolebaseId, oldStage)																											-- 隐藏BOSS奖励次数限制
			local nUserCount = GetSceneUserCount(scene)
			x040000_StageControl(scene, 1)

			x040000_Success(scene)
		end
	end
end
function x040000_CreateMonster( scene,idx,camp, nlv)					--刷怪（
	local count = #x040000_g_MonsterPosList[idx]
	for i = 1, count  do
		CreateMonster(scene,  x040000_g_IdPuTong[idx][i][nlv], x040000_g_MonsterPosList[idx][i][3], x040000_g_MonsterPosList[idx][i][1],x040000_g_MonsterPosList[idx][i][2])
	end
end
function x040000_Stage_0(scene ,stage,substage)
	if substage == 1 then
		StoryAnimation(scene, x040000_g_CSParamAnimationID)
	end
end
function x040000_Stage_1(scene ,stage,substage)                      
	if substage == 1 then
		--BroadCastBossTips(scene, 700062, 1400002, 1001109)
		if GetCopySceneParam(scene,x040000_g_CSMonEnd) == 0 then
			CreateMonster(scene, x040000_g_BossId[1][1], x040000_g_BossPosList[1][1][3], x040000_g_BossPosList[1][1][1],x040000_g_BossPosList[1][1][2])
			SetCopySceneParam(scene, x040000_g_CSMonEnd, 1)
		end
	end
end
