199 lines
7.9 KiB
Lua
199 lines
7.9 KiB
Lua
local EventAction_RoundBegining = {
|
||
GameTime = 0;
|
||
--- 准备阶段时间
|
||
PreparationTime = 0;
|
||
GameEndEvent = -1;
|
||
}
|
||
|
||
-- 触发器激活时,将执行Action的Execute
|
||
function EventAction_RoundBegining:Execute(...)
|
||
if not UGCGameSystem.IsServer() then return end
|
||
self.bEnableActionTick = true
|
||
|
||
-- 初始化游戏时间
|
||
self.GameStartTime = UGCSystemLibrary.GetGameTime()
|
||
self.LastUpdateRemainTime = self.GameTime
|
||
self.RoundCurrentGameTime = 0.
|
||
UGCGameSystem.GameState:SetGameTime(self.GameTime)
|
||
|
||
|
||
-- 设置当前游戏模式
|
||
UGCGameSystem.GameState:SetGameStateType(CustomEnum.EGameState.Playing)
|
||
-- 设置为下一个回合
|
||
UGCGameSystem.GameState:NewRound()
|
||
-- 准备阶段启用房间阻挡
|
||
UGCGameSystem.GameState:EnableHouseBlock(true)
|
||
-- 重置钥匙
|
||
if UGCGameSystem.GameState:GetRoundNum() > 1 then
|
||
UGCGameSystem.GameState:ResetKey()
|
||
else
|
||
UGCGameSystem.GameState:ResetReadKey()
|
||
end
|
||
-- 重置队伍钥匙持有时间
|
||
UGCGameSystem.GameState:ResetHoldsTheKeyTime()
|
||
-- 循环更新钥匙持有时间
|
||
UGCGameSystem.GameState:LoopUpdateTeamKeyTime()
|
||
|
||
-- 给予上轮未死亡玩家的背包物品
|
||
UGCGameSystem.GameState:EnableLoopAddPlayerRecordBackpack()
|
||
-- 清空死亡盒子和可拾取物
|
||
UGCSystemLibrary.RemoveActorFromClassName("PlayerTombBox")
|
||
UGCSystemLibrary.RemoveActorFromClassName("PickUpWrapperActor")
|
||
-- 记录当前玩家的隐藏分
|
||
UGCGameSystem.GameState:RecordPlayerScore()
|
||
|
||
-- 重置所有玩家
|
||
local TempPlayerControllers = UGCGameSystem.GetAllPlayerController()
|
||
--UGCLogSystem.LogTree("[EventAction_RoundBegining_Execute]1", UGCGameSystem.GetAllPlayerController(true))
|
||
--UGCLogSystem.LogTree("[EventAction_RoundBegining_Execute]2", UGCGameSystem.GetAllPlayerController())
|
||
for _,PlayerController in pairs(TempPlayerControllers) do
|
||
if UE.IsValid(PlayerController.Pawn) then
|
||
UGCGameSystem.MyObserversChangeTarget(PlayerController)
|
||
-- Test
|
||
-- PlayerController.Pawn:K2_DestroyActor()
|
||
end
|
||
UGCGameSystem.LeaveSpectating(PlayerController)
|
||
-- UGCGameSystem.GetRespawnComponent():AddRespawnPlayer(PlayerController.PlayerKey, 0)
|
||
-- UGCGameSystem.RespawnPlayer(PlayerController.PlayerKey)
|
||
PlayerController.PlayerState:ResetInjuryInfo()
|
||
--所有玩家进入战斗状态
|
||
PlayerController:Fight();
|
||
end
|
||
|
||
-- 清除观战Handle
|
||
UGCGameSystem.GameState:CleanSpectateHandle()
|
||
|
||
-- 设置所有玩家不可移动
|
||
-- UGCSystemLibrary.SetAllPlayerIsMoveable(false)
|
||
|
||
-- 隔帧复活所有玩家
|
||
UGCEventSystem.SetTimer(UGCGameSystem.GameState, function() self:RespawnAllPlayer() end, 0.1)
|
||
|
||
-- 显示控制UI
|
||
UGCSendRPCSystem.ActorRPCNotify(nil, UGCGameSystem.GameState, "ShowControlPanel")
|
||
-- 显示回合准备UI
|
||
-- UGCSendRPCSystem.ClientShowUI(nil, WidgetConfig.EUIType.RoundReady)
|
||
-- 客户端发送回合重置事件
|
||
UGCSendRPCSystem.RPCEvent(nil, EventEnum.RoundBegining)
|
||
|
||
UGCLogSystem.Log("[EventAction_RoundBegining_Execute] Finish")
|
||
return true
|
||
end
|
||
|
||
function EventAction_RoundBegining:RespawnAllPlayer()
|
||
--local TempPlayerControllers = UGCGameSystem.GetAllPlayerController()
|
||
--for _,PlayerController in pairs(TempPlayerControllers) do
|
||
-- UGCGameSystem.RespawnPlayer(PlayerController.PlayerKey)
|
||
--end
|
||
-- Test
|
||
UGCGameSystem.SendModeCustomEvent("ResetAllPlayer")
|
||
end
|
||
|
||
function EventAction_RoundBegining:RoundFinish()
|
||
self.bEnableActionTick = false
|
||
if self.GameEndEvent then
|
||
-- 发送回合结束事件
|
||
UGCEventSystem.SendEvent(self.GameEndEvent)
|
||
end
|
||
end
|
||
|
||
function EventAction_RoundBegining:Update(DeltaSeconds)
|
||
local CurrentRealTime = UGCSystemLibrary.GetGameTime();
|
||
self.RoundCurrentGameTime = CurrentRealTime - self.GameStartTime
|
||
local RemainTime = self.GameTime - self.RoundCurrentGameTime;
|
||
local CurrentUpdateRemainTime = math.ceil(RemainTime)
|
||
|
||
-- 判断是否存在获胜队伍
|
||
if self:DetectionWinner() then
|
||
self:RoundFinish()
|
||
return
|
||
end
|
||
|
||
-- 更新游戏时间
|
||
if self.LastUpdateRemainTime - CurrentUpdateRemainTime >= 1 then
|
||
-- 判断游戏时间是否已结束
|
||
if CurrentUpdateRemainTime <= 0 then
|
||
self.LastUpdateRemainTime = 0
|
||
self:RoundFinish()
|
||
else
|
||
self.LastUpdateRemainTime = CurrentUpdateRemainTime
|
||
end
|
||
UGCGameSystem.GameState:SetGameTime(self.LastUpdateRemainTime)
|
||
|
||
if self.RoundCurrentGameTime >= self.PreparationTime and self.DoOnceDisHouseBlock == nil then
|
||
self.DoOnceDisHouseBlock = true
|
||
self:EndOfPreparationTime()
|
||
end
|
||
end
|
||
|
||
end
|
||
|
||
function EventAction_RoundBegining:EndOfPreparationTime()
|
||
UGCLogSystem.Log("[EventAction_RoundBegining_EndOfPreparationTime]")
|
||
-- 准备阶段结束关闭房间阻挡
|
||
UGCGameSystem.GameState:EnableHouseBlock(false)
|
||
UGCGameSystem.GameState:ReadyTimeFinish()
|
||
-- 若准备阶段不能行动则设置玩家移动速度缩放
|
||
if GlobalConfigs.GameSetting.ReadyCanNotMove then
|
||
local AllPlayerPawn = UGCGameSystem.GetAllPlayerPawn()
|
||
for i, v in pairs(AllPlayerPawn) do
|
||
v:SetCanActionable(true)
|
||
end
|
||
--UGCSystemLibrary.SetAllPlayerIsMoveable(true)
|
||
end
|
||
-- 刷新所有玩家观战
|
||
local TempPlayerControllers = UGCGameSystem.GetAllPlayerController()
|
||
for _,PlayerController in pairs(TempPlayerControllers) do
|
||
UGCGameSystem.MyObserversChangeTarget(PlayerController)
|
||
UGCGameSystem.LeaveSpectating(PlayerController)
|
||
end
|
||
|
||
-- 发送准备时间结束到客户端
|
||
UGCSendRPCSystem.RPCEvent(nil, EventEnum.RoundReadyFinish)
|
||
end
|
||
|
||
function EventAction_RoundBegining:DetectionWinner()
|
||
if self.RoundCurrentGameTime >= self.PreparationTime then
|
||
local CTTeamAlive, TTeamAlive = false, false
|
||
local CTPlayers = UGCTeamSystem.GetPlayerKeysByTeamID(TeamConfig.TeamType.CT)
|
||
local TPlayers = UGCTeamSystem.GetPlayerKeysByTeamID(TeamConfig.TeamType.T)
|
||
for i, v in pairs(CTPlayers) do
|
||
local TempPawn = UGCGameSystem.GetPlayerPawnByPlayerKey(v)
|
||
if TempPawn and TempPawn:IsAlive() then
|
||
CTTeamAlive = true
|
||
break
|
||
end
|
||
end
|
||
for i, v in pairs(TPlayers) do
|
||
local TempPawn = UGCGameSystem.GetPlayerPawnByPlayerKey(v)
|
||
if TempPawn and TempPawn:IsAlive() then
|
||
TTeamAlive = true
|
||
break
|
||
end
|
||
end
|
||
--UGCLogSystem.Log("[EventAction_RoundBegining_DetectionWinner] CTTeamAlive:%s, TTeamAlive:%s", tostring(CTTeamAlive), tostring(TTeamAlive))
|
||
if CTTeamAlive and TTeamAlive then
|
||
local CTHoldsTheKeyTime = UGCGameSystem.GameState:GetTeamHoldsTheKeyTimeFormTeamID(TeamConfig.TeamType.CT)
|
||
local THoldsTheKeyTime = UGCGameSystem.GameState:GetTeamHoldsTheKeyTimeFormTeamID(TeamConfig.TeamType.T)
|
||
--UGCLogSystem.Log("[EventAction_RoundBegining_DetectionWinner] CTHoldsTheKeyTime:%s, THoldsTheKeyTime:%s", tostring(CTHoldsTheKeyTime), tostring(THoldsTheKeyTime))
|
||
if math.max(CTHoldsTheKeyTime, THoldsTheKeyTime) >= GlobalConfigs.GameSetting.TeamNeedHoldsTheKeyTime then
|
||
if CTHoldsTheKeyTime > THoldsTheKeyTime then
|
||
UGCGameSystem.GameState:SetWinner(TeamConfig.TeamType.CT)
|
||
else
|
||
UGCGameSystem.GameState:SetWinner(TeamConfig.TeamType.T)
|
||
end
|
||
else
|
||
return false
|
||
end
|
||
elseif CTTeamAlive then
|
||
UGCGameSystem.GameState:SetWinner(TeamConfig.TeamType.CT)
|
||
elseif TTeamAlive then
|
||
UGCGameSystem.GameState:SetWinner(TeamConfig.TeamType.T)
|
||
end
|
||
|
||
UGCLogSystem.Log("[EventAction_RoundBegining_DetectionWinner] Finish")
|
||
return true
|
||
end
|
||
end
|
||
|
||
return EventAction_RoundBegining |