2025-01-04 23:00:19 +08:00
---@class UGCGameState_C:BP_UGCGameState_C
--Edit Below--
---@type UGCGameState_C
UGCGameSystem.UGCRequire ( ' Script.Global.Global ' )
UGCGameSystem.UGCRequire ( ' Script.Common.ue_enum_custom ' )
local UGCGameState = {
WaitPlayerJoinTime = 0 ;
GameStateType = CustomEnum.EGameState . Waiting ;
GameTime = 0 ; -- 游戏倒计时时间
PlayerPersonalInfos = { } ; -- 玩家信息{PlayerKey = {UID, PlayerKey, TeamID, IsOffline, PlayerName, Gender, IconURL, AchievementScore, IsSelectTeam}, ...}
PlayerScoreDatas = { } ; -- 玩家得分信息{[PlayerKey] = {Kills = int32, Assists = int32, Score = int32}...}
TeamScore = { } ; -- 队伍得分{[TeamID] = Score}
PlayerJoinNum = 0 ; -- 玩家加入的数量作为个人TeamID
AllAlivePlayers = { } ; -- 存活的玩家 PlayerKeys
MapKey = - 1 ; -- 选择出的地图的索引
SyncPlayModeUIInfo = { } ; -- 同步游玩模式显示的UI
-- Round
RoundCount = 0 ; -- 当前回合
WiningTeam = - 1 ; -- 当前获胜队伍
-- 武器配置选择
PlayerWeaponCombination = { } ; -- 玩家可选的武器组合索引
PlayerSelectedWeaponIndex = { } ; -- 玩家选择的武器配置索引
PlayerAutoSelectWeaponHandle = { } ; -- 自动选择武器索引
-- 呼吸回血的玩家
RespiratoryRegurgitationPlayers = { } ;
} ;
function UGCGameState : GetReplicatedProperties ( )
return
" GameTime " ,
" PlayerPersonalInfos " ,
" WaitPlayerJoinTime " ,
" GameStateType " ,
" PlayerScoreDatas " ,
" TeamScore " ,
" AllAlivePlayers " ,
" MapKey " ,
" SyncPlayModeUIInfo " ,
" RoundCount " ,
" WiningTeam " ,
" PlayerWeaponCombination " ,
" PlayerSelectedWeaponIndex " ,
BuffManager.GetReplicatedProperties ( ) ,
ArchiveDataConfig.GetAllReplicatedPropertiesName ( )
end
-------------------------------------------------------- OnRep --------------------------------------------------------
function UGCGameState : OnRep_PlayerScoreDatas ( )
PlayerScoreSystem.SetPlayerScoreDatas ( self.PlayerScoreDatas )
UGCEventSystem.SendEvent ( EventEnum.UpdatePlayerScoreData )
end
function UGCGameState : OnRep_PlayerPersonalInfos ( )
UGCEventSystem.SendEvent ( EventEnum.UpdatePlayerScoreData )
UGCEventSystem.SendEvent ( EventEnum.UpdatePlayerInfo )
-- 更新加入队伍聊天房间
local PC = UGCSystemLibrary.GetLocalPlayerController ( )
if PC then
PC : UpdateTeamVoiceRoom ( )
end
end
function UGCGameState : OnRep_GameStateType ( )
if self : HasAuthority ( ) then return end
UGCEventSystem.SendEvent ( EventEnum.GameStateChange , self.GameStateType )
end
function UGCGameState : OnRep_AllAlivePlayers ( )
UGCEventSystem.SendEvent ( EventEnum.PlayerIsAliveIsChange )
end
function UGCGameState : OnRep_RoundCount ( )
UGCEventSystem.SendEvent ( EventEnum.NewRound , self.RoundCount )
end
function UGCGameState : OnRep_SyncPlayModeUIInfo ( )
for _ , UIType in pairs ( WidgetConfig.SyncShowPlayModeWidget ) do
local Params = self.SyncPlayModeUIInfo [ UIType ]
if Params == nil then
WidgetManager : ClosePanel ( UIType )
end
end
for UIType , Params in pairs ( self.SyncPlayModeUIInfo ) do
WidgetManager : ShowPanel ( UIType , false , table.unpack ( Params ) )
end
end
function UGCGameState : OnRep_PlayerWeaponCombination ( )
UGCEventSystem.SendEvent ( EventEnum.PlayerWeaponCombinationUpdate , self.PlayerWeaponCombination )
end
function UGCGameState : OnRep_PlayerSelectedWeaponIndex ( )
UGCEventSystem.SendEvent ( EventEnum.PlayerSelectedWeaponIndexUpdate , self.PlayerSelectedWeaponIndex )
end
function UGCGameState : OnRep_TeamScore ( )
UGCEventSystem.SendEvent ( EventEnum.UpdateTeamScore , self.TeamScore )
end
function UGCGameState : OnRep_MapKey ( )
UGCEventSystem.SendEvent ( EventEnum.UpdateMapKey , self.MapKey )
self : LoadNowMiniMap ( )
end
------------------------------------------------------ OnRep End ------------------------------------------------------
function UGCGameState : ReceiveBeginPlay ( )
UGCLogSystem.Log ( " [UGCGameState_ReceiveBeginPlay] " )
--屏蔽死亡盒子
-- self.IsShowDeadBox = false;
-- 显示飘字
self.bIsShowHitValue = true ;
-- 注册存档API
ArchiveDataConfig.Register ( self )
-- 注册BuffSystem
BuffManager.InitRegister ( self )
-- 注册粒子特效
ParticleConfig.Init ( self )
-- 初始化全局逻辑
GlobalInit.Init ( )
self : AddBind ( )
-- 开启滑铲State部分
self.bIsOpenShovelingAbility = false
-- 注册排行信息
PlayerScoreSystem.RegisterInfo ( PlayerScoreSystem.Config . ScoreList )
-- 初始化RPC系统
UGCSendRPCSystem.InitUGCSendRPCSystem ( self , " UGCSendRPCSystemFunc " )
if UGCGameSystem.IsServer ( ) then
-- 绑定更新积分的函数
PlayerScoreSystem.BindChangeScoreDataCallBack ( self.UpdateAllPlayerScoreDatas , self )
else
self : OnRep_SyncPlayModeUIInfo ( )
end
UGCLogSystem.Log ( " [UGCGameState_ReceiveBeginPlay] Finish " )
end
--function UGCGameState:ReceiveTick(DeltaTime)
--end
function UGCGameState : ReceiveEndPlay ( )
self : RemoveBind ( )
end
function UGCGameState : AddBind ( )
UGCCommoditySystem.BuyUGCCommodityResultDelegate : Add ( self.OnBuyUGCCommodityResult , self )
if self : HasAuthority ( ) then
UGCEventSystem.AddListener ( EventEnum.PlayerLogin , self.PlayerLogin , self )
UGCEventSystem.AddListener ( EventEnum.PlayerExit , self.PlayerExit , self )
else
end
end
function UGCGameState : RemoveBind ( )
UGCCommoditySystem.BuyUGCCommodityResultDelegate : Remove ( self.OnBuyUGCCommodityResult , self )
if self : HasAuthority ( ) then
UGCEventSystem.RemoveListener ( EventEnum.PlayerLogin , self.PlayerLogin , self )
UGCEventSystem.RemoveListener ( EventEnum.PlayerExit , self.PlayerExit , self )
else
end
end
function UGCGameState : PlayerLogin ( PlayerPawn , PlayerKey )
UGCLogSystem.Log ( " [UGCGameState_PlayerLogin] PlayerKey:%s " , tostring ( PlayerKey ) )
2025-01-07 21:25:05 +08:00
-- 第一次进入则处理
if self : PlayerIsFirstLogin ( PlayerKey ) then
-- 更新玩家队伍设置
self : UpdatePlayerTeam ( PlayerKey )
-- 获取玩家信息
self : GetUserInfo ( PlayerKey )
-- 注册玩家得分信息
PlayerScoreSystem.InitPlayerScoreData ( PlayerKey )
-- 增加玩家游玩次数
self : AddPlayerNumberOfPlays ( PlayerKey )
end
2025-01-04 23:00:19 +08:00
--UGCEventSystem.SetTimer(self, function()
-- UGCLogSystem.Log("[UGCGameState_PlayerLogin] --PlayerKey:%s", tostring(PlayerKey))
-- self:AddPlayerNumberOfPlays(PlayerKey) end, 15)
UGCLogSystem.Log ( " [UGCGameState_PlayerLogin] Finish " )
end
function UGCGameState : PlayerExit ( PlayerPawn , PlayerKey )
if GlobalConfigs.GameSetting . EnablePlayerJoin then
PlayerScoreSystem.RemovePlayerScoreInfo ( PlayerKey )
end
end
2025-01-07 21:25:05 +08:00
function UGCGameState : PlayerIsFirstLogin ( PlayerKey )
return ( self.PlayerPersonalInfos [ PlayerKey ] == nil )
end
2025-01-04 23:00:19 +08:00
--- 玩家登录获取玩家数据
---@param PlayerKey uint
function UGCGameState : GetUserInfo ( PlayerKey )
if self.PlayerPersonalInfos [ PlayerKey ] then return self.PlayerPersonalInfos [ PlayerKey ] end
local UserInfo = UGCPlayerStateSystem.GetPlayerAccountInfo ( PlayerKey )
local PS = UGCGameSystem.GetPlayerStateByPlayerKey ( PlayerKey ) ;
if UserInfo then
--- UID, PlayerName, TeamID, Gender, PlatformGender, PlayerLevel, SegmentLevel, IconURL
local UserInfoCpy = UserInfo : Copy ( )
UGCLogSystem.Log ( " [UGCGameState_GetUserInfo] PlayerName:%s " , UserInfoCpy.PlayerName )
self.PlayerPersonalInfos [ PlayerKey ] = table.DeepCopy ( UE.ToTable ( UserInfo ) )
UGCLogSystem.LogTree ( " [UGCGameState_GetUserInfo] UserInfo: " , self.PlayerPersonalInfos [ PlayerKey ] )
if PS and UE.IsValid ( PS ) then
self.PlayerPersonalInfos [ PlayerKey ] . AvatarBoxId = PS.AvatarBoxId
else
self.PlayerPersonalInfos [ PlayerKey ] . AvatarBoxId = 0
end
UGCLogSystem.LogTree ( " [UGCGameState_GetUserInfo] UserInfo: " , self.PlayerPersonalInfos [ PlayerKey ] )
return self.PlayerPersonalInfos [ PlayerKey ]
else
UGCLogSystem.LogError ( " [UGCGameState_GetUserInfo] UserInfo Error PlayerKey:%s " , tostring ( PlayerKey ) )
end
end
-------------------------------------------------- ArchiveData --------------------------------------------------
function UGCGameState : GetArchiveDataByType ( PlayerKey , ArchiveType )
local UID = self : GetPlayerUIDByPlayerKey ( PlayerKey )
if UID then
local ArchiveData = UGCPlayerStateSystem.GetPlayerArchiveData ( UID )
if ArchiveData then
UGCLogSystem.Log ( " [UGCGameState_GetArchiveDataByType] Succeed " )
return ArchiveData [ ArchiveType ]
end
end
return nil
end
function UGCGameState : SavePlayerArchiveData ( PlayerKey , ArchiveType , Data )
local UID = self : GetPlayerUIDByPlayerKey ( PlayerKey )
if UID then
local ArchiveData = UGCPlayerStateSystem.GetPlayerArchiveData ( UID )
if ArchiveData == nil then
ArchiveData = { }
end
ArchiveData [ ArchiveType ] = Data
UGCPlayerStateSystem.SavePlayerArchiveData ( UID , ArchiveData )
return true
end
return false
end
------------------------------------------------ ArchiveData End ------------------------------------------------
-- 存档 ---------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------- NumberOfPlays -------------------------------------------------
--- 增加玩家游玩次数
function UGCGameState : AddPlayerNumberOfPlays ( PlayerKey )
local NumberOfPlays = self : GetArchiveDataByType ( PlayerKey , ArchiveDataConfig.EArchiveType . NumberOfPlays )
if NumberOfPlays then
self : SavePlayerArchiveData ( PlayerKey , ArchiveDataConfig.EArchiveType . NumberOfPlays , NumberOfPlays + 1 )
else
self : SavePlayerArchiveData ( PlayerKey , ArchiveDataConfig.EArchiveType . NumberOfPlays , 1 )
end
end
--- 获取玩家游玩次数
function UGCGameState : GetPlayerNumberOfPlays ( PlayerKey )
return ArchiveDataConfig.GetPlayerArchiveDataFromType ( PlayerKey , ArchiveDataConfig.EArchiveType . NumberOfPlay )
end
----------------------------------------------- NumberOfPlays End -----------------------------------------------
-- 存档 End -----------------------------------------------------------------------------------------------------------------------------------------------
-- Team Score Data ----------------------------------------------------------------------------------------
--- 更新返回所有玩家得分
function UGCGameState : UpdateAllPlayerScoreDatas ( )
self.PlayerScoreDatas = PlayerScoreSystem.GetPlayerScoreDatas ( )
UGCLogSystem.LogTree ( " [UGCGameState_UpdateAllPlayerScoreDatas] " , self.PlayerScoreDatas )
end
--- 获取队伍得分
function UGCGameState : GetTeamScore ( TeamID )
return ( self.TeamScore [ TeamID ] and self.TeamScore [ TeamID ] or 0 )
end
--- 获取最高的队伍得分
function UGCGameState : GetMaxTeamScore ( )
local Res = 0
for i , v in pairs ( self.TeamScore ) do
Res = math.max ( Res , v )
end
return Res
end
--- 重置队伍得分
function UGCGameState : ResetTeamScore ( )
self.TeamScore = { }
end
--- 增加队伍得分
function UGCGameState : AddTeamScore ( TeamID , Score )
self.TeamScore [ TeamID ] = self : GetTeamScore ( TeamID ) + Score
UGCEventSystem.SendEvent ( EventEnum.UpdateTeamScore )
end
--- 新回合
function UGCGameState : AddNewRound ( )
self : ResetRoundInfo ( )
self.RoundCount = self.RoundCount + 1
end
function UGCGameState : IsFinishRound ( )
return self.RoundCount >= GlobalConfigs.GameSetting . MaxRound
end
--- 重置回合信息
function UGCGameState : ResetRoundInfo ( )
self.WinningTeam = - 1
end
--- 获取当前回合数
function UGCGameState : GetRoundCount ( )
return self.RoundCount
end
--- 设置获胜方
function UGCGameState : SetWinningTeam ( TeamID )
if self.WinningTeam > 0 then
return
end
self.WinningTeam = TeamID
self : AddTeamScore ( TeamID , 1 )
end
--- 获取当前获胜方
function UGCGameState : GetWinningTeam ( )
return self.WinningTeam
end
--- 获取队伍中的玩家
function UGCGameState : GetTeamPlayer ( TeamID )
local Res = { }
for PlayerKey , PlayerInfo in pairs ( self.PlayerPersonalInfos ) do
if PlayerInfo.TeamID == TeamID then
Res [ # Res + 1 ] = PlayerKey
end
end
return Res
end
-- Team Score Data End ------------------------------------------------------------------------------------
--- 获取当前游戏状态
function UGCGameState : GetGameStateType ( )
return self.GameStateType
end
--- 设置当前游戏状态
function UGCGameState : SetGameStateType ( NewGameStateType )
if not self : HasAuthority ( ) then return end
if self.GameStateType ~= NewGameStateType then
self.GameStateType = NewGameStateType
UGCEventSystem.SendEvent ( EventEnum.GameStateChange , self.GameStateType )
end
end
--- 设置游戏结束
function UGCGameState : GameFinish ( )
self : SetGameStateType ( CustomEnum.EGameState . End )
end
--- 获取一个新的队伍ID 个人战使用
function UGCGameState : GetNewTeamID ( )
-- body
self.PlayerJoinNum = self.PlayerJoinNum + 1
return self.PlayerJoinNum
end
UGCGameState.IsPreparationTime = false
function UGCGameState : SetIsPreparationTime ( InIsPreparationTime )
self.IsPreparationTime = InIsPreparationTime
end
function UGCGameState : GetIsPreparationTime ( )
return self.IsPreparationTime
end
------------------------------------------------------------------ 获取玩家信息 ------------------------------------------------------------------
function UGCGameState : GetPlayerNameByPlayerKey ( PlayerKey )
if self.PlayerPersonalInfos [ PlayerKey ] then
return self.PlayerPersonalInfos [ PlayerKey ] . PlayerName
else
return " "
end
end
function UGCGameState : GetPlayerTeamIDByPlayerKey ( PlayerKey )
if self.PlayerPersonalInfos [ PlayerKey ] then
return self.PlayerPersonalInfos [ PlayerKey ] . TeamID
else
return - 1
end
end
function UGCGameState : GetHeadIconByPlayerKey ( PlayerKey )
if self.PlayerPersonalInfos [ PlayerKey ] then
return self.PlayerPersonalInfos [ PlayerKey ] . IconURL
else
return " "
end
end
function UGCGameState : GetPlayerUIDByPlayerKey ( PlayerKey )
return self.PlayerPersonalInfos [ PlayerKey ] . UID
end
function UGCGameState : GetPlayerHeadInfo ( PlayerKey )
local PlayerInfo = self.PlayerPersonalInfos [ PlayerKey ]
--- return {UID:string, IconURL:string, Gender:int, AvatarBoxId:int, PlayerLevel:int, PlayerName:string} 其中AvatarBoxId可以从PlayerState中获取
local Res = {
UIDString = " " ,
IconURL = " " ,
Gender = 1 ,
AvatarBoxId = 0 ,
PlayerLevel = 1 ,
PlayerName = " Null " ,
}
if PlayerInfo then
Res.UIDString = tostring ( PlayerInfo.UID )
Res.IconURL = PlayerInfo.IconURL
Res.Gender = PlayerInfo.Gender
Res.AvatarBoxId = PlayerInfo.AvatarBoxId
Res.PlayerLevel = PlayerInfo.PlayerLevel
Res.PlayerName = PlayerInfo.PlayerName
end
return Res
end
---------------------------------------------------------------- 获取玩家信息 End ----------------------------------------------------------------
function UGCGameState : GetGameTime ( )
return self.GameTime
end
function UGCGameState : SetGameTime ( NewTime )
if UGCGameSystem.IsServer ( ) then
self.GameTime = NewTime
else
UGCLogSystem.LogError ( " [UGCGameState_SetGameTime] 客户端无法设置游戏时间 " )
end
end
function UGCGameState : SetPlayerIsAlive ( PlayerKey , Pawn )
if Pawn then
self.AllAlivePlayers [ PlayerKey ] = 1
else
self.AllAlivePlayers [ PlayerKey ] = nil
end
end
function UGCGameState : GetPlayerIsAlive ( PlayerKey )
if self.AllAlivePlayers [ PlayerKey ] then
return true
end
return false
end
--- 获取队伍存活的玩家数
function UGCGameState : GetTeamAlivePlayerCount ( TeamID )
local Count = 0
local Players = self : GetTeamPlayer ( TeamID )
UGCLogSystem.LogTree ( " [UGCGameState_GetTeamAlivePlayerCount] Players " , Players )
UGCLogSystem.LogTree ( " [UGCGameState_GetTeamAlivePlayerCount] AllAlivePlayers: " , self.AllAlivePlayers )
for i , v in pairs ( Players ) do
if self : GetPlayerIsAlive ( v ) then
Count = Count + 1
end
end
UGCLogSystem.Log ( " [UGCGameState_GetTeamAlivePlayerCount] Count:%s " , tostring ( Count ) )
return Count
end
--------------------------------------------- SyncUIInfo ---------------------------------------------
-- PlayMode -------------------------------------------------------------------------------------------
function UGCGameState : ShowSimplePlayModeUI ( UIType , Params )
if Params == nil then Params = { } end
self.SyncPlayModeUIInfo = { }
self.SyncPlayModeUIInfo [ UIType ] = Params
end
function UGCGameState : AddPlayModeUI ( UIType , Params )
if table.hasValue ( WidgetConfig.SyncShowPlayModeWidget , UIType ) then
if Params == nil then Params = { } end
self.SyncPlayModeUIInfo [ UIType ] = Params
end
end
function UGCGameState : RemovePlayModeUI ( UIType )
self.SyncPlayModeUIInfo [ UIType ] = nil
end
-- PlayMode End ---------------------------------------------------------------------------------------
--------------------------------------------- SyncUIInfo End ---------------------------------------------
-- PlayerWeaponCombination ---------------------------------------------------------------------------------------------------------------
function UGCGameState : SetPlayerWeaponCombination ( PlayerKey , WeaponCombinationType )
self.PlayerWeaponCombination [ PlayerKey ] = WeaponCombinationType
self : ResetPlayerSelectWeaponIndex ( PlayerKey )
end
function UGCGameState : GetPlayerWeaponCombination ( PlayerKey )
if self.PlayerWeaponCombination [ PlayerKey ] then
return self.PlayerWeaponCombination [ PlayerKey ]
else
return 1
end
end
--- 重置玩家选择的武器配置索引
function UGCGameState : ResetPlayerSelectWeaponIndex ( PlayerKey )
self.PlayerSelectedWeaponIndex [ PlayerKey ] = 1
end
--- 重置所有玩家的武器配置索引
function UGCGameState : ResetAllPlayerSelectWeaponIndex ( )
self.PlayerSelectedWeaponIndex = { }
end
--- 设置玩家选择的武器配置索引
function UGCGameState : PlayerSelectWeaponIndex ( PlayerKey , WeaponCombinationIndex )
self.PlayerSelectedWeaponIndex [ PlayerKey ] = WeaponCombinationIndex
self : UpdatePlayerWeapon ( PlayerKey )
if self.PlayerAutoSelectWeaponHandle [ PlayerKey ] then
UGCEventSystem.StopTimer ( self.PlayerAutoSelectWeaponHandle [ PlayerKey ] )
self.PlayerAutoSelectWeaponHandle [ PlayerKey ] = nil
end
end
--- 校验玩家选择的武器配置索引
function UGCGameState : CheckPlayerSelectWeaponIndex ( PlayerKey )
local SelectedWeaponIndex = self : GetPlayerSelectedWeaponIndex ( PlayerKey )
if SelectedWeaponIndex then
local WeaponCombination = WeaponSelectionCombinationConfig.WeaponCombinationList [ self : GetPlayerWeaponCombination ( PlayerKey ) ]
if WeaponCombination then
if WeaponCombination.Weapon [ SelectedWeaponIndex ] then
return true
end
end
end
return false
end
--- 获取玩家选择的武器配置索引
function UGCGameState : GetPlayerSelectedWeaponIndex ( PlayerKey )
return self.PlayerSelectedWeaponIndex [ PlayerKey ]
end
--- 获取玩家选择的武器索引对应的武器及配件
function UGCGameState : GetPlayerSelectedWeaponAndParts ( PlayerKey )
local Res = { }
if not self : CheckPlayerSelectWeaponIndex ( PlayerKey ) then
self.PlayerSelectedWeaponIndex [ PlayerKey ] = 1
end
local PlayerWeaponCombination = self : GetPlayerWeaponCombination ( PlayerKey )
local PlayerSelectedWeaponIndex = self : GetPlayerSelectedWeaponIndex ( PlayerKey )
local WeaponCombination = WeaponSelectionCombinationConfig.WeaponCombinationList [ PlayerWeaponCombination ]
local SavedWeaponComb = ArchiveDataConfig.GetPlayerArchiveDataFromType ( PlayerKey , ArchiveDataConfig.EArchiveType . WeaponCombs )
local PlayerCustomWeaponParts = ArchiveDataConfig.GetPlayerArchiveDataFromType ( PlayerKey , ArchiveDataConfig.EArchiveType . CustomWeaponParts )
local Weapons
-- 判断是否有保存的武器组合
if SavedWeaponComb and SavedWeaponComb [ PlayerWeaponCombination ] and SavedWeaponComb [ PlayerWeaponCombination ] [ PlayerSelectedWeaponIndex ] then
Weapons = SavedWeaponComb [ PlayerWeaponCombination ] [ PlayerSelectedWeaponIndex ]
elseif WeaponCombination then
Weapons = WeaponCombination.Weapon [ PlayerSelectedWeaponIndex ]
end
if Weapons then
UGCLogSystem.LogTree ( " [UGCGameState_GetPlayerSelectedWeaponAndParts] Weapons: " , Weapons )
for i , WeaponID in pairs ( Weapons ) do
if Res [ WeaponID ] == nil then
Res [ WeaponID ] = 1
else
Res [ WeaponID ] = Res [ WeaponID ] + 1
end
local Parts = MyWeaponSystem.GetWeaponBastParts ( WeaponID )
if PlayerCustomWeaponParts and PlayerCustomWeaponParts [ WeaponID ] then
Parts = PlayerCustomWeaponParts [ WeaponID ]
end
for _ , PartID in pairs ( Parts ) do
if Res [ PartID ] then
Res [ PartID ] = 1 + Res [ PartID ]
else
Res [ PartID ] = 1
end
end
end
end
return Res
end
--- 获取玩家选择的武器Item表
function UGCGameState : GetPlayerSelectedWeaponItemInfo ( PlayerKey )
local Res = { }
if not self : CheckPlayerSelectWeaponIndex ( PlayerKey ) then
self.PlayerSelectedWeaponIndex [ PlayerKey ] = 1
end
local PlayerWeaponCombination = self : GetPlayerWeaponCombination ( PlayerKey )
local PlayerSelectedWeaponIndex = self : GetPlayerSelectedWeaponIndex ( PlayerKey )
local WeaponCombination = WeaponSelectionCombinationConfig.WeaponCombinationList [ PlayerWeaponCombination ]
local SavedWeaponComb = ArchiveDataConfig.GetPlayerArchiveDataFromType ( PlayerKey , ArchiveDataConfig.EArchiveType . WeaponCombs )
local Weapons
-- 判断是否有保存的武器组合
if SavedWeaponComb and SavedWeaponComb [ PlayerWeaponCombination ] and SavedWeaponComb [ PlayerWeaponCombination ] [ PlayerSelectedWeaponIndex ] then
Weapons = SavedWeaponComb [ PlayerWeaponCombination ] [ PlayerSelectedWeaponIndex ]
elseif WeaponCombination then
Weapons = WeaponCombination.Weapon [ PlayerSelectedWeaponIndex ]
end
if Weapons then
local PlayerCustomWeaponParts = ArchiveDataConfig.GetPlayerArchiveDataFromType ( PlayerKey , ArchiveDataConfig.EArchiveType . WeaponCombs )
for i , WeaponID in pairs ( Weapons ) do
local WeaponItemInfo = { }
WeaponItemInfo.ItemID = WeaponID
WeaponItemInfo.Count = 1
WeaponItemInfo.SubItemList = { }
local Parts = MyWeaponSystem.GetWeaponBastParts ( WeaponID )
if PlayerCustomWeaponParts and PlayerCustomWeaponParts [ WeaponID ] then
Parts = PlayerCustomWeaponParts [ WeaponID ]
end
for PartIndex , PartID in pairs ( Parts ) do
WeaponItemInfo.SubItemList [ PartIndex ] = { ItemID = PartID , Count = 1 }
end
Res [ # Res + 1 ] = WeaponItemInfo
end
end
return Res
end
--- 检测并给予玩家武器和配件
function UGCGameState : CheckWeaponAndParts ( InPlayerKey , IgnoreMagnifyingGlass )
if IgnoreMagnifyingGlass == nil then IgnoreMagnifyingGlass = true end
local TargetPawn = UGCGameSystem.GetPlayerPawnByPlayerKey ( InPlayerKey )
if TargetPawn == nil then return end
local WeaponAndParts = self : GetPlayerSelectedWeaponAndParts ( InPlayerKey )
UGCLogSystem.LogTree ( " [UGCGameState_CheckWeaponAndParts] " , WeaponAndParts )
---@return ItemDataList LuaTable @LuaTable<ItemData>, ItemData结构: ItemID,InstanceID,Count,Type,SubType,IsAvatar
local AllItems = UGCBackPackSystem.GetAllItemData ( TargetPawn )
local BackPackWeaponAndParts = { }
-- 验证玩家当前背包武器及配件是否需要销毁
for i , ItemInfo in pairs ( AllItems ) do
local ItemID = ItemInfo.ItemID
if ( ItemID < 108000 and ItemID > 100000 )
or ( ItemID >= 200000 and ItemID < 300000 ) then
if BackPackWeaponAndParts [ ItemInfo.ItemID ] == nil then
BackPackWeaponAndParts [ ItemInfo.ItemID ] = 1
else
BackPackWeaponAndParts [ ItemInfo.ItemID ] = BackPackWeaponAndParts [ ItemInfo.ItemID ] + 1
end
end
end
-- 验证玩家当前背包武器及配件是否需要销毁
for _ , ItemInfo in pairs ( AllItems ) do
local TypeID = UGCSystemLibrary.GetItemTypeID ( ItemInfo.ItemID )
if not IgnoreMagnifyingGlass or TypeID ~= 203 then
if ( ItemInfo.ItemID < 108000 and ItemInfo.ItemID > 100000 )
or ( TypeID >= 200 and TypeID < 300 )
then
local TargetItemCount = WeaponAndParts [ ItemInfo.ItemID ]
if TargetItemCount == nil then TargetItemCount = 0 end
if BackPackWeaponAndParts [ ItemInfo.ItemID ] > TargetItemCount then
--- 销毁背包中的物品
--UGCBackPackSystem.DropItem(TargetPawn, ItemInfo.ItemID, ItemInfo.Count - TargetItemCount, true)
for i = 1 , BackPackWeaponAndParts [ ItemInfo.ItemID ] - TargetItemCount do
UGCBackPackSystem.DropItem ( TargetPawn , ItemInfo.ItemID , 1 , true )
end
end
end
end
end
local bGiveWeapon = false
-- 添加武器及配件
for ItemID , TargetCount in pairs ( WeaponAndParts ) do
local Count = UGCBackPackSystem.GetItemCount ( TargetPawn , ItemID )
UGCLogSystem.Log ( " [UGCGameState_CheckWeaponAndParts] ItemID:%s, Count:%s " , tostring ( ItemID ) , tostring ( Count ) )
if TargetCount > Count then
--UGCBackPackSystem.AddItem(TargetPawn, ItemID, TargetCount - Count)
for i = 1 , TargetCount - Count do
UGCBackPackSystem.AddItem ( TargetPawn , ItemID , 1 )
end
local ItemTypeID = UGCSystemLibrary.GetItemTypeID ( ItemID )
if ItemTypeID > 100 and ItemTypeID < 200 then
bGiveWeapon = true
end
end
end
-- 补满弹夹
if bGiveWeapon then
UGCEventSystem.SetTimer ( TargetPawn , function ( )
for i , v in pairs ( ShootWeaponEnums ) do
local Weapon = UGCWeaponManagerSystem.GetWeaponBySlot ( TargetPawn , v )
if UE.IsValid ( Weapon ) then
UGCGunSystem.EnableClipInfiniteBullets ( Weapon , true )
local MaxBulletNumInOneClip = UGCGunSystem.GetMaxBulletNumInOneClip ( Weapon )
Weapon : SetCurrentBulletNumInClipOnServer ( MaxBulletNumInOneClip , true )
-- 玩家离开换弹状态
if UE.IsValid ( TargetPawn ) then
UGCPawnSystem.LeavePawnState ( TargetPawn , EPawnState.Roload )
end
end
end
end ,
1.
)
end
end
--- 更新玩家的武器装备
function UGCGameState : UpdatePlayerWeapon ( InPlayerKey )
local TargetPawn = UGCGameSystem.GetPlayerPawnByPlayerKey ( InPlayerKey )
if TargetPawn == nil then return end
local AllItems = UGCBackPackSystem.GetAllItemData ( TargetPawn )
-- 清除玩家武器
--for _, ItemInfo in pairs(AllItems) do
-- local TypeID = UGCSystemLibrary.GetItemTypeID(ItemInfo.ItemID)
-- if (ItemInfo.ItemID < 108000 and ItemInfo.ItemID > 100000)
-- or (TypeID >= 200 and TypeID < 300)
-- then
-- UGCBackPackSystem.DropItem(TargetPawn, ItemInfo.ItemID, ItemInfo.Count, true)
-- end
--end
local WeaponIDs = { }
for _ , ItemInfo in pairs ( AllItems ) do
if ( ItemInfo.ItemID < 108000 and ItemInfo.ItemID > 100000 ) then
WeaponIDs [ # WeaponIDs + 1 ] = ItemInfo.ItemID
end
end
2025-01-07 21:25:05 +08:00
local PlayerCustomWeaponParts = ArchiveDataConfig.GetPlayerArchiveDataFromType ( InPlayerKey , ArchiveDataConfig.EArchiveType . CustomWeaponParts )
2025-01-04 23:00:19 +08:00
for i , WeaponID in pairs ( WeaponIDs ) do
local Parts = MyWeaponSystem.GetWeaponBastParts ( WeaponID )
if PlayerCustomWeaponParts and PlayerCustomWeaponParts [ WeaponID ] then
Parts = PlayerCustomWeaponParts [ WeaponID ]
end
for _ , PartID in pairs ( Parts ) do
UGCBackPackSystem.DropItem ( TargetPawn , PartID , 1 , true )
end
UGCBackPackSystem.DropItem ( TargetPawn , WeaponID , 1 , true )
end
local WeaponItemInfo = self : GetPlayerSelectedWeaponItemInfo ( InPlayerKey )
UGCLogSystem.LogTree ( " [UGCGameState_UpdatePlayerWeapon] WeaponItemInfo: " , WeaponItemInfo )
self : PlayerAddItemInfo ( InPlayerKey , WeaponItemInfo )
end
---@param InItems {ItemID, Count, SubItemList:配件{{ItemID, Count}, ...}}
function UGCGameState : PlayerAddItemInfo ( InPlayerKey , InItems )
self : AddItem ( InPlayerKey , InItems )
UGCEventSystem.SetTimer ( self , function ( ) UGCSystemLibrary.PlayerFullBullet ( InPlayerKey ) end , 1. )
end
function UGCGameState : AddItem ( InPlayerKey , InItems )
local PC = UGCGameSystem.GetPlayerControllerByPlayerKey ( InPlayerKey )
local BackpackComponent = PC : GetBackpackComponent ( )
for _ , Item in pairs ( InItems ) do
if ItemUtils.IsUGCItem ( Item.ItemID ) == true then
local ItemDefineID = BackpackUtils.GenerateItemDefineIDByItemTableIDWithRandomInstanceID ( Item.ItemID )
local ItemInfo = CreateStruct ( " BattleItemPickupInfo " )
UGCLogSystem.Log ( " [UGCGameState_PlayerAddItemInfo] ItemID:%s, InstID:%s " , tostring ( Item.ItemID ) , tostring ( ItemDefineID.InstanceID ) )
ItemInfo.Count = Item.Count
ItemInfo.bAutoEquip = ( 2 == ItemDefineID.Type ) or ( 8 == ItemDefineID.Type )
BackpackComponent : RegisterItemGenerated ( ItemDefineID.TypeSpecificID , ItemInfo.Count , ItemDefineID.InstanceID )
BackpackComponent : PickupItem ( ItemDefineID , ItemInfo , EBattleItemPickupReason.Initial )
-- BackpackComponent:PickupInitialItem(ItemDefineID, ItemInfo, true)
local BattleItemUseTarget =
{
TargetDefineID = ItemDefineID ,
-- TargetAssociationName = "",
FilterTargetWhenPickup = true ,
}
for _ , SubItem in ipairs ( Item.SubItemList or { } ) do
if ItemUtils.IsUGCItem ( SubItem.ItemID ) == true then
local SubItemDefineID = BackpackUtils.GenerateItemDefineIDByItemTableIDWithRandomInstanceID ( SubItem.ItemID )
local EquipPickupInfo = CreateStruct ( " BattleItemPickupInfo " )
EquipPickupInfo.Count = SubItem.Count
EquipPickupInfo.bAutoEquip = ( 2 == SubItemDefineID.Type ) or ( 8 == SubItemDefineID.Type )
EquipPickupInfo.AutoEquipTarget = BattleItemUseTarget
UGCLogSystem.Log ( " [UGCGameState_UpdatePlayerWeapon], SubItem.ItemID= " .. SubItem.ItemID .. " SubItem.Count= " .. SubItem.Count )
BackpackComponent : PickupInitialItem ( SubItemDefineID , EquipPickupInfo , true )
end
end
end
end
end
--- 显示玩家选择武器UI, 并延迟默认选择第一个
function UGCGameState : ShowPlayerSelectWeaponWidget ( PlayerKey )
UGCSendRPCSystem.ClientShowUI ( PlayerKey , WidgetConfig.EUIType . WeaponSelect )
if self.PlayerAutoSelectWeaponHandle [ PlayerKey ] then
UGCEventSystem.StopTimer ( self.PlayerAutoSelectWeaponHandle [ PlayerKey ] )
end
self.PlayerAutoSelectWeaponHandle [ PlayerKey ] = UGCEventSystem.SetTimer ( self , function ( )
self.PlayerAutoSelectWeaponHandle [ PlayerKey ] = nil
self : PlayerSelectWeaponIndex ( PlayerKey , 1 )
end , GlobalConfigs.GameSetting . WeaponSelectTime )
end
--- 获取当前默认配置项的其他配件(头甲等出生给予的配置)
function UGCGameState : GetPlayerBeBornParts ( InPlayerKey )
local WeaponCombinationList = WeaponSelectionCombinationConfig.WeaponCombinationList [ self : GetPlayerWeaponCombination ( InPlayerKey ) ]
if WeaponCombinationList then
return WeaponCombinationList.OtherParts
end
return { }
end
-- 玩家自定义武器组合
function UGCGameState : PlayerCustomWeapon ( PlayerKey , ProgrammeIndex , WeaponComb , PartsComb )
UGCLogSystem.Log ( " [UGCGameState_PlayerCustomWeapon] PlayerKey:%s, ProgrammeIndex:%s " , tostring ( PlayerKey ) , tostring ( ProgrammeIndex ) )
UGCLogSystem.LogTree ( " [UGCGameState_PlayerCustomWeapon] WeaponComb: " , WeaponComb )
UGCLogSystem.LogTree ( " [UGCGameState_PlayerCustomWeapon] PartsComb: " , PartsComb )
if ProgrammeIndex == nil or WeaponComb == nil then return end
local CustomWeaponList = { }
local PlayerWeaponCombination = self : GetPlayerWeaponCombination ( PlayerKey )
for i , v in pairs ( WeaponSelectionCombinationConfig.PlayerCustomWeapon [ PlayerWeaponCombination ] ) do
for _ , WeaponID in pairs ( v.WeaponIDs ) do
CustomWeaponList [ # CustomWeaponList + 1 ] = WeaponID
end
end
for i , v in pairs ( WeaponComb ) do
if not table.hasValue ( CustomWeaponList , v ) then
UGCLogSystem.LogError ( " [UGCGameState_PlayerCustomWeapon] 有错误的武器ID:%s " , tostring ( v ) )
return
end
end
local PlayerWeaponCombs = ArchiveDataConfig.GetPlayerArchiveDataFromType ( PlayerKey , ArchiveDataConfig.EArchiveType . WeaponCombs )
if PlayerWeaponCombs == nil then PlayerWeaponCombs = { } end
if PlayerWeaponCombs [ PlayerWeaponCombination ] == nil then PlayerWeaponCombs [ PlayerWeaponCombination ] = { } end
PlayerWeaponCombs [ PlayerWeaponCombination ] [ ProgrammeIndex ] = WeaponComb
ArchiveDataConfig.SavePlayerArchiveData ( PlayerKey , ArchiveDataConfig.EArchiveType . WeaponCombs , PlayerWeaponCombs )
local PlayerCustomWeaponParts = ArchiveDataConfig.GetPlayerArchiveDataFromType ( PlayerKey , ArchiveDataConfig.EArchiveType . WeaponCombs )
if PlayerCustomWeaponParts == nil then PlayerCustomWeaponParts = { } end
for i , WeaponID in pairs ( WeaponComb ) do
local CanSave = true
for _ , PartID in pairs ( PartsComb [ i ] ) do
if not MyWeaponSystem.PartIsWeaponCanBeUsed ( WeaponID , PartID ) then
CanSave = false
break
end
end
if CanSave then
PlayerCustomWeaponParts [ WeaponID ] = PartsComb [ i ]
UGCLogSystem.Log ( " [UGCGameState_PlayerCustomWeapon] Save CustomParts Succeed " )
else
UGCLogSystem.LogError ( " [UGCGameState_PlayerCustomWeapon] Save CustomParts Failure " )
end
end
ArchiveDataConfig.SavePlayerArchiveData ( PlayerKey , ArchiveDataConfig.EArchiveType . CustomWeaponParts , PlayerWeaponCombs )
self : PlayerSelectWeaponIndex ( PlayerKey , ProgrammeIndex )
UGCLogSystem.Log ( " [UGCGameState_PlayerCustomWeapon] Finish " )
end
-- PlayerWeaponCombination End -----------------------------------------------------------------------------------------------------------
-- 内购 -------------------------------------------------------------------------------------------------------------------------------------------------
--可以通过参数得知玩家物品的变化已经是否购买成功
function UGCGameState : OnBuyUGCCommodityResult ( bSucceeded , PlayerKey , CommodityID , Count , UID , ProductID )
local Result = string.format (
" ([UGCGameState_OnBuyUGCCommodityResult bSucceeded=%s PlayerKey=%s CommodityID=%s Count=%s) " ,
tostring ( bSucceeded ) ,
tostring ( PlayerKey ) ,
tostring ( CommodityID ) ,
tostring ( Count ) ,
tostring ( ProductID )
)
ugcprint ( Result )
local cond = UGCGameSystem.IsServer ( )
if cond then
if bSucceeded then
self : AddGoldBrick ( PlayerKey , Count )
UGCLogSystem.Log ( " [UGCGameState_OnBuyUGCCommodityResult] AddSucceed " )
end
local CommodityList = UGCCommoditySystem.GetAllPlayerUGCCommodityList ( )
local PlayerController = UGCGameSystem.GetPlayerControllerByPlayerKey ( PlayerKey )
ugcprint ( ToTreeString ( CommodityList [ PlayerController : GetInt64UID ( ) ] ) )
else
local CommodityList = UGCCommoditySystem.GetUGCCommodityList ( )
ugcprint ( ToTreeString ( CommodityList ) )
end
end
-- 内购 End ---------------------------------------------------------------------------------------------------------------------------------------------
-- Map ---------------------------------------------------------------------------------------------------------------------------------------------
function UGCGameState : SetMapKey ( InMapKey )
self.MapKey = InMapKey
end
function UGCGameState : GetMapKey ( )
return self.MapKey
end
function UGCGameState : LoadNowMiniMap ( )
UGCLogSystem.Log ( " [UGCGameState_LoadNowMiniMap] " )
if self : HasAuthority ( ) or self.MapKey == nil then
UGCLogSystem.LogError ( " [UGCGameState_LoadNowMiniMap] self.MapSelectionFinalResult is nil " )
return
end
local MiniMapInfo = MapConfig.MapInfo [ self.MapKey ] . MiniMapInfo
if MiniMapInfo.MapPath then
UGCLogSystem.LogTree ( " [UGCGameState_LoadNowMiniMap] " , MiniMapInfo )
UGCWidgetManagerSystem.ChangeMap ( MiniMapInfo.MapPath , MiniMapInfo.MapCentre , MiniMapInfo.MapSize , MiniMapInfo.MapScale )
UGCLogSystem.Log ( " [UGCGameState_LoadNowMiniMap] Finish " )
end
end
-- Map End -----------------------------------------------------------------------------------------------------------------------------------------
-- 呼吸回血 -----------------------------------------------------------------------------------------------------------------------------------------
--- 设置可呼吸回血的玩家
function UGCGameState : SetRespiratoryRegurgitationPlayers ( InPlayers )
self.RespiratoryRegurgitationPlayers = InPlayers
end
--- 获取可呼吸回血的玩家
function UGCGameState : GetRespiratoryRegurgitationPlayers ( )
return self.RespiratoryRegurgitationPlayers
end
-- 呼吸回血 End -------------------------------------------------------------------------------------------------------------------------------------
-- 准备阶段 -----------------------------------------------------------------------------------------------------------------------------------------
function UGCGameState : IsReadyState ( )
return self : GetGameTime ( ) >= GlobalConfigs.GameSetting . RoundTime
end
-- 准备阶段 End -------------------------------------------------------------------------------------------------------------------------------------
-- Skill -------------------------------------------------------------------------------------------------------------------------------------
function UGCGameState : PlayerUseSkill ( SkillType , InPlayerKey )
UGCLogSystem.Log ( " [UGCGameState_PlayerUseSkill] " )
SkillConfig.ExeSkill ( SkillType , UGCGameSystem.GetPlayerPawnByPlayerKey ( InPlayerKey ) )
UGCLogSystem.Log ( " [UGCGameState_PlayerUseSkill] Finish " )
end
-- Skill End -------------------------------------------------------------------------------------------------------------------------------------
-- Debug -------------------------------------------------------------------------------------------------------------------------------------
function UGCGameState : DebugLogic ( InPlayerKey )
local DetectPlayerActor = UGCSystemLibrary.GetUniqueInstanceFromPath ( UGCGameSystem.GetUGCResourcesFullPath ( ' Asset/Blueprint/Skill/DetectActor/BP_DetectPlayerNew.BP_DetectPlayerNew_C ' ) )
if DetectPlayerActor then
local Res1 = DetectPlayerActor : CanSeeOutlineSpeicalConditionServer ( UGCGameSystem.GetPlayerPawnByPlayerKey ( InPlayerKey ) )
local Res2 = DetectPlayerActor : CanPlayerBeDetected ( UGCGameSystem.GetPlayerPawnByPlayerKey ( InPlayerKey ) )
UGCLogSystem.Log ( " [UGCGameState_DebugLogic] Res1:%s, Res2:%s " , tostring ( Res1 ) , tostring ( Res2 ) )
else
UGCLogSystem.LogError ( " [UGCGameState_DebugLogic] " )
end
end
-- Debug End -------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------ GameState Abstract RPC ------------------------------------------------
function UGCGameState : UGCSendRPCSystemFunc ( ... )
UGCSendRPCSystem.RPCFunc ( ... )
end
---------------------------------------------- GameState Abstract RPC End ----------------------------------------------
-- 工程函数设置 根据工程而修改调整的函数 -------------------------------------------------------------------------------------
--- 根据游戏队伍模式更新玩家队伍
---@param PlayerKey uint
function UGCGameState : UpdatePlayerTeam ( PlayerKey )
--if GlobalConfigs.GameModeSetting.TeamModeType == CustomEnum.ETeamMode.PersonalWarfare then
-- local NewTeamID = self:GetNewTeamID()
-- UGCTeamSystem.ChangePlayerTeamID(PlayerKey, NewTeamID)
-- UGCLogSystem.Log("[UGCGameState_UpdatePlayerTeam] NewTeamID:%s", tostring(NewTeamID))
--end
2025-01-07 21:25:05 +08:00
--local PlayerTeamID = UGCPlayerStateSystem.GetTeamID(PlayerKey)
--UGCLogSystem.Log("[UGCGameState_UpdatePlayerTeam]PlayerTeamID:%s", tostring(PlayerTeamID))
--if PlayerTeamID > 2 then
-- if self.LastChangeTeamIsTeam1 then
-- self.LastChangeTeamIsTeam1 = false
-- UGCTeamSystem.ChangePlayerTeamID(PlayerKey, 2)
-- else
-- self.LastChangeTeamIsTeam1 = true
-- UGCTeamSystem.ChangePlayerTeamID(PlayerKey, 1)
-- end
-- PlayerTeamID = UGCPlayerStateSystem.GetTeamID(PlayerKey)
-- UGCLogSystem.Log("[UGCGameState_UpdatePlayerTeam] NewTeamID:%s", tostring(PlayerTeamID))
--end
--
--local PC = UGCGameSystem.GetPlayerControllerByPlayerKey(PlayerKey)
--if PC then
-- PC:UpdatePlayerStartType()
-- UGCLogSystem.Log("[UGCGameState_UpdatePlayerTeam] Finish")
--else
-- UGCLogSystem.LogError("[UGCGameState_UpdatePlayerTeam] PC is nil")
--end
2025-01-04 23:00:19 +08:00
end
-- 工程设置-------------------------------------------------------------------------------------------------------------
function UGCGameState : GetAvailableServerRPCs ( )
return
" UGCSendRPCSystemFunc "
end
return UGCGameState ;