2025-01-04 23:00:19 +08:00

182 lines
6.7 KiB
Lua
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

local EventAction_RoundBegin = {
GameTime = 0;
--- 准备阶段时间
PreparationTime = 0;
GameEndEvent = -1;
}
-- 触发器激活时将执行Action的Execute
function EventAction_RoundBegin:Execute(...)
if not UGCGameSystem.IsServer() then return end
self.DoOnceEnableMove = 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")
-- 设置准备阶段参数
if self.PreparationTime > 0 then
--- 存在准备阶段
-- 设置所有玩家不可移动
UGCSystemLibrary.SetAllPlayerIsMovable(false)
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
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))
if self.GameTimeInst <= 0 then
self:RoundFinish()
end
end
function EventAction_RoundBegin:EndOfPreparationTime()
UGCLogSystem.Log("[EventAction_RoundBegin_EndOfPreparationTime]")
UGCSystemLibrary.SetAllPlayerIsMovable(true)
-- 发送准备时间结束到客户端
UGCSendRPCSystem.RPCEvent(nil, EventEnum.RoundReadyFinish)
end
-- 根据工程的修改而改变的开始执行逻辑 ----------------------------------------------------------------------------------------------------
function EventAction_RoundBegin:ExecuteOtherLogic()
-- 监听玩家突破防线
UGCEventSystem.AddListener(EventEnum.PlayerEnterLineOfDefense, self.PlayerEnterLineOfDefense, self)
-- 切换玩家出生点
UGCGameSystem.GameState:ChangeBreakThroughPlayerStart()
-- 重置突围次数
UGCGameSystem.GameState:ResetBreakThroughCount()
-- 开启防守玩家的呼吸回血
-- UGCGameSystem.GameState:SetRespiratoryRegurgitationPlayers({self.DefenderPlayerKey})
-- 初始化突围成功
self.TeamBreakThroughSucceed = false
-- 队伍提示
local AllPC = UGCGameSystem.GetAllPlayerController()
for i, v in pairs(AllPC) do
if UGCGameSystem.GameState:PlayerIsAttacker(v.PlayerKey) then
UGCGameSystem.GameState:SetPlayerWeaponCombination(v.PlayerKey, WeaponSelectionCombinationConfig.ECombinationType.Combination1)
UGCSendRPCSystem.ClientShowUI(v.PlayerKey, WidgetConfig.EUIType.TeamChangeTip, true, false, false)
else
UGCGameSystem.GameState:SetPlayerWeaponCombination(v.PlayerKey, WeaponSelectionCombinationConfig.ECombinationType.Combination2)
UGCSendRPCSystem.ClientShowUI(v.PlayerKey, WidgetConfig.EUIType.TeamChangeTip, true, false, true)
end
if GlobalConfigs.GameSetting.CanRespawnSelectWeapon then
UGCGameSystem.GameState:ShowPlayerSelectWeaponWidget(v.PlayerKey)
end
end
end
-- 根据工程的修改而改变的结束逻辑
function EventAction_RoundBegin:RoundFinishOtherLogic()
-- 增加回合胜利玩家的得分
local IsBreakThroughSucceed = UGCGameSystem.GameState:IsBreakThroughSucceed()
local AllPC = UGCGameSystem.GetAllPlayerController()
for i, v in pairs(AllPC) do
if UGCGameSystem.GameState:PlayerIsAttacker(v.PlayerKey) == IsBreakThroughSucceed then
PlayerScoreSystem.AddPlayerScoreData(v.PlayerKey, PlayerScoreSystem.Config.EScoreType.RoundWin, 1)
UGCSendRPCSystem.RPCEvent(v.PlayerKey, EventEnum.AddTip, TipConfig.TipType.AddScore, PlayerScoreSystem.Config.EScoreType.RoundWin)
end
end
if not self.TeamBreakThroughSucceed then
-- 设置进攻失败的时间
UGCGameSystem.GameState:SetTeamBreakThroughTime(-1)
end
UGCEventSystem.RemoveListener(EventEnum.PlayerEnterLineOfDefense, self.PlayerEnterLineOfDefense, self)
end
-- 玩家进入防线
function EventAction_RoundBegin:PlayerEnterLineOfDefense(PlayerKey)
if not UGCGameSystem.GameState:GetCanBreakThrough() then return end
-- 通知GameState突围冷却
UGCGameSystem.GameState:PlayerBreakThrough()
UGCLogSystem.Log("[EventAction_RoundBegin_PlayerEnterLineOfDefense] PlayerKey:%s", tostring(PlayerKey))
-- 增加突围数
UGCGameSystem.GameState:AddBreakThroughCount()
-- 增加突破得分
PlayerScoreSystem.AddPlayerScoreData(PlayerKey, PlayerScoreSystem.Config.EScoreType.EnterDefenseLine, 1)
-- 发送得分信息
UGCSendRPCSystem.RPCEvent(PlayerKey, EventEnum.AddTip, TipConfig.TipType.AddScore, PlayerScoreSystem.Config.EScoreType.EnterDefenseLine)
-- 广播提示
local AllPK = UGCSystemLibrary.GetAllPlayerKeys()
for i, OtherPlayerKey in pairs(AllPK) do
if OtherPlayerKey ~= PlayerKey then
UGCSendRPCSystem.RPCEvent(OtherPlayerKey, EventEnum.AddTip, TipConfig.TipType.PlayerBreakthrough, PlayerKey)
end
end
if UGCGameSystem.GameState:IsBreakThroughSucceed() then
-- 队伍突围成功
self.TeamBreakThroughSucceed = true
-- 设置进攻成功的时间
UGCGameSystem.GameState:SetTeamBreakThroughTime(KismetMathLibrary.Round((GlobalConfigs.GameSetting.RoundTime - self.GameTimeInst)))
self:RoundFinish()
else
UGCSystemLibrary.RespawnPlayer(PlayerKey)
end
end
-- 根据工程的修改而改变的开始执行逻辑 ----------------------------------------------------------------------------------------------------
return EventAction_RoundBegin