339 lines
13 KiB
Lua
339 lines
13 KiB
Lua
|
---@class UGCPlayerPawn_C:BP_UGCPlayerPawn_C
|
||
|
--Edit Below--
|
||
|
---@type UGCPlayerPawn_C
|
||
|
local UGCPlayerPawn = {
|
||
|
-- Attr -------------------------
|
||
|
-- 伤害缩放
|
||
|
Attr_DamageScale = 1;
|
||
|
-- 防御缩放
|
||
|
Attr_DefenseScale = 1;
|
||
|
-- 闪避概率
|
||
|
Attr_Dodge = 0;
|
||
|
-- Attr End ---------------------
|
||
|
};
|
||
|
|
||
|
-- Replicated -------------------------------------------------------------------------------------------------------
|
||
|
function UGCPlayerPawn:GetReplicatedProperties()
|
||
|
return
|
||
|
|
||
|
end
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
-- Replicated End ---------------------------------------------------------------------------------------------------
|
||
|
|
||
|
-- Attr -------------------------------------------------------------------------------------------------------------
|
||
|
|
||
|
function UGCPlayerPawn:SetDamageScale(InDamageScale)
|
||
|
self.Attr_DamageScale = InDamageScale
|
||
|
end
|
||
|
|
||
|
function UGCPlayerPawn:GetDamageScale()
|
||
|
return self.Attr_DamageScale
|
||
|
end
|
||
|
|
||
|
function UGCPlayerPawn:SetDefenseScale(InDefenseScale)
|
||
|
-- 防御值不能小于0
|
||
|
if InDefenseScale <= 0 then return false end
|
||
|
self.Attr_DefenseScale = InDefenseScale
|
||
|
return true
|
||
|
end
|
||
|
|
||
|
function UGCPlayerPawn:GetDefenseScale()
|
||
|
return self.Attr_DefenseScale
|
||
|
end
|
||
|
|
||
|
function UGCPlayerPawn:SetDodge(InDodge)
|
||
|
self.Attr_Dodge = InDodge
|
||
|
return true
|
||
|
end
|
||
|
|
||
|
function UGCPlayerPawn:GetDodge()
|
||
|
return self.Attr_DefenseScale
|
||
|
end
|
||
|
|
||
|
-- Attr End ---------------------------------------------------------------------------------------------------------
|
||
|
|
||
|
-- 基础设置 -----------------------------------------------------------------------------------------------------------
|
||
|
--- 关闭盒子掉落
|
||
|
function UGCPlayerPawn:IsSkipSpawnDeadTombBox(EventInstigater)
|
||
|
return true
|
||
|
end
|
||
|
|
||
|
--- 处理飘字 客户端触发
|
||
|
function UGCPlayerPawn:UGC_GetDamageNumberConfigIndex(Damage, IsHeadShot, InstigatorController, DamageCauser, DamageType)
|
||
|
if GlobalConfigs.GameSetting.EnableInexactEnunciation then
|
||
|
if InstigatorController == UGCSystemLibrary.GetLocalPlayerController() then
|
||
|
return 0
|
||
|
else
|
||
|
return -1
|
||
|
end
|
||
|
end
|
||
|
return -1
|
||
|
end
|
||
|
|
||
|
-- 基础设置 End -------------------------------------------------------------------------------------------------------
|
||
|
|
||
|
function UGCPlayerPawn:ReceiveBeginPlay()
|
||
|
self.SuperClass.ReceiveBeginPlay(self);
|
||
|
--- 设置翻墙功能
|
||
|
self.bVaultIsOpen = true
|
||
|
--- 设置滑铲功能
|
||
|
self.IsOpenShovelAbility = true
|
||
|
|
||
|
UGCEventSystem.SendEvent(EventEnum.PlayerBeginPlay, self)
|
||
|
|
||
|
|
||
|
|
||
|
self:AddEvent()
|
||
|
if self:HasAuthority() then
|
||
|
if UE.IsValid(self:GetController()) then
|
||
|
self:ReceivePossessed(self:GetController())
|
||
|
UGCLogSystem.Log("[UGCPlayerPawn_ReceiveBeginPlay] Controller Is Valid")
|
||
|
end
|
||
|
else
|
||
|
|
||
|
end
|
||
|
end
|
||
|
|
||
|
--- 客户端必定执行的BeginPlay
|
||
|
function UGCPlayerPawn:ClientMustBeExeBeginPlay()
|
||
|
if self.DoOnceMustBeExeBeginPlay then return end
|
||
|
self.DoOnceMustBeExeBeginPlay = true
|
||
|
self.ClientUpdatedPlayerKey = false
|
||
|
--local MainControlPanel = UGCWidgetManagerSystem.GetMainUI()
|
||
|
--if UE.IsValid(MainControlPanel) then
|
||
|
-- MainControlPanel.MainControlBaseUI.ChangeSight_UIBP:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
||
|
-- -- MainControlPanel.MainControlBaseUI.ChangeSight_UIBP:ShowList(); --- 倍镜切换
|
||
|
--end
|
||
|
end
|
||
|
|
||
|
|
||
|
function UGCPlayerPawn:ReceivePossessed(NewController)
|
||
|
self.SuperClass.ReceivePossessed(self, NewController);
|
||
|
UGCLogSystem.Log("[UGCPlayerPawn_ReceivePossessed] PlayerKey:%s", tostring(NewController.PlayerKey))
|
||
|
UGCEventSystem.SendEvent(EventEnum.PlayerPossessed, NewController.PlayerKey)
|
||
|
UGCGameSystem.GameState:SetPlayerIsAlive(NewController.PlayerKey, self)
|
||
|
|
||
|
if UGCSystemLibrary.GetIsPreparationState() then
|
||
|
UGCSystemLibrary.SetPlayerPawnMovable(self, false)
|
||
|
end
|
||
|
|
||
|
|
||
|
end
|
||
|
|
||
|
|
||
|
|
||
|
function UGCPlayerPawn:ReceiveTick(DeltaTime)
|
||
|
self.SuperClass.ReceiveTick(self, DeltaTime);
|
||
|
if not UGCGameSystem.IsServer() then
|
||
|
self:ClientMustBeExeBeginPlay()
|
||
|
self:UpdatePlayerKey()
|
||
|
--local HeadPos = self.Mesh:GetSocketLocation("head")
|
||
|
--UGCLogSystem.Log("[UGCPlayerPawn_ReceiveTick]HeadPos:%s, ActorPos:%s", VectorHelper.ToString(HeadPos), VectorHelper.ToString(self:K2_GetActorLocation()))
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function UGCPlayerPawn:ReceiveEndPlay()
|
||
|
self:RemoveEvent()
|
||
|
self.SuperClass.ReceiveEndPlay(self);
|
||
|
end
|
||
|
|
||
|
function UGCPlayerPawn:ShowPlayerDeadEffect()
|
||
|
UGCLogSystem.Log("[UGCPlayerPawn_ShowPlayerDeadEffect]")
|
||
|
if GlobalConfigs.GameSetting.EnableDeadEffect then
|
||
|
self:SetActorHiddenInGame(true)
|
||
|
ParticleConfig.AddParticleFromPosAndRot(ParticleConfig.EParticleType.PlayerDead ,self:K2_GetActorLocation(), VectorHelper.RotZero())
|
||
|
end
|
||
|
end
|
||
|
|
||
|
|
||
|
function UGCPlayerPawn:AddEvent()
|
||
|
if self:HasAuthority() then
|
||
|
self.DeadNotifyDelegate:Add(self.PlayerDead, self)
|
||
|
self.DamageNotifyDelegate:Add(self.PlayerInjury, self)
|
||
|
else
|
||
|
self.OnDeath:Add(self.ShowPlayerDeadEffect, self)
|
||
|
--UGCEventSystem.AddListener(EventEnum.PlayerDeathInfo, self.ShowPlayerDeadEffect, self)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function UGCPlayerPawn:RemoveEvent()
|
||
|
if self:HasAuthority() then
|
||
|
self.DeadNotifyDelegate:Remove(self.PlayerDead, self)
|
||
|
self.DamageNotifyDelegate:Remove(self.PlayerInjury, self)
|
||
|
|
||
|
|
||
|
if self.CheckBornItemsHandle then
|
||
|
UGCEventSystem.StopTimer(self.CheckBornItemsHandle)
|
||
|
self.CheckBornItemsHandle = nil
|
||
|
end
|
||
|
if self.CheckWeaponAndPartsHandle then
|
||
|
UGCEventSystem.StopTimer(self.CheckWeaponAndPartsHandle)
|
||
|
self.CheckWeaponAndPartsHandle = nil
|
||
|
end
|
||
|
else
|
||
|
self.OnDeath:Remove(self.ShowPlayerDeadEffect, self)
|
||
|
-- UGCEventSystem.RemoveListener(EventEnum.PlayerDeathInfo, self.ShowPlayerDeadEffect, self)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
|
||
|
function UGCPlayerPawn:CheckWeaponAndParts()
|
||
|
UGCGameSystem.GameState:CheckWeaponAndParts(self.PlayerKey)
|
||
|
end
|
||
|
|
||
|
|
||
|
|
||
|
function UGCPlayerPawn:CheckBornItems()
|
||
|
UGCLogSystem.Log("[UGCPlayerPawn_CheckBornItems] PlayerKey:%s", tostring(self.PlayerKey))
|
||
|
UGCLogSystem.LogTree("[UGCPlayerPawn_CheckBornItems]", self.DefaultBackPack)
|
||
|
for i = #self.DefaultBackPack, 1, -1 do
|
||
|
local ItemID = self.DefaultBackPack[i].ItemID
|
||
|
local Count = self.DefaultBackPack[i].Count
|
||
|
local InstCount = UGCBackPackSystem.GetItemCount(self, ItemID)
|
||
|
if InstCount >= Count then
|
||
|
UGCLogSystem.Log("[UGCPlayerPawn_CheckBornItems] i:%s", tostring(i))
|
||
|
table.remove(self.DefaultBackPack, i)
|
||
|
UGCLogSystem.LogTree("[UGCPlayerPawn_CheckBornItems]", self.DefaultBackPack)
|
||
|
else
|
||
|
UGCBackPackSystem.AddItem(self, ItemID, Count - InstCount)
|
||
|
end
|
||
|
end
|
||
|
if #self.DefaultBackPack == 0 then
|
||
|
UGCEventSystem.StopTimer(self.CheckBornItemsHandle)
|
||
|
self.CheckBornItemsHandle = nil
|
||
|
UGCLogSystem.Log("[UGCPlayerPawn_CheckBornItems] Succeed PlayerKey:%s", tostring(self.PlayerKey));
|
||
|
end
|
||
|
end
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
-------------------------------------------------- Delegate --------------------------------------------------
|
||
|
|
||
|
---@param DamageInfo FDamageInfoCollection
|
||
|
---@return VictimKey, CauserKey, WeaponID, DamageType, IsHeadShotDamage, Distance, DamageValue uint, uint, int, EDamageType, bool, float, float
|
||
|
function UGCPlayerPawn:GetDamageInfoCollectionInfo(DamageInfo)
|
||
|
local CauserController = DamageInfo.Instigator
|
||
|
local WeaponID = -1
|
||
|
local CauserKey = CauserController and CauserController.PlayerKey or -1
|
||
|
local VictimKey = self.PlayerKey
|
||
|
local CauserItemID = DamageInfo.CauserItemID
|
||
|
--- 近战投掷、投掷手雷
|
||
|
if CauserItemID then
|
||
|
WeaponID = CauserItemID
|
||
|
end
|
||
|
UGCLogSystem.Log("[UGCPlayerPawn_GetDamageInfoCollectionInfo] WeaponID:%d", WeaponID)
|
||
|
local Distance = 0.
|
||
|
if CauserController and CauserController.Pawn then
|
||
|
Distance = VectorHelper.GetDistance(self:K2_GetActorLocation(), CauserController.Pawn:K2_GetActorLocation())
|
||
|
end
|
||
|
|
||
|
local IsHeadShotDamage = (DamageInfo.Hit.BoneName == "head")
|
||
|
return VictimKey, CauserKey, WeaponID, DamageInfo.DamageType, IsHeadShotDamage, Distance, DamageInfo.Damage
|
||
|
end
|
||
|
|
||
|
---@param DamageInfo FDamageInfoCollection
|
||
|
function UGCPlayerPawn:PlayerDead(DamageInfo)
|
||
|
local VictimKey, CauserKey, WeaponID, DamageType, IsHeadShotDamage, Distance, DamageValue = self:GetDamageInfoCollectionInfo(DamageInfo)
|
||
|
UGCSendRPCSystem.RPCEvent(nil, EventEnum.PlayerDeathInfo, VictimKey, CauserKey, WeaponID, DamageType, IsHeadShotDamage, Distance, DamageValue)
|
||
|
UGCEventSystem.SendEvent(EventEnum.PlayerDeathInfo, VictimKey, CauserKey, WeaponID, DamageType, IsHeadShotDamage, Distance, DamageValue)
|
||
|
UGCGameSystem.GameState:SetPlayerIsAlive(VictimKey, nil)
|
||
|
end
|
||
|
|
||
|
---@param DamageInfo FDamageInfoCollection
|
||
|
---@param ReturnValue float
|
||
|
function UGCPlayerPawn:PlayerInjury(DamageInfo)
|
||
|
local VictimKey, CauserKey, WeaponID, DamageType, IsHeadShotDamage, Distance, DamageValue = self:GetDamageInfoCollectionInfo(DamageInfo)
|
||
|
UGCEventSystem.SendEvent(EventEnum.PlayerInjuryInfo, VictimKey, CauserKey, WeaponID, DamageType, IsHeadShotDamage, Distance, DamageValue)
|
||
|
UGCSendRPCSystem.RPCEvent(CauserKey, EventEnum.PlayerInjuryInfo, VictimKey, CauserKey, WeaponID, DamageType, IsHeadShotDamage, Distance, DamageValue)
|
||
|
end
|
||
|
|
||
|
------------------------------------------------ Delegate End ------------------------------------------------
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
------------------------------------------------ ModifyDamage ------------------------------------------------
|
||
|
|
||
|
function UGCPlayerPawn:UGC_TakeDamageOverrideEvent(Damage, DamageType, EventInstigator, DamageCauser, Hit)
|
||
|
local DamageAmount = Damage
|
||
|
UGCLogSystem.Log("[UGCPlayerPawn_UGC_TakeDamageOverrideEvent] InDamageAmount:%s", tostring(DamageAmount))
|
||
|
if EventInstigator and EventInstigator.PlayerKey then
|
||
|
local CauserTeamID = UGCPlayerStateSystem.GetTeamID(EventInstigator.PlayerKey)
|
||
|
local SelfTeamID = UGCPlayerStateSystem.GetTeamID(self.PlayerKey)
|
||
|
|
||
|
local CauserPawn = UGCGameSystem.GetPlayerPawnByPlayerKey(EventInstigator.PlayerKey)
|
||
|
local DamageScale = CauserPawn and CauserPawn:GetDamageScale() or 1
|
||
|
|
||
|
if EventInstigator.PlayerKey == self.PlayerKey and GlobalConfigs.GameSetting.bEnableSelfHarm then
|
||
|
--- 对自己的伤害
|
||
|
DamageAmount = GlobalConfigs.GameSetting.SelfHarmInjuryRatio * DamageAmount
|
||
|
else
|
||
|
--- 伤害设置(友方、敌方)
|
||
|
DamageAmount = (CauserTeamID == SelfTeamID and GlobalConfigs.GameSetting.FriendlyInjuryRatio * DamageAmount or DamageAmount) * DamageScale / self:GetDefenseScale()
|
||
|
end
|
||
|
|
||
|
elseif DamageCauser and DamageCauser:GetOwner() then
|
||
|
UGCLogSystem.Log("[UGCPlayerPawn_UGC_TakeDamageOverrideEvent] DamageCauser:GetOwner():%s", KismetSystemLibrary.GetObjectName(DamageCauser:GetOwner()))
|
||
|
local TargetPlayerKey = DamageCauser:GetOwner().PlayerKey
|
||
|
if TargetPlayerKey then
|
||
|
local CauserTeamID = UGCPlayerStateSystem.GetTeamID(TargetPlayerKey)
|
||
|
local SelfTeamID = UGCPlayerStateSystem.GetTeamID(self.PlayerKey)
|
||
|
DamageAmount = (CauserTeamID == SelfTeamID and GlobalConfigs.GameSetting.FriendlyInjuryRatio * DamageAmount or DamageAmount)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
-- 掉落伤害
|
||
|
if DamageType == EDamageType.FallingDamage then
|
||
|
DamageAmount = GlobalConfigs.GameSetting.bEnableDropDamage and DamageAmount or 0.
|
||
|
end
|
||
|
|
||
|
if DamageType == EDamageType.MeleeDamage then
|
||
|
DamageAmount = DamageAmount * GlobalConfigs.GameSetting.MeleeDamageScale
|
||
|
end
|
||
|
|
||
|
UGCLogSystem.Log("[UGCPlayerPawn_UGC_TakeDamageOverrideEvent] ModifyDamageAmount:%s", tostring(DamageAmount))
|
||
|
return DamageAmount
|
||
|
end
|
||
|
|
||
|
---------------------------------------------- ModifyDamage End ----------------------------------------------
|
||
|
|
||
|
|
||
|
|
||
|
--- 播放粒子
|
||
|
function UGCPlayerPawn:PlayParticle(InParticleType)
|
||
|
ParticleConfig.AddParticleAttachPlayer(self, InParticleType)
|
||
|
end
|
||
|
|
||
|
function UGCPlayerPawn:UpdatePlayerKey()
|
||
|
if self.ClientUpdatedPlayerKey == false then
|
||
|
if self.PlayerKey and self.PlayerKey > 0 then
|
||
|
self.ClientUpdatedPlayerKey = true
|
||
|
UGCLogSystem.Log("[UGCPlayerPawn_UpdatePlayerKey]PlayerKey:%s", tostring(self.PlayerKey))
|
||
|
if UGCPlayerStateSystem.GetTeamID(self.PlayerKey) ~= UGCPlayerStateSystem.GetTeamID(UGCSystemLibrary.GetLocalPlayerKey()) then
|
||
|
-- UGCGameSystem.GameState:RegisterPostProcessMgr(self)
|
||
|
STExtraBlueprintFunctionLibrary.EnablePlayerAvatarOutline(self, true)
|
||
|
UGCLogSystem.Log("[UGCPlayerPawn_UpdatePlayerKey] EnablePlayerAvatarOutline")
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
|
||
|
-----------------------------------------------------------------------------------------------------------------------
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
--function UGCPlayerPawn:GetAvailableServerRPCs()
|
||
|
-- return
|
||
|
--end
|
||
|
|
||
|
|
||
|
return UGCPlayerPawn;
|