x020032_g_scriptId = 020032

x020032_g_CSParamIdxCurStage = 0			  --副本参数	
x020032_g_CSParamIdxCurSubStage = 1
x020032_g_CSParamIdxMonsterIndex = 2
x020032_g_CSParamIdxStoryIndex = 3
x020032_g_CSParamIdxAnimationIndex = 4
x020032_g_CSParamIdxMonsterNum = 5 

x020032_g_DeathNum = 3    --   杀死多少个小弟触发召唤怪物

x020032_g_BosstipId = 50007   --  喊话的字典号Id
x020032_g_BossId = 801     --  喊话的形象ID
x020032_g_GroupPointPos ={}
x020032_g_GroupPointPos[1]= {306,225}    --  临时buff采集点坐标
x020032_g_GroupPointId = 4	--   临时buff采集点编号

x020032_g_BossNumEnumId = 987  --  存储MdId  不用改


--副本任务
function x020032_OnCopySceneOpen( scene )
	AddCSMissionByStiry(scene)
end     

--创建怪物
function x020032_Stage_CreatMonster( scene,idx,camp)							
	local nMonsterIndex = GetCopySceneParam(scene,x020032_g_CSParamIdxMonsterIndex)
	CreateMonsterByStory(scene, nMonsterIndex)
	SetCopySceneParam(scene,x020032_g_CSParamIdxMonsterIndex,nMonsterIndex+1)
end

--剧情对话
function x020032_StartClienStory(scene)
	local nStoryIndex = GetCopySceneParam(scene,x020032_g_CSParamIdxStoryIndex)
	StartClientStoryByStory(scene, nStoryIndex);
	SetCopySceneParam(scene,x020032_g_CSParamIdxStoryIndex, nStoryIndex+1)
end

--剧情动画
function x020032_StartStoryAnimation(scene)
	local nAnimationIndex = GetCopySceneParam(scene,x020032_g_CSParamIdxAnimationIndex)
	StartStoryAnimationByStory(scene, nAnimationIndex)
	SetCopySceneParam(scene,x020032_g_CSParamIdxAnimationIndex, nAnimationIndex+1)
end

--剧情回调
function x020032_OnStoryEventEnd(scene,storyId,animationId)

end

--任务完成回调
function x020032_OnMissionComplete(scene, nObjId, nMissionId)
	local nCurStage = GetCopySceneParam(scene,x020032_g_CSParamIdxCurStage)
	--print("Return",nCurStage)
	if nCurStage == 2 then
		SetCopySceneParam(scene,x020032_g_CSParamIdxCurStage,nCurStage+1)
		SetCopySceneParam(scene,x020032_g_CSParamIdxCurSubStage,0)
	elseif nCurStage == 4 then 
		SetCopySceneParam(scene,x020032_g_CSParamIdxCurStage,nCurStage+1)
		SetCopySceneParam(scene,x020032_g_CSParamIdxCurSubStage,0)
	elseif nCurStage == 7 then 
		SetCopySceneParam(scene,x020032_g_CSParamIdxCurStage,nCurStage+1)
		SetCopySceneParam(scene,x020032_g_CSParamIdxCurSubStage,0)
	end
end
function x020032_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 x020032_Succeed(scene)
	local nUserCount = GetSceneUserCount(scene)
	for i=0,nUserCount-1 do		
		local nUserObjId = GetUserObjIdByIdx(scene,i)
		AddActivtyNum(scene, nUserObjId, 40)
		x020032_CheckMissionMD(scene,nUserObjId,x020032_g_BossNumEnumId)
		local oldTime = GetMissionMD(scene, nUserObjId, 4, x020032_g_BossNumEnumId)
		SetMissionMD(scene, nUserObjId, 4, x020032_g_BossNumEnumId, oldTime+1)
	end
	AccoutByStory(scene)
end

--死亡回调
function x020032_OnObjDie( scene,objId,rolebaseId,killerId )
	local nCurStage = GetCopySceneParam(scene,x020032_g_CSParamIdxCurStage)
	local MonCount = GetHostileMonsterCount(scene)
	if nCurStage == 6 then
		local nFlag = GetCopySceneParam(scene,x020032_g_CSParamIdxMonsterNum)
		if MonCount == x020032_g_DeathNum then
			if nFlag == 0 then
				SetCopySceneParam(scene,x020032_g_CSParamIdxMonsterNum,1)
				x020032_Stage_CreatMonster(scene,nCurStage,1)
			end
		elseif MonCount == 0 then
			--print("Die",nCurStage)
			SetCopySceneParam(scene,x020032_g_CSParamIdxCurStage,nCurStage+1)
			SetCopySceneParam(scene,x020032_g_CSParamIdxCurSubStage,0)
		end
	else
		if MonCount == 0 then
			SetCopySceneParam(scene,x020032_g_CSParamIdxCurStage,nCurStage+1)
			SetCopySceneParam(scene,x020032_g_CSParamIdxCurSubStage,0)
		end
	end
end

