x020027_g_scriptId = 020027

x020027_g_CSParamIdxCurStage = 0			  --副本参数	
x020027_g_CSParamIdxCurSubStage = 1
x020027_g_CSParamIdxMonsterIndex = 2
x020027_g_CSParamIdxStoryIndex = 3
x020027_g_CSParamIdxAnimationIndex = 4

x020027_g_BeginAnimationId = 9012			--进场动画storyanimationID
x020027_g_BossAnimationId = 9999
x020027_g_EndAnimationId = 9019				--结束动画storyanimationID

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

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

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

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

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

end

--奖励结算
function x02027_Succeed(scene)
	AccoutByStory(scene)
end

--死亡回调
function x020027_OnObjDie( scene,objId,rolebaseId,killerId )
	local MonCount = GetHostileMonsterCount(scene)
	if(MonCount == 0) then
		local nCurStage = GetCopySceneParam(scene,x020027_g_CSParamIdxCurStage)
		--print("Enter in Stage", nCurStage+1)
		SetCopySceneParam(scene,x020027_g_CSParamIdxCurStage,nCurStage+1)
		SetCopySceneParam(scene,x020027_g_CSParamIdxCurSubStage,0)
	end
end

--副本Tick
function x020027_OnCopySceneTick(scene,tickCount)
	local curStage = GetCopySceneParam(scene,x020027_g_CSParamIdxCurStage) +1
	local curSubStage = GetCopySceneParam(scene,x020027_g_CSParamIdxCurSubStage) +1
	SetCopySceneParam(scene, x020027_g_CSParamIdxCurSubStage, curSubStage)

	if curStage == 1 then  --1
		x020027_Stage_1(scene, curStage, curSubStage)
	elseif curStage == 2 then
		x020027_Stage_Common(scene, curStage, curSubStage)
	elseif curStage == 3 then --2
		x020027_Stage_Common_2(scene, curStage, curSubStage)
	elseif curStage == 4 then
		x020027_Stage_Common(scene, curStage, curSubStage)
	elseif curStage == 5 then --3
		x020027_Stage_Common_2(scene, curStage, curSubStage)
	elseif curStage == 6 then
		x020027_Stage_Common(scene, curStage, curSubStage)
	elseif curStage == 7 then --4
		x020027_Stage_Boss(scene, curStage, curSubStage)
	elseif curStage == 8 then
		x020027_Stage_End(scene, curStage, curSubStage)
	elseif curStage == 9 then
		--print("end",curStage)
		SetCopySceneSuccess(scene)
	end
end

function x020027_Stage_Common(scene, stage, substage)
	if substage == 1 then
		--print("stage",stage-1)
		OnCSMissionStage(scene,stage-1)
		x020027_CreateMonster(scene,stage,1)
	elseif substage == 2 then
		x020027_StartClienStory(scene)
	end
end

function x020027_Stage_1(scene, stage, substage)
	if substage == 1 then
		x020027_StartStoryAnimation(scene)
	elseif substage == 10 then
		--print("First",stage)
		SetCopySceneParam(scene,x020027_g_CSParamIdxCurStage,stage)
		SetCopySceneParam(scene,x020027_g_CSParamIdxCurSubStage,0)
	end
end

--7
function x020027_Stage_Boss(scene, stage, substage)
	if substage == 1 then
		--print("Boss",stage)
		x020027_StartClienStory(scene)
	elseif substage == 4 then
		x020027_StartStoryAnimation(scene)
	elseif substage == 14 then
		--print("Boss",stage-1)
		OnCSMissionStage(scene,stage-1)
		x020027_StartClienStory(scene)
		x020027_CreateMonster(scene,stage,1)
	end

end

function x020027_Stage_Common_2(scene, stage, substage)
	if substage == 2 then
		x020027_StartClienStory(scene)
	elseif substage == 4 then
		--print("stage",stage)
		SetCopySceneParam(scene,x020027_g_CSParamIdxCurStage,stage)
		SetCopySceneParam(scene,x020027_g_CSParamIdxCurSubStage,0)
	end
end

function x020027_Stage_End(scene, stage, substage)
	if substage == 1 then
		--print("stage",stage)
		x020027_StartStoryAnimation(scene)
	elseif substage == 15 then
		--print("stage",stage,15)
		x02027_Succeed(scene)

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