UGCProjects/BreakThrough/Script/Blueprint/UGCPlayerController.lua
2025-01-04 23:00:19 +08:00

235 lines
8.8 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

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

---@class UGCPlayerController_C:BP_UGCPlayerController_C
--Edit Below--
---@type UGCPlayerController_C
local UGCPlayerController = {
NeedExePlayerIsFirstTimePlaying = false;
bAutoShowGuide = false;
};
--function UGCPlayerController:GetReplicatedProperties()
-- return
--end
function UGCPlayerController:ReceiveBeginPlay()
self.SuperClass.ReceiveBeginPlay(self);
require("Script.Global.WidgetManager.WidgetManager")
-- 不要自动切换相机
self.bAutoManageActiveCameraTarget = false
if self:HasAuthority() then
-- 更新出生点位置
self:UpdatePlayerStartType()
self.PlayerControllerRespawnedDelegate:AddInstance(self.ServerRespawnPlayer, self)
else
TipConfig.Init(self)
WidgetManager:Init(WidgetConfig.PlayModeUI)
-- self:ShowNowGameStateTypeUI()
self:ShowDefaultUI()
UGCEventSystem.AddListener(EventEnum.GameStateChange, self.GameStateChange, self)
UGCEventSystem.AddListener(EventEnum.PlayerDeathInfo, self.CameraMoveToKiller, self)
UGCEventSystem.AddListener(ArchiveDataConfig.GetParamNotifyEvent(ArchiveDataConfig.EArchiveType.NumberOfPlays), self.ShowGuide, self)
self.PlayerControllerRespawnedDelegate:AddInstance(self.ShowRespawnWidget, self)
self:ShowGuide()
UGCLogSystem.Log("[UGCPlayerController_ReceiveBeginPlay] Finish")
end
end
function UGCPlayerController:ServerRespawnPlayer()
UGCLogSystem.Log("[UGCPlayerController_ServerRespawnPlayer] PlayerKey:%s", tostring(self.PlayerKey))
-- 更新背包
self:UpdatePlayerBackPack()
end
function UGCPlayerController:UpdatePlayerBackPack()
UGCLogSystem.Log("[UGCPlayerController_UpdatePlayerBackPack]")
-- 先给武器
UGCGameSystem.GameState:UpdatePlayerWeapon(self.PlayerKey)
-- 延迟2s给默认配置
self.DefaultBackPack = TableHelper.DeepCopy(UGCGameSystem.GameState:GetPlayerBeBornParts(self.PlayerKey))
if self.AddDefaultBackPackHandle then
UGCEventSystem.StopTimer(self.AddDefaultBackPackHandle)
end
self.AddDefaultBackPackHandle = UGCEventSystem.SetTimer(self, function()
UGCGameSystem.GameState:PlayerAddItemInfo(self.PlayerKey, self.DefaultBackPack)
self.AddDefaultBackPackHandle = nil
end, 2)
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:ShowRespawnWidget()
UGCLogSystem.Log("[UGCPlayerController_ShowRespawnWidget]")
-- 客户端显示重选武器按键
WidgetManager:ShowPanel(WidgetConfig.EUIType.ReselectWeaponBtn, false)
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
UGCGameSystem.GameState:UpdatePlayerIsAttacker(self)
--if TeamID == 1 then
-- if UGCGameSystem.GameState:GetTeam1IsAttack() then
-- self:SetStartPointType(EPlayerStartType.Attack)
-- else
-- self:SetStartPointType(EPlayerStartType.Defend)
-- end
-- UGCLogSystem.Log("[UGCPlayerController_UpdatePlayerStartType] 1")
--else
-- if UGCGameSystem.GameState:GetTeam1IsAttack() then
-- self:SetStartPointType(EPlayerStartType.Defend)
-- else
-- self:SetStartPointType(EPlayerStartType.Attack)
-- end
-- UGCLogSystem.Log("[UGCPlayerController_UpdatePlayerStartType] 2")
--end
UGCSystemLibrary.RespawnPlayer(self.PlayerKey)
else
self:SetStartPointType(EPlayerStartType.Attack)
UGCEventSystem.SetTimer(self, self.UpdatePlayerStartType, 0.1)
end
end
-- 判断显示拍脸图
function UGCPlayerController:ShowGuide()
UGCLogSystem.Log("[UGCPlayerController_ShowGuide] PlayerKey:%s", tostring(self.PlayerKey))
local PlayNumber = ArchiveDataConfig.GetPlayerArchiveDataFromType(self.PlayerKey, ArchiveDataConfig.EArchiveType.NumberOfPlays)
if PlayNumber and PlayNumber <= 1 and self.ShowOnce == nil then
self.ShowOnce = true
UGCLogSystem.Log("[UGCPlayerController_ShowGuide] PlayNumber:%s", tostring(PlayNumber))
WidgetManager:ShowPanel(WidgetConfig.EUIType.Guide, false)
end
end
-- 显示默认UI
function UGCPlayerController:ShowDefaultUI()
WidgetManager:ShowPanel(WidgetConfig.EUIType.DamageAnim, false)
-- WidgetManager:ShowPanel(WidgetConfig.EUIType.SelectBuff, false)
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:AutoShowGuide()
if self.bAutoShowGuide then
WidgetManager:ShowPanel(WidgetConfig.EUIType.Guide, false)
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:GetReplicatedProperties()
return
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:SetToGodSchedule(InToGodSchedule)
self.ToGodSchedule = InToGodSchedule
end
function UGCPlayerController:GetToGodSchedule()
if self.ToGodSchedule then
return self.ToGodSchedule
else
return 0
end
end
-- 临时存储玩家的增幅 End ---------------------------------------------
function UGCPlayerController:GetAvailableServerRPCs()
return
"Client_PlayerIsFirstTimePlaying"
end
return UGCPlayerController;