--任务副本5
--进入副本→刷第一波小怪→击杀第一波小怪→副本完成→传出副本

x040008_g_scriptId = 040008

--副本参数
x040008_g_CSParamIdxCurStage = 0			  --大阶段	
x040008_g_CSParamIdxCurSubStage = 1           --小阶段
x040008_g_CSMovEndTick = 2					  -- Mov结束Tick
x040008_g_SumTick = 3						  -- 总Tick

x040008_g_CSParamAnimationID = 300           --mov动画ID
x040008_g_CSFirstTick = 2    -- 第一次特殊召出怪物时间戳  从mov结束开始算

x040008_g_FirstMissionId = 1800
x040008_g_SecMissionId = 1801

x040008_g_MonstorList={}
x040008_g_MonstorList[1]={1001104, 1001104, 1001104, 1001104, 1001104, 1001104, 1001104, 1001104, 1001104, 1001104}  --普通小怪

x040008_g_SpMonstorList={}
x040008_g_SpMonstorList[1] = {1001104, 1001104}  -- 第一次特殊小怪
x040008_g_SpMonstorList[2] = {1001104, 1001104}	 -- 血脉变身后出现的特殊小怪

x040008_g_MonstorPosList={}
x040008_g_MonstorPosList[1]={{31.72,29.58,-1.57},{31.53,36.21,-1.57},{35.8,36.21,-1.57},{36.35,29.41,-1.57},{42.38,32.85,-1.57},{37.73,32.85,-1.57},{32.84,32.85,-1.57},{28.83,32.85,-1.57},{40.45,29.41,-1.57},{40.54,36.01,-1.57}} --小怪坐标
x040008_g_MonstorPosList[2] = {{31.72,29.58,-1.57},{31.53,36.21,-1.57}}	 -- 第一次特殊小怪物
x040008_g_MonstorPosList[3] = {{31.72,29.58,-1.57},{31.53,36.21,-1.57}}	 -- 血脉变身后特殊小怪
function x040008_OnCopySceneTimeOut(scene)
	ClearPlayer(scene)
end
function x040008_OnCopySceneOpen(scene)

end
function x040008_OnCopySceneBloodAwaken(scene)
	--print("引導結束")
	local nUserCount = GetSceneUserCount(scene)
	for i=0,nUserCount-1 do
		local nUserObjId = GetUserObjIdByIdx(scene,i)
		AbandonMissionById(scene, nUserObjId, x040008_g_FirstMissionId)
	end
	x040008_CopySceneSpMonstor2(scene)
	x040008_CopyScenePause(scene, false)
end
function x040008_CopySceneSpMonstor2( scene)
	local curStage = GetCopySceneParam(scene,x040008_g_CSParamIdxCurStage)
	if curStage < 2 then
		local count = #x040008_g_SpMonstorList[2]
		for i = 1, count do
			CreateMonster(scene, x040008_g_SpMonstorList[2][i], x040008_g_MonstorPosList[3][i][3], x040008_g_MonstorPosList[3][i][1], x040008_g_MonstorPosList[3][i][2])
		end
	end
end
function x040008_OnObjEnter(scene, objId)
--	RemoveBloodSkillCDTime(scene,objId)
	AcceptMission(scene, objId, x040008_g_FirstMissionId)
	x040008_ClearAllMonster(scene)
	SetCopySceneParam(scene, x040008_g_CSParamIdxCurStage, 0)
	SetCopySceneParam(scene, x040008_g_CSParamIdxCurSubStage, 0)
	SetCopySceneParam(scene, x040008_g_CSMovEndTick, 0)
end
function x040008_OnMissionComplete(scene, nObjId, nMissionId)
	--print("開始引導")
	RemoveBloodSkillCDTime(scene,nObjId)
	x040008_CopyScenePause(scene, true)
