185 lines
6.8 KiB
Lua
185 lines
6.8 KiB
Lua
|
---@class UGCPlayerPawn_C:BP_UGCPlayerPawn_C
|
|||
|
---@field ShapeMesh UStaticMeshComponent
|
|||
|
---@field ShapeTransformCollision UCapsuleComponent
|
|||
|
---@field ShapeTransformation UShapeTransformationComponent
|
|||
|
---@field SpringArm USpringArmComponent
|
|||
|
---@field BigCamera UCameraComponent
|
|||
|
--Edit Below--
|
|||
|
---@type UGCPlayerPawn_C
|
|||
|
local UGCPlayerPawn = {};
|
|||
|
|
|||
|
function UGCPlayerPawn:ReceiveBeginPlay()
|
|||
|
self.SuperClass.ReceiveBeginPlay(self);
|
|||
|
|
|||
|
self.bVaultIsOpen = DefaultSettings.OpenVault;
|
|||
|
self.IsOpenShovelAbility = DefaultSettings.OpenShovel;
|
|||
|
|
|||
|
-- 因为无敌时间是 2 s,因此设置为 1.3 s
|
|||
|
UGCEventSystem.SetTimer(self, function() self:InitPawn(); end, 1);
|
|||
|
end
|
|||
|
|
|||
|
--function UGCPlayerPawn:ReceiveTick(DeltaTime)
|
|||
|
-- self.SuperClass.ReceiveTick(self, DeltaTime);
|
|||
|
--end
|
|||
|
|
|||
|
function UGCPlayerPawn:ReceiveEndPlay()
|
|||
|
self.SuperClass.ReceiveEndPlay(self);
|
|||
|
if GlobalTickTool then GlobalTickTool:RemoveTick(self) end
|
|||
|
end
|
|||
|
|
|||
|
--function UGCPlayerPawn:GetReplicatedProperties()
|
|||
|
-- return
|
|||
|
--end
|
|||
|
|
|||
|
function UGCPlayerPawn:GetAvailableServerRPCs()
|
|||
|
return "ReplacePartId"
|
|||
|
, "OnPlayerShoot"
|
|||
|
, "OnWeaponBulletHit"
|
|||
|
end
|
|||
|
|
|||
|
function UGCPlayerPawn:ReceivePossessed(NewController)
|
|||
|
self.SuperClass.ReceivePossessed(self, NewController);
|
|||
|
table.func(MiniGameManager, "OnPlayerPossessed", self, NewController);
|
|||
|
end
|
|||
|
|
|||
|
function UGCPlayerPawn:InitPawn()
|
|||
|
table.func(MiniGameManager, "OnPawnInit", self);
|
|||
|
if IsServer then
|
|||
|
self:EnablePickUp(DefaultSettings.EnableAutoPickUp);
|
|||
|
---@type PlayerKDAItem1
|
|||
|
self:AddInitItems();
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
---@return bool 是否开启掉落盒子
|
|||
|
function UGCPlayerPawn:IsSkipSpawnDeadTombBox(EventInstigater) return DefaultSettings.EnableDeadBox; end
|
|||
|
|
|||
|
--- 服务器/客户端收到伤害数据
|
|||
|
---@param Damage float
|
|||
|
---@param DamageType UDamageType
|
|||
|
---@param InstigatedBy UGCPlayerController_C
|
|||
|
---@param DamageCauser AActor
|
|||
|
function UGCPlayerPawn:BPReceiveDamage(Damage, DamageType, InstigatedBy, DamageCauser)
|
|||
|
table.func(MiniGameManager, "BPReceiveDamage", self, Damage, DamageType, EventInstigator, Causer);
|
|||
|
if Damage > 0 then
|
|||
|
UGCEventSystem.SendEvent(EventTypes.PlayerInjury, self.PlayerKey, UE.IsValid(InstigatedBy) and InstigatedBy.PlayerKey or nil, Damage)
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
--- 武器攻击到什么东西的时候
|
|||
|
---@param ShootWeapon ASTExtraShootWeapon
|
|||
|
---@param Bullet ASTExtraShootWeaponBulletBase
|
|||
|
---@param HitInfo FHitResult
|
|||
|
function UGCPlayerPawn:UGC_WeaponBulletHitEvent(ShootWeapon, Bullet, HitInfo)
|
|||
|
self.SuperClass.UGC_WeaponBulletHitEvent(self, ShootWeapon, Bullet, HitInfo);
|
|||
|
MiniGameManager:OnWeaponBulletHit(self, ShootWeapon, Bullet, HitInfo);
|
|||
|
end
|
|||
|
|
|||
|
---@param ShootWeapon ASTExtraShootWeapon
|
|||
|
---@param Bullet ASTExtraShootWeaponBulletBase
|
|||
|
function UGCPlayerPawn:UGC_WeaponShootBulletEvent(ShootWeapon, Bullet)
|
|||
|
self.SuperClass.UGC_WeaponShootBulletEvent(self, ShootWeapon, Bullet);
|
|||
|
UGCLogSystem.Log("[UGCPlayerPawn:UGC_WeaponShootBulletEvent] 执行")
|
|||
|
-- 发送 RPC
|
|||
|
UnrealNetwork.CallUnrealRPC(self:GetPlayerControllerSafety(), self, "OnPlayerShoot", ShootWeapon, Bullet:GetShootID());;
|
|||
|
self:OnPlayerShoot(ShootWeapon, Bullet:GetShootID());
|
|||
|
end
|
|||
|
|
|||
|
function UGCPlayerPawn:OnPlayerShoot(ShootWeapon, BulletID)
|
|||
|
MiniGameManager:OnPlayerShoot(self, ShootWeapon, BulletID);
|
|||
|
end
|
|||
|
|
|||
|
---@param InVal float
|
|||
|
function UGCPlayerPawn:SetMaxHealth(InVal)
|
|||
|
local CurrMax = UGCPawnAttrSystem.GetHealthMax(self);
|
|||
|
local NextMax = InVal * 100;
|
|||
|
if CurrMax == NextMax then return ; end
|
|||
|
local Health = UGCPawnAttrSystem.GetHealth(self)
|
|||
|
local NextHealth = NextMax / CurrMax * Health;
|
|||
|
UGCPawnAttrSystem.SetHealthMax(self, NextMax);
|
|||
|
UGCPawnAttrSystem.SetHealth(self, NextHealth);
|
|||
|
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, ...);
|
|||
|
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
|
|||
|
|
|||
|
--- 当玩家获取武器之后执行
|
|||
|
---@param Weapon ASTExtraWeapon
|
|||
|
function UGCPlayerPawn:OnPostGetWeapon(Weapon)
|
|||
|
table.func(MiniGameManager, "OnPlayerGetWeapon", self, Weapon)
|
|||
|
end
|
|||
|
|
|||
|
--- 替换配件
|
|||
|
---@param InPartId int32
|
|||
|
---@param InType EWeaponPartType
|
|||
|
function UGCPlayerPawn:ReplacePartId(InPartId, InType)
|
|||
|
UGCLogSystem.Log("[UGCPlayerPawn:ReplacePartId] 替换 InPartId = %d", InPartId);
|
|||
|
-- 移除当前
|
|||
|
local Weapon = UGCWeaponManagerSystem.GetCurrentWeapon(self);
|
|||
|
if Weapon == nil then return ; end
|
|||
|
if not ItemTool.IsShootWeapon(Weapon) then return ; 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) end
|
|||
|
local PS = UGCGameSystem.GetPlayerStateByPlayerKey(self.PlayerKey);
|
|||
|
if UE.IsValid(PS) then
|
|||
|
PS:UpdateWeaponAttachment(self, Weapon);
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
return UGCPlayerPawn;
|