1205 lines
47 KiB
Lua
1205 lines
47 KiB
Lua
---@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}...}
|
||
|
||
PlayerJoinNum = 0; -- 玩家加入的数量作为个人TeamID
|
||
|
||
PlayerIsAlive = {}; -- 玩家是否存活
|
||
|
||
|
||
SyncPlaceModeUIInfo = {}; -- 同步放置模式显示的UI
|
||
SyncPlayModeUIInfo = {}; -- 同步游玩模式显示的UI
|
||
PreSavedMap = {}; -- 当存储地图量达上限时,临时存储的地图
|
||
AllDefender = {}; -- 所有将进行防守的玩家
|
||
DefenderIndex = 0; -- 当前防守的玩家索引
|
||
PlayerSelectPlaceMapCode = {}; -- 玩家进入游戏时保存的地图代码 {[PlayerKey] = {MapCode, MapName}}
|
||
LastPlayMapInfo = {}; -- 上次游玩的地图代码和名字 {MapCode, MapName, LastPlayerKey}
|
||
|
||
|
||
-- 突破防线的次数信息
|
||
BreakThroughNum = 0;
|
||
MaxBreakThroughNum = 0;
|
||
|
||
-- 武器配置选择
|
||
PlayerWeaponCombination = {}; -- 玩家可选的武器组合索引
|
||
PlayerSelectedWeaponIndex = {}; -- 玩家选择的武器配置索引
|
||
PlayerAutoSelectWeaponHandle = {}; -- 自动选择武器索引
|
||
|
||
-- 呼吸回血的玩家
|
||
RespiratoryRegurgitationPlayers = {};
|
||
};
|
||
|
||
function UGCGameState:GetReplicatedProperties()
|
||
return
|
||
"GameTime",
|
||
"PlayerPersonalInfos",
|
||
"WaitPlayerJoinTime",
|
||
"GameStateType",
|
||
"PlayerScoreDatas",
|
||
|
||
|
||
"PlayerIsAlive",
|
||
|
||
"SyncPlaceModeUIInfo",
|
||
"SyncPlayModeUIInfo",
|
||
|
||
"LastPlayMapInfo",
|
||
|
||
"BreakThroughNum",
|
||
"MaxBreakThroughNum",
|
||
"AllDefender",
|
||
"DefenderIndex",
|
||
|
||
"PlayerWeaponCombination",
|
||
"PlayerSelectedWeaponIndex",
|
||
|
||
|
||
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)
|
||
end
|
||
|
||
function UGCGameState:OnRep_GameStateType()
|
||
if self:HasAuthority() then return end
|
||
UGCEventSystem.SendEvent(EventEnum.GameStateChange, self.GameStateType)
|
||
end
|
||
|
||
function UGCGameState:OnRep_PlayerIsAlive()
|
||
UGCEventSystem.SendEvent(EventEnum.PlayerIsAliveIsChange)
|
||
end
|
||
|
||
function UGCGameState:OnRep_SyncPlaceModeUIInfo()
|
||
for _, UIType in pairs(WidgetConfig.SyncShowPlaceModeWidget) do
|
||
local Params = self.SyncPlaceModeUIInfo[UIType]
|
||
if Params == nil then
|
||
WidgetManager:ClosePanel(UIType)
|
||
end
|
||
end
|
||
|
||
for UIType, Params in pairs(self.SyncPlaceModeUIInfo) do
|
||
WidgetManager:ShowPanel(UIType, false, table.unpack(Params))
|
||
end
|
||
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_LastPlayMapInfo()
|
||
UGCEventSystem.SendEvent(EventEnum.UpdateLastPlayMapInfo, self.UpdateLastPlayMapInfo)
|
||
end
|
||
|
||
function UGCGameState:OnRep_DefenderIndex()
|
||
UGCEventSystem.SendEvent(EventEnum.UpdateDefender, self:GetNowDefender())
|
||
end
|
||
|
||
function UGCGameState:OnRep_AllDefender()
|
||
UGCEventSystem.SendEvent(EventEnum.UpdateDefender, self:GetNowDefender())
|
||
end
|
||
|
||
------------------------------------------------------ OnRep End ------------------------------------------------------
|
||
|
||
|
||
function UGCGameState:ReceiveBeginPlay()
|
||
UGCLogSystem.Log("[UGCGameState_ReceiveBeginPlay]")
|
||
|
||
--- 注册存档API
|
||
ArchiveDataConfig.Register(self)
|
||
|
||
--屏蔽死亡盒子
|
||
self.IsShowDeadBox = false;
|
||
self:AddBind()
|
||
GlobalInit.Init()
|
||
-- 开启滑铲State部分
|
||
self.bIsOpenShovelingAbility = true
|
||
-- 注册排行信息
|
||
PlayerScoreSystem.RegisterInfo(PlacementModeConfig.ScoreVal)
|
||
-- 初始化RPC系统
|
||
UGCSendRPCSystem.InitUGCSendRPCSystem(self, "UGCSendRPCSystemFunc")
|
||
|
||
if UGCGameSystem.IsServer() then
|
||
|
||
-- 生成放置控制器
|
||
UGCGameSystem.SpawnActor(self, UE.LoadClass(PlacementModeConfig.PlaceManagerPath), VectorHelper.VectorZero(), VectorHelper.RotZero(), VectorHelper.ScaleOne(), nil)
|
||
|
||
-- 绑定更新积分的函数
|
||
PlayerScoreSystem.BindChangeScoreDataCallBack(self.UpdateAllPlayerScoreDatas, self)
|
||
|
||
if PlacementModeConfig.IsPlaceMode() then
|
||
UGCEventSystem.SendEvent(EventEnum.PlaceMode)
|
||
-- 显示放置模式的主菜单
|
||
self:ShowSimplePlaceModeUI(WidgetConfig.EUIType.PlaceModeMainMenu)
|
||
else
|
||
UGCEventSystem.SendEvent(EventEnum.LineOfDefenseMode)
|
||
end
|
||
else
|
||
-- UGCLogSystem.SetEnableLog(false)
|
||
if PlacementModeConfig.IsPlaceMode() then
|
||
self:OnRep_SyncPlaceModeUIInfo()
|
||
else
|
||
self:OnRep_SyncPlayModeUIInfo()
|
||
end
|
||
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))
|
||
-- 更新玩家队伍设置
|
||
self:UpdatePlayerTeam(PlayerKey)
|
||
-- 获取玩家信息
|
||
self:GetUserInfo(PlayerKey)
|
||
-- 注册玩家得分信息
|
||
PlayerScoreSystem.InitPlayerScoreData(PlayerKey)
|
||
|
||
-- 更新玩家进入游戏时保存的地图代码
|
||
self:UpdatePlayerSelectPlaceMapCode(PlayerKey)
|
||
if PlacementModeConfig.IsPlaceMode() then
|
||
-- 更新放置模式的玩家已保存的地图信息
|
||
-- self:UpdateSimplePlayerSavedPlaceMap(PlayerKey)
|
||
-- 每日登录任务
|
||
self:AddTaskCountByType(PlayerKey, DailyTasksConfig.ETaskType.DailyLogin, 1)
|
||
self:AddPlayerNumberOfPlays(PlayerKey)
|
||
end
|
||
if not table.hasValue(self.AllDefender, PlayerKey) then
|
||
self.AllDefender[#self.AllDefender + 1] = PlayerKey
|
||
end
|
||
|
||
UGCLogSystem.Log("[UGCGameState_PlayerLogin] Finish")
|
||
end
|
||
|
||
function UGCGameState:PlayerExit(PlayerPawn, PlayerKey)
|
||
if GlobalConfigs.GameSetting.EnablePlayerJoin then
|
||
PlayerScoreSystem.RemovePlayerScoreInfo(PlayerKey)
|
||
end
|
||
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
|
||
end
|
||
|
||
--- 玩家登录获取玩家数据
|
||
---@param PlayerKey uint
|
||
function UGCGameState:GetUserInfo(PlayerKey)
|
||
if self.PlayerPersonalInfos[PlayerKey] then return self.PlayerPersonalInfos[PlayerKey] end
|
||
|
||
local UserInfo = UGCPlayerStateSystem.GetPlayerAccountInfo(PlayerKey)
|
||
if UserInfo then
|
||
--- UID,PlayerName,TeamID,Gender,PlatformGender,PlayerLevel,SegmentLevel,IconURL
|
||
local UserInfoCpy = UserInfo:Copy()
|
||
UGCLogSystem.Log("[UGCGameState_GetUserInfo] PlayerName:%s", UserInfoCpy.PlayerName)
|
||
|
||
local CustomUserInfo = {
|
||
UID = UserInfoCpy.UID,
|
||
PlayerKey = PlayerKey,
|
||
TeamID = UserInfoCpy.TeamID,
|
||
IsOffline = false,
|
||
PlayerName = UserInfoCpy.PlayerName,
|
||
Gender = UserInfoCpy.PlatformGender,
|
||
IconURL = UserInfoCpy.IconURL,
|
||
IsSelectTeam = false,
|
||
}
|
||
self.PlayerPersonalInfos[PlayerKey] = CustomUserInfo
|
||
|
||
|
||
UGCLogSystem.LogTree("[UGCGameState_GetUserInfo] CustomUserInfo:", CustomUserInfo)
|
||
return CustomUserInfo
|
||
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 -----------------------------------------------
|
||
|
||
--- 收藏一个地图到存档
|
||
function UGCGameState:AddSavePlaceMap(PlayerKey, MapName, MapCode)
|
||
local SavedMapList = ArchiveDataConfig.GetPlayerArchiveDataFromType(PlayerKey, ArchiveDataConfig.EArchiveType.SavedMap)
|
||
if SavedMapList == nil then
|
||
SavedMapList = {}
|
||
end
|
||
local TempSavedInfo = {MapName = MapName, MapCode = MapCode}
|
||
if #SavedMapList >= PlacementModeConfig.PlacingAttr.MaxSavedMapNum then
|
||
self.PreSavedMap[PlayerKey] = TempSavedInfo
|
||
UGCSendRPCSystem.ClientShowUI(PlayerKey, WidgetConfig.EUIType.ReplaceSavedMap)
|
||
return false
|
||
else
|
||
SavedMapList[#SavedMapList + 1] = TempSavedInfo
|
||
local IsSaveSucceed = ArchiveDataConfig.SavePlayerArchiveData(PlayerKey, ArchiveDataConfig.EArchiveType.SavedMap, SavedMapList)
|
||
UGCLogSystem.Log("[UGCGameState_AddSavePlaceMap] IsSaveSucceed:%s", tostring(IsSaveSucceed))
|
||
UGCLogSystem.LogTree("[UGCGameState_AddSavePlaceMap] SavedMapList:", SavedMapList)
|
||
if PlacementModeConfig.IsPlaceMode() then
|
||
UGCSendRPCSystem.ActorRPCNotify(PlayerKey, self, "ShowSetPlayMapSecondaryConfirmation")
|
||
end
|
||
return true
|
||
end
|
||
end
|
||
|
||
--- 给玩家二次确认是否要将新摆的地图设置为游玩地图
|
||
function UGCGameState:ShowSetPlayMapSecondaryConfirmation()
|
||
local SecondaryConfirmationWidget = WidgetManager:GetPanel(WidgetConfig.EUIType.SecondaryConfirmation)
|
||
SecondaryConfirmationWidget:SetTextInfo("是否将该地图设置为游玩地图?", "取消", "设置游玩")
|
||
SecondaryConfirmationWidget:BindConfirmCallBack(function()
|
||
UGCSendRPCSystem.ActorRPCNotify(nil, self, "SetPlayNewMap", UGCSystemLibrary.GetLocalPlayerKey())
|
||
end)
|
||
WidgetManager:ShowPanel(WidgetConfig.EUIType.SecondaryConfirmation, false)
|
||
end
|
||
|
||
--- 保存当前游玩的他人地图
|
||
function UGCGameState:SaveNowPlayMap(InPlayerKey)
|
||
if self:AddSavePlaceMap(InPlayerKey, self.LastPlayMapInfo.MapName, self.LastPlayMapInfo.MapCode) then
|
||
UGCSendRPCSystem.RPCEvent(InPlayerKey, EventEnum.AddTip, TipConfig.TipType.CollectionSuccessful)
|
||
end
|
||
end
|
||
|
||
|
||
--- 移除一个地图
|
||
function UGCGameState:RemoveSavedMap(PlayerKey, MapIndex)
|
||
UGCLogSystem.Log("[UGCGameState_RemoveSavedMap] Start")
|
||
local SavedMapList = ArchiveDataConfig.GetPlayerArchiveDataFromType(PlayerKey, ArchiveDataConfig.EArchiveType.SavedMap)
|
||
local SelectMapIndex = ArchiveDataConfig.GetPlayerArchiveDataFromType(PlayerKey, ArchiveDataConfig.EArchiveType.SelectMapIndex)
|
||
if SavedMapList == nil or SavedMapList[MapIndex] == nil then
|
||
return false
|
||
end
|
||
if SelectMapIndex == MapIndex then
|
||
ArchiveDataConfig.SavePlayerArchiveData(PlayerKey, ArchiveDataConfig.EArchiveType.SelectMapIndex, -1)
|
||
elseif SelectMapIndex > MapIndex then
|
||
ArchiveDataConfig.SavePlayerArchiveData(PlayerKey, ArchiveDataConfig.EArchiveType.SelectMapIndex, SelectMapIndex - 1)
|
||
end
|
||
UGCLogSystem.LogTree("[UGCGameState_RemoveSavedMap]", SavedMapList)
|
||
table.remove(SavedMapList, MapIndex)
|
||
ArchiveDataConfig.SavePlayerArchiveData(PlayerKey, ArchiveDataConfig.EArchiveType.SavedMap, SavedMapList)
|
||
UGCLogSystem.LogTree("[UGCGameState_RemoveSavedMap] Finish", SavedMapList)
|
||
return true
|
||
end
|
||
|
||
|
||
|
||
|
||
|
||
--- 设置玩家选择的地图
|
||
function UGCGameState:SetPlayMap(PlayerKey, MapIndex)
|
||
if PlacementModeConfig.IsPlaceMode() then
|
||
if MapIndex == nil or MapIndex > 0 and MapIndex <= PlacementModeConfig.PlacingAttr.MaxSavedMapNum then
|
||
ArchiveDataConfig.SavePlayerArchiveData(PlayerKey, ArchiveDataConfig.EArchiveType.SelectMapIndex, MapIndex)
|
||
end
|
||
end
|
||
return true
|
||
end
|
||
|
||
--- 将玩家最新最新加入的地图设置为游玩模式
|
||
function UGCGameState:SetPlayNewMap(PlayerKey)
|
||
if PlacementModeConfig.IsPlaceMode() then
|
||
local SavedMap = ArchiveDataConfig.GetPlayerArchiveDataFromType(PlayerKey, ArchiveDataConfig.EArchiveType.SavedMap)
|
||
if SavedMap == nil then return false end
|
||
ArchiveDataConfig.SavePlayerArchiveData(PlayerKey, ArchiveDataConfig.EArchiveType.SelectMapIndex, #SavedMap)
|
||
end
|
||
return true
|
||
end
|
||
|
||
--- 移除调被替换的地图信息,添加玩家预存的地图信息
|
||
function UGCGameState:ReplaceMap(PlayerKey, RemoveMapIndex)
|
||
if self.PreSavedMap[PlayerKey] then
|
||
if self:RemoveSavedMap(PlayerKey, RemoveMapIndex) then
|
||
self:AddSavePlaceMap(PlayerKey, self.PreSavedMap[PlayerKey].MapName, self.PreSavedMap[PlayerKey].MapCode)
|
||
self.PreSavedMap[PlayerKey] = nil
|
||
end
|
||
end
|
||
end
|
||
|
||
--- 重置已保存的地图的名字
|
||
function UGCGameState:SetSavedMapName(PlayerKey, MapIndex, Name)
|
||
local SavedMapList = ArchiveDataConfig.GetPlayerArchiveDataFromType(PlayerKey, ArchiveDataConfig.EArchiveType.SavedMap)
|
||
if SavedMapList and SavedMapList[MapIndex] then
|
||
SavedMapList[MapIndex].MapName = Name
|
||
ArchiveDataConfig.SavePlayerArchiveData(PlayerKey, ArchiveDataConfig.EArchiveType.SavedMap, SavedMapList)
|
||
end
|
||
end
|
||
|
||
|
||
-- 存档 End -----------------------------------------------------------------------------------------------------------------------------------------------
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
-- Score Data ----------------------------------------------------------------------------------------
|
||
--- 更新返回所有玩家得分
|
||
function UGCGameState:UpdateAllPlayerScoreDatas()
|
||
self.PlayerScoreDatas = PlayerScoreSystem.GetPlayerScoreDatas()
|
||
UGCLogSystem.LogTree("[UGCGameState_UpdateAllPlayerScoreDatas]", self.PlayerScoreDatas)
|
||
end
|
||
|
||
-- 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
|
||
|
||
|
||
|
||
|
||
------------------------------------------------------------------ 获取玩家信息 ------------------------------------------------------------------
|
||
|
||
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
|
||
|
||
---------------------------------------------------------------- 获取玩家信息 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.PlayerIsAlive[PlayerKey] = Pawn
|
||
else
|
||
self.PlayerIsAlive[PlayerKey] = nil
|
||
end
|
||
end
|
||
|
||
|
||
|
||
function UGCGameState:GetPlayerIsAlive(PlayerKey)
|
||
if self.PlayerIsAlive[PlayerKey] then
|
||
return true
|
||
end
|
||
return false
|
||
end
|
||
|
||
function UGCGameState:GetAlivePawn(PlayerKey)
|
||
return self.PlayerIsAlive[PlayerKey]
|
||
end
|
||
|
||
|
||
--------------------------------------------- SyncUIInfo ---------------------------------------------
|
||
|
||
-- PlaceMode ------------------------------------------------------------------------------------------
|
||
function UGCGameState:ShowSimplePlaceModeUI(UIType, Params)
|
||
if Params == nil then Params = {} end
|
||
self.SyncPlaceModeUIInfo = {}
|
||
self.SyncPlaceModeUIInfo[UIType] = Params
|
||
end
|
||
|
||
function UGCGameState:AddPlaceModeUI(UIType, Params)
|
||
if table.hasValue(WidgetConfig.SyncShowPlaceModeWidget, UIType) then
|
||
if Params == nil then Params = {} end
|
||
self.SyncPlaceModeUIInfo[UIType] = Params
|
||
end
|
||
end
|
||
|
||
function UGCGameState:RemovePlaceModeUI(UIType)
|
||
self.SyncPlaceModeUIInfo[UIType] = nil
|
||
end
|
||
|
||
|
||
|
||
-- PlaceMode End --------------------------------------------------------------------------------------
|
||
|
||
-- 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 ---------------------------------------------
|
||
|
||
--------------------------------------------- 回合双方的参数设置 ---------------------------------------------
|
||
|
||
--- 打乱防守方顺序
|
||
function UGCGameState:ShuffleAllDefender()
|
||
table.Shuffle(self.AllDefender)
|
||
end
|
||
|
||
function UGCGameState:GetNewDefender()
|
||
for i = self.DefenderIndex + 1, #self.AllDefender do
|
||
self.DefenderIndex = self.DefenderIndex + 1
|
||
if UGCGameSystem.GetPlayerControllerByPlayerKey(self.AllDefender[self.DefenderIndex]) then
|
||
break
|
||
end
|
||
end
|
||
return self.AllDefender[self.DefenderIndex]
|
||
end
|
||
|
||
function UGCGameState:GetNowDefender()
|
||
return self.AllDefender[self.DefenderIndex]
|
||
end
|
||
|
||
-- 刷新此回合需要突破防线的次数
|
||
function UGCGameState:UpdateNumOfBreakingThroughDefenseLine()
|
||
self.MaxBreakThroughNum = PlacementModeConfig.GetNumOfBreakingThroughDefenseLine()
|
||
self.BreakThroughNum = 0
|
||
|
||
local Defender = self:GetNewDefender()
|
||
local AllPC = UGCGameSystem.GetAllPlayerController()
|
||
for i, v in pairs(AllPC) do
|
||
if v.PlayerKey == Defender then
|
||
v:SetStartPointType(EPlayerStartType.Defender)
|
||
UGCTeamSystem.ChangePlayerTeamID(v.PlayerKey, 2)
|
||
else
|
||
v:SetStartPointType(EPlayerStartType.Attacker)
|
||
UGCTeamSystem.ChangePlayerTeamID(v.PlayerKey, 1)
|
||
end
|
||
end
|
||
end
|
||
|
||
function UGCGameState:AddBreakThroughNum()
|
||
self.BreakThroughNum = self.BreakThroughNum + 1
|
||
end
|
||
|
||
function UGCGameState:GetBreakThroughNum()
|
||
return self.BreakThroughNum
|
||
end
|
||
|
||
function UGCGameState:IsAttackSucceed()
|
||
return self.BreakThroughNum >= self.MaxBreakThroughNum
|
||
end
|
||
|
||
--- 判断是否为最后一位玩家
|
||
function UGCGameState:IsFinishPlayer()
|
||
for i = self.DefenderIndex + 1, #self.AllDefender do
|
||
if UGCGameSystem.GetPlayerControllerByPlayerKey(self.AllDefender[i]) then
|
||
return false
|
||
end
|
||
end
|
||
return true
|
||
end
|
||
|
||
--- 获取当前防守玩家默认的地图代码
|
||
function UGCGameState:GetNowDefenderSelectMap()
|
||
return self.PlayerSelectPlaceMapCode[self:GetNowDefender()].MapCode
|
||
end
|
||
--- 刷新上次游玩的地图信息 用途是在回合结算界面时加载新地图而临时保留上次玩家的地图信息
|
||
function UGCGameState:UpdateLastPlayMapInfo()
|
||
self.LastPlayMapInfo = self.PlayerSelectPlaceMapCode[self:GetNowDefender()]
|
||
self.LastPlayMapInfo["LastPlayerKey"] = self:GetNowDefender()
|
||
end
|
||
|
||
--- 更新玩家进入时保存的地图
|
||
function UGCGameState:UpdatePlayerSelectPlaceMapCode(PlayerKey)
|
||
if self.PlayerSelectPlaceMapCode[PlayerKey] then return end
|
||
local MapIndex = self:GetArchiveDataByType(PlayerKey, ArchiveDataConfig.EArchiveType.SelectMapIndex)
|
||
local SavedMapList = self:GetArchiveDataByType(PlayerKey, ArchiveDataConfig.EArchiveType.SavedMap)
|
||
if MapIndex == nil or SavedMapList == nil or SavedMapList[MapIndex] == nil then
|
||
self.PlayerSelectPlaceMapCode[PlayerKey] = {MapCode = PlacementModeConfig.GlobalDefaultPlaceCode, MapName = "默认地图"}
|
||
else
|
||
self.PlayerSelectPlaceMapCode[PlayerKey] = {MapCode = SavedMapList[MapIndex].MapCode, MapName = SavedMapList[MapIndex].MapName}
|
||
end
|
||
end
|
||
|
||
--- 获取防守方MVP
|
||
function UGCGameState:GetDefendMVP()
|
||
local ResPlayerKey = -1
|
||
local DefendSucceedNum = 0
|
||
local PlayerKill = 0
|
||
for i, v in pairs(PlayerScoreSystem.GetPlayerScoreDatas()) do
|
||
local TempDefendSucceedNum = PlayerScoreSystem.GetPlayerScoreDataFromType(i, PlacementModeConfig.AddScoreType.DefendSucceedAddScore)
|
||
local TempPlayerKillNum = PlayerScoreSystem.GetPlayerScoreDataFromType(i, PlacementModeConfig.AddScoreType.KillAddScore)
|
||
|
||
if ResPlayerKey < 0
|
||
or TempDefendSucceedNum > DefendSucceedNum
|
||
or (TempDefendSucceedNum == DefendSucceedNum and PlayerKill > TempPlayerKillNum)
|
||
then
|
||
ResPlayerKey = i
|
||
DefendSucceedNum = TempDefendSucceedNum
|
||
PlayerKill = TempPlayerKillNum
|
||
end
|
||
end
|
||
return ResPlayerKey
|
||
end
|
||
|
||
--- 获取进攻方MVP
|
||
function UGCGameState:GetAttackMVP()
|
||
local ResPlayerKey = -1
|
||
local PlayerBreakThroughNum = 0
|
||
local PlayerKill = 0
|
||
for i, v in pairs(PlayerScoreSystem.GetPlayerScoreDatas()) do
|
||
local TempPlayerBreakThroughNum = PlayerScoreSystem.GetPlayerScoreDataFromType(i, PlacementModeConfig.AddScoreType.EnterDefenseLineAddScore)
|
||
local TempPlayerKillNum = PlayerScoreSystem.GetPlayerScoreDataFromType(i, PlacementModeConfig.AddScoreType.KillAddScore)
|
||
|
||
if ResPlayerKey < 0
|
||
or TempPlayerBreakThroughNum > PlayerBreakThroughNum
|
||
or (TempPlayerBreakThroughNum == PlayerBreakThroughNum and PlayerKill > TempPlayerKillNum)
|
||
then
|
||
ResPlayerKey = i
|
||
PlayerBreakThroughNum = TempPlayerBreakThroughNum
|
||
PlayerKill = TempPlayerKillNum
|
||
end
|
||
end
|
||
return ResPlayerKey
|
||
end
|
||
------------------------------------------- 回合双方的参数设置 End -------------------------------------------
|
||
-- 修改消耗品数量 ---------------------------------------------------------------------------------------------------------------------------
|
||
function UGCGameState:AddGold(PlayerKey, Gold)
|
||
if UGCGameSystem.IsServer() then
|
||
local GoldCount = ArchiveDataConfig.GetPlayerArchiveDataFromType(PlayerKey, ArchiveDataConfig.EArchiveType.Gold)
|
||
if GoldCount == nil then GoldCount = 0 end
|
||
ArchiveDataConfig.SavePlayerArchiveData(PlayerKey, ArchiveDataConfig.EArchiveType.Gold, GoldCount + Gold)
|
||
end
|
||
end
|
||
|
||
function UGCGameState:AddGoldBrick(PlayerKey, GoldBrick)
|
||
if UGCGameSystem.IsServer() then
|
||
local GoldBrickCount = ArchiveDataConfig.GetPlayerArchiveDataFromType(PlayerKey, ArchiveDataConfig.EArchiveType.GoldBrick)
|
||
if GoldBrickCount == nil then GoldBrickCount = 0 end
|
||
ArchiveDataConfig.SavePlayerArchiveData(PlayerKey, ArchiveDataConfig.EArchiveType.GoldBrick, GoldBrickCount + GoldBrick)
|
||
end
|
||
end
|
||
|
||
function UGCGameState:AddExp(PlayerKey, Exp)
|
||
if UGCGameSystem.IsServer() then
|
||
local ExpCount = ArchiveDataConfig.GetPlayerArchiveDataFromType(PlayerKey, ArchiveDataConfig.EArchiveType.Exp)
|
||
if ExpCount == nil then ExpCount = 0 end
|
||
ArchiveDataConfig.SavePlayerArchiveData(PlayerKey, ArchiveDataConfig.EArchiveType.Exp, ExpCount + Exp)
|
||
end
|
||
end
|
||
|
||
-- 修改消耗品数量 End -----------------------------------------------------------------------------------------------------------------------
|
||
|
||
|
||
|
||
-- Buy -----------------------------------------------------------------------------------------------------------------------------------
|
||
--- Server or Client
|
||
--- 校验玩家的解锁物是否符合要求
|
||
function UGCGameState:CheckUnlockProperty(PlayerKey, UnlockType, UnlockCost)
|
||
if UnlockType == PlacementModeConfig.EUnlockType.None then
|
||
return true
|
||
elseif UnlockType == PlacementModeConfig.EUnlockType.Gold then
|
||
local Gold = ArchiveDataConfig.GetPlayerArchiveDataFromType(PlayerKey, ArchiveDataConfig.EArchiveType.Gold)
|
||
if Gold == nil then Gold = 0 end
|
||
return Gold >= UnlockCost
|
||
elseif UnlockType == PlacementModeConfig.EUnlockType.Level then
|
||
local Exp = ArchiveDataConfig.GetPlayerArchiveDataFromType(PlayerKey, ArchiveDataConfig.EArchiveType.Exp)
|
||
if Exp == nil then Exp = 0 end
|
||
return LevelConfig.GetLevel(Exp) >= UnlockCost
|
||
elseif UnlockType == PlacementModeConfig.EUnlockType.GoldBrick then
|
||
local GoldBrick = ArchiveDataConfig.GetPlayerArchiveDataFromType(PlayerKey, ArchiveDataConfig.EArchiveType.GoldBrick)
|
||
if GoldBrick == nil then GoldBrick = 0 end
|
||
return GoldBrick >= UnlockCost
|
||
end
|
||
return true
|
||
end
|
||
|
||
--- Server
|
||
--- 消耗玩家的资产
|
||
function UGCGameState:ExpendPlayerProperty(PlayerKey, UnlockType, Cost)
|
||
if self:CheckUnlockProperty(PlayerKey, UnlockType, Cost) then
|
||
if UnlockType == PlacementModeConfig.EUnlockType.Gold then
|
||
local Gold = ArchiveDataConfig.GetPlayerArchiveDataFromType(PlayerKey, ArchiveDataConfig.EArchiveType.Gold)
|
||
ArchiveDataConfig.SavePlayerArchiveData(PlayerKey, ArchiveDataConfig.EArchiveType.Gold, Gold - Cost)
|
||
elseif UnlockType == PlacementModeConfig.EUnlockType.GoldBrick then
|
||
local GoldBrick = ArchiveDataConfig.GetPlayerArchiveDataFromType(PlayerKey, ArchiveDataConfig.EArchiveType.GoldBrick)
|
||
ArchiveDataConfig.SavePlayerArchiveData(PlayerKey, ArchiveDataConfig.EArchiveType.GoldBrick, GoldBrick - Cost)
|
||
end
|
||
return true
|
||
else
|
||
UGCSendRPCSystem.RPCEvent(PlayerKey, EventEnum.AddTip, TipConfig.TipType.ConsumablesInsufficient, UnlockType)
|
||
return false
|
||
end
|
||
end
|
||
|
||
--- 解锁放置物
|
||
function UGCGameState:UnlockPlaceItem(PlayerKey, PlaceItemType)
|
||
if UGCGameSystem.IsServer() and table.hasValue(EPlaceItemType, PlaceItemType) then
|
||
local ItemIncrement = ArchiveDataConfig.GetPlayerArchiveDataFromType(PlayerKey, ArchiveDataConfig.EArchiveType.ItemIncrement)
|
||
if ItemIncrement == nil then ItemIncrement = {} end
|
||
local Increment = ItemIncrement[PlaceItemType]
|
||
if Increment == nil or Increment == 0 then
|
||
local UnlockType, UnlockCost = PlacementModeConfig.GetPlaceItemUnlockInfo(PlaceItemType)
|
||
local ExpendSucceed = self:ExpendPlayerProperty(PlayerKey, UnlockType, UnlockCost)
|
||
if ExpendSucceed then
|
||
ItemIncrement[PlaceItemType] = 1
|
||
ArchiveDataConfig.SavePlayerArchiveData(PlayerKey, ArchiveDataConfig.EArchiveType.ItemIncrement, ItemIncrement)
|
||
UGCSendRPCSystem.RPCEvent(PlayerKey, EventEnum.AddTip, TipConfig.TipType.UnlockSucceed)
|
||
end
|
||
--UGCSendRPCSystem.RPCEvent(PlayerKey, EventEnum.UnlockCallBack, ExpendSucceed, UnlockType)
|
||
end
|
||
end
|
||
end
|
||
|
||
--- 增加放置物
|
||
function UGCGameState:AddItemIncrement(PlayerKey, PlaceItemType)
|
||
if UGCGameSystem.IsServer() and table.hasValue(EPlaceItemType, PlaceItemType) then
|
||
local ItemIncrement = ArchiveDataConfig.GetPlayerArchiveDataFromType(PlayerKey, ArchiveDataConfig.EArchiveType.ItemIncrement)
|
||
if ItemIncrement == nil then ItemIncrement = {} end
|
||
local Increment = ItemIncrement[PlaceItemType] and ItemIncrement[PlaceItemType] or 0
|
||
local PlaceItemInfo = PlacementModeConfig.ItemInfo[PlaceItemType]
|
||
local CanPlaceCount = Increment + PlaceItemInfo.InitialCount
|
||
if CanPlaceCount > 0 and CanPlaceCount < PlaceItemInfo.MaxCount then
|
||
local UnlockType, UnlockCost = PlacementModeConfig.GetPlaceItemIncrementInfo(PlaceItemType)
|
||
local ExpendSucceed = self:ExpendPlayerProperty(PlayerKey, UnlockType, UnlockCost)
|
||
if ExpendSucceed then
|
||
ItemIncrement[PlaceItemType] = Increment + 1
|
||
ArchiveDataConfig.SavePlayerArchiveData(PlayerKey, ArchiveDataConfig.EArchiveType.ItemIncrement, ItemIncrement)
|
||
UGCSendRPCSystem.RPCEvent(PlayerKey, EventEnum.AddTip, TipConfig.TipType.IncrementSucceed)
|
||
end
|
||
--UGCSendRPCSystem.RPCEvent(PlayerKey, EventEnum.IncrementCallBack, ExpendSucceed, UnlockType)
|
||
end
|
||
end
|
||
end
|
||
|
||
-- 兑换 ------------------------------
|
||
|
||
--- 金币兑换经验
|
||
function UGCGameState:GoldToExp(PlayerKey, Gold)
|
||
if self:ExpendPlayerProperty(PlayerKey, PlacementModeConfig.EUnlockType.Gold, Gold) then
|
||
self:AddExp(PlayerKey, Gold * PlacementModeConfig.PlacingAttr.RatioGoldToExp)
|
||
UGCSendRPCSystem.RPCEvent(PlayerKey, EventEnum.AddTip, TipConfig.TipType.ExchangeSucceed)
|
||
end
|
||
end
|
||
|
||
--- 金砖兑换金币
|
||
function UGCGameState:GoldBrickToGold(PlayerKey, GoldBrick)
|
||
if self:ExpendPlayerProperty(PlayerKey, PlacementModeConfig.EUnlockType.GoldBrick, GoldBrick) then
|
||
self:AddGold(PlayerKey, GoldBrick * PlacementModeConfig.PlacingAttr.RatioGoldBrickToGold)
|
||
UGCSendRPCSystem.RPCEvent(PlayerKey, EventEnum.AddTip, TipConfig.TipType.ExchangeSucceed)
|
||
end
|
||
end
|
||
|
||
-- 兑换 End --------------------------
|
||
|
||
|
||
-- Buy End -------------------------------------------------------------------------------------------------------------------------------
|
||
|
||
|
||
-- Task ----------------------------------------------------------------------------------------------------------------------------------
|
||
--- 增加每日任务的完成量
|
||
function UGCGameState:AddTaskCountByType(InPlayerKey, TaskType, AddCount)
|
||
UGCLogSystem.Log("[UGCGameState_AddTaskCountByType]")
|
||
if DailyTasksConfig.TaskInfo[TaskType] == nil then
|
||
UGCLogSystem.LogError("[UGCGameState_AddTaskCountByType] TaskType:%s is nil", tostring(TaskType))
|
||
return
|
||
end
|
||
self:CheckNewDay(InPlayerKey)
|
||
local DailyTasks = ArchiveDataConfig.GetPlayerArchiveDataFromType(InPlayerKey, ArchiveDataConfig.EArchiveType.DailyTasks)
|
||
if DailyTasks == nil then
|
||
DailyTasks = {}
|
||
end
|
||
local LastTaskCount = 0
|
||
if DailyTasks[TaskType] then
|
||
LastTaskCount = DailyTasks[TaskType]
|
||
end
|
||
local TaskDailyLimit = DailyTasksConfig.TaskInfo[TaskType].DailyLimit
|
||
if LastTaskCount < TaskDailyLimit then
|
||
local NowTaskCount = math.clamp(LastTaskCount + AddCount, 0, TaskDailyLimit)
|
||
local IsDisposable = DailyTasksConfig.TaskInfo[TaskType].IsDisposable
|
||
if IsDisposable or TaskDailyLimit == NowTaskCount then
|
||
for i, v in pairs(DailyTasksConfig.TaskInfo[TaskType].Reward) do
|
||
local AddRewardCount = IsDisposable and (v.Count * (NowTaskCount - LastTaskCount)) or v.Count
|
||
if v.Type == ArchiveDataConfig.EArchiveType.Gold then
|
||
self:AddGold(InPlayerKey, AddRewardCount)
|
||
elseif v.Type == ArchiveDataConfig.EArchiveType.Exp then
|
||
self:AddExp(InPlayerKey, AddRewardCount)
|
||
end
|
||
end
|
||
end
|
||
DailyTasks[TaskType] = NowTaskCount
|
||
ArchiveDataConfig.SavePlayerArchiveData(InPlayerKey, ArchiveDataConfig.EArchiveType.DailyTasks, DailyTasks)
|
||
UGCLogSystem.Log("[UGCGameState_AddTaskCountByType] Succeed")
|
||
end
|
||
UGCLogSystem.Log("[UGCGameState_AddTaskCountByType] Finish")
|
||
|
||
end
|
||
|
||
function UGCGameState:CheckNewDay(InPlayerKey)
|
||
local DailyTasksUpdateDay = ArchiveDataConfig.GetPlayerArchiveDataFromType(InPlayerKey, ArchiveDataConfig.EArchiveType.DailyTasksUpdateDay)
|
||
local Day = UGCSystemLibrary.GetDayOfYear()
|
||
UGCLogSystem.Log("[UGCGameState_CheckNewDay] LastDay:%s, NowDay, %s", tostring(DailyTasksUpdateDay), tostring(Day))
|
||
if DailyTasksUpdateDay ~= Day then
|
||
self:ResetTaskArchiveData(InPlayerKey, Day)
|
||
end
|
||
end
|
||
|
||
function UGCGameState:ResetTaskArchiveData(InPlayerKey, NowDay)
|
||
UGCLogSystem.Log("[UGCGameState_ResetTaskArchiveData] InPlayerKey:%s, NowDay:%s", tostring(InPlayerKey), tostring(NowDay))
|
||
ArchiveDataConfig.SavePlayerArchiveData(InPlayerKey, ArchiveDataConfig.EArchiveType.DailyTasksUpdateDay, NowDay)
|
||
ArchiveDataConfig.SavePlayerArchiveData(InPlayerKey, ArchiveDataConfig.EArchiveType.DailyTasks, {})
|
||
end
|
||
|
||
-- Task 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] = nil
|
||
end
|
||
|
||
--- 重置所有玩家的武器配置索引
|
||
function UGCGameState:ResetAllPlayerSelectWeaponIndex()
|
||
self.PlayerSelectedWeaponIndex = {}
|
||
end
|
||
|
||
--- 设置玩家选择的武器配置索引
|
||
function UGCGameState:PlayerSelectWeaponIndex(PlayerKey, WeaponCombinationIndex)
|
||
self.PlayerSelectedWeaponIndex[PlayerKey] = WeaponCombinationIndex
|
||
self:CheckWeaponAndParts(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 self:CheckPlayerSelectWeaponIndex(PlayerKey) then
|
||
local Weapons = WeaponSelectionCombinationConfig.WeaponCombinationList[self:GetPlayerWeaponCombination(PlayerKey)].Weapon[self:GetPlayerSelectedWeaponIndex(PlayerKey)]
|
||
for i, WeaponID in pairs(Weapons) do
|
||
Res[WeaponID] = 1
|
||
for _, PartID in pairs(WeaponTable.RecommendedWeaponParts[WeaponID]) do
|
||
if Res[PartID] then
|
||
Res[PartID] = 1 + Res[PartID]
|
||
else
|
||
Res[PartID] = 1
|
||
end
|
||
end
|
||
end
|
||
end
|
||
return Res
|
||
end
|
||
|
||
--- 检测并给予玩家武器和配件
|
||
function UGCGameState:CheckWeaponAndParts(InPlayerKey)
|
||
local TargetPawn = UGCGameSystem.GetPlayerPawnByPlayerKey(InPlayerKey)
|
||
if TargetPawn == nil then return end
|
||
|
||
local WeaponAndParts = UGCGameSystem.GameState:GetPlayerSelectedWeaponAndParts(InPlayerKey)
|
||
|
||
---@return ItemDataList LuaTable @LuaTable<ItemData>, ItemData结构:ItemID,InstanceID,Count,Type,SubType,IsAvatar
|
||
local AllItems = UGCBackPackSystem.GetAllItemData(TargetPawn)
|
||
|
||
-- 验证玩家当前背包武器及配件是否需要销毁
|
||
for i, ItemInfo in pairs(AllItems) do
|
||
local TypeID = UGCSystemLibrary.GetItemTypeID(ItemInfo.ItemID)
|
||
if TypeID < 300 and TypeID > 100 then
|
||
local TargetItemCount = WeaponAndParts[ItemInfo.ItemID]
|
||
if TargetItemCount == nil then TargetItemCount = 0 end
|
||
if ItemInfo.Count > TargetItemCount then
|
||
--- 销毁背包中的物品
|
||
UGCBackPackSystem.DropItem(TargetPawn, ItemInfo.ItemID, ItemInfo.Count - TargetItemCount, true)
|
||
end
|
||
end
|
||
end
|
||
|
||
local bGiveWeapon = false
|
||
-- 添加武器及配件
|
||
for ItemID, TargetCount in pairs(WeaponAndParts) do
|
||
local Count = UGCBackPackSystem.GetItemCount(TargetPawn, ItemID)
|
||
if TargetCount > Count then
|
||
UGCBackPackSystem.AddItem(TargetPawn, ItemID, TargetCount - Count)
|
||
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
|
||
|
||
--- 显示玩家选择武器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
|
||
|
||
-- PlayerWeaponCombination End -----------------------------------------------------------------------------------------------------------
|
||
|
||
|
||
--- 玩家点赞
|
||
function UGCGameState:AddLike(InPlayerLike)
|
||
local PlayerKey = self.LastPlayMapInfo.LastPlayerKey
|
||
if PlayerKey then
|
||
local LikeCount = ArchiveDataConfig.GetPlayerArchiveDataFromType(PlayerKey, ArchiveDataConfig.EArchiveType.Like)
|
||
if LikeCount then
|
||
LikeCount = LikeCount + 1
|
||
else
|
||
LikeCount = 1
|
||
end
|
||
ArchiveDataConfig.SavePlayerArchiveData(PlayerKey, ArchiveDataConfig.EArchiveType.Like, LikeCount)
|
||
self:AddTaskCountByType(InPlayerLike, DailyTasksConfig.ETaskType.LikeOtherPlayerMap, 1)
|
||
UGCSendRPCSystem.RPCEvent(PlayerKey, EventEnum.AddTip, TipConfig.TipType.PlayerLike)
|
||
end
|
||
end
|
||
|
||
-- Shop -------------------------------------------------------------------------------------------------------------------------------------------------
|
||
|
||
|
||
--可以通过参数得知玩家物品的变化已经是否购买成功
|
||
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
|
||
|
||
-- Shop -------------------------------------------------------------------------------------------------------------------------------------------------
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
-- Debug ---------------------------------------------------------------------------------------------------------------------------------
|
||
function UGCGameState:Debug_AddGold(PlayerKey)
|
||
if GlobalConfigs.IsDebug then
|
||
if UGCGameSystem.IsServer() then
|
||
self:AddGold(PlayerKey, 10000)
|
||
else
|
||
UGCSendRPCSystem.ActorRPCNotify(PlayerKey, self, "Debug_AddGold", PlayerKey)
|
||
end
|
||
end
|
||
end
|
||
|
||
|
||
function UGCGameState:Debug_AddGoldBrick(PlayerKey)
|
||
if GlobalConfigs.IsDebug then
|
||
if UGCGameSystem.IsServer() then
|
||
self:AddGoldBrick(PlayerKey, 100)
|
||
else
|
||
UGCSendRPCSystem.ActorRPCNotify(PlayerKey, self, "Debug_AddGoldBrick", PlayerKey)
|
||
end
|
||
end
|
||
end
|
||
|
||
function UGCGameState:Debug_AddExp(PlayerKey)
|
||
if GlobalConfigs.IsDebug then
|
||
if UGCGameSystem.IsServer() then
|
||
self:AddExp(PlayerKey, 10000)
|
||
else
|
||
UGCSendRPCSystem.ActorRPCNotify(nil, self, "Debug_AddExp", PlayerKey)
|
||
end
|
||
end
|
||
end
|
||
|
||
function UGCGameState:Debug_ClearArchiveData(PlayerKey)
|
||
if GlobalConfigs.IsDebug then
|
||
if UGCGameSystem.IsServer() then
|
||
ArchiveDataConfig.ClearPlayerArchiveData(PlayerKey)
|
||
else
|
||
UGCSendRPCSystem.ActorRPCNotify(nil, self, "Debug_ClearArchiveData", PlayerKey)
|
||
end
|
||
end
|
||
end
|
||
|
||
function UGCGameState:Debug_ClearArchiveDataFromType(PlayerKey, InArchiveDataType)
|
||
if GlobalConfigs.IsDebug then
|
||
if UGCGameSystem.IsServer() then
|
||
ArchiveDataConfig.SavePlayerArchiveData(PlayerKey, InArchiveDataType, nil)
|
||
else
|
||
UGCSendRPCSystem.ActorRPCNotify(nil, self, "Debug_ClearArchiveData", PlayerKey)
|
||
end
|
||
end
|
||
end
|
||
|
||
-- Debug End -----------------------------------------------------------------------------------------------------------------------------
|
||
|
||
--- 设置可呼吸回血的玩家
|
||
function UGCGameState:SetRespiratoryRegurgitationPlayers(InPlayers)
|
||
self.RespiratoryRegurgitationPlayers = InPlayers
|
||
end
|
||
|
||
--- 获取可呼吸回血的玩家
|
||
function UGCGameState:GetRespiratoryRegurgitationPlayers()
|
||
return self.RespiratoryRegurgitationPlayers
|
||
end
|
||
|
||
------------------------------------------------ GameState Abstract RPC ------------------------------------------------
|
||
function UGCGameState:UGCSendRPCSystemFunc(...)
|
||
UGCSendRPCSystem.RPCFunc(...)
|
||
end
|
||
---------------------------------------------- GameState Abstract RPC End ----------------------------------------------
|
||
|
||
|
||
|
||
function UGCGameState:GetAvailableServerRPCs()
|
||
return
|
||
"UGCSendRPCSystemFunc"
|
||
end
|
||
return UGCGameState;
|