x020082_g_scriptId = 020082

-- 出生坐标
x020082_g_HostPos = {54.90885, 44.26264, -3.1415}

x020082_g_PlayerPosX = 190.65
x020082_g_PlayerPosZ = 271.07
x020082_g_PlayerPosF = -0.5
x020082_g_PlayerPosRand = 10
x020082_g_WaitTime = 55 --等待匹配时间
x020082_g_MaxPeopleNum = 30  --等待人数30人
x020082_g_MinPeopleNum = 0
x020082_g_WaitTime_2 = 5 --提前开启  更改时间 让玩家准备时间变成5秒
x020082_g_WaitTime_3 = 7 --8秒提示
--阶段0  等待所有玩家进入  60秒 或者人数达到30
--阶段1  等待游戏开始     30秒
--阶段2  游戏开始			暂时不限时间
x020082_g_Stage = 0 
x020082_g_StageTime = 1


--缩圈进度
x020082_g_CurQuanIndex = 2
x020082_g_QuanTime = 3
x020082_g_NextQuanIndex = 4
--
x020082_g_CopySceneTime = 5


x020082_g_GroupPoint_1 = 3006
x020082_g_GroupPointPosX_1 = 204.29
x020082_g_GroupPointPosZ_1 = 266.27
x020082_g_GroupPointFaceDir_1 = 3.3

x020082_g_GroupPoint_2 = 3007
x020082_g_GroupPointPosX_2 = 229
x020082_g_GroupPointPosZ_2 = 260.5
x020082_g_GroupPointFaceDir_2 = 3.3

x020082_g_GroupPoint_3 = 3008
x020082_g_GroupPointPosX_3 = 175
x020082_g_GroupPointPosZ_3 = 270.36
x020082_g_GroupPointFaceDir_3 = 3.3

x020082_g_GroupPoint_4 = 3009
x020082_g_GroupPointPosX_4 = 148
x020082_g_GroupPointPosZ_4 = 246.5
x020082_g_GroupPointFaceDir_4 = 3.3


--副本开始阶段
function x020082_OnCopySceneOpen(scene)
	SetCopySceneParam(scene,x020082_g_Stage,0)
	SetCopySceneParam(scene,x020082_g_CurQuanIndex,0)
	SetCopySceneParam(scene,x020082_g_QuanTime,0)
	SetCopySceneParam(scene,x020082_g_NextQuanIndex,0)
	SetCopySceneParam(scene,x020082_g_CopySceneTime,0)
	SetCopySceneParam(scene,x020082_g_StageTime,0)
end

function x020082_OnObjEnter(scene,objId)
	local nTime = 0
	local nStage = GetCopySceneParam(scene,x020082_g_Stage)
	if(nStage == 0) then
		nTime = x020082_g_WaitTime - GetCopySceneParam(scene,x020082_g_StageTime)
	end
	if(nStage == 1) then
		nTime = x020082_g_WaitTime_2 - GetCopySceneParam(scene,x020082_g_StageTime)
	end
	if(nStage == 2) then
		nTime = GetCopySceneParam(scene,x020082_g_QuanTime)
	end
	AddPlayerByChiJi(scene,objId,nStage,nTime)
	TestFullHp(scene,objId)
	SetScenePos(scene, objId, x020082_g_PlayerPosX+RandomMon(-x020082_g_PlayerPosRand,x020082_g_PlayerPosRand), x020082_g_PlayerPosZ+RandomMon(-x020082_g_PlayerPosRand,x020082_g_PlayerPosRand), x020082_g_PlayerPosF)
