UGCProjects/GZJ/Script/Blueprint/Item/BP_ItemActorBase.lua

178 lines
5.4 KiB
Lua
Raw Normal View History

2025-01-08 22:46:12 +08:00
---@class BP_ItemActorBase_C:AActor
---@field WidgetComponent UWidgetComponent
---@field ParticleSystem UParticleSystemComponent
---@field StaticMesh UStaticMeshComponent
---@field Sphere USphereComponent
---@field QualityFX TArray<FSoftObjectPath>
--Edit Below--
local BP_ItemActorBase = {
ItemData = {},
-- 尝试放在一起
IdAndCount = "",
ThisID = -1,
bHasInit = false,
bIsPicking = false;
bCanBeAutoPickup = true,
DiscardPlayerKey = -1,
};
function BP_ItemActorBase:ReceiveBeginPlay()
self.SuperClass.ReceiveBeginPlay(self);
self.bHasInit = true
if self:HasAuthority() then
local TheData = self.IdAndCount
self.IdAndCount = TheData .. ";"
end
end
function BP_ItemActorBase:SetIsPicking(InPick)
self.bIsPicking = InPick
end
function BP_ItemActorBase:GetReplicatedProperties()
return
"ItemData", "ThisID", "IdAndCount", "bCanBeAutoPickup", "DiscardPlayerKey"
end
function BP_ItemActorBase:IsAutoPickupDisabled(PlayerKey)
return PlayerKey == self.DiscardPlayerKey and self.bCanBeAutoPickup == false
end
function BP_ItemActorBase:SetAutoPickupDisabled(PlayerKey)
self.DiscardPlayerKey = PlayerKey
self.bCanBeAutoPickup = false
if self.AutoPickupHandle == nil then
self.AutoPickupHandle = EventSystem.SetTimer(self, function()
self.bCanBeAutoPickup = true
end, 10.0)
end
end
function BP_ItemActorBase:SetItemValue()
local TheId = self:GetItemID()
if type(TheId) == "nil" then
print(string.format('[BP_ItemActorBase:SetItemValue] 没找到 Id: type ' .. type(TheId)))
return
elseif type(TheId) == "number" then
-- print(string.format('[BP_ItemActorBase:SetItemValue] 找到了 ' .. tostring(TheId)))
if UE.IsValid(self.WidgetComponent) and UE.IsValid(self.WidgetComponent.Widget) then
local bSuccess = self.WidgetComponent.Widget:SetItemData(TheId)
if not bSuccess then
self.WidgetComponent.Widget:SetVisibility(ESlateVisibility.Collapsed)
end
end
self:SpawnEffect(TheId, GetItemTypeByItemId(TheId), GetItemWeaponTypeByItemId(TheId))
end
end
function BP_ItemActorBase:OnRep_IdAndCount()
-- 解析该字符串
-- print("[BP_ItemActorBase:OnRep_IdAndCount] 开始执行")
-- 添加到所有的 Player Controller 中
local Controller = GameDataManager.GetLocalPlayerController()
table.insert(Controller.AllItemActors[ETeleportType.InArena], self)
self:SetItemValue()
end
function BP_ItemActorBase:OnRep_ItemData()
if not self.bHasInit then
return
end
--local val = IsWeaponPartItem(self:GetItemID() )
print("[BP_ItemActorBase:OnRep_ItemData] 开始执行")
if type(self.ItemData) == "table" then
for i = 1, #self.ItemData do
print(self.ItemData[i])
end
end
print("[BP_ItemActorBase:OnRep_ItemData] 结束执行")
-- 获取 ItemType
local ItemId = self.ItemData[1]
if ItemId == nil then
return
end
-- 显示出来
self.WidgetComponent.Widget:SetItemData(ItemId)
self.WidgetComponent.Widget:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
self:SpawnEffect(ItemId, GetItemTypeByItemId(ItemId), GetItemWeaponTypeByItemId(ItemId))
end
function BP_ItemActorBase:SpawnEffect(InId, InItemType, InWeaponClassType)
local MeshPath = nil
local val = (InId // 10000) == EDropItemSet.WeaponParts + 1
if not val then
MeshPath = GameDataManager.GetItemMeshPathByItemType(InItemType)
else
MeshPath = GameDataManager.GetItemMeshPathByItemType(InItemType, InWeaponClassType)
end
AsyncLoadTools:LoadObjectBySoftPath(MeshPath,
function(Asset)
if UE.IsValid(self) and UE.IsValid(self.StaticMesh) then
self.StaticMesh:SetStaticMesh(Asset)
end
end)
local FXPath = self.QualityFX[self:GetItemQuality()]
if FXPath then
AsyncLoadTools:LoadObjectBySoftPath(FXPath,
function(Asset)
if UE.IsValid(self) and UE.IsValid(self.ParticleSystem) then
self.ParticleSystem:SetHiddenInGame(false, false)
self.ParticleSystem:SetTemplate(Asset)
end
end)
else
if self.ParticleSystem then
self.ParticleSystem:SetHiddenInGame(true, false)
end
end
end
function BP_ItemActorBase:SetThisID(InThisID)
self.ThisID = InThisID
end
-- C
function BP_ItemActorBase:SetItemData(InData)
self.IdAndCount = string.format("%d;%d", InData.ItemID, InData.Count)
self.ItemData = InData
self:SetItemValue()
end
function BP_ItemActorBase:SetPickItemData(InStr)
-- print(string.format("[BP_ItemActorBase:SetItemData] 测试一下数据类型:%s具体数值%s", type(InStr), InStr))
self.IdAndCount = InStr
self:OnRep_IdAndCount()
end
function BP_ItemActorBase:GetItemID()
local Arr = string.splitToNumber(self.IdAndCount, ";")
return Arr[1]
end
function BP_ItemActorBase:GetItemCount()
local Arr = string.splitToNumber(self.IdAndCount, ";")
-- print(string.format("[BP_ItemActorBase:GetItemID] 此时 Count = %d", Arr[2]))
return Arr[2]
end
function BP_ItemActorBase:GetThisID()
return self.ThisID
end
function BP_ItemActorBase:GetItemQuality()
return self:GetItemID() % 100 // 10
end
--[[
function BP_ItemActorBase:GetAvailableServerRPCs()
return
end
--]]
return BP_ItemActorBase;