243 lines
8.4 KiB
Lua
243 lines
8.4 KiB
Lua
local EventAction_RoundBegin = {
|
||
GameTime = 0;
|
||
--- 准备阶段时间
|
||
PreparationTime = 0;
|
||
GameEndEvent = -1;
|
||
DoOnceFinish = false;
|
||
}
|
||
|
||
-- 触发器激活时,将执行Action的Execute
|
||
function EventAction_RoundBegin:Execute(...)
|
||
if not UGCGameSystem.IsServer() then return end
|
||
self.DoOnceEnableMove = false
|
||
self.DoOnceFinish = false;
|
||
-- 初始化游戏时间
|
||
self.GameTimeInst = self.GameTime + math.max(self.PreparationTime, 0)
|
||
|
||
-- 新回合
|
||
UGCGameSystem.GameState:AddNewRound()
|
||
-- 显示战斗界面
|
||
UGCGameSystem.GameState:ShowSimplePlayModeUI(WidgetConfig.EUIType.FightPanel)
|
||
-- 设置当前游戏模式
|
||
UGCGameSystem.GameState:SetGameStateType(CustomEnum.EGameState.Playing)
|
||
|
||
-- 清空死亡盒子、可拾取物、投掷物
|
||
UGCSystemLibrary.RemoveActorFromClassName("PlayerTombBox")
|
||
UGCSystemLibrary.RemoveActorFromClassName("PickUpWrapperActor")
|
||
UGCSystemLibrary.RemoveActorFromClassName("EliteProjectile")
|
||
|
||
|
||
|
||
-- 设置准备阶段参数
|
||
if self.PreparationTime > 0 then
|
||
--- 存在准备阶段
|
||
-- 设置所有玩家不可移动
|
||
if not GlobalConfigs.GameSetting.ReadyCanMove then
|
||
UGCSystemLibrary.SetAllPlayerIsMovable(false)
|
||
end
|
||
else
|
||
--- 不存在准备阶段
|
||
self.DoOnceEnableMove = true
|
||
end
|
||
|
||
-- 玩法逻辑
|
||
self:ExecuteOtherLogic()
|
||
|
||
|
||
-- 重置所有玩家,需要放在所有逻辑最后边
|
||
self:RespawnAllPlayers()
|
||
|
||
self.bEnableActionTick = true
|
||
UGCLogSystem.Log("[EventAction_RoundBegin_Execute] Finish")
|
||
return true
|
||
end
|
||
|
||
function EventAction_RoundBegin:RespawnAllPlayers()
|
||
UGCGameSystem.SendModeCustomEvent("ResetAllPlayers")
|
||
end
|
||
|
||
function EventAction_RoundBegin:RoundFinish()
|
||
self.bEnableActionTick = false
|
||
if self.DoOnceFinish then return end
|
||
self.DoOnceFinish = true;
|
||
|
||
self:RoundFinishOtherLogic()
|
||
if self.GameEndEvent then
|
||
-- 发送回合结束事件
|
||
UGCEventSystem.SendEvent(self.GameEndEvent)
|
||
end
|
||
|
||
end
|
||
|
||
function EventAction_RoundBegin:Update(DeltaSeconds)
|
||
if not self.bEnableActionTick then
|
||
return
|
||
end
|
||
|
||
self.GameTimeInst = self.GameTimeInst - DeltaSeconds
|
||
|
||
-- 判断准备阶段是否结束
|
||
if self.GameTimeInst <= self.GameTime and not self.DoOnceEnableMove then
|
||
self.DoOnceEnableMove = true
|
||
self:EndOfPreparationTime()
|
||
end
|
||
|
||
-- 设置游戏时间
|
||
UGCGameSystem.GameState:SetGameTime(math.clamp(math.floor(self.GameTimeInst), 0, self.GameTime + self.PreparationTime))
|
||
|
||
if self.GameTimeInst <= 0 then
|
||
self:RoundFinish()
|
||
end
|
||
self:UpdateOtherLogic(DeltaSeconds)
|
||
end
|
||
|
||
function EventAction_RoundBegin:EndOfPreparationTime()
|
||
UGCLogSystem.Log("[EventAction_RoundBegin_EndOfPreparationTime]")
|
||
if not GlobalConfigs.GameSetting.ReadyCanMove then
|
||
UGCSystemLibrary.SetAllPlayerIsMovable(true)
|
||
end
|
||
-- 发送准备时间结束到客户端
|
||
UGCSendRPCSystem.RPCEvent(nil, EventEnum.RoundReadyFinish)
|
||
self:OtherEndOfPreparationTimeLogic()
|
||
end
|
||
|
||
--根据工程的修改而改变的逻辑 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||
|
||
-- 根据工程的修改而改变的开始执行逻辑
|
||
function EventAction_RoundBegin:ExecuteOtherLogic()
|
||
|
||
-- 判断玩家是否死亡,死亡则重生
|
||
local AllPC = UGCGameSystem.GetAllPlayerController()
|
||
for i, PC in pairs(AllPC) do
|
||
if not UE.IsValid(PC.Pawn) or not PC.Pawn:IsAlive() then
|
||
UGCGameSystem.RespawnPlayer(PC.PlayerKey)
|
||
end
|
||
-- 新增一个增益
|
||
-- PC:AddCanObtainIncreaseCount()
|
||
end
|
||
|
||
-- 绑定玩家死亡
|
||
UGCEventSystem.AddListener(EventEnum.PlayerDeathInfo, self.PlayerDeath, self)
|
||
|
||
-- 绑定攻点成功通知
|
||
UGCEventSystem.AddListener(EventEnum.UpdateSuccessfullyOccupied, self.SuccessfullyOccupied, self)
|
||
|
||
|
||
-- 切换玩家出生点
|
||
|
||
-- 开始缩圈
|
||
-- UGCBlueprintFunctionLibrary.TogglePoisonCircle(UGCGameSystem.GameState, true);
|
||
SignalCircleConfig.TogglePoisonCircle()
|
||
|
||
-- 重置载具
|
||
UGCLogSystem.Log("[EventAction_RoundBegin_ExecuteOtherLogic] ResetAllSavedVehicle")
|
||
MyVehicleSystem.ResetAllSavedVehicle()
|
||
|
||
-- 激活攻点
|
||
if UGCGameSystem.GameState:GetMapModeType() == MapConfig.EModeType.AttackPoint then
|
||
self.AttackPointActor = UGCSystemLibrary.GetUniqueInstanceFromPath(UGCGameSystem.GetUGCResourcesFullPath('Asset/Blueprint/SceneActor/AttackPoint/BP_AttackPoint.BP_AttackPoint_C'))
|
||
if UE.IsValid(self.AttackPointActor) then
|
||
self.AttackPointActor:SetActiveAttackPoint(true)
|
||
else
|
||
UGCLogSystem.LogError("[EventAction_RoundBegin_ExecuteOtherLogic] AttackPointActor is nil")
|
||
end
|
||
end
|
||
|
||
end
|
||
|
||
-- 根据工程的修改而改变的准备阶段结束逻辑
|
||
function EventAction_RoundBegin:OtherEndOfPreparationTimeLogic()
|
||
UGCLogSystem.Log("[EventAction_RoundBegin_OtherEndOfPreparationTimeLogic]")
|
||
|
||
end
|
||
|
||
-- 根据工程的修改而改变的Tick逻辑
|
||
function EventAction_RoundBegin:UpdateOtherLogic(DeltaSeconds)
|
||
|
||
-- 每2秒检测一方玩家是否已全部阵亡
|
||
self.CheckTeamPlayerLastTime = self.CheckTeamPlayerLastTime and self.CheckTeamPlayerLastTime + DeltaSeconds or 0
|
||
if self.CheckTeamPlayerLastTime > 2 then
|
||
self.CheckTeamPlayerLastTime = 0
|
||
self.CheckTeamPlayerLastTime = self.CheckTeamPlayerLastTime + DeltaSeconds
|
||
self:CheckTeamPlayer()
|
||
end
|
||
end
|
||
|
||
-- 根据工程的修改而改变的结束逻辑
|
||
function EventAction_RoundBegin:RoundFinishOtherLogic()
|
||
-- 移除绑定玩家死亡,判断是否有胜利方
|
||
UGCEventSystem.RemoveListener(EventEnum.PlayerDeathInfo, self.PlayerDeath, self)
|
||
-- 移除攻点成功的绑定
|
||
UGCEventSystem.RemoveListener(EventEnum.UpdateSuccessfullyOccupied, self.PlayerDeath, self)
|
||
-- 销毁载具
|
||
MyVehicleSystem.DestroyAllSavedVehicle()
|
||
-- 增加回合胜利玩家的得分
|
||
-- 设置玩家无敌状态
|
||
local AllPawn = UGCGameSystem.GetAllPlayerPawn()
|
||
for i, PlayerPawn in pairs(AllPawn) do
|
||
UGCPawnSystem.SetIsInvincible(PlayerPawn, true)
|
||
end
|
||
|
||
-- 关闭攻点
|
||
if UGCGameSystem.GameState:GetMapModeType() == MapConfig.EModeType.AttackPoint then
|
||
self.AttackPointActor = UGCSystemLibrary.GetUniqueInstanceFromPath(UGCGameSystem.GetUGCResourcesFullPath('Asset/Blueprint/SceneActor/AttackPoint/BP_AttackPoint.BP_AttackPoint_C'))
|
||
if UE.IsValid(self.AttackPointActor) then
|
||
self.AttackPointActor:SetActiveAttackPoint(false)
|
||
else
|
||
UGCLogSystem.LogError("[RoundFinishOtherLogic_ExecuteOtherLogic] AttackPointActor is nil")
|
||
end
|
||
end
|
||
end
|
||
|
||
-- 有玩家死亡
|
||
function EventAction_RoundBegin:PlayerDeath(PlayerKey)
|
||
UGCLogSystem.Log("[EventAction_RoundBegin_PlayerDeath]")
|
||
-- 判断是否有胜利方
|
||
self:CheckTeamPlayer()
|
||
local PC = UGCGameSystem.GetPlayerControllerByPlayerKey(PlayerKey)
|
||
if UE.IsValid(PC) then
|
||
UGCLogSystem.Log("[EventAction_RoundBegin_PlayerDeath] 观战")
|
||
-- 让观战自己的队友观战别人
|
||
UGCGameSystem.MyObserversChangeTarget(PC)
|
||
--进入观战
|
||
UGCGameSystem.EnterSpectating(PC)
|
||
end
|
||
end
|
||
|
||
-- 检测一方玩家是否已全部阵亡
|
||
function EventAction_RoundBegin:CheckTeamPlayer()
|
||
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
|
||
if CTTeamAlive == false then
|
||
UGCGameSystem.GameState:SetWinningTeam(TeamConfig.TeamType.T)
|
||
self:RoundFinish()
|
||
elseif TTeamAlive == false then
|
||
UGCGameSystem.GameState:SetWinningTeam(TeamConfig.TeamType.CT)
|
||
self:RoundFinish()
|
||
end
|
||
end
|
||
|
||
function EventAction_RoundBegin:SuccessfullyOccupied()
|
||
UGCGameSystem.GameState:SetWinningTeam(UGCGameSystem.GameState:GetAttackTeam())
|
||
self:RoundFinish()
|
||
end
|
||
|
||
|
||
|
||
|
||
return EventAction_RoundBegin |