165 lines
6.6 KiB
Lua
165 lines
6.6 KiB
Lua
|
local EventAction_CountdownMode = {
|
|||
|
GameTime = 0;
|
|||
|
GameEndEvent = -1;
|
|||
|
}
|
|||
|
|
|||
|
-- 触发器激活时,将执行Action的Execute
|
|||
|
function EventAction_CountdownMode:Execute(...)
|
|||
|
if not UGCGameSystem.IsServer() then return end
|
|||
|
self.bEnableActionTick = true
|
|||
|
-- 设置当前游戏模式
|
|||
|
UGCGameSystem.GameState:SetGameStateType(CustomEnum.EGameState.Playing)
|
|||
|
|
|||
|
-- 显示战斗界面UI
|
|||
|
UGCGameSystem.GameState:ShowSimplePlayModeUI(WidgetConfig.EUIType.FightPanel)
|
|||
|
if GlobalConfigs.GameSetting.CanRespawnSelectWeapon then
|
|||
|
-- 显示武器选择界面
|
|||
|
local AllPlayerKey = UGCSystemLibrary.GetAllPlayerKeys()
|
|||
|
for i, PlayerKey in pairs(AllPlayerKey) do
|
|||
|
UGCGameSystem.GameState:ShowPlayerSelectWeaponWidget(PlayerKey)
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
-- 重置玩家积分信息
|
|||
|
PlayerScoreSystem.ResetAllPlayerScoreData()
|
|||
|
-- 重置和平默认的击杀数
|
|||
|
UGCSystemLibrary.ResetAllPlayerKillsAndAssists()
|
|||
|
-- 重置队伍得分
|
|||
|
UGCGameSystem.GameState:ResetTeamScore()
|
|||
|
|
|||
|
|
|||
|
|
|||
|
-- 绑定游戏结束事件
|
|||
|
UGCEventSystem.AddListener(EventEnum.GameStateChange, self.GameFinish, self)
|
|||
|
|
|||
|
-- 初始化游戏时间
|
|||
|
self.GameStartTime = UGCSystemLibrary.GatRealTimeSeconds()
|
|||
|
UGCGameSystem.GameState:SetGameTime(self.GameTime)
|
|||
|
|
|||
|
|
|||
|
-- 其他额外逻辑
|
|||
|
self:ExecuteOtherLogic()
|
|||
|
|
|||
|
-- 重置所有玩家
|
|||
|
UGCGameSystem.SendModeCustomEvent("ResetAllPlayers")
|
|||
|
|
|||
|
UGCLogSystem.Log("[EventAction_CountdownMode_Execute] Finish")
|
|||
|
return true
|
|||
|
end
|
|||
|
|
|||
|
function EventAction_CountdownMode:GameFinish(GameStateType)
|
|||
|
UGCLogSystem.Log("[EventAction_CountdownMode_GameFinish]")
|
|||
|
if GameStateType == CustomEnum.EGameState.End then
|
|||
|
-- 其他额外逻辑
|
|||
|
self:GameFinishOtherLogic()
|
|||
|
|
|||
|
self.bEnableActionTick = false
|
|||
|
if self.GameEndEvent then
|
|||
|
-- 发送游戏结束事件
|
|||
|
UGCEventSystem.SendEvent(self.GameEndEvent)
|
|||
|
else
|
|||
|
UGCLogSystem.Log("[EventAction_CountdownMode_GameFinish] GameEndEvent is nil")
|
|||
|
end
|
|||
|
UGCEventSystem.RemoveListener(EventEnum.GameStateChange, self.GameFinish, self)
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
function EventAction_CountdownMode:Update(DeltaSeconds)
|
|||
|
local NowRealTime = UGCSystemLibrary.GatRealTimeSeconds()
|
|||
|
local RemainTime = self.GameTime - (NowRealTime - self.GameStartTime);
|
|||
|
|
|||
|
-- 更新游戏时间
|
|||
|
if self.LastRemainTime ~= RemainTime then
|
|||
|
-- 判断游戏时间是否已结束
|
|||
|
if RemainTime <= 0 then
|
|||
|
self.LastRemainTime = 0
|
|||
|
UGCGameSystem.GameState:GameFinish()
|
|||
|
else
|
|||
|
self.LastRemainTime = RemainTime
|
|||
|
end
|
|||
|
UGCGameSystem.GameState:SetGameTime(self.LastRemainTime)
|
|||
|
end
|
|||
|
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
-- 其他逻辑 根据工程改变而修改------------------------------------------------------------
|
|||
|
function EventAction_CountdownMode:ExecuteOtherLogic()
|
|||
|
-- 绑定到检查点函数
|
|||
|
UGCEventSystem.AddListener(EventEnum.OverlapCheckPoint, self.OverlapCheckPoint, self)
|
|||
|
local AllPC = UGCGameSystem.GetAllPlayerController()
|
|||
|
for i, v in pairs(AllPC) do
|
|||
|
v:SetStartPointType(EPlayerStartType.Default)
|
|||
|
v:ClearPlayerSpawnBuffs()
|
|||
|
end
|
|||
|
-- 销毁初始阻挡墙
|
|||
|
local BlockWallPath = UGCGameSystem.GetUGCResourcesFullPath('Asset/Blueprint/ParkourActor/BlockWall/BP_WaitingBlockWall.BP_WaitingBlockWall_C')
|
|||
|
local AllWaitingWalls = GameplayStatics.GetAllActorsOfClass(UGCGameSystem.GameState, UE.LoadClass(BlockWallPath), {})
|
|||
|
for i, v in pairs(AllWaitingWalls) do
|
|||
|
v:K2_DestroyActor()
|
|||
|
end
|
|||
|
-- 重置检查点
|
|||
|
local CheckPointsPath = UGCGameSystem.GetUGCResourcesFullPath('Asset/Blueprint/ParkourActor/BP_CheckPoints.BP_CheckPoints_C')
|
|||
|
local AllCheckPointsPath = GameplayStatics.GetAllActorsOfClass(UGCGameSystem.GameState, UE.LoadClass(CheckPointsPath), {})
|
|||
|
for i, v in pairs(AllCheckPointsPath) do
|
|||
|
v:ResetCheckPoint()
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
function EventAction_CountdownMode:GameFinishOtherLogic()
|
|||
|
-- 移除绑定到检查点函数
|
|||
|
UGCEventSystem.RemoveListener(EventEnum.OverlapCheckPoint, self.OverlapCheckPoint, self)
|
|||
|
end
|
|||
|
|
|||
|
function EventAction_CountdownMode:OverlapCheckPoint(PlayerKey, PointIndex, IsDestination)
|
|||
|
local PC = UGCGameSystem.GetPlayerControllerByPlayerKey(PlayerKey)
|
|||
|
UGCLogSystem.Log("[EventAction_CountdownMode_OverlapCheckPoint] PointIndex:%s", tostring(PointIndex))
|
|||
|
if PC then
|
|||
|
local Level = PlayerScoreSystem.GetPlayerScoreDataFromType(PlayerKey, PlayerScoreSystem.Config.EScoreType.Level)
|
|||
|
-- 刷新出生点
|
|||
|
if Level < PointIndex then
|
|||
|
PC:SetStartPointType(PointIndex)
|
|||
|
PlayerScoreSystem.SetPlayerScoreDataFromType(PlayerKey, PlayerScoreSystem.Config.EScoreType.Level, PointIndex)
|
|||
|
PlayerScoreSystem.SetPlayerScoreDataFromType(PlayerKey, PlayerScoreSystem.Config.EScoreType.Remainder, GlobalConfigs.GameSetting.GameTime - UGCGameSystem.GameState:GetGameTime());
|
|||
|
UGCLogSystem.Log("[EventAction_CountdownMode_OverlapCheckPoint] Finish")
|
|||
|
for i = Level + 1, PointIndex do
|
|||
|
if GameObjectConfig.LevelBuff[i] then
|
|||
|
for _, BuffAssetType in pairs(GameObjectConfig.LevelBuff[i]) do
|
|||
|
PC:AddPlayerSpawnBuff(BuffAssetType)
|
|||
|
UGCLogSystem.Log("[EventAction_CountdownMode_OverlapCheckPoint] BuffAssetType:%s", tostring(BuffAssetType))
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
if IsDestination then
|
|||
|
-- 玩家完成了比赛
|
|||
|
UGCLogSystem.Log("[EventAction_CountdownMode_OverlapCheckPoint] PlayerKey:%s 完成了比赛", tostring(PlayerKey))
|
|||
|
-- 纪录得分
|
|||
|
local IsNewRecord = false
|
|||
|
local PlayerScore = PlayerScoreSystem.GetPlayerScore(PlayerKey)
|
|||
|
local PlayerScoreData = ArchiveDataConfig.GetPlayerArchiveDataFromType(PlayerKey, ArchiveDataConfig.EArchiveType.ScoreData)
|
|||
|
if PlayerScoreData then
|
|||
|
local RecordScore = PlayerScoreData.Score
|
|||
|
if RecordScore < PlayerScore then
|
|||
|
IsNewRecord = true
|
|||
|
end
|
|||
|
else
|
|||
|
IsNewRecord = true
|
|||
|
end
|
|||
|
-- 存档
|
|||
|
ArchiveDataConfig.SavePlayerArchiveData(PlayerKey, ArchiveDataConfig.EArchiveType.ScoreData, {Level = Level, Time = UGCGameSystem.GameState:GetGameTime(), Score = PlayerScore})
|
|||
|
-- 显结算界面
|
|||
|
UGCSendRPCSystem.ClientShowUI(PlayerKey, WidgetConfig.EUIType.Settlement,true, false, IsNewRecord, IsDestination)
|
|||
|
-- 发送玩家结束协议
|
|||
|
UGCGameSystem.SendPlayerSettlement(PlayerKey);
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
return EventAction_CountdownMode
|