x020007_g_scriptId=020007

-- 玩家坐标
x020007_g_BluePosX=95.27
x020007_g_BluePosZ=60.55

-- 机器人坐标
x020007_g_RedPosX=32.94
x020007_g_RedPosZ=60.41

-- 定身Buff 用于控制玩家开场时间内无法移动
x020007_g_StunBuff=20253

-- CopySceneParam
x020007_g_Start = 3 -- 开始标识
x020007_g_Blue = 1 -- 玩家ObjId
x020007_g_Red = 2 -- 机器人ObjId

function x020007_OnCopySceneOpen(scene)
	SetCopySceneParam(scene,x020007_g_Start,0)
	SetCopySceneParam(scene,x020007_g_Blue,0)
	SetCopySceneParam(scene,x020007_g_Red,0)
end

function x020007_OnObjEnter(scene,objId)

	--大于0，表明副本已经开始过了，直接返回
	if (GetCopySceneParam(scene,x020007_g_Start) > 0) then
		return
	end
	
	-- 玩家初始化
	SetCopySceneParam(scene,x020007_g_Blue,objId)
	SetCopySceneParam(scene,x020007_g_Red,CreatePvpRobot(scene,objId,0,x020007_g_RedPosX,x020007_g_RedPosZ))
	SetCopySceneParam(scene,x020007_g_Start,1)

	SendImpactToUnit(scene,objId,x020007_g_StunBuff)
	--SetScenePos(scene,objId,x020007_g_BluePosX,x020007_g_BluePosZ,3.14)
	TestFullHp(scene,objId)
	RemoveCDTime(scene,objId)
	AutoCombat(scene,objId,true)
	--AccoutByCopyScene(scene)
	
	-- 创建一个和玩家属性相同的机器人
	
		
	--if(x020007_g_BluePlayerId == nil) then 
		--x020007_g_BluePlayerId = objId
		--x020007_g_BluePlayerGuid = tostring(GetPlayerGuidById(scene,x020007_g_BluePlayerId)) 
		--SetPos(scene,objId,x020007_g_BluePosX,x020007_g_BluePosZ,-3.14)
		--TestFullHp(scene,objId)
		--RemoveCDTime(scene,objId)
		--SetPvpCamp(scene,objId,6)
		--AutoCombat(scene,objId,true)
		
		--if(x020007_g_CurPlayerCount == nil) then
			--x020007_g_CurPlayerCount = 1
		--end			
	--else
		--if(x020007_g_RedPlayerId == nil) then 
			--x020007_g_RedPlayerId = objId
			--x020007_g_RedPlayerGuid = tostring(GetPlayerGuidById(scene,x020007_g_RedPlayerId))
			--SetPos(scene,objId,x020007_g_RedPosX,x020007_g_RedPosZ,0)
			--TestFullHp(scene,objId)
			--RemoveCDTime(scene,objId)
			--SetPvpCamp(scene,objId,7)
			--AutoCombat(scene,objId,true)
			--x020007_g_CurPlayerCount = x020007_g_CurPlayerCount + 1
			--if (x020015_g_Start == nil) then
				--x020015_g_Start = 1
			--end			
		--end
	--end
end

function x020007_OnObjLeave(scene,objId,rolebaseId)
	x020007_Modify(scene,objId)
end
	
function x020007_OnObjDie(scene,objId,rolebaseId,killerId)
	x020007_Modify(scene,objId)
end

function x020007_Modify(scene,objId)
	--大于1，表明已经分出过胜负了，不要再次结算
	if (GetCopySceneParam(scene,x020007_g_Start) > 1) then
		return
	end

	local blue = GetCopySceneParam(scene,x020007_g_Blue)
	local red = GetCopySceneParam(scene,x020007_g_Red)
	
	-- 玩家落败
	if (objId == blue) then
		RecordPvpRankData(scene,blue,false)
		SetCopySceneFail(scene)
	
	else
	-- 玩家胜利
		RecordPvpRankData(scene,blue,true)		
		SetCopySceneSuccess(scene)
	end
	SetCopySceneParam(scene,x020007_g_Start,2)
	x020007_Succeed(scene)
	RecordPvpMatching(scene,blue)
	--if (x020007_g_BluePlayerId ~= nil) and (x020007_g_RedPlayerId ~= nil) and (GetCopySceneStatus(scene) < 4) then
		--if (objId == x020007_g_BluePlayerId) then
			--RecordPvpRankData(scene,x020007_g_BluePlayerGuid,x020007_g_RedPlayerGuid,1,false,false,"")
		--elseif(objId == x020007_g_RedPlayerId) then
			--RecordPvpRankData(scene,x020007_g_BluePlayerGuid,x020007_g_RedPlayerGuid,1,true,false,"")
		--else
			--return
		--end
		--x020007_g_BluePlayerId = nil
		--x020007_g_RedPlayerId = nil
		--x020007_Succeed(scene)
		--SetCopySceneSuccess(scene)
	--end
end

function x020007_Succeed(scene)
	local blue = GetCopySceneParam(scene,x020007_g_Blue)

	RemoveImpact(scene,blue,x020007_g_StunBuff)	
	SetHpFull(scene,blue)
	RemoveCDTime(scene,blue)
	AutoCombat(scene,blue,false)
	
	--local nUserCount = GetSceneUserCount(scene)
	--for i=0,nUserCount-1 do		
		--local nUserObjId = GetUserObjIdByIdx(scene,i)
		--SetHpFull(scene,nUserObjId)
		--RemoveCDTime(scene,nUserObjId)
		--AutoCombat(scene,nUserObjId,false)
	--end
end

function x020007_OnObjLeaveByCopySceneTimeOut(scene,objId)
	local blue = GetCopySceneParam(scene,x020007_g_Blue)
	
	-- 副本超时结束判断玩家胜利
		RecordPvpRankData(scene,blue,true)		
		SetCopySceneSuccess(scene)

	SetCopySceneParam(scene,x020007_g_Start,2)
	x020007_Succeed(scene)
	RecordPvpMatching(scene,blue)
end


