x020001_g_scriptId=020001

x020001_g_MonsterIdList={}
x020001_g_MonsterIdList[1]={29,29,29}
x020001_g_MonsterIdList[2]={29,29,29}
x020001_g_MonsterIdList[3]={29,29,29}

x020001_g_MonsterPosList={}
x020001_g_MonsterPosList[1]={{51,197},{51,190},{51,206}}
x020001_g_MonsterPosList[2]={{51,197},{51,190},{51,206}}
x020001_g_MonsterPosList[3]={{51,197},{51,190},{51,206}}


x020001_g_CSParamIdxCurStage=0

x020001_g_StoryAnimationId =15
x020001_g_ClientStoryId = 15

function x020001_OnCopySceneTick(scene,tickCount)
	if tickCount==0 then    
		SetCopySceneParam(scene,x020001_g_CSParamIdxCurStage,0)
	end
	if tickCount%3 == 0 then
		SceneEffect(scene,51,197,tickCount)
	elseif tickCount%3 == 1 then
		NpcPaoPaoByRBId(scene,29,502)
	else
		NpcAnimationByRBId(scene,29,3)
	end
	
	local nCurStage = GetCopySceneParam(scene,x020001_g_CSParamIdxCurStage)
	if(nCurStage%3==0) then
		local nIdx = math.floor(nCurStage/3)
		if(nIdx<#x020001_g_MonsterIdList) then
			local nCount = #x020001_g_MonsterIdList[nIdx+1]

			for i=1,nCount do
				CreateMonster(scene,x020001_g_MonsterIdList[nIdx+1][i],0,x020001_g_MonsterPosList[nIdx+1][i][1],x020001_g_MonsterPosList[nIdx+1][i][2])
			end

			if(nIdx == 0) then
				StoryAnimation(scene,x020001_g_StoryAnimationId)
				SetNpcCampByRBId(scene,29,1)
			end

			if(nIdx == 1) then
				StartClientStory(scene,x020001_g_ClientStoryId)
				SetNpcCampByRBId(scene,29,1)
			end

			if(nIdx == 2) then
				StartClientStory(scene,x020001_g_ClientStoryId)
				SetNpcCampByRBId(scene,29,1)
			end
		else
			SetCopySceneSuccess(scene);
		end
		SetCopySceneParam(scene,x020001_g_CSParamIdxCurStage,nCurStage+1)
	elseif(nCurStage%3==2) then
		SetCopySceneParam(scene,x020001_g_CSParamIdxCurStage,nCurStage+1)
	end
end


function x020001_OnObjDie( scene,objId,killerId )

	local MonCount = GetHostileMonsterCount(scene)
	if(MonCount == 0) then
		local nCurStage = GetCopySceneParam(scene,x020001_g_CSParamIdxCurStage)
		SetCopySceneParam(scene,x020001_g_CSParamIdxCurStage,nCurStage+1)
	end
end

function x020001_OnStoryEventEnd(scene,storyId,animationId)
	if(storyId == x020001_g_ClientStoryId) then
		SetNpcCampByRBId(scene,29,3)
	end

	if(animationId == x020001_g_StoryAnimationId) then
		SetNpcCampByRBId(scene,29,3)
	end
end