390 lines
15 KiB
Lua
390 lines
15 KiB
Lua
---@class UGCPlayerController_C:BP_UGCPlayerController_C
|
||
--Edit Below--
|
||
---@type UGCPlayerController_C
|
||
local UGCPlayerController = {
|
||
NeedExePlayerIsFirstTimePlaying = false;
|
||
|
||
|
||
-- 可获得的增益次数
|
||
CanObtainIncreaseCount = 0;
|
||
-- 当前可选择的增益
|
||
NowCanSelectIncrease = {};
|
||
-- 拥有的增益
|
||
OwnedIncrease = {}; -- [IncreaseType] = Level
|
||
-- 增益已满
|
||
IncreaseIsFull = false;
|
||
};
|
||
|
||
-- Replicated -------------------------------------------------------------------------------------------------------
|
||
|
||
function UGCPlayerController:GetReplicatedProperties()
|
||
return
|
||
"CanObtainIncreaseCount",
|
||
"NowCanSelectIncrease",
|
||
"OwnedIncrease"
|
||
end
|
||
|
||
function UGCPlayerController:OnRep_CanObtainIncreaseCount()
|
||
if UGCEventSystem then
|
||
UGCEventSystem.SendEvent(EventEnum.UpdateCanObtainIncreaseCount, self, self.CanObtainIncreaseCount)
|
||
end
|
||
end
|
||
|
||
function UGCPlayerController:OnRep_NowCanSelectIncrease()
|
||
if UGCEventSystem then
|
||
UGCEventSystem.SendEvent(EventEnum.UpdateNowCanSelectIncrease, self, self.NowCanSelectIncrease)
|
||
end
|
||
end
|
||
|
||
function UGCPlayerController:OnRep_OwnedIncrease()
|
||
if UGCEventSystem then
|
||
UGCEventSystem.SendEvent(EventEnum.UpdateOwnedIncrease, self, self.OwnedIncrease)
|
||
end
|
||
end
|
||
|
||
-- Replicated End ---------------------------------------------------------------------------------------------------
|
||
|
||
function UGCPlayerController:ReceiveBeginPlay()
|
||
self.SuperClass.ReceiveBeginPlay(self);
|
||
require("Script.Global.WidgetManager.WidgetManager")
|
||
|
||
-- 不要自动切换相机
|
||
self.bAutoManageActiveCameraTarget = false
|
||
|
||
self.OnPlayerTeamIDChanged:Add(self.PlayerTeamIDChanged, self)
|
||
if self:HasAuthority() then
|
||
-- 更新出生点位置
|
||
self:UpdatePlayerStartType()
|
||
self.PlayerControllerRespawnedDelegate:AddInstance(self.ServerRespawnPlayer, self)
|
||
else
|
||
TipConfig.Init(self)
|
||
WidgetManager:Init(WidgetConfig.PlayModeUI)
|
||
self:ShowDefaultUI()
|
||
UGCEventSystem.AddListener(EventEnum.GameStateChange, self.GameStateChange, self)
|
||
UGCEventSystem.AddListener(EventEnum.PlayerDeathInfo, self.CameraMoveToKiller, self)
|
||
UGCEventSystem.AddListener(ArchiveDataConfig.GetParamNotifyEvent(ArchiveDataConfig.EArchiveType.NumberOfPlays), self.ShowFirstPlayWidget, self)
|
||
self:ShowFirstPlayWidget()
|
||
UGCLogSystem.Log("[UGCPlayerController_ReceiveBeginPlay] Finish")
|
||
self.PlayerControllerRespawnedDelegate:AddInstance(self.ShowRespawnWidget, self)
|
||
|
||
|
||
|
||
-- self:ShowNowGameStateTypeUI()
|
||
|
||
end
|
||
|
||
end
|
||
|
||
function UGCPlayerController:ServerRespawnPlayer()
|
||
UGCLogSystem.Log("[UGCPlayerController_ServerRespawnPlayer]")
|
||
|
||
-- 更新背包
|
||
self:UpdatePlayerBackPack()
|
||
-- 更新增益到Pawn
|
||
-- self:UpdateAlreadyOwnedBuffs()
|
||
|
||
-- 挑战者Buff
|
||
if UGCGameSystem.GameState:PlayerIsChallenge(self.PlayerKey) then
|
||
for i, v in pairs(ProjectConfig.ChallengeBuffs) do
|
||
BuffSystemAPI.PlayerAddBuff(self.Pawn, v)
|
||
end
|
||
end
|
||
end
|
||
|
||
function UGCPlayerController:AddMagnifyingGlass()
|
||
self.AddMagnifyingGlassHandle = nil
|
||
if UE.IsValid(self.Pawn) then
|
||
for i, ItemInfo in pairs(WeaponSelectionCombinationConfig.MagnifyingGlass) do
|
||
UGCLogSystem.Log("[UGCPlayerController_AddMagnifyingGlass] ItemID:%s, ItemCount:%s", tostring(ItemInfo.ItemID), tostring(ItemInfo.Count))
|
||
UGCBackPackSystem.AddItem(self.Pawn, ItemInfo.ItemID, ItemInfo.Count)
|
||
end
|
||
end
|
||
end
|
||
|
||
function UGCPlayerController:UpdatePlayerBackPack()
|
||
|
||
self.DefaultBackPack = TableHelper.DeepCopy(UGCGameSystem.GameState:GetPlayerBeBornParts(self.PlayerKey))
|
||
-- 默认装备
|
||
UGCGameSystem.GameState:PlayerAddItemInfo(self.PlayerKey, self.DefaultBackPack)
|
||
-- 默认武器
|
||
UGCGameSystem.GameState:UpdatePlayerWeapon(self.PlayerKey)
|
||
|
||
UGCLogSystem.LogTree("[UGCPlayerController_UpdatePlayerBackPack] DefaultBackPack:", self.DefaultBackPack)
|
||
|
||
UGCEventSystem.SetTimer(self, function()
|
||
if UE.IsValid(self.Pawn) then
|
||
self.Pawn:SetAllWeaponBulletNumToMaxOnServer(true, false)
|
||
for i, v in pairs(ShootWeaponEnums) do
|
||
local Weapon = UGCWeaponManagerSystem.GetWeaponBySlot(self.Pawn, v)
|
||
if UE.IsValid(Weapon) then
|
||
UGCGunSystem.EnableClipInfiniteBullets(Weapon, true)
|
||
local MaxBulletNumInOneClip = UGCGunSystem.GetMaxBulletNumInOneClip(Weapon)
|
||
Weapon:SetCurrentBulletNumInClipOnServer(MaxBulletNumInOneClip, true)
|
||
-- 玩家离开换弹状态
|
||
UGCPawnSystem.LeavePawnState(self.Pawn, EPawnState.Roload)
|
||
end
|
||
end
|
||
end
|
||
end, 3)
|
||
end
|
||
|
||
function UGCPlayerController:PlayerTeamIDChanged(Controller)
|
||
local TeamID = UGCPlayerControllerSystem.GetTeamID(Controller)
|
||
UGCLogSystem.Log("[UGCPlayerController_PlayerTeamIDChanged] TeamID:%s", tostring(TeamID))
|
||
UGCEventSystem.SendEvent(EventEnum.PlayerTeamChange, Controller, TeamID)
|
||
end
|
||
|
||
function UGCPlayerController:UpdatePlayerStartType()
|
||
if self.UpdatePlayerStartCount == nil then
|
||
self.UpdatePlayerStartCount = 1
|
||
else
|
||
self.UpdatePlayerStartCount = 1 + self.UpdatePlayerStartCount
|
||
end
|
||
local TeamID = UGCPlayerControllerSystem.GetTeamID(self)
|
||
UGCLogSystem.Log("[UGCPlayerController_UpdatePlayerStartType] TeamID:%s, UpdatePlayerStartCount:%s", tostring(TeamID), tostring(self.UpdatePlayerStartCount))
|
||
if TeamID > 0 then
|
||
if TeamID == 1 then
|
||
self:SetStartPointType(EPlayerStartType.Team1)
|
||
UGCLogSystem.Log("[UGCPlayerController_UpdatePlayerStartType] 1")
|
||
else
|
||
self:SetStartPointType(EPlayerStartType.Team2)
|
||
UGCLogSystem.Log("[UGCPlayerController_UpdatePlayerStartType] 2")
|
||
end
|
||
UGCSystemLibrary.RespawnPlayer(self.PlayerKey)
|
||
else
|
||
self:SetStartPointType(EPlayerStartType.Team1)
|
||
UGCEventSystem.SetTimer(self, self.UpdatePlayerStartType, 0.1)
|
||
end
|
||
end
|
||
|
||
-- 判断显示拍脸图
|
||
function UGCPlayerController:ShowFirstPlayWidget()
|
||
UGCLogSystem.Log("[UGCPlayerController_ShowFirstPlayWidget] PlayerKey:%s", tostring(self.PlayerKey))
|
||
local PlayNumber = ArchiveDataConfig.GetPlayerArchiveDataFromType(self.PlayerKey, ArchiveDataConfig.EArchiveType.NumberOfPlays)
|
||
if PlayNumber and PlayNumber <= 1 then
|
||
UGCLogSystem.Log("[UGCPlayerController_ShowFirstPlayWidget] PlayNumber:%s", tostring(PlayNumber))
|
||
|
||
for i, v in pairs(WidgetConfig.FirstPlayWidget) do
|
||
WidgetManager:ShowPanel(v, false)
|
||
end
|
||
end
|
||
end
|
||
|
||
function UGCPlayerController:ShowRespawnWidget()
|
||
UGCLogSystem.Log("[UGCPlayerController_ShowRespawnWidget]")
|
||
-- 客户端显示重选武器按键
|
||
WidgetManager:ShowPanel(WidgetConfig.EUIType.ReselectWeaponBtn, false)
|
||
-- 海岛工程会重生小地图会显示错误 这里刷新一下
|
||
UGCGameSystem.GameState:LoadNowMiniMap()
|
||
end
|
||
|
||
-- 显示默认UI
|
||
function UGCPlayerController:ShowDefaultUI()
|
||
for i, UIType in pairs(WidgetConfig.DefaultShowWidget) do
|
||
WidgetManager:ShowPanel(UIType, false)
|
||
end
|
||
end
|
||
|
||
-- 游戏模式改变
|
||
function UGCPlayerController:GameStateChange(NewGameStateType)
|
||
if NewGameStateType == CustomEnum.EGameState.End or NewGameStateType == CustomEnum.EGameState.InsufficientNumberOfPeople then
|
||
-- 移除不可显示UI
|
||
UGCLogSystem.Log("[UGCPlayerController_GameStateChange]")
|
||
WidgetManager:DestroyPanel(WidgetConfig.EUIType.InvincibleTime)
|
||
WidgetManager:DestroyPanel(WidgetConfig.EUIType.WaitingTime)
|
||
end
|
||
-- self:ShowNowGameStateTypeUI()
|
||
end
|
||
|
||
function UGCPlayerController:Client_PlayerIsFirstTimePlaying()
|
||
if self:HasAuthority() then return end
|
||
UGCLogSystem.Log("[UGCGameState_Client_PlayerIsFirstTimePlaying]")
|
||
if WidgetManager.Initialized == false then
|
||
self.NeedExePlayerIsFirstTimePlaying = true
|
||
else
|
||
self:PlayerIsFirstTimePlaying()
|
||
end
|
||
end
|
||
|
||
|
||
|
||
function UGCPlayerController:CameraMoveToKiller(VictimKey, CauserKey)
|
||
if GlobalConfigs.GameSetting.EnableLerpCamera and VictimKey == self.PlayerKey then
|
||
local TrackCamera = UGCSystemLibrary.GetUniqueInstanceFromPath(UGCGameSystem.GetUGCResourcesFullPath('Asset/Blueprint/SceneActor/BP_TrackKillerCamera.BP_TrackKillerCamera_C'))
|
||
if UE.IsValid(TrackCamera) then
|
||
self:SetViewTargetWithBlend(TrackCamera, 0.,EViewTargetBlendFunction.VTBlend_Linear, 0., false);
|
||
UGCLogSystem.Log("[UGCPlayerController_CameraMoveToKiller] Succeed")
|
||
else
|
||
UGCLogSystem.LogError("[UGCPlayerController_CameraMoveToKiller] TrackCamera is nil")
|
||
end
|
||
end
|
||
end
|
||
|
||
|
||
|
||
--- 设置玩家的出生点类型
|
||
function UGCPlayerController:SetStartPointType(InStartPointType)
|
||
self.StartPointType = InStartPointType
|
||
end
|
||
|
||
--- 获取玩家的出生点类型
|
||
function UGCPlayerController:GetStartPointType()
|
||
if self.StartPointType == nil then
|
||
self.StartPointType = EPlayerStartType.Default
|
||
end
|
||
return self.StartPointType
|
||
end
|
||
|
||
--- 商城注册
|
||
function UGCPlayerController:Server_OnUGCCommodityPlayerDataReady()
|
||
UGCLogSystem.Log("[UGCPlayerController_Server_OnUGCCommodityPlayerDataReady]")
|
||
--注册了名为PlacementModeConfig.PlacingAttr.GoldBrickName的协议,用于购买9000001号商品(商品表已配置该商品),单次购买数量为1
|
||
--UGCCommoditySystem.RegBuyCMD(PlacementModeConfig.PlacingAttr.GoldBrickName, 9000000, 100)
|
||
UGCLogSystem.Log("[UGCPlayerController_Server_OnUGCCommodityPlayerDataReady] Finish")
|
||
end
|
||
|
||
-- 临时存储玩家的增幅 和 战神进度-------------------------------------------------
|
||
function UGCPlayerController:SetOwnedIncrease(InOwnedIncrease)
|
||
self.OwnedIncrease = InOwnedIncrease
|
||
end
|
||
|
||
function UGCPlayerController:GetOwnedIncrease()
|
||
if self.OwnedIncrease then
|
||
return self.OwnedIncrease
|
||
else
|
||
return {}
|
||
end
|
||
end
|
||
|
||
-- -----------------------------------------------------------------------------
|
||
|
||
function UGCPlayerController:UpdateAlreadyOwnedBuffs()
|
||
if UE.IsValid(self.Pawn) then
|
||
for IncreaseType, Level in pairs(self.OwnedIncrease) do
|
||
BuffSystemAPI.PlayerAddBuff(self.Pawn, GodOfWarConfig.BuffList[IncreaseType][Level])
|
||
end
|
||
end
|
||
end
|
||
|
||
--- 获取可获得增量次数的数值
|
||
function UGCPlayerController:GetCanObtainIncreaseCount()
|
||
if self.CanObtainIncreaseCount then
|
||
return self.CanObtainIncreaseCount
|
||
else
|
||
return 0
|
||
end
|
||
end
|
||
--- 设置可获得增量次数的数值
|
||
function UGCPlayerController:SetCanObtainIncreaseCount(InCanObtainIncreaseCount)
|
||
self.CanObtainIncreaseCount = InCanObtainIncreaseCount
|
||
end
|
||
--- 获取当前可选择增量类型的列表
|
||
function UGCPlayerController:GetNowCanSelectIncrease()
|
||
if self.NowCanSelectIncrease then
|
||
return self.NowCanSelectIncrease
|
||
else
|
||
return {}
|
||
end
|
||
end
|
||
--- 设置当前可选择增量类型的列表
|
||
function UGCPlayerController:SetNowCanSelectIncrease(InNowCanSelectIncrease)
|
||
self.NowCanSelectIncrease = InNowCanSelectIncrease
|
||
end
|
||
|
||
--- 增加可选增益层数
|
||
function UGCPlayerController:AddCanObtainIncreaseCount()
|
||
-- 判断增益是否满了
|
||
if self.IncreaseIsFull then return end
|
||
if self.CanObtainIncreaseCount > 0 then
|
||
self.CanObtainIncreaseCount = self.CanObtainIncreaseCount + 1
|
||
else
|
||
self.CanObtainIncreaseCount = 1
|
||
self:UpdateNowCanSelectIncrease()
|
||
end
|
||
end
|
||
|
||
|
||
--- 玩家选择增益
|
||
function UGCPlayerController:PlayerSelectIncrease(SelectIndex)
|
||
if self.CanObtainIncreaseCount > 0 and SelectIndex > 0 and SelectIndex <= GodOfWarConfig.CanSelectIncreaseCount then
|
||
-- 给予玩家增幅
|
||
if self:PlayerAddIncrease(self.NowCanSelectIncrease[SelectIndex]) then
|
||
self.CanObtainIncreaseCount = self.CanObtainIncreaseCount - 1
|
||
if self.CanObtainIncreaseCount > 0 then
|
||
self:UpdateNowCanSelectIncrease()
|
||
else
|
||
self.NowCanSelectIncrease = {}
|
||
end
|
||
end
|
||
end
|
||
end
|
||
|
||
|
||
|
||
--- 玩家获得增益
|
||
function UGCPlayerController:PlayerAddIncrease(InIncreaseType)
|
||
UGCLogSystem.Log("[UGCPlayerController_PlayerAddIncrease] InIncreaseType:%s", tostring(InIncreaseType))
|
||
if self.OwnedIncrease[InIncreaseType] == nil then
|
||
self.OwnedIncrease[InIncreaseType] = 0
|
||
end
|
||
if #GodOfWarConfig.BuffList[InIncreaseType] > self.OwnedIncrease[InIncreaseType] then
|
||
self.OwnedIncrease[InIncreaseType] = self.OwnedIncrease[InIncreaseType] + 1
|
||
local TargetPawn = UGCGameSystem.GetPlayerPawnByPlayerKey(self.PlayerKey)
|
||
if UE.IsValid(TargetPawn) then
|
||
if self.OwnedIncrease[InIncreaseType] > 1 then
|
||
-- 移除上一级增幅
|
||
BuffSystemAPI.PlayerRemoveBuffFromBuffAssetType(TargetPawn, GodOfWarConfig.BuffList[InIncreaseType][self.OwnedIncrease[InIncreaseType] - 1], 1)
|
||
end
|
||
local UseBuffRes = BuffSystemAPI.PlayerAddBuff(TargetPawn, GodOfWarConfig.BuffList[InIncreaseType][self.OwnedIncrease[InIncreaseType]])
|
||
-- 播放特效
|
||
ParticleConfig.ClientAddParticleAttachPlayer(self.PlayerKey, TargetPawn, ParticleConfig.EParticleType.AddBuff)
|
||
UGCLogSystem.Log("[UGCPlayerController_PlayerAddIncrease] UseBuffRes:%s", tostring(UseBuffRes))
|
||
end
|
||
return true
|
||
end
|
||
return false
|
||
end
|
||
|
||
--- 更新当前可选增益
|
||
function UGCPlayerController:UpdateNowCanSelectIncrease()
|
||
UGCLogSystem.Log("[UGCPlayerController_UpdateNowCanSelectIncrease]")
|
||
local PlayerCanAddIncrease = {}
|
||
for i, IncreaseType in pairs(GodOfWarConfig.EIncreaseType) do
|
||
if self.OwnedIncrease[IncreaseType] == nil or #GodOfWarConfig.BuffList[IncreaseType] > self.OwnedIncrease[IncreaseType] then
|
||
PlayerCanAddIncrease[#PlayerCanAddIncrease + 1] = IncreaseType
|
||
end
|
||
end
|
||
if #PlayerCanAddIncrease > 0 then
|
||
table.Shuffle(PlayerCanAddIncrease)
|
||
UGCLogSystem.LogTree("[UGCPlayerController_UpdateNowCanSelectIncrease] PlayerCanAddIncrease:", PlayerCanAddIncrease)
|
||
for i = 0, GodOfWarConfig.CanSelectIncreaseCount - 1 do
|
||
self.NowCanSelectIncrease[i + 1] = PlayerCanAddIncrease[(i % #PlayerCanAddIncrease) + 1]
|
||
end
|
||
UGCLogSystem.LogTree("[UGCPlayerController_UpdateNowCanSelectIncrease] NowCanSelectIncrease:", self.NowCanSelectIncrease)
|
||
else
|
||
-- 已满
|
||
self.NowCanSelectIncrease = {}
|
||
self.CanObtainIncreaseCount = 0
|
||
self.IncreaseIsFull = true
|
||
end
|
||
end
|
||
|
||
|
||
|
||
--- 获取玩家拥有增效的等级
|
||
function UGCPlayerController:GetOwnedIncreaseLevel(InIncreaseType)
|
||
return self.OwnedIncrease[InIncreaseType] and self.OwnedIncrease[InIncreaseType] or 0
|
||
end
|
||
|
||
function UGCPlayerController:GetAllOwnedIncreaseLevel()
|
||
return self.OwnedIncrease
|
||
end
|
||
|
||
-- 临时存储玩家的增幅 End ---------------------------------------------
|
||
|
||
function UGCPlayerController:GetAvailableServerRPCs()
|
||
return
|
||
"Client_PlayerIsFirstTimePlaying"
|
||
end
|
||
|
||
return UGCPlayerController; |