--副本Tick
function x020032_OnCopySceneTick(scene,tickCount)
	local curStage = GetCopySceneParam(scene,x020032_g_CSParamIdxCurStage)
	local curSubStage = GetCopySceneParam(scene,x020032_g_CSParamIdxCurSubStage)
	SetCopySceneParam(scene, x020032_g_CSParamIdxCurSubStage, curSubStage+1)
	if curStage == 0 then  
		x020032_Stage_0(scene, curStage, curSubStage)
	elseif curStage == 1 then
		x020032_Stage_1(scene, curStage, curSubStage)
	elseif curStage == 2 then
		x020032_Stage_2(scene, curStage, curSubStage)
	elseif curStage == 3 then 
		x020032_Stage_3(scene, curStage, curSubStage)
	elseif curStage == 4 then
		x020032_Stage_4(scene, curStage, curSubStage)
	elseif curStage == 5 then 
		x020032_Stage_5(scene, curStage, curSubStage)
	elseif curStage == 6 then
		x020032_Stage_6(scene, curStage, curSubStage)
	elseif curStage == 7 then 
		x020032_Stage_7(scene, curStage, curSubStage)
	elseif curStage == 8 then
		x020032_Stage_8(scene, curStage, curSubStage)
	elseif curStage == 9 then
		x020032_Stage_End(scene, curStage, curSubStage)
	elseif curStage == 10 then
		SetCopySceneSuccess(scene)
	end
end

--第0阶段
function x020032_Stage_0(scene ,stage,substage)
	if substage == 1 then
		--print("Enter Stage",stage)
		x020032_StartStoryAnimation(scene)
	elseif substage == 19 then
		OnCSMissionStage(scene,stage)
		x020032_Stage_CreatMonster(scene,stage,1)
	end
end

--第1阶段
function x020032_Stage_1(scene ,stage,substage)
	if substage == 1 then
		--print("Enter Stage",stage)
		OnCSMissionStage(scene,stage)
		x020032_Stage_CreatMonster(scene,stage,1)
	end
end

--第2阶段
function x020032_Stage_2(scene ,stage,substage)
	if substage == 1 then
		--print("Enter Stage",stage)
		OnCSMissionStage(scene,stage)
	end
end

--第3阶段
function x020032_Stage_3(scene ,stage,substage)
	if substage == 1 then
		--print("Enter Stage",stage)
		x020032_StartStoryAnimation(scene)
	elseif substage == 12 then
		OnCSMissionStage(scene,stage)
		x020032_Stage_CreatMonster(scene,stage,1)
	end
end

--第4阶段
function x020032_Stage_4(scene ,stage,substage)
	if substage == 1 then
		--print("Enter Stage",stage)
		local nUserCount = GetSceneUserCount(scene)
		for i=0,nUserCount-1 do
			local nUserObjId = GetUserObjIdByIdx(scene,i)
			ShowBossTips(scene, nUserObjId,x020032_g_BossId, x020032_g_BosstipId)
		end
		SetSceneBuff(scene,x020032_g_GroupPointId,x020032_g_GroupPointPos[1][1],x020032_g_GroupPointPos[1][2],0)
		OnCSMissionStage(scene,stage)
	end
end

--第5阶段
function x020032_Stage_5(scene ,stage,substage)
	if substage == 1 then
		--print("Enter Stage",stage)
		x020032_StartStoryAnimation(scene)
	elseif substage == 11 then
		OnCSMissionStage(scene,stage)
		x020032_Stage_CreatMonster(scene,stage,1)
	end
end

--第6阶段
function x020032_Stage_6(scene ,stage,substage)
	if substage == 1 then
		--print("Enter Stage",stage)
		OnCSMissionStage(scene,stage)
		x020032_Stage_CreatMonster(scene,stage,1)
	end
end

--第7阶段
function x020032_Stage_7(scene ,stage,substage)
	--print("stage",stage,"substage",substage)
	if substage == 1 then
		x020032_StartStoryAnimation(scene)
	elseif substage == 17 then
		OnCSMissionStage(scene,stage)
	end
end

--第8阶段
function x020032_Stage_8(scene ,stage,substage)
	--print("stage",stage,"substage",substage)
	if substage == 1 then
		x020032_StartStoryAnimation(scene)
	elseif substage == 11 then 
		OnCSMissionStage(scene,stage)
		x020032_Stage_CreatMonster(scene,stage,1)
	end
end

--最后阶段
function x020032_Stage_End(scene ,stage,substage)
	if substage == 1 then
		--print("Enter Stage",stage)
		x020032_Succeed(scene)
		SetCopySceneParam(scene,x020032_g_CSParamIdxCurStage,stage+1)
		SetCopySceneParam(scene,x020032_g_CSParamIdxCurSubStage,0)

		local nUserCount = GetSceneUserCount(scene)
		for i=0,nUserCount-1 do	
			local nUserObjId = GetUserObjIdByIdx(scene,i)	
			AddActivtyNum(scene, nUserObjId, 9)
			RemoveImpact(nScene, nUserObjId, 20252)
		end
	end
end



