286 lines
10 KiB
Lua
286 lines
10 KiB
Lua
---@class UGCPlayerPawn_C:BP_UGCPlayerPawn_C
|
|
--Edit Below--
|
|
---@type UGCPlayerPawn_C
|
|
local UGCPlayerPawn = {};
|
|
|
|
function UGCPlayerPawn:ReceiveBeginPlay()
|
|
self.SuperClass.ReceiveBeginPlay(self);
|
|
|
|
self.bVaultIsOpen = DefaultSettings.OpenVault;
|
|
|
|
self.DamageNotifyDelegate:Add(self.PlayerInjury, self)
|
|
|
|
--- 仅客户端
|
|
--self.OnCharacterShootDelegate:Add(function(Pawn, Weapon)
|
|
-- UGCLogSystem.Log("[UGCPlayerPawn:ReceiveBeginPlay] %s 开始射击", UE.GetName(Weapon));
|
|
--end, self);
|
|
|
|
--self.OnCharacterStartFireDelegate:Add(function(Pawn, Weapon)
|
|
-- UGCLogSystem.Log("[UGCPlayerPawn:ReceiveBeginPlay] Weapon = %s 开火", UE.GetName(Weapon))
|
|
--end, self)
|
|
end
|
|
|
|
--function UGCPlayerPawn:ReceiveTick(DeltaTime)
|
|
-- self.SuperClass.ReceiveTick(self, DeltaTime);
|
|
--end
|
|
|
|
function UGCPlayerPawn:ReceiveEndPlay()
|
|
if GlobalTickTool then GlobalTickTool:RemoveTickByOwner(self) end
|
|
self.SuperClass.ReceiveEndPlay(self);
|
|
end
|
|
|
|
--function UGCPlayerPawn:GetReplicatedProperties()
|
|
-- return;
|
|
--end
|
|
|
|
function UGCPlayerPawn:GetAvailableServerRPCs()
|
|
return "ReplacePartId"
|
|
end
|
|
|
|
function UGCPlayerPawn:ReceivePossessed(NewController)
|
|
self.SuperClass.ReceivePossessed(self, NewController);
|
|
UGCLogSystem.Log("[UGCPlayerPawn:ReceivePossessed] 是否可以滑铲:%s", tostring(GameState.EnableShovel));
|
|
UGCPawnSystem.DisabledPawnState(self, EPawnState.Shoveling, not GameState.EnableShovel);
|
|
table.func(MiniManager, "OnPlayerPossessed", self, NewController);
|
|
end
|
|
|
|
---@return bool 是否开启掉落盒子
|
|
function UGCPlayerPawn:IsSkipSpawnDeadTombBox(EventInstigater) return DefaultSettings.EnableDeadBox; end
|
|
|
|
----------------------------------------- 玩家伤害处理 -----------------------------------------
|
|
|
|
function UGCPlayerPawn:PreInstigatedDamage(DamageAmount, DamageEvent, DamageCauser, Victim)
|
|
UGCLogSystem.Log("[UGCPlayerPawn:PreInstigatedDamage] DamageAmount = %f", DamageAmount);
|
|
return DamageAmount;
|
|
end
|
|
|
|
---@param ShootWeapon ASTExtraShootWeapon
|
|
---@param Bullet ASTExtraShootWeaponBulletBase
|
|
function UGCPlayerPawn:UGC_WeaponShootBulletEvent(ShootWeapon, Bullet)
|
|
self.SuperClass.UGC_WeaponShootBulletEvent(self, ShootWeapon, Bullet);
|
|
end
|
|
|
|
--- 武器攻击到什么东西的时候
|
|
---@param ShootWeapon ASTExtraShootWeapon
|
|
---@param Bullet ASTExtraShootWeaponBulletBase
|
|
---@param HitInfo FHitResult
|
|
function UGCPlayerPawn:UGC_WeaponBulletHitEvent(ShootWeapon, Bullet, HitInfo)
|
|
--local HitActor = HitInfo.Actor:Get()
|
|
--if HitActor and UE.IsValid(HitActor) and UE.Is then
|
|
-- UGCLogSystem.Log("[UGCPlayerPawn:UGC_WeaponBulletHitEvent] 击中 %s", UE.GetName(HitActor));
|
|
--
|
|
--end
|
|
end
|
|
|
|
function UGCPlayerPawn:PlayerInjury(DamageInfo)
|
|
if IsServer then
|
|
local DamageData = self:GetDamageData(DamageInfo)
|
|
MiniManager:OnPlayerInjury(DamageData.VictimKey, DamageData.CauserKey, DamageData);
|
|
end
|
|
end
|
|
|
|
---@param DamageInfo FDamageInfoCollection
|
|
function UGCPlayerPawn:GetDamageData(DamageInfo)
|
|
local CauserController = DamageInfo.Instigator
|
|
local WeaponID = -1
|
|
local CauserKey = CauserController and CauserController.PlayerKey or -1
|
|
local VictimKey = self.PlayerKey
|
|
local CauserItemID = DamageInfo.CauserItemID
|
|
UGCLogSystem.LogTree(string.format("[UGCPlayerPawn:GetDamageData] DamageInfo ="), DamageInfo)
|
|
--- 近战投掷、投掷手雷
|
|
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 = VictimKey, -- 受伤者
|
|
CauserKey = CauserKey, -- 导致者
|
|
WeaponID = WeaponID, -- 武器ID
|
|
DamageType = DamageInfo.DamageType,
|
|
IsHeadShotDamage = IsHeadShotDamage, -- 暴击
|
|
--Distance = Distance, -- 距离,
|
|
Damage = DamageInfo.Damage,
|
|
};
|
|
end
|
|
|
|
-------------------------------- 玩家物品处理 --------------------------------
|
|
--- 添加物品,如果是要添加武器,可以在后面的选项进行配置,可添加选项为 是否需要添加对应的配件 武器无限子弹配置 EFillBulletType (bool&EFillBulletType | EFillBulletType)
|
|
---@param InItemId int32
|
|
---@param InItemCount int32
|
|
function UGCPlayerPawn:AddItem(InItemId, InItemCount, ...)
|
|
UGCLogSystem.Log("[UGCPlayerPawn:AddItem] InItemId = %d", InItemId);
|
|
ItemTool.AddItem(self, InItemId, InItemCount, ...);
|
|
|
|
UGCLogSystem.Log("[ItemTool.AddItem] 执行")
|
|
ItemTool.FillAllWeaponBullets(self);
|
|
UGCEventSystem.SetTimer(self, function()
|
|
UGCLogSystem.Log("[ItemTool.AddItem] 再次添加子弹")
|
|
ItemTool.FillAllWeaponBullets(self);
|
|
end, 1);
|
|
end
|
|
|
|
--- 添加初始物品
|
|
function UGCPlayerPawn:AddInitItems(Weapons)
|
|
if table.isEmpty(Weapons) then Weapons = DefaultSettings.PlayerInitEquipment end
|
|
if not table.isEmpty(Weapons) then
|
|
for i, v in pairs(Weapons) do
|
|
local ItemId = -1;
|
|
if type(v[1]) == 'string' then
|
|
local Item = EnglishNamedWeapon[v[1]]
|
|
if Item == nil then
|
|
ItemId = ItemNameTable[v[1]] == nil and ItemId or ItemNameTable[v[1]]
|
|
else
|
|
ItemId = Item.ItemId;
|
|
end
|
|
elseif type(v[1]) == 'number' then
|
|
ItemId = v[1];
|
|
end
|
|
local Params = {};
|
|
if #v > 1 then for c = 2, #v do Params[#Params + 1] = v[c]; end end
|
|
UGCLogSystem.LogTree(string.format("[UGCPlayerPawn:AddInitItems] First = %s, Params =", v[1]), Params)
|
|
if ItemId ~= -1 then self:AddItem(ItemId, table.unpackTable(Params)); end
|
|
end
|
|
end
|
|
end
|
|
|
|
---@return EFillBulletType
|
|
function UGCPlayerPawn:GetInfiniteType()
|
|
local Type = self.PlayerState:GetInfiniteType();
|
|
UGCLogSystem.Log("[UGCPlayerPawn:GetInfiniteType] Type = %s", tostring(Type))
|
|
return Type
|
|
end
|
|
|
|
---@param InType EFillBulletType
|
|
function UGCPlayerPawn:SetInfiniteType(InType)
|
|
UGCLogSystem.Log("[UGCPlayerPawn:SetInfiniteType] 执行 InType = %s", tostring(InType))
|
|
self.PlayerState:SetInfiniteType(InType);
|
|
end
|
|
|
|
---
|
|
---@param slot ESurviveWeaponPropSlot
|
|
---@overload fun(slot:ESurviveWeaponPropSlot) OnEquipWeapon
|
|
function UGCPlayerPawn:OnEquipWeapon(slot)
|
|
--UGCLogSystem.Log("[UGCPlayerPawn:OnEquipWeapon] slot = %s, ESurviveWeaponPropSlot.SWPS_HandProp = %d", tostring(slot), ESurviveWeaponPropSlot.SWPS_HandProp);
|
|
--if slot == ESurviveWeaponPropSlot.SWPS_HandProp then
|
|
-- UGCLogSystem.Log("[UGCPlayerPawn:OnEquipWeapon] 切换成拳头")
|
|
--end
|
|
local Weapon = UGCWeaponManagerSystem.GetWeaponBySlot(self, slot);
|
|
UGCEventSystem.SendEvent(EventTypes.PlayerChangeWeapon, self, slot, Weapon);
|
|
end
|
|
|
|
UGCPlayerPawn.CurrBulletNum = -1;
|
|
|
|
--- 当玩家获取武器之后执行
|
|
---@param Weapon ASTExtraShootWeapon
|
|
function UGCPlayerPawn:OnPostGetWeapon(Weapon)
|
|
table.func(MiniManager, "OnPlayerGetWeapon", self, Weapon)
|
|
|
|
--- 绑定 delegate
|
|
if ItemTool.IsShootWeapon(Weapon) then
|
|
--- 客户端
|
|
--Weapon.OnBulletNumChangeDelegate:Add(function()
|
|
-- UGCLogSystem.Log("[UGCPlayerPawn:OnPostGetWeapon] 子弹数量改变");
|
|
--end, self);
|
|
--
|
|
--Weapon.OnWeaponShootDelegate:Add(function()
|
|
-- UGCLogSystem.Log("[UGCPlayerPawn:OnPostGetWeapon] 武器开火")
|
|
--end, self);
|
|
|
|
Weapon.OnDSBulletNumChangeDelegate:Add(self.OnBulletNumChanged, self);
|
|
end
|
|
end
|
|
|
|
function UGCPlayerPawn:OnBulletNumChanged(Weapon)
|
|
local BulletCount = Weapon.CurBulletNumInClip;
|
|
if self.CurrBulletNum == -1 then self.CurrBulletNum = BulletCount; end
|
|
if self.CurrBulletNum > BulletCount then
|
|
local ItemID = Weapon:GetWeaponItemID();
|
|
table.func(MiniManager, "OnBulletNumChange", self.PlayerKey, ItemID, self.CurrBulletNum, BulletCount);
|
|
end
|
|
self.CurrBulletNum = BulletCount;
|
|
end
|
|
|
|
--- 替换配件
|
|
---@param InPartId int32
|
|
---@param InType EWeaponPartType
|
|
function UGCPlayerPawn:ReplacePartId(InPartId, InType)
|
|
UGCLogSystem.Log("[UGCPlayerPawn:ReplacePartId] 替换 InPartId = %s", tostring(InPartId));
|
|
-- 移除当前
|
|
local Weapon = UGCWeaponManagerSystem.GetCurrentWeapon(self);
|
|
if Weapon == nil or (not UE.IsValid(Weapon)) then
|
|
UGCLogSystem.Log("[UGCPlayerPawn:ReplacePartId] 不存在武器 或 武器无效");
|
|
return ;
|
|
end
|
|
|
|
local ItemID = Weapon:GetWeaponItemID();
|
|
|
|
if table.isEmpty(WeaponSuits[ItemID]) then
|
|
UGCLogSystem.Log("[UGCPlayerPawn:ReplacePartId] 武器不是 射击武器")
|
|
return ;
|
|
end
|
|
|
|
-- 找到类型
|
|
if InType == nil then InType = WeaponParts[InPartId].Type end
|
|
|
|
local DefineID = ItemTool.GetDefineIDBySocketType(Weapon, ItemTool.GetWeaponAttachmentSocketType(InType));
|
|
if DefineID then UGCBackPackSystem.DropItemByInstanceID(self, DefineID.InstanceID, 1, true); end
|
|
if InPartId ~= 0 then
|
|
ItemTool.AddItem(self, InPartId, 1);
|
|
UGCLogSystem.Log("[UGCPlayerPawn:ReplacePartId] 添加一次配件")
|
|
end
|
|
|
|
-- 查看一下当前是什么武器
|
|
if InPartId ~= 0 then
|
|
-- 检查武器上是否有这个配件
|
|
local SocketType = ItemTool.GetWeaponAttachmentSocketType(InType)
|
|
-- 检查上面是否存在
|
|
local PartDefineID = ItemTool.GetDefineIDBySocketType(Weapon, SocketType);
|
|
if PartDefineID == nil or PartDefineID.TypeSpecificID ~= InPartId then
|
|
local Times = 10;
|
|
repeat
|
|
local bSuccess = UGCBackPackSystem.AddItem(self, InPartId, 1);
|
|
Times = Times - 1;
|
|
until bSuccess or Times <= 0;
|
|
if Times <= 0 then
|
|
UGCLogSystem.Log("[UGCPlayerPawn:ReplacePartId] 还是没添加上去");
|
|
-- 输出所有已经安装过的配件
|
|
local ItemIds = ItemTool.GetWeaponParts(Weapon);
|
|
UGCLogSystem.LogTree(string.format("[UGCPlayerPawn:ReplacePartId] ItemIds ="), ItemIds);
|
|
end
|
|
UGCLogSystem.Log("[UGCPlayerPawn:ReplacePartId] 再次添加配件"); -- 这里已经有问题了
|
|
end
|
|
end
|
|
|
|
local PS = UGCGameSystem.GetPlayerStateByPlayerKey(self.PlayerKey);
|
|
table.func(PS, "UpdateWeaponAttachment", self, Weapon);
|
|
end
|
|
|
|
--- 处理飘字 客户端触发
|
|
function UGCPlayerPawn:UGC_GetDamageNumberConfigIndex(Damage, IsHeadShot, InstigatorController, DamageCauser, DamageType)
|
|
if DefaultSettings.EnableDamageText then
|
|
if InstigatorController == LocalPlayerController then
|
|
return LocalPlayerController.EnableDamageText and 0 or -1;
|
|
end
|
|
end
|
|
return -1
|
|
end
|
|
|
|
-------------------------------- 测试 --------------------------------
|
|
|
|
function UGCPlayerPawn:AddOutline()
|
|
if IsClient then
|
|
if DefaultSettings.EnableOutline then
|
|
if self.PlayerKey ~= LocalPlayerKey then
|
|
UGCLogSystem.Log("[UGCPlayerPawn:AddOutline] 尝试添加")
|
|
STExtraBlueprintFunctionLibrary.EnablePlayerAvatarOutline(self, true);
|
|
--UGCGameSystem.GameState:RegisterPostProcessMgr(self);
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
return UGCPlayerPawn; |