end
function x040008_CopyScenePause(scene, IsPause)
	local nUserCount = GetSceneUserCount(scene)
	for i=0,nUserCount-1 do
		local nUserObjId = GetUserObjIdByIdx(scene,i)
	--	AwardCSItemBox(scene,nUserObjId,x040008_g_IdCSxiayiBox, x040008_g_IdCSItemBox)
		if IsPause == true then
			AutoCombat(scene,nUserObjId,false)
			SetNpcCampByRBId(scene, x040008_g_MonstorList[1][1], 1)	
			AddUserCombatTime(scene,nUserObjId,500000);
			StopAllNpcMove(scene, x040008_g_MonstorList[1][1])
		elseif IsPause == false then
			AutoCombat(scene,nUserObjId,true)
			SetNpcCampByRBId(scene, x040008_g_MonstorList[1][1], 3)	
			AddUserCombatTime(scene,nUserObjId,5000);
		end
	end
	--AutoCombat(scene,objId,false)
end
function x040008_OnObjLeave(scene, objId)
	AbandonMissionById(scene, objId, x040008_g_FirstMissionId)
	AbandonMissionById(scene, objId, x040008_g_SecMissionId)
end
function x040008_ClearAllMonster(scene)
	local count = #x040008_g_MonstorList[1]
	--print(count)
	for i = 1, count do
    	DeleMonsterByRoleId(scene,  x040008_g_MonstorList[1][i])
    end
end
--死亡回调
function x040008_OnObjDie( scene,objId,rolebaseId,killerId )
	local nCurStage = GetCopySceneParam(scene,x040008_g_CSParamIdxCurStage)
	local MonCount = GetHostileMonsterCount(scene)
	if MonCount == 0 then
		SetCopySceneParam(scene,x040008_g_CSParamIdxCurStage,nCurStage+1)
		SetCopySceneParam(scene,x040008_g_CSParamIdxCurSubStage,0)
	end
end

--副本Tick
function x040008_OnCopySceneTick(scene,tickCount)
	local curStage = GetCopySceneParam(scene,x040008_g_CSParamIdxCurStage)
	local curSubStage = GetCopySceneParam(scene,x040008_g_CSParamIdxCurSubStage)
	SetCopySceneParam(scene, x040008_g_CSParamIdxCurSubStage, curSubStage+1)
	SetCopySceneParam(scene, x040008_g_SumTick, tickCount)
	if curStage == 0 then
		x040008_Stage_1(scene, curStage, curSubStage, tickCount)
	elseif curStage == 1 then
		x040008_Stage_2(scene, curStage, curSubStage)
	end
end
function x040008_OnStoryEventEnd(scene,nStoryId,nAnimationId)
	if nAnimationId == x040008_g_CSParamAnimationID then
		x040008_CopyScenePause(scene, false)
		local nCurStage = GetCopySceneParam(scene,x040008_g_CSParamIdxCurStage)
		local MonCount = GetHostileMonsterCount(scene)

		local curtick = GetCopySceneParam(scene, x040008_g_SumTick)
		SetCopySceneParam(scene, x040008_g_CSMovEndTick, curtick)
	end
end
function x040008_Stage_0(scene ,stage,substage)
	if substage == 1 then
		StoryAnimation(scene, x040008_g_CSParamAnimationID)
	end
end
--第0阶段 播放MOV 刷第一波小怪
function x040008_Stage_1(scene ,stage,substage, tick)
	local EndTick = GetCopySceneParam(scene, x040008_g_CSMovEndTick)
	if substage == 1 then
		--TellPlayerAutoCombat(scene)
		local count = #x040008_g_MonstorList[1]
		for i = 1, count do
			CreateMonster(scene, x040008_g_MonstorList[1][i], x040008_g_MonstorPosList[1][i][3], x040008_g_MonstorPosList[1][i][1], x040008_g_MonstorPosList[1][i][2])
		end
	elseif substage == 2 then
		x040008_CopyScenePause(scene, true)
		StoryAnimation(scene, x040008_g_CSParamAnimationID)
	elseif (tick == x040008_g_CSFirstTick + EndTick) and EndTick ~= 0 then
		local count = #x040008_g_SpMonstorList[1]
		for i = 1, count do
			CreateMonster(scene, x040008_g_SpMonstorList[1][i], x040008_g_MonstorPosList[2][i][3], x040008_g_MonstorPosList[2][i][1], x040008_g_MonstorPosList[2][i][2])
		end
	end
end
function x040008_Stage_2(scene ,stage,substage)
	if substage == 1 then
		ChangeJobCopyEnd(scene, true)
		SetCopySceneSuccess(scene)
	end
end