end
--每个玩家死了播一个Tips （区分入魔和非入魔）
function x020082_OnCopySceneTick(scene,tickCount)
	local nCopySceneStage = GetCopySceneParam(scene,x020082_g_Stage)
	if(nCopySceneStage == 2) then --如果战斗开始  就计算缩圈时间--1
		local nQuanTime = GetCopySceneParam(scene,x020082_g_QuanTime)--获取缩圈过了多少秒
		UpdateDuQuan(scene,GetCopySceneParam(scene,x020082_g_CurQuanIndex),nQuanTime,GetCopySceneParam(scene,x020082_g_NextQuanIndex)) --检测是否缩圈（更改nQuTime）
		SetCopySceneParam(scene,x020082_g_StageTime,GetCopySceneParam(scene,x020082_g_StageTime)+1)
		SetCopySceneParam(scene,x020082_g_QuanTime,GetCopySceneParam(scene,x020082_g_QuanTime)+1)
		x020082_DuQuanBuff(scene)
		x020082_RuMo(scene)  -- Tips  1人、2人、3人
	end--1
	if(nCopySceneStage == 0) then--1
		local nTime = GetCopySceneParam(scene,x020082_g_StageTime)

		SetCopySceneParam(scene,x020082_g_StageTime,nTime+1)
		local nUserCount = GetSceneUserCount(scene)
		if(nTime >= x020082_g_WaitTime) then--可以开始了--2
			x020082_ChiJiStart(scene)
		end
		if(nUserCount >= x020082_g_MaxPeopleNum) then--2
			if(nTime < x020082_g_WaitTime - x020082_g_WaitTime_2) then --大于55已经开始倒计时就不改变值了--3
				SetCopySceneParam(scene,x020082_g_StageTime,x020082_g_WaitTime - x020082_g_WaitTime_2)
				TellChiJiGameStage(scene,0,5)
				SendChiJiTipToAllPlayer(scene,"#{1663182}","",-1,false)
				nTime = x020082_g_WaitTime - x020082_g_WaitTime_2
				DelThisRoom(scene)
			end--3
		end
		if(nTime == x020082_g_WaitTime - x020082_g_WaitTime_3) then --开始倒计时--2
			--SendChiJiTipToAllPlayer(scene,"#{1663183}")
			DelThisRoom(scene)
		end--2
	end--1
	if(nCopySceneStage == 1) then --进入准备开始阶段--1

		local nStageTime = GetCopySceneParam(scene,x020082_g_StageTime)
		local nQuanTime = GetCopySceneParam(scene,x020082_g_QuanTime)--获取缩圈过了多少秒
		--UpdateDuQuan(scene,GetCopySceneParam(scene,x020082_g_CurQuanIndex),nQuanTime,GetCopySceneParam(scene,x020082_g_NextQuanIndex)) --检测是否缩圈
		SetCopySceneParam(scene,x020082_g_StageTime,GetCopySceneParam(scene,x020082_g_StageTime)+1)
		--SetCopySceneParam(scene,x020082_g_QuanTime,GetCopySceneParam(scene,x020082_g_QuanTime)+1)
		if(nStageTime == 24) then--2
		   --SendChiJiTipToAllPlayer(scene,"#{1663185}","",5,true)
			--Tips倒计时5秒钟
		end--2
		if(nStageTime == 30) then  -- 强制降落--2
			--JiangLuoAllPlayer(scene)
			SetCopySceneParam(scene,x020082_g_Stage,2)--更改状态为游戏开始
			SetCopySceneParam(scene,x020082_g_StageTime,0)
			InitSuoquan(scene)


		end--2
	end--1

end
function x020082_DuQuanBuff(scene) --给玩家上掉血buff
	local nUserCount = GetSceneUserCount(scene)
	for i=0,nUserCount-1 do
		local nUserObjId = GetUserObjIdByIdx(scene,i)
		UpdateQuanBuff(scene,GetCopySceneParam(scene,x020082_g_CurQuanIndex),nUserObjId)
	end
end
function x020082_RuMo(scene)
	if(GetRuMoPlayerCount(scene) == 0) then
		UpdateRuMoPlayer(scene)
	end 
	UpdateRuMoBuff(scene)
end
function x020082_ChiJiStart(scene)--游戏开始
	SendChiJiTipToAllPlayer(scene,"#{1663184}","",-1,true)
	TellChiJiGameStage(scene,1,30)
	SetCopySceneParam(scene,x020082_g_Stage,1)
	SetCopySceneParam(scene,x020082_g_StageTime,0)
	ChiJiGameStart(scene)
    SetSceneBuff(scene,x020082_g_GroupPoint_1,x020082_g_GroupPointPosX_1,x020082_g_GroupPointPosZ_1,x020082_g_GroupPointFaceDir_1)
    SetSceneBuff(scene,x020082_g_GroupPoint_2,x020082_g_GroupPointPosX_2,x020082_g_GroupPointPosZ_2,x020082_g_GroupPointFaceDir_2)
    SetSceneBuff(scene,x020082_g_GroupPoint_3,x020082_g_GroupPointPosX_3,x020082_g_GroupPointPosZ_3,x020082_g_GroupPointFaceDir_3)
    SetSceneBuff(scene,x020082_g_GroupPoint_4,x020082_g_GroupPointPosX_4,x020082_g_GroupPointPosZ_4,x020082_g_GroupPointFaceDir_4)
    AddRuMoPlayerBuff(scene)
end
function x020082_OnObjDie(scene,objId1,rolebaseId,killerId)
	--SetCopySceneParam(scene,x020082_g_Stage,2)
	ChiJiPlayerDie(scene,objId1,killerId)
end
function x020082_OnObjReconnect(scene, objId)
	-- body
	local nTime = 0
	local nStage = GetCopySceneParam(scene,x020082_g_Stage)
	if(nStage == 0) then
		nTime = x020082_g_WaitTime - GetCopySceneParam(scene,x020082_g_StageTime)
	end
	if(nStage == 1) then
		nTime = x020082_g_WaitTime_2 - GetCopySceneParam(scene,x020082_g_StageTime)
	end
	if(nStage == 2) then
		nTime = GetCopySceneParam(scene,x020082_g_QuanTime)
	end
	AddPlayerByChiJi(scene,objId,nStage,nTime)
	TestFullHp(scene,objId)
	SetScenePos(scene, objId, x020082_g_PlayerPosX+RandomMon(-x020082_g_PlayerPosRand,x020082_g_PlayerPosRand), x020082_g_PlayerPosZ+RandomMon(-x020082_g_PlayerPosRand,x020082_g_PlayerPosRand), x020082_g_PlayerPosF)
end
