220 lines
7.8 KiB
Lua
220 lines
7.8 KiB
Lua
---@class BP_WeaponItem_C:BP_CustomItemBase_C
|
|
---@field ParticleSystem UParticleSystemComponent
|
|
---@field Scene USceneComponent
|
|
---@field StaticMesh UStaticMeshComponent
|
|
---@field ChildActor UChildActorComponent
|
|
--Edit Below--
|
|
---@type BP_CustomItemBase_C
|
|
local ItemBase = require('Script.Blueprint/SceneObj/PickUp/BP_CustomItemBase')
|
|
|
|
---@type BP_WeaponItem_C
|
|
local BP_WeaponItem = ItemBase:new(DefaultSettings.SceneObj.Weapon);
|
|
|
|
BP_WeaponItem.WrapperActor = nil;
|
|
|
|
function BP_WeaponItem:ReceiveBeginPlay()
|
|
self:LuaInit();
|
|
end
|
|
|
|
--- 玩家进入的时候会调用
|
|
function BP_WeaponItem:OnPlayerAddItem(InPawn)
|
|
if not DefaultSettings.EnableAutoPickUp then
|
|
if self.ItemId ~= 0 then
|
|
UGCPawnSystem.LeavePawnState(InPawn, EPawnState.GunReload);
|
|
ItemTool.ClearCurrentWeapon(InPawn, true);
|
|
---@type APickUpWrapperActor
|
|
--ItemTool.DropMeleeWeapon(InPawn, true);
|
|
ItemTool.AddWeaponItem(InPawn, self.ItemId, 1, true, InPawn:GetInfiniteType());
|
|
if self.ChildActor.ChildActor then self.ChildActor:DestroyChildActor(false); end
|
|
self:PostAddWeapon(InPawn);
|
|
end
|
|
else
|
|
InPawn:SetInPickUp(true, self);
|
|
end
|
|
end
|
|
|
|
---@param InPawn UGCPlayerPawn_C 玩家
|
|
---@param InWeaponId int32 武器 ID
|
|
function BP_WeaponItem:OnAutoItemUsed(InPawn, InWeaponId)
|
|
-- 在此检测一下是否存在
|
|
if InWeaponId == self.ItemId then
|
|
UGCLogSystem.Log("[BP_WeaponItem:OnAutoItemUsed] 就是我自己!!")
|
|
end
|
|
if InWeaponId == nil then InWeaponId = self.ItemId; end
|
|
if self.ChildActor.ChildActor ~= nil then self.ChildActor:DestroyChildActor(false); end
|
|
InPawn:SetInPickUp(false)
|
|
self:ReplaceWeapon(InPawn, InWeaponId);
|
|
end
|
|
|
|
function BP_WeaponItem:ReplaceWeapon(InPawn, InWeaponId)
|
|
-- 开始自主添加
|
|
local IdType = ItemTool.GetWeaponType(InWeaponId);
|
|
if IdType == EWeaponIdType.Pistol then
|
|
local Weapon = UGCWeaponManagerSystem.GetWeaponBySlot(InPawn, ESurviveWeaponPropSlot.SWPS_SubShootWeapon);
|
|
if Weapon ~= nil then ItemTool.ClearWeapon(InPawn, Weapon); end
|
|
ItemTool.AddWeaponItem(InPawn, InWeaponId, 1, true, InPawn:GetInfiniteType());
|
|
elseif IdType == EWeaponIdType.Melee then
|
|
local Weapon = UGCWeaponManagerSystem.GetWeaponBySlot(InPawn, ESurviveWeaponPropSlot.SWPS_MeleeWeapon);
|
|
if Weapon ~= nil then ItemTool.ClearWeapon(InPawn, Weapon); end
|
|
ItemTool.AddWeaponItem(InPawn, InWeaponId, 1, false);
|
|
else
|
|
local Slots = ItemTool.PawnWeaponSlots(InPawn)
|
|
UGCLogSystem.LogTree(string.format("[BP_WeaponItem:OnAutoItemUsed] Slots ="), Slots)
|
|
local bHadAllMainWeapon = table.hasValues(Slots, { ESurviveWeaponPropSlot.SWPS_MainShootWeapon1, ESurviveWeaponPropSlot.SWPS_MainShootWeapon2 })
|
|
if bHadAllMainWeapon then
|
|
local bHave, slot = ItemTool.CheckPlayerHasWeapon(InPawn, InWeaponId);
|
|
if bHave then
|
|
-- 替换一下
|
|
ItemTool.ClearWeapon(InPawn, UGCWeaponManagerSystem.GetWeaponBySlot(InPawn, slot));
|
|
else
|
|
ItemTool.ClearCurrentWeapon(InPawn, true);
|
|
end
|
|
end
|
|
--ItemTool.OnlyClearParts(InPawn)
|
|
ItemTool.AddWeaponItem(InPawn, InWeaponId, 1, true, InPawn:GetInfiniteType());
|
|
end
|
|
self:PostAddWeapon(InPawn);
|
|
end
|
|
|
|
--- 这是在拾取之后调用的函数,此时已经拾取过了,无法隔断
|
|
function BP_WeaponItem:PostAddWeapon(InPawn)
|
|
self.bCanPickUp = false;
|
|
-- 随机设置成别的
|
|
self:OnItemUsed(InPawn);
|
|
DOREPONCE(self, "bCanPickUp");
|
|
end
|
|
|
|
function BP_WeaponItem:OnPlayerOut(OtherActor)
|
|
-- 检查是否已经拾取了?
|
|
if self:IsItemIdValid() then
|
|
-- 说明玩家没有拾取
|
|
else
|
|
-- 玩家已经拾取了
|
|
self:OnItemUsed(OtherActor);
|
|
end
|
|
OtherActor:SetInPickUp(false, self)
|
|
end
|
|
|
|
function BP_WeaponItem:AutoPickUp(InPawn)
|
|
if self.ChildActor.ChildActor == nil then
|
|
self:OnItemUsed(InPawn);
|
|
--GameState:ClearWrappers();
|
|
end
|
|
end
|
|
|
|
function BP_WeaponItem:RandomNewItem()
|
|
--UGCLogSystem.Log("[BP_WeaponItem:RandomNewItem] AllWeaponCount = %d", AllWeaponCount);
|
|
if AllWeaponCount == 0 then
|
|
GetWeaponIdTable();
|
|
UGCLogSystem.LogTree(string.format("[BP_WeaponItem:RandomNewItem] AllWeaponCount = %d WeaponIdTable =", AllWeaponCount), WeaponIdTable);
|
|
end
|
|
self:SetItemId(WeaponIdTable[math.random(AllWeaponCount)]);
|
|
UGCLogSystem.Log("[BP_WeaponItem:RandomNewItem] ItemId = %d", self.ItemId);
|
|
local Path = UGCItemSystem.GetPickupWrapperClassPath(self.ItemId);
|
|
local Class = UE.LoadClass(Path)
|
|
self:RandomNewItem_Internal(Class)
|
|
--UE.AsyncLoadClass(Path, function(TargetClass)
|
|
-- self:RandomNewItem_Internal(TargetClass);
|
|
--end);
|
|
end
|
|
|
|
--- 使用 ChildActor 进行调用
|
|
function BP_WeaponItem:RandomNewItem_Internal(TargetClass)
|
|
if self.ChildActor.ChildActor ~= nil then self.ChildActor:DestroyChildActor(false); end
|
|
UGCLogSystem.Log("[BP_WeaponItem:RandomNewItem] TargetClass = %s", UE.GetName(TargetClass));
|
|
self.ChildActor:SetChildActorClass(TargetClass);
|
|
self.ChildActor:CreateChildActor();
|
|
if self.ChildActor.ChildActor then
|
|
self.ChildActor.ChildActor:SetOwner(self);
|
|
self.WrapperActor = self.ChildActor.ChildActor;
|
|
|
|
if self.WrapperActor.UGC_PickUpWrapperDestroyDelegate then
|
|
self.WrapperActor.UGC_PickUpWrapperDestroyDelegate:Add(self.OnPickedUp, self);
|
|
end
|
|
end
|
|
self:SetCanPickUp(true);
|
|
self:SetChildActorCanPickUp(DefaultSettings.EnableAutoPickUp);
|
|
end
|
|
|
|
--- 使用回调进行调用
|
|
function BP_WeaponItem:RandomNewItem_Internal1(TargetClass)
|
|
---@type APickUpWrapperActor
|
|
self.WrapperActor = ScriptGameplayStatics.SpawnActor(self, TargetClass, VectorHelper.Add(self:K2_GetActorLocation(), VectorHelper.MakeVector(0, 0, 100)), self:K2_GetActorRotation(), self:GetActorScale3D(), self);
|
|
if self.WrapperActor then
|
|
if self.WrapperActor.UGC_PickUpWrapperDestroyDelegate then
|
|
self.WrapperActor.UGC_PickUpWrapperDestroyDelegate:Add(self.OnPickedUp, self);
|
|
end
|
|
end
|
|
end
|
|
|
|
--- 当被拾取销毁之后执行
|
|
function BP_WeaponItem:OnPickedUp()
|
|
if self.WrapperActor.UGC_PickUpWrapperDestroyDelegate then
|
|
self.WrapperActor.UGC_PickUpWrapperDestroyDelegate:Remove(self.OnPickedUp, self);
|
|
end
|
|
self:PostAddWeapon(nil);
|
|
end
|
|
|
|
function BP_WeaponItem:OnRep_ItemId()
|
|
UGCLogSystem.Log("[BP_WeaponItem:OnRep_ItemId] ItemId = %d", self.ItemId);
|
|
self:SetChildActorCanPickUp(DefaultSettings.EnableAutoPickUp)
|
|
self:HandleEffect(self.ParticleSystem, "SceneObj_Weapon");
|
|
self.CachedItemId = self.ItemId;
|
|
end
|
|
|
|
---@param CanPickUp bool
|
|
function BP_WeaponItem:SetChildActorCanPickUp(CanPickUp)
|
|
if self.ChildActor.ChildActor ~= nil then
|
|
if IsServer then
|
|
self.ChildActor.ChildActor.bCanBePickedUp = CanPickUp;
|
|
else
|
|
self.ChildActor.ChildActor.bClientEnableMarkHasBeenPickedUp = CanPickUp;
|
|
end
|
|
end
|
|
end
|
|
|
|
function BP_WeaponItem:OnTestTick()
|
|
local ChildActor = self.ChildActor.ChildActor
|
|
if ChildActor then
|
|
local TheOwner = ChildActor:GetOwner();
|
|
if TheOwner then
|
|
UGCLogSystem.Log("[BP_WeaponItem:OnTestTick] TheOwner = %s", UE.GetName(TheOwner));
|
|
else
|
|
UGCLogSystem.Log("[BP_WeaponItem:OnTestTick] TheOwner is nil");
|
|
end
|
|
else
|
|
UGCLogSystem.Log("[BP_WeaponItem:OnTestTick] ChildActor is nil");
|
|
end
|
|
end
|
|
|
|
function BP_WeaponItem:ReceiveTick(DeltaTime)
|
|
self.SuperClass.ReceiveTick(self, DeltaTime);
|
|
self:RotateChildActor(DeltaTime);
|
|
end
|
|
|
|
function BP_WeaponItem:ReceiveEndPlay()
|
|
self.SuperClass.ReceiveEndPlay(self);
|
|
end
|
|
|
|
--function BP_WeaponItem:GetReplicatedProperties()
|
|
-- return "WrapperActor"
|
|
--end
|
|
|
|
--[[
|
|
function BP_WeaponItem:GetAvailableServerRPCs()
|
|
return
|
|
end
|
|
--]]
|
|
|
|
function BP_WeaponItem:RotateChildActor(DeltaTime)
|
|
if IsClient then
|
|
if self.ChildActor.ChildActor ~= nil and UE.IsValid(self.ChildActor.ChildActor) then
|
|
self.ChildActor.ChildActor:K2_SetActorRotation(VectorHelper.RotAdd(self.ChildActor.ChildActor:K2_GetActorRotation(), VectorHelper.VecToRot(VectorHelper.MakeVector(0, 0, DeltaTime * self.RotationLength))));
|
|
end
|
|
--if self.WrapperActor and UE.IsValid(self.WrapperActor) then
|
|
-- self.WrapperActor:K2_SetActorRotation(VectorHelper.RotAdd(self.WrapperActor:K2_GetActorRotation(), VectorHelper.VecToRot(VectorHelper.MakeVector(0, 0, DeltaTime * self.RotationLength))));
|
|
--end
|
|
end
|
|
end
|
|
|
|
return BP_WeaponItem; |