UGCProjects/OneShotKill/Script/Blueprint/UGCPlayerController.lua

446 lines
17 KiB
Lua
Raw Normal View History

2025-01-04 23:00:19 +08:00
---@class UGCPlayerController_C:BP_UGCPlayerController_C
--Edit Below--
---@type UGCPlayerController_C
local UGCPlayerController = {
NeedExePlayerIsFirstTimePlaying = false;
-- 成神进度
ToGodSchedule = 0;
-- 可获得的增益次数
CanObtainIncreaseCount = 0;
-- 当前可选择的增益
NowCanSelectIncrease = {};
-- 拥有的增益
OwnedIncrease = {}; -- [IncreaseType] = Level
-- 增益已满
IncreaseIsFull = false;
-- 是否为战神
IsGodOfWar = false;
};
-- Replicated -------------------------------------------------------------------------------------------------------
function UGCPlayerController:GetReplicatedProperties()
return
"ToGodSchedule",
"CanObtainIncreaseCount",
"NowCanSelectIncrease",
"OwnedIncrease",
"IsGodOfWar"
end
function UGCPlayerController:OnRep_ToGodSchedule()
if UGCEventSystem then
UGCEventSystem.SendEvent(EventEnum.UpdateToGodSchedule, self, self.ToGodSchedule)
end
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: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.ShowFirstPlayWidget, self)
self:ShowFirstPlayWidget()
UGCLogSystem.Log("[UGCPlayerController_ReceiveBeginPlay] Finish")
self.PlayerControllerRespawnedDelegate:AddInstance(self.ShowRespawnWidget, self)
end
end
function UGCPlayerController:ServerRespawnPlayer()
UGCLogSystem.Log("[UGCPlayerController_ServerRespawnPlayer] PlayerKey:%s", tostring(self.PlayerKey))
-- 更新背包
self:UpdatePlayerBackPack()
---- 更新增益到Pawn
self:UpdateAlreadyOwnedBuffs()
---- 增加一个增益
--self:AddCanObtainIncreaseCount()
UGCLogSystem.Log("[UGCPlayerController_ServerRespawnPlayer] Finish")
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]")
-- 客户端显示重生的UI
for i, v in pairs(WidgetConfig.PlayerRespawnShowWidget) do
WidgetManager:ShowPanel(v, false)
end
end
-- 显示默认UI
function UGCPlayerController:ShowDefaultUI()
for i, v in pairs(WidgetConfig.DefaultShowWidget) do
WidgetManager:ShowPanel(v, false)
end
end
-- 游戏模式改变
function UGCPlayerController:GameStateChange(NewGameStateType)
if NewGameStateType == CustomEnum.EGameState.End or NewGameStateType == CustomEnum.EGameState.InsufficientNumberOfPeople then
-- 移除不可显示UI
end
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:SetToGodSchedule(InToGodSchedule)
self.ToGodSchedule = InToGodSchedule
if self:PlayerIsGod() and self.ToGodSchedule < GodOfWarConfig.ToGodCondition then
self.IsGodOfWar = false
end
end
--- 判断玩家是否为战神
function UGCPlayerController:PlayerIsGod()
return self.IsGodOfWar
end
--- 增加成神进度
function UGCPlayerController:AddToGodSchedule(AddCount)
-- 关闭延迟检测战神参数
if self.CheckToGodScheduleHandle then
UGCEventSystem.StopTimer(self.CheckToGodScheduleHandle)
self.CheckToGodScheduleHandle = nil
end
if AddCount == nil then AddCount = 0 end
self.ToGodSchedule = self.ToGodSchedule + AddCount
UGCLogSystem.Log("[UGCPlayerController_AddToGodSchedule] AddCount:%s, ToGodSchedule:%s", tostring(AddCount), tostring(self.ToGodSchedule))
if self.ToGodSchedule >= GodOfWarConfig.ToGodCondition and not self:PlayerIsGod() then
local SelfPawn = UGCSystemLibrary.GetAlivePlayerPawnByPlayerKey(self.PlayerKey)
if UE.IsValid(SelfPawn) then
local UseBuffRes = BuffSystemAPI.PlayerAddBuff(SelfPawn, GodOfWarConfig.GodOfWarBuff)
UGCLogSystem.Log("[AddToGodSchedule_AddToGodSchedule] Finish UseBuffRes:%s", tostring(UseBuffRes))
UGCSendRPCSystem.ActorRPCNotify(nil, SelfPawn, "PlayerToGodEffect", self.PlayerKey)
self.IsGodOfWar = true
else
UGCLogSystem.Log("[UGCPlayerController_AddToGodSchedule] Pawn is not Alive. PlayerKey:%s", tostring(self.PlayerKey))
if self.CheckToGodScheduleHandle == nil then
self.CheckToGodScheduleHandle = UGCEventSystem.SetTimer(self, function()
self.CheckToGodScheduleHandle = nil
self:AddToGodSchedule()
end , 1)
end
end
end
end
function UGCPlayerController:GetToGodSchedule()
if self.ToGodSchedule then
return self.ToGodSchedule
else
return 0
end
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()
-- UGCLogSystem.Log("[UGCPlayerController_AddCanObtainIncreaseCount] PlayerKey:%s", tostring(self.PlayerKey))
-- 判断增益是否满了
if self.IncreaseIsFull then return end
if self.CanObtainIncreaseCount > 0 then
self.CanObtainIncreaseCount = self.CanObtainIncreaseCount + 1
else
self.CanObtainIncreaseCount = 1
self:UpdateNowCanSelectIncrease()
end
-- UGCLogSystem.Log("[UGCPlayerController_AddCanObtainIncreaseCount] Finish")
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:ClearPlayerIncrease()
UGCLogSystem.Log("[UGCPlayerController_ClearPlayerIncrease]")
local TargetPawn = UGCGameSystem.GetPlayerPawnByPlayerKey(self.PlayerKey)
if UE.IsValid(TargetPawn) then
for IncreaseType, Level in pairs(self.OwnedIncrease) do
BuffSystemAPI.PlayerRemoveBuffFromBuffAssetType(TargetPawn, GodOfWarConfig.BuffList[IncreaseType][Level], 1)
end
end
self.OwnedIncrease = {}
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;