447 lines
17 KiB
Lua
447 lines
17 KiB
Lua
---@class UGCPlayerPawn_C:BP_UGCPlayerPawn_C
|
||
---@field P_StarAttach UParticleSystemComponent
|
||
--Edit Below--
|
||
---@type UGCPlayerPawn_C
|
||
local UGCPlayerPawn = {
|
||
|
||
-- Attr -------------------------
|
||
-- 伤害缩放
|
||
Attr_DamageScale = 1;
|
||
-- 防御缩放
|
||
Attr_DefenseScale = 1;
|
||
-- 闪避概率
|
||
Attr_Dodge = 0;
|
||
--
|
||
-- Attr End ---------------------
|
||
|
||
HasStar = false;
|
||
};
|
||
|
||
-- Replicated -------------------------------------------------------------------------------------------------------
|
||
function UGCPlayerPawn:GetReplicatedProperties()
|
||
return
|
||
"HasStar"
|
||
end
|
||
|
||
function UGCPlayerPawn:OnRep_HasStar()
|
||
self.P_StarAttach:SetActive(self.HasStar, true)
|
||
self.P_StarAttach:SetHiddenInGame(not self.HasStar)
|
||
--if self.HasStar then
|
||
-- if self.StarParticle == nil then
|
||
-- UGCLogSystem.Log("[UGCPlayerPawn_OnRep_HasStar] SpawnFX")
|
||
-- self.StarParticle = ParticleConfig.AddParticleAttachPlayer(self, ParticleConfig.EParticleType.StarAttach)
|
||
-- else
|
||
-- -- 这里是防止客户端EndPlay没调,导致没把粒子删除而是隐藏的问题
|
||
-- UGCLogSystem.Log("[UGCPlayerPawn_OnRep_HasStar] ShowFX")
|
||
-- self.StarParticle:SetHiddenInGame(false)
|
||
-- end
|
||
--else
|
||
-- if self.StarParticle then
|
||
-- self.StarParticle:SetHiddenInGame(true)
|
||
-- end
|
||
--end
|
||
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:ReceiveBeginPlay()
|
||
self.SuperClass.ReceiveBeginPlay(self);
|
||
-- 设置翻墙功能
|
||
self.bVaultIsOpen = true
|
||
-- 设置滑铲功能
|
||
self.IsOpenShovelAbility = true
|
||
|
||
-- 参数初始化
|
||
self:InitParam()
|
||
|
||
UGCEventSystem.SendEvent(EventEnum.PlayerBeginPlay, self)
|
||
|
||
if self:HasAuthority() then
|
||
self:AddEvent()
|
||
if UE.IsValid(self:GetController()) then
|
||
self:ReceivePossessed(self:GetController())
|
||
UGCLogSystem.Log("[UGCPlayerPawn_ReceiveBeginPlay] Controller Is Valid")
|
||
end
|
||
else
|
||
|
||
end
|
||
|
||
self:OtherBeginPlayLogic()
|
||
end
|
||
|
||
--- 客户端必定执行的BeginPlay
|
||
function UGCPlayerPawn:ClientMustBeExeBeginPlay()
|
||
if self.DoOnceMustBeExeBeginPlay then return end
|
||
self.DoOnceMustBeExeBeginPlay = true
|
||
self.ClientUpdatedPlayerKey = false
|
||
-- 初始化多段跳
|
||
self.JumpMaxCount = GlobalConfigs.GameSetting.JumpMaxCount
|
||
end
|
||
|
||
function UGCPlayerPawn:InitParam()
|
||
-- 初始重力设置
|
||
self:SetGravityScale(GlobalConfigs.GameSetting.GravityScale)
|
||
-- 初始化多段跳
|
||
self.JumpMaxCount = GlobalConfigs.GameSetting.JumpMaxCount
|
||
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
|
||
|
||
self:OtherPossessedLogic(NewController)
|
||
end
|
||
|
||
|
||
|
||
function UGCPlayerPawn:ReceiveTick(DeltaTime)
|
||
self.SuperClass.ReceiveTick(self, DeltaTime);
|
||
if not UGCGameSystem.IsServer() then
|
||
self:ClientMustBeExeBeginPlay()
|
||
self:UpdatePlayerKey()
|
||
end
|
||
end
|
||
|
||
function UGCPlayerPawn:ReceiveEndPlay()
|
||
self:RemoveEvent()
|
||
self:OtherEndPlayLogic()
|
||
self.SuperClass.ReceiveEndPlay(self);
|
||
end
|
||
|
||
|
||
function UGCPlayerPawn:AddEvent()
|
||
if self:HasAuthority() then
|
||
self.DeadNotifyDelegate:Add(self.PlayerDead, self)
|
||
self.DamageNotifyDelegate:Add(self.PlayerInjury, self)
|
||
else
|
||
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
|
||
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)
|
||
UGCLogSystem.LogTree("[UGCPlayerPawn_PlayerDead] DamageInfo:", UE.ToTable(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
|
||
|
||
function UGCPlayerPawn:OnDeathCallBack(DeadCharacter,Killer,DamageCauser,KillingHitInfo,KillingHitImpulseDir,KillingHitDamageTypeID,DamageTypeClass,IsHeadShotDamage)
|
||
local CauserKey = Killer and Killer.PlayerKey
|
||
local WeaponID = -1
|
||
local DamageType = EDamageType.UGCCustomDamageType + 1
|
||
UGCLogSystem.Log("[UGCPlayerPawn_TestOnDeath] PlayerKey:%s, CauserKey:%s", tostring(self.PlayerKey), tostring(CauserKey))
|
||
UGCSendRPCSystem.RPCEvent(nil, EventEnum.PlayerDeathInfo, self.PlayerKey, CauserKey, WeaponID, DamageType, IsHeadShotDamage, 0, 0)
|
||
UGCEventSystem.SendEvent(EventEnum.PlayerDeathInfo, self.PlayerKey, CauserKey, WeaponID, DamageType, IsHeadShotDamage, 0, 0)
|
||
UGCGameSystem.GameState:SetPlayerIsAlive(self.PlayerKey, nil)
|
||
end
|
||
|
||
------------------------------------------------ Delegate End ------------------------------------------------
|
||
|
||
|
||
|
||
|
||
------------------------------------------------ ModifyDamage ------------------------------------------------
|
||
---@field UGC_TakeDamageOverrideEvent:fun(Damage:float,DamageType:EDamageType,EventInstigator:AController,DamageCauser:AActor,Hit:FHitResult):float
|
||
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))
|
||
|
||
DamageAmount = DamageAmount * GlobalConfigs.GameSetting.DamageRate
|
||
|
||
return DamageAmount
|
||
end
|
||
|
||
---------------------------------------------- ModifyDamage End ----------------------------------------------
|
||
|
||
|
||
-- UGC Event -------------------------------------------------------------------------------------------------------
|
||
-- 这些事件都是官方的回调或者可重写的事件
|
||
|
||
---@field UGC_PlayerDeadEvent:fun(Killer:AController,DamageType:EDamageType)
|
||
---@field UGC_PlayerPickUpEvent:fun()
|
||
---@field UGC_LeavePawnStateEvent:fun(PawnState:EPawnState)
|
||
---@field UGC_EnterPawnStateEvent:fun(PawnState:EPawnState)
|
||
---@field UGC_CloseScopeEvent:fun()
|
||
---@field UGC_OpenScopeEvent:fun()
|
||
---@field UGC_ReloadEndEvent:fun()
|
||
---@field UGC_ReloadStartEvent:fun()
|
||
---@field UGC_WeaponSwitchEvent:fun()
|
||
---@field UGC_WeaponStopFireEvent:fun()
|
||
---@field UGC_WeaponStartFireEvent:fun(isAuto:ESTEWeaponShootType)
|
||
---@field UGC_EquipWeaponEvent:fun(Slot:ESurviveWeaponPropSlot)
|
||
---@field UGC_ChangeCurrentUsingWeaponEvent:fun(UsingWeaponSlot:ESurviveWeaponPropSlot,LastSlot:ESurviveWeaponPropSlot)
|
||
|
||
--- 子弹命中
|
||
---@field UGC_WeaponBulletHitEvent:fun(ShootWeapon:ASTExtraShootWeapon,Bullet:ASTExtraShootWeaponBulletBase,HitInfo:FHitResult)
|
||
function UGCPlayerPawn:UGC_WeaponBulletHitEvent(ShootWeapon, Bullet, HitInfo)
|
||
UGCEventSystem.SendEvent(EventEnum.BulletHitCallBack, self, ShootWeapon, Bullet, HitInfo)
|
||
end
|
||
|
||
|
||
---@field UGC_WeaponShootBulletEvent:fun(ShootWeapon:ASTExtraShootWeapon,Bullet:ASTExtraShootWeaponBulletBase)
|
||
|
||
-- UGC Event End -----------------------------------------------------------------------------------------------------
|
||
|
||
|
||
--- 处理飘字
|
||
function UGCPlayerPawn:UGC_GetDamageNumberConfigIndex(Damage, IsHeadShot, InstigatorController, DamageCauser, DamageType)
|
||
UGCLogSystem.Log("[UGCPlayerPawn_UGC_GetDamageNumberConfigIndex]")
|
||
if GlobalConfigs.GameSetting.ShowDamageNumber and InstigatorController == UGCSystemLibrary.GetLocalPlayerController() then
|
||
return 0
|
||
else
|
||
return -1
|
||
end
|
||
end
|
||
|
||
|
||
--- 播放粒子
|
||
function UGCPlayerPawn:PlayParticle(InParticleType)
|
||
ParticleConfig.AddParticleAttachPlayer(self, InParticleType)
|
||
end
|
||
|
||
|
||
-----------------------------------------------------------------------------------------------------------------------
|
||
|
||
|
||
-- Effect ------------------
|
||
---玩家获得增效的客户端显示效果
|
||
function UGCPlayerPawn:PlayerAddIncreaseEffect(InIncreaseType)
|
||
ParticleConfig.AddParticleAttachPlayer(self, ParticleConfig.EParticleType.AddBuff)
|
||
end
|
||
--- 玩家成神的客户端显示效果
|
||
function UGCPlayerPawn:PlayerToGodEffect(PlayerKey)
|
||
UGCEventSystem.SendEvent(EventEnum.AddTip, TipConfig.TipType.GodOfWarCome, PlayerKey)
|
||
if UGCSystemLibrary.GetLocalPlayerKey() == PlayerKey then
|
||
ParticleConfig.AddParticleAttachPlayer(self, ParticleConfig.EParticleType.GodOfWarSelf)
|
||
else
|
||
ParticleConfig.AddParticleAttachPlayer(self, ParticleConfig.EParticleType.GodOfWar)
|
||
end
|
||
end
|
||
|
||
--- 客户端玩家Key更新
|
||
function UGCPlayerPawn:UpdatePlayerKey()
|
||
if self.ClientUpdatedPlayerKey == false then
|
||
if self.PlayerKey and self.PlayerKey > 0 then
|
||
self.ClientUpdatedPlayerKey = true
|
||
self:Stroke()
|
||
self:OtherClientUpdatePlayerKey()
|
||
end
|
||
end
|
||
end
|
||
|
||
--- Client
|
||
--- 描边
|
||
function UGCPlayerPawn:Stroke()
|
||
if GlobalConfigs.GameSetting.EnableStroke and not UGCGameSystem.GameState:IsHuntTime() then
|
||
UGCLogSystem.Log("[UGCPlayerPawn_Stroke]PlayerKey:%s", tostring(self.PlayerKey))
|
||
if UGCGameSystem.GameState:GetPlayerTeamIDByPlayerKey(self.PlayerKey) ~= UGCGameSystem.GameState:GetPlayerTeamIDByPlayerKey(UGCSystemLibrary.GetLocalPlayerKey()) then
|
||
-- UGCGameSystem.GameState:RegisterPostProcessMgr(self)
|
||
STExtraBlueprintFunctionLibrary.EnablePlayerAvatarOutline(self, true)
|
||
UGCLogSystem.Log("[UGCPlayerPawn_Stroke] EnablePlayerAvatarOutline")
|
||
end
|
||
end
|
||
end
|
||
|
||
-- OtherLogic --------------------------------------------------------------------------------------
|
||
|
||
function UGCPlayerPawn:OtherBeginPlayLogic()
|
||
|
||
end
|
||
|
||
function UGCPlayerPawn:OtherEndPlayLogic()
|
||
if UGCGameSystem.IsServer() then
|
||
if not self.HasStar then
|
||
UGCEventSystem.RemoveListener(EventEnum.UpdatePlayerScoreData, self.CheckPlayerHasStar, self)
|
||
end
|
||
else
|
||
if self.StarParticle then
|
||
self.StarParticle:K2_DestroyComponent()
|
||
self.StarParticle = nil
|
||
end
|
||
end
|
||
end
|
||
|
||
function UGCPlayerPawn:OtherPossessedLogic(NewController)
|
||
UGCEventSystem.AddListener(EventEnum.UpdatePlayerScoreData, self.CheckPlayerHasStar, self)
|
||
end
|
||
|
||
function UGCPlayerPawn:OtherClientUpdatePlayerKey()
|
||
|
||
end
|
||
|
||
|
||
|
||
|
||
|
||
-- OtherLogic End ----------------------------------------------------------------------------------
|
||
|
||
return UGCPlayerPawn; |