2025-01-04 23:00:19 +08:00
|
|
|
|
ItemTool = {};
|
|
|
|
|
|
|
|
|
|
----------------------------------- 武器 -----------------------------------
|
|
|
|
|
|
|
|
|
|
--- 设置玩家所有武器槽武器的子弹属性
|
|
|
|
|
---@param InPawn UGCPlayerPawn_C 玩家
|
|
|
|
|
---@param InfiniteType EFillBulletType 无限子弹类型
|
|
|
|
|
---@param IsEnable bool 是否设置
|
|
|
|
|
function ItemTool.SetAllWeaponInfinite(InPawn, InfiniteType, IsEnable)
|
|
|
|
|
if IsEnable == nil then IsEnable = true; end
|
|
|
|
|
for i, v in pairs(ShootWeaponEnums) do
|
|
|
|
|
local Weapon = UGCWeaponManagerSystem.GetWeaponBySlot(InPawn, v)
|
|
|
|
|
ItemTool.SetWeaponInfinite(InPawn, Weapon, InfiniteType, IsEnable);
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
---@param InWeapon ASTExtraShootWeapon 射击武器
|
|
|
|
|
---@param InfiniteType EFillBulletType 武器无限子弹类型
|
|
|
|
|
---@param IsEnable bool 是否开启
|
|
|
|
|
function ItemTool.SetWeaponInfinite(InPawn, InWeapon, InfiniteType, IsEnable)
|
|
|
|
|
if UE.IsValid(InWeapon) and ItemTool.IsShootWeapon(InWeapon) then
|
|
|
|
|
if InfiniteType == EFillBulletType.Infinite then
|
|
|
|
|
UGCGunSystem.EnableInfiniteBullets(InWeapon, IsEnable);
|
|
|
|
|
elseif InfiniteType == EFillBulletType.ClipInfinite then
|
|
|
|
|
UGCGunSystem.EnableClipInfiniteBullets(InWeapon, IsEnable);
|
|
|
|
|
elseif InfiniteType == EFillBulletType.Fill then
|
|
|
|
|
ItemTool.FillWeaponBullet(InPawn, InWeapon);
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--- 填充玩家身上的所有武器子弹
|
|
|
|
|
---@param InPawn UGCPlayerPawn_C
|
|
|
|
|
function ItemTool.FillAllWeaponBullets(InPawn)
|
|
|
|
|
if UE.IsValid(InPawn) then
|
|
|
|
|
InPawn:SetAllWeaponBulletNumToMaxOnServer(true, false)
|
|
|
|
|
ItemTool.FillCurrentWeaponBullet(InPawn);
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--- 填充对应武器子弹
|
|
|
|
|
---@param InPawn UGCPlayerPawn_C
|
|
|
|
|
---@param InWeapon ASTExtraShootWeapon
|
|
|
|
|
function ItemTool.FillWeaponBullet(InPawn, InWeapon)
|
|
|
|
|
InPawn:SetTargetWeaponBulletNumToMaxOnServer(InWeapon, true, false);
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ItemTool.FillCurrentWeaponBullet(InPawn)
|
|
|
|
|
local Weapon = UGCWeaponManagerSystem.GetCurrentWeapon(InPawn);
|
|
|
|
|
if Weapon and UE.IsValid(Weapon) and ItemTool.IsShootWeapon(Weapon) then
|
|
|
|
|
local MaxCount = UGCGunSystem.GetMaxBulletNumInOneClip(Weapon);
|
|
|
|
|
Weapon:SetCurrentBulletNumInClipOnServer(MaxCount, true);
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
---@param InPawn UGCPlayerPawn_C 玩家
|
|
|
|
|
---@param InWeaponId int32 武器 ID
|
|
|
|
|
---@param FillBulletType EFillBulletType 无限子弹类型
|
|
|
|
|
---@param IsEnable bool 是否设置
|
|
|
|
|
function ItemTool.SetWeaponInfiniteById(InPawn, InWeaponId, FillBulletType, IsEnable)
|
|
|
|
|
if FillBulletType ~= nil then
|
|
|
|
|
if FillBulletType <= 3 then
|
|
|
|
|
-- 获取这个武器
|
|
|
|
|
local Weapons = ItemTool.GetWeaponsById(InPawn, InWeaponId);
|
|
|
|
|
for i, Weapon in pairs(Weapons) do
|
|
|
|
|
ItemTool.SetWeaponInfinite(InPawn, Weapon, FillBulletType, IsEnable);
|
|
|
|
|
end
|
|
|
|
|
table.func(InPawn, "SetInfiniteType", FillBulletType)
|
|
|
|
|
else
|
|
|
|
|
if WeaponAmmoIdMap[InWeaponId] and FillBulletType > 0 then
|
|
|
|
|
UGCBackPackSystem.AddItem(InPawn, WeaponAmmoIdMap[InWeaponId], FillBulletType);
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
--ItemTool.SetAllWeaponInfinite(InPawn, EFillBulletType.Fill, IsEnable);
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--- 找到玩家身上的一把枪械或者近战武器这些
|
|
|
|
|
---@param InPawn UGCPlayerPawn_C 玩家
|
|
|
|
|
---@param IsForce bool 是否强制找到一把枪,默认都是强制
|
|
|
|
|
---@return ASTExtraWeapon
|
|
|
|
|
function ItemTool.GetPlayerFirstWeapon(InPawn, IsForce)
|
|
|
|
|
for i, v in pairs(ShootWeaponEnums) do
|
|
|
|
|
local Weapon = UGCWeaponManagerSystem.GetWeaponBySlot(InPawn, v);
|
|
|
|
|
if UE.IsValid(Weapon) then return Weapon; end
|
|
|
|
|
end
|
|
|
|
|
return nil;
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
---@param InPawn UGCPlayerPawn_C 玩家
|
|
|
|
|
---@param InWeaponId int32 武器 ID
|
|
|
|
|
---@return ASTExtraShootWeapon* 射击武器
|
|
|
|
|
function ItemTool.GetWeaponsById(InPawn, InWeaponId)
|
|
|
|
|
local Weapons = {};
|
|
|
|
|
for i, v in pairs(ShootWeaponEnums) do
|
|
|
|
|
local Weapon = UGCWeaponManagerSystem.GetWeaponBySlot(InPawn, v);
|
|
|
|
|
if UE.IsValid(Weapon) then
|
|
|
|
|
if Weapon:GetWeaponItemID() == InWeaponId then
|
|
|
|
|
table.insert(Weapons, Weapon);
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return Weapons;
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
---@param InPawn UGCPlayerPawn_C 玩家
|
|
|
|
|
---@param InWeaponId int32 武器 ID
|
|
|
|
|
---@param InCount int32 武器数量
|
|
|
|
|
---@param bAppend bool 是否需要添加配件
|
|
|
|
|
---@param FillBulletType EFillBulletType 是否需要添加子弹
|
|
|
|
|
function ItemTool.AddWeaponItem(InPawn, InWeaponId, InCount, bAppend, FillBulletType)
|
|
|
|
|
if not UE.IsValid(InPawn) then return end
|
|
|
|
|
local bHadAdd = false;
|
2025-01-16 13:35:17 +08:00
|
|
|
|
local Times = 10;
|
|
|
|
|
repeat
|
|
|
|
|
bHadAdd = UGCBackPackSystem.AddItem(InPawn, InWeaponId, InCount)
|
|
|
|
|
Times = Times - 1;
|
|
|
|
|
until bHadAdd or Times <= 0;
|
|
|
|
|
|
2025-01-04 23:00:19 +08:00
|
|
|
|
local Weapon = ItemTool.GetLastWeapon(InPawn, InWeaponId);
|
|
|
|
|
if not bAppend then return Weapon end
|
|
|
|
|
ItemTool.AddWeaponParts(InPawn, InWeaponId, bAppend);
|
|
|
|
|
if FillBulletType ~= nil then
|
2025-01-16 13:35:17 +08:00
|
|
|
|
ItemTool.SetWeaponInfinite(InPawn, Weapon, FillBulletType, true);
|
2025-01-04 23:00:19 +08:00
|
|
|
|
end
|
|
|
|
|
return Weapon;
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--- 移除玩家身上所有的武器
|
|
|
|
|
---@param InPawn UGCPlayerPawn_C
|
|
|
|
|
function ItemTool.ClearAllWeapon(InPawn)
|
|
|
|
|
for i, v in pairs(ShootWeaponEnums) do
|
|
|
|
|
local Weapon = UGCWeaponManagerSystem.GetWeaponBySlot(InPawn, v);
|
|
|
|
|
if Weapon and UE.IsValid(Weapon) then
|
|
|
|
|
ItemTool.ClearWeapon(InPawn, Weapon);
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
---@param Weapon ASTExtraWeapon
|
|
|
|
|
---@param InPawn UGCPlayerPawn_C
|
|
|
|
|
---@return table<int32, FItemDefineID>
|
|
|
|
|
function ItemTool.GetWeaponPartsDefineIDs(InPawn, Weapon)
|
|
|
|
|
local BackComp = UGCBackPackSystem.GetBackpackComponent(InPawn);
|
|
|
|
|
local InstanceIds = {};
|
|
|
|
|
local CustomList = {};
|
|
|
|
|
for i = 0, 5 do
|
|
|
|
|
local DefineID = Weapon:GetWeaponAttachmentIDBySocketType(i);
|
|
|
|
|
if DefineID.bValidInstance and DefineID.bValidItem then
|
|
|
|
|
InstanceIds[DefineID.InstanceID] = DefineID;
|
|
|
|
|
CustomList[i] = {
|
|
|
|
|
TypeSpecificID = DefineID.TypeSpecificID,
|
|
|
|
|
InstanceID = DefineID.InstanceID,
|
|
|
|
|
Type = DefineID.Type,
|
|
|
|
|
};
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return InstanceIds, CustomList;
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
---@param Weapon ASTExtraWeapon
|
|
|
|
|
---@param InPawn UGCPlayerPawn_C
|
|
|
|
|
function ItemTool.ClearWeapon(InPawn, Weapon)
|
|
|
|
|
local BackComp = UGCBackPackSystem.GetBackpackComponent(InPawn);
|
|
|
|
|
local InstanceIds = ItemTool.GetWeaponPartsDefineIDs(InPawn, Weapon);
|
|
|
|
|
UGCLogSystem.Log("[ItemTool.ClearWeapon] 开始移除")
|
|
|
|
|
for i, v in pairs(InstanceIds) do
|
|
|
|
|
local bDrop = BackComp:DropItem(v, 1, EBattleItemDropReason.Force);
|
|
|
|
|
if not bDrop then
|
|
|
|
|
UGCLogSystem.Log("[ItemTool.ClearWeapon] 移除配件失败,Weapon Id = %d, Part Id = %d", Weapon:GetWeaponItemID(), v.TypeSpecificID);
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
-- 寻找当前的武器子弹,再清除这些子弹
|
|
|
|
|
local WeaponInstanceID = Weapon:GetItemDefineID().InstanceID
|
|
|
|
|
-- 找到子弹
|
|
|
|
|
local AmmoId = WeaponAmmoIdMap[Weapon:GetWeaponItemID()];
|
|
|
|
|
UGCLogSystem.Log("[ItemTool.ClearWeapon] 移除 武器 %d", Weapon:GetWeaponItemID())
|
|
|
|
|
UGCBackPackSystem.DropItemByInstanceID(InPawn, WeaponInstanceID, 1, true);
|
|
|
|
|
|
|
|
|
|
if type(AmmoId) ~= 'number' then return ; end
|
|
|
|
|
local Count = BackComp:GetItemCount(AmmoId)
|
|
|
|
|
if Count > 0 then
|
|
|
|
|
UGCBackPackSystem.DropItem(InPawn, AmmoId, Count, true);
|
|
|
|
|
UGCLogSystem.Log("[ItemTool.ClearWeapon] 移除 %d 子弹 %d 个", AmmoId, Count)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--- 清空背包中的所有配件和子弹
|
|
|
|
|
function ItemTool.OnlyClearParts(InPawn)
|
|
|
|
|
local Comp = UGCBackPackSystem.GetBackpackComponent(InPawn)
|
|
|
|
|
local AllData = UGCBackPackSystem.GetAllItemData(InPawn)
|
|
|
|
|
for i, v in pairs(AllData) do
|
|
|
|
|
if GetCustomItemType(v.ItemID) == ECustomItemType.Bullet or
|
|
|
|
|
GetCustomItemType(v.ItemID) == ECustomItemType.Part
|
|
|
|
|
then
|
|
|
|
|
UGCBackPackSystem.DropItemByInstanceID(InPawn, v.InstanceID, v.Count, true);
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--- 获取武器的所有配件
|
|
|
|
|
---@param InWeapon ASTExtraWeapon 武器
|
|
|
|
|
---@return table<int32, int32>
|
|
|
|
|
function ItemTool.GetWeaponParts(InWeapon)
|
|
|
|
|
local Table = {};
|
|
|
|
|
if ItemTool.IsShootWeapon(InWeapon) then
|
|
|
|
|
if InWeapon.AttachedAttachmentID then
|
|
|
|
|
for i, v in pairs(InWeapon.AttachedAttachmentID) do
|
|
|
|
|
if not table.hasValue(Table, v) then Table[#Table + 1] = v; end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return Table;
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--- 是否是射击枪械类
|
|
|
|
|
---@param InWeapon ASTExtraWeapon 武器
|
|
|
|
|
---@return bool 是否是射击枪械类
|
|
|
|
|
function ItemTool.IsShootWeapon(InWeapon)
|
|
|
|
|
if InWeapon == nil then return false end
|
|
|
|
|
return UE.IsA(InWeapon, UGCGameSystem.GameState:GetShootWeaponClass());
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
---@param InPawn UGCPlayerPawn_C
|
|
|
|
|
---@param InFunc fun(Weapon:ASTExtraWeapon)
|
|
|
|
|
function ItemTool.ForeachWeapon(InPawn, InFunc)
|
|
|
|
|
for i, v in pairs(ShootWeaponEnums) do
|
|
|
|
|
local Weapon = UGCWeaponManagerSystem.GetWeaponBySlot(InPawn, v);
|
|
|
|
|
if UE.IsValid(Weapon) then InFunc(Weapon); end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
---@param InWeaponId int32
|
|
|
|
|
---@return bool 是否是射击武器
|
|
|
|
|
function ItemTool.IsShootWeaponById(InWeaponId)
|
|
|
|
|
return GetWeaponIdType(InWeaponId) ~= EWeaponIdType.Melee;
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
---@param InWeaponId int32
|
|
|
|
|
---@return bool 是否是近战武器
|
|
|
|
|
function ItemTool.IsMeleeWeaponById(InWeaponId)
|
|
|
|
|
return GetWeaponIdType(InWeaponId) == EWeaponIdType.Melee;
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
----------------------------------- 普通物品 -----------------------------------
|
|
|
|
|
---@return FItemDefineID
|
|
|
|
|
function ItemTool.AddItem(InPawn, InItemId, InCount, ...)
|
|
|
|
|
UGCLogSystem.Log("[ItemTool.AddItem] ItemId = %d, Count = %d", InItemId, InCount);
|
|
|
|
|
if not ItemUtils.IsUGCItem(InItemId) then return ; end
|
|
|
|
|
if not UE.IsValidPawn(InPawn) then return ; end
|
|
|
|
|
---@type FItemDefineID
|
|
|
|
|
local ItemDefineID = BackpackUtils.GenerateItemDefineIDByItemTableIDWithRandomInstanceID(InItemId);
|
|
|
|
|
local ItemInfo = CreateStruct("BattleItemPickupInfo")
|
|
|
|
|
ItemInfo.bAutoEquip = (2 == ItemDefineID.Type) or (8 == ItemDefineID.Type)
|
|
|
|
|
ItemInfo.Count = InCount;
|
|
|
|
|
|
|
|
|
|
local BackpackComponent = UGCBackPackSystem.GetBackpackComponent(InPawn);
|
|
|
|
|
BackpackComponent:RegisterItemGenerated(ItemDefineID.TypeSpecificID, ItemInfo.Count, ItemDefineID.InstanceID)
|
|
|
|
|
BackpackComponent:PickupItem(ItemDefineID, ItemInfo, EBattleItemPickupReason.Initial)
|
|
|
|
|
|
|
|
|
|
local Params = { ... };
|
2025-01-16 13:35:17 +08:00
|
|
|
|
if table.isEmpty(Params) then return ; end
|
2025-01-04 23:00:19 +08:00
|
|
|
|
-- 添加配件,验证是否有配件
|
|
|
|
|
local FillBulletType = nil;
|
|
|
|
|
if WeaponSuits[InItemId] ~= nil then
|
|
|
|
|
if type(Params[1]) == 'boolean' and type(Params[2]) == 'number' then
|
|
|
|
|
local bAppend = Params[1];
|
|
|
|
|
FillBulletType = Params[2];
|
|
|
|
|
-- 那说明要添加进去
|
|
|
|
|
ItemTool.AddWeaponParts(InPawn, ItemDefineID, bAppend);
|
|
|
|
|
elseif type(Params[1]) == 'int32' then
|
|
|
|
|
FillBulletType = Params[1];
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if FillBulletType then
|
|
|
|
|
local Weapon = ItemTool.GetWeaponByInstanceId(InPawn, ItemDefineID.InstanceID);
|
|
|
|
|
if Weapon then
|
|
|
|
|
ItemTool.SetWeaponInfinite(InPawn, Weapon, FillBulletType, true);
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
---@param ItemDefineID FItemDefineID 武器的属性
|
|
|
|
|
function ItemTool.AddWeaponParts(InPawn, ItemDefineID, Count)
|
|
|
|
|
UGCLogSystem.Log("[ItemTool.AddWeaponParts] 开始添加配件")
|
|
|
|
|
if not UE.IsValidPawn(InPawn) then return ; end
|
|
|
|
|
local BackpackComponent = UGCBackPackSystem.GetBackpackComponent(InPawn);
|
|
|
|
|
-- 添加配件
|
|
|
|
|
local BattleItemUseTarget = {
|
|
|
|
|
TargetDefineID = ItemDefineID,
|
|
|
|
|
TargetAssociationName = "",
|
|
|
|
|
FilterTargetWhenPickup = true,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
local WeaponItemId = ItemDefineID.TypeSpecificID;
|
|
|
|
|
|
|
|
|
|
-- 获取玩家是否保存过该武器的配置
|
|
|
|
|
local Weapons = ArchiveTable[InPawn.PlayerKey].Weapons
|
|
|
|
|
local AddSubitems = {};
|
|
|
|
|
if Weapons and Weapons[WeaponItemId] then AddSubitems = Weapons[WeaponItemId]; end
|
|
|
|
|
|
|
|
|
|
if table.isEmpty(AddSubitems) then
|
|
|
|
|
UGCLogSystem.LogTree(string.format("[ItemTool.AddWeaponParts] WeaponSuits[WeaponItemId] ="), WeaponSuits[WeaponItemId])
|
|
|
|
|
if WeaponSuits[WeaponItemId] then
|
|
|
|
|
local TheList = WeaponSuits[WeaponItemId][EWeaponPartType.Best];
|
|
|
|
|
if not table.isEmpty(TheList) then
|
2025-01-07 21:21:33 +08:00
|
|
|
|
AddSubitems = TheList[1];
|
2025-01-04 23:00:19 +08:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if not table.isEmpty(AddSubitems) then
|
|
|
|
|
for i, subItemId in pairs(AddSubitems) do
|
|
|
|
|
local SubItemDefineID = BackpackUtils.GenerateItemDefineIDByItemTableIDWithRandomInstanceID(subItemId)
|
|
|
|
|
local EquipPickupInfo = CreateStruct("BattleItemPickupInfo")
|
|
|
|
|
EquipPickupInfo.Count = 1
|
|
|
|
|
EquipPickupInfo.bAutoEquip = (2 == SubItemDefineID.Type) or (8 == SubItemDefineID.Type)
|
|
|
|
|
EquipPickupInfo.AutoEquipTarget = BattleItemUseTarget
|
|
|
|
|
BackpackComponent:PickupInitialItem(SubItemDefineID, EquipPickupInfo, true)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ItemTool.HasSameItem(InPawn, InItemId)
|
|
|
|
|
local AllItems = UGCBackPackSystem.GetAllItemData(InPawn);
|
|
|
|
|
for i, v in pairs(AllItems) do
|
|
|
|
|
if v.ItemID == InItemId then return true, v.InstanceID; end
|
|
|
|
|
end
|
|
|
|
|
return false, nil;
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ItemTool.GetItemInstanceId(InPawn, InItemId, Last)
|
|
|
|
|
local AllItems = UGCBackPackSystem.GetAllItemData(InPawn);
|
|
|
|
|
local InstanceIds = {};
|
|
|
|
|
for i, v in pairs(AllItems) do
|
|
|
|
|
if v.ItemID == InItemId then table.insert(InstanceIds, v.InstanceID) end
|
|
|
|
|
end
|
|
|
|
|
if #InstanceIds == 1 then return InstanceIds[1]; end
|
|
|
|
|
if Last then
|
|
|
|
|
local InstanceId = -1;
|
|
|
|
|
for i, v in pairs(InstanceIds) do
|
|
|
|
|
if v > InstanceId then InstanceId = v; end
|
|
|
|
|
end
|
|
|
|
|
return InstanceId;
|
|
|
|
|
end
|
|
|
|
|
return InstanceIds[1];
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ItemTool.GetWeaponItemInstanceId(InPawn, InWeaponId, Last)
|
|
|
|
|
local InstanceIds = {};
|
|
|
|
|
for i, v in pairs(ShootWeaponEnums) do
|
|
|
|
|
local Weapon = UGCWeaponManagerSystem.GetWeaponBySlot(InPawn, v)
|
|
|
|
|
if Weapon then
|
|
|
|
|
if Weapon:GetWeaponItemID() == InWeaponId then
|
|
|
|
|
table.insert(InstanceIds, Weapon:GetItemDefineID().InstanceID);
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if #InstanceIds == 1 then return InstanceIds[1]; end
|
|
|
|
|
if Last then
|
|
|
|
|
local InstanceId = -1;
|
|
|
|
|
for i, v in pairs(InstanceIds) do
|
|
|
|
|
if v > InstanceId then InstanceId = v; end
|
|
|
|
|
end
|
|
|
|
|
return InstanceId;
|
|
|
|
|
end
|
|
|
|
|
return InstanceIds[1];
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--- 获取最后获得到的武器
|
|
|
|
|
function ItemTool.GetLastWeapon(InPawn, InWeaponId)
|
|
|
|
|
local WeaponRet = nil;
|
|
|
|
|
local InstanceId = 0;
|
|
|
|
|
for i, v in pairs(ShootWeaponEnums) do
|
|
|
|
|
local Weapon = UGCWeaponManagerSystem.GetWeaponBySlot(InPawn, v)
|
|
|
|
|
if Weapon then
|
|
|
|
|
local TheId = Weapon:GetItemDefineID().InstanceID;
|
|
|
|
|
local ItemId = Weapon:GetWeaponItemID();
|
|
|
|
|
if (InWeaponId == nil) or (InWeaponId == ItemId) then
|
|
|
|
|
if TheId > InstanceId then
|
|
|
|
|
InstanceId = TheId;
|
|
|
|
|
WeaponRet = Weapon;
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return WeaponRet;
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
----------------------------------- 护甲 -----------------------------------
|
|
|
|
|
|
|
|
|
|
function ItemTool.ReplaceItem(InPawn, InItemId)
|
|
|
|
|
local Items = UGCBackPackSystem.GetAllItemData(InPawn)
|
|
|
|
|
local TheId = GetItemIdType(InItemId)
|
|
|
|
|
for i, v in pairs(Items) do
|
|
|
|
|
if GetCustomItemType(v.ItemID) == ECustomItemType.Equipment and GetItemIdType(v.ItemID) == TheId then
|
|
|
|
|
UGCBackPackSystem.DropItem(InPawn, v.ItemID, v.Count, true);
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
UGCBackPackSystem.AddItem(InPawn, InItemId, 1);
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
---@param InPawn UGCPlayerPawn_C
|
|
|
|
|
function ItemTool.RemoveArmorItem(InPawn)
|
|
|
|
|
local Item = UGCBackPackSystem.GetConsumablesInBackpack(InPawn);
|
|
|
|
|
for i, v in pairs(Item) do
|
|
|
|
|
local ItemTable = UE.ToTable(v)
|
|
|
|
|
UGCLogSystem.LogTree(string.format("[ItemTool.RemoveArmorItem] ItemTable ="), ItemTable)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
---@param InPawn UGCPlayerPawn_C
|
|
|
|
|
---@return table<int32, ESurviveWeaponPropSlot>
|
|
|
|
|
function ItemTool.PawnWeaponSlots(InPawn)
|
|
|
|
|
local Slots = {};
|
|
|
|
|
for i, v in pairs(ShootWeaponEnums) do
|
|
|
|
|
local Weapon = UGCWeaponManagerSystem.GetWeaponBySlot(InPawn, v);
|
|
|
|
|
if Weapon then table.insert(Slots, v); end
|
|
|
|
|
end
|
|
|
|
|
return Slots;
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ItemTool.GetWeaponType(InWeaponId)
|
|
|
|
|
return InWeaponId // 1000;
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ItemTool.CheckPlayerHasWeapon(InPawn, InWeaponId)
|
|
|
|
|
for i, v in pairs(ShootWeaponEnums) do
|
|
|
|
|
local Weapon = UGCWeaponManagerSystem.GetWeaponBySlot(InPawn, v)
|
|
|
|
|
if Weapon then
|
|
|
|
|
if Weapon:GetWeaponItemID() == InWeaponId then
|
|
|
|
|
return true, v;
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return false, nil;
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--- 通过 InstanceID 获取武器实例
|
|
|
|
|
function ItemTool.GetWeaponByInstanceId(InPawn, InstanceId)
|
|
|
|
|
for i, v in pairs(ShootWeaponEnums) do
|
|
|
|
|
local Weapon = UGCWeaponManagerSystem.GetWeaponBySlot(InPawn, v)
|
|
|
|
|
if Weapon then
|
|
|
|
|
if Weapon:GetItemDefineID().InstanceID == InstanceId then
|
|
|
|
|
return Weapon;
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return nil;
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ItemTool.ClearAllItems(InPawn)
|
|
|
|
|
local Comp = UGCBackPackSystem.GetBackpackComponent(InPawn)
|
|
|
|
|
Comp:ClearItems();
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ItemTool.GetAllWeaponPartDefineIDs(InPawn)
|
|
|
|
|
local Ret = {};
|
|
|
|
|
for i, v in pairs(ShootWeaponEnums) do
|
|
|
|
|
local Weapon = UGCWeaponManagerSystem.GetWeaponBySlot(InPawn, v)
|
|
|
|
|
if Weapon then
|
|
|
|
|
local DefineIDs = ItemTool.GetWeaponPartsDefineIDs(InPawn, Weapon);
|
|
|
|
|
for c, d in pairs(DefineIDs) do
|
|
|
|
|
Ret[c] = d;
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return Ret;
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
---@param InPawn UGCPlayerPawn_C
|
|
|
|
|
---@param InList table<int32, ECustomItemType>
|
|
|
|
|
---@param bWeaponParts bool 是否清除武器上的配件
|
|
|
|
|
function ItemTool.ClearItemsByCustomItemType(InPawn, InList, bWeaponParts)
|
|
|
|
|
-- 找到武器上面的
|
|
|
|
|
local Items = UGCBackPackSystem.GetAllItemData(InPawn)
|
|
|
|
|
if InList == nil then
|
|
|
|
|
InList = {
|
|
|
|
|
ECustomItemType.Bullet,
|
|
|
|
|
ECustomItemType.Part,
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
local BaiMingDan = {};
|
|
|
|
|
if bWeaponParts and table.hasValue(InList, ECustomItemType.Part) then
|
|
|
|
|
BaiMingDan = ItemTool.GetAllWeaponPartDefineIDs(InPawn);
|
|
|
|
|
UGCLogSystem.LogTree(string.format("[ItemTool.ClearItemsByCustomItemType] BaiMingDan ="), BaiMingDan)
|
|
|
|
|
end
|
|
|
|
|
local Func = function(InType)
|
|
|
|
|
for i, v in pairs(InList) do
|
|
|
|
|
if v == InType then return true; end
|
|
|
|
|
end
|
|
|
|
|
return false;
|
|
|
|
|
end
|
|
|
|
|
for i, v in pairs(Items) do
|
|
|
|
|
local ItemType = GetCustomItemType(v.ItemID)
|
|
|
|
|
if Func(ItemType) and BaiMingDan[v.InstanceID] == nil then
|
|
|
|
|
local bSuccess, Times = false, 10;
|
|
|
|
|
repeat
|
|
|
|
|
bSuccess = UGCBackPackSystem.DropItemByInstanceID(InPawn, v.InstanceID, v.Count, true)
|
|
|
|
|
Times = Times - 1;
|
|
|
|
|
until bSuccess or Times <= 0;
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--- 添加所有的握把
|
|
|
|
|
function ItemTool.AddAllGrip(InPawn, WithoutList)
|
|
|
|
|
local WithoutTable = {};
|
|
|
|
|
if not table.isEmpty(WithoutList) then
|
|
|
|
|
for i, v in pairs(WithoutList) do
|
|
|
|
|
WithoutTable[v] = true;
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
for i, v in pairs(WeaponTypeParts[EWeaponPartType.Grip]) do
|
|
|
|
|
if WithoutTable[v] == nil then
|
|
|
|
|
ItemTool.AddItem(InPawn, v, 1);
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--- 添加枪口让玩家装备
|
|
|
|
|
function ItemTool.AddAllMuzzle(InPawn, InWeaponId, WithoutList)
|
|
|
|
|
-- 找到 WeaponSuits
|
|
|
|
|
if table.isEmpty(WeaponSuits[InWeaponId]) then return ; end
|
|
|
|
|
local Muzzles = WeaponSuits[InWeaponId][EWeaponPartType.Muzzle]
|
|
|
|
|
if table.isEmpty(Muzzles) then return ; end
|
|
|
|
|
local WithoutTable = {};
|
|
|
|
|
if not table.isEmpty(WithoutList) then
|
|
|
|
|
for i, v in pairs(WithoutList) do
|
|
|
|
|
WithoutTable[v] = true;
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
for i, v in pairs(Muzzles) do
|
|
|
|
|
if WithoutTable[v] == nil then
|
|
|
|
|
ItemTool.AddItem(InPawn, v, 1);
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
---@param InWeaponPartType EWeaponPartType
|
|
|
|
|
---@return EWeaponAttachmentSocketType
|
|
|
|
|
function ItemTool.GetWeaponAttachmentSocketType(InWeaponPartType)
|
|
|
|
|
return WeaponTypeName[InWeaponPartType].WeaponAttachmentSocketType;
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
---@param Weapon ASTExtraWeapon
|
|
|
|
|
---@param InType EWeaponAttachmentSocketType
|
|
|
|
|
---@return FItemDefineID
|
|
|
|
|
function ItemTool.GetDefineIDBySocketType(Weapon, InType)
|
|
|
|
|
local DefineId = Weapon:GetWeaponAttachmentIDBySocketType(InType)
|
|
|
|
|
if DefineId.bValidItem and DefineId.bValidInstance then
|
|
|
|
|
return DefineId;
|
|
|
|
|
end
|
|
|
|
|
return nil;
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ItemTool.AddRangeItems(InPawn, Begin, End)
|
|
|
|
|
for i = Begin, End do
|
|
|
|
|
if UGCItemSystem.IsUGCItem(i) then
|
2025-01-16 13:35:17 +08:00
|
|
|
|
local Times = 10;
|
|
|
|
|
local bSuccess = false;
|
2025-01-04 23:00:19 +08:00
|
|
|
|
repeat
|
2025-01-16 13:35:17 +08:00
|
|
|
|
bSuccess = UGCBackPackSystem.AddItem(InPawn, i, 1);
|
|
|
|
|
until bSuccess or Times <= 0;
|
2025-01-04 23:00:19 +08:00
|
|
|
|
end
|
|
|
|
|
end
|
2025-01-07 21:21:33 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ItemTool.WeaponAddPart(InWeapon, PartId)
|
|
|
|
|
UGCGunSystem.CreateAndAddGunAttachment(InWeapon, PartId);
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 设置当前武器配件(直接装上,估计需要验证)
|
|
|
|
|
function ItemTool.CurrWeaponAddPart(InPawn, InPart)
|
|
|
|
|
local Weapon = UGCWeaponManagerSystem.GetCurrentWeapon(InPawn);
|
|
|
|
|
if Weapon and ItemTool.IsShootWeapon(Weapon) then
|
|
|
|
|
UGCGunSystem.CreateAndAddGunAttachment(Weapon, InPart);
|
|
|
|
|
end
|
2025-01-08 22:46:12 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
---@param Weapon ASTExtraShootWeapon
|
|
|
|
|
---@return int32[]
|
|
|
|
|
function ItemTool.GetWeaponPartList(Weapon)
|
|
|
|
|
local Parts = {};
|
|
|
|
|
if Weapon and UE.IsValid(Weapon) and ItemTool.IsShootWeapon(Weapon) then
|
|
|
|
|
local SocketTypes = UGCGunSystem.GetAvailableWeaponAttachmentSocketTypeList(Weapon);
|
|
|
|
|
for i, v in pairs(SocketTypes) do
|
|
|
|
|
local ItemDefineID = UGCGunSystem.GetWeaponAttachmentIDBySocketType(Weapon, v);
|
|
|
|
|
if ItemDefineID and ItemDefineID.bValidItem and ItemDefineID.bValidInstance then
|
|
|
|
|
table.insert(Parts, ItemDefineID.TypeSpecificID);
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return Parts;
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ItemTool.GetCurrWeaponPartList(Pawn)
|
|
|
|
|
local Weapon = UGCWeaponManagerSystem.GetCurrentWeapon(Pawn);
|
|
|
|
|
return ItemTool.GetWeaponPartList(Weapon);
|
|
|
|
|
end
|
2025-01-16 13:35:17 +08:00
|
|
|
|
|
|
|
|
|
--- 武器明确指定使用这些配件
|
|
|
|
|
---@param InWeapon ASTExtraShootWeapon
|
|
|
|
|
---@param Parts table<int32, int32>
|
|
|
|
|
function ItemTool.SetWeaponParts(InWeapon, Parts)
|
|
|
|
|
if not ItemTool.IsShootWeapon(InWeapon) then return ; end
|
|
|
|
|
ItemTool.RemoveAllParts(InWeapon);
|
|
|
|
|
if table.isEmpty(Parts) then return ; end
|
|
|
|
|
for i, v in pairs(Parts) do
|
|
|
|
|
ItemTool.WeaponAddPart(InWeapon, v);
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
---@param InWeapon ASTExtraShootWeapon
|
|
|
|
|
function ItemTool.GetAllPartTypes(InWeapon)
|
|
|
|
|
local WeaponID = InWeapon:GetWeaponItemID();
|
|
|
|
|
local Parts = {};
|
|
|
|
|
if table.isEmpty(WeaponSuits[WeaponID]) then return Parts; end
|
|
|
|
|
for PartType, v in pairs(WeaponSuits[WeaponID]) do
|
|
|
|
|
if PartType ~= 0 then
|
|
|
|
|
table.insert(Parts, PartType);
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return Parts;
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
---@param InWeapon ASTExtraShootWeapon
|
|
|
|
|
function ItemTool.RemoveAllParts(InWeapon)
|
|
|
|
|
-- 检查是否有配件
|
|
|
|
|
local PartTypes = ItemTool.GetAllPartTypes(InWeapon);
|
|
|
|
|
if table.isEmpty(PartTypes) then return ; end
|
|
|
|
|
UGCLogSystem.LogTree(string.format("[ItemTool.RemoveAllParts] PartTypes ="), PartTypes)
|
|
|
|
|
local Pawn = InWeapon:GetOwnerPawn();
|
|
|
|
|
local WeaponID = InWeapon:GetWeaponItemID();
|
|
|
|
|
local BackComp = UGCBackPackSystem.GetBackpackComponent(Pawn);
|
|
|
|
|
for i, PartType in pairs(PartTypes) do
|
|
|
|
|
local SocketType = ItemTool.GetWeaponAttachmentSocketType(PartType);
|
|
|
|
|
UGCLogSystem.Log("[ItemTool.RemoveAllParts] SocketType = " .. SocketType);
|
|
|
|
|
local DefineID = UGCGunSystem.GetWeaponAttachmentIDBySocketType(InWeapon, SocketType);
|
|
|
|
|
-- 移除
|
|
|
|
|
UGCLogSystem.Log("[ItemTool.RemoveAllParts] 开始移除");
|
|
|
|
|
local bDrop = BackComp:DropItem(DefineID, 1, EBattleItemDropReason.Force);
|
|
|
|
|
if not bDrop then
|
|
|
|
|
UGCLogSystem.Log("[ItemTool.RemoveAllParts] 移除配件失败,WeaponID = %d, PartID = %d", WeaponID, DefineID.TypeSpecificID);
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
---@return ASTExtraShootWeapon
|
|
|
|
|
function ItemTool.GetLocalPawnCurrWeapon()
|
|
|
|
|
local Pawn = UE.GetLocalPawn();
|
|
|
|
|
if UE.IsValidPawn(Pawn) then
|
|
|
|
|
return UGCWeaponManagerSystem.GetCurrentWeapon(Pawn);
|
|
|
|
|
end
|
|
|
|
|
return nil;
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ItemTool.GetLocalPawnCurrWeaponID()
|
|
|
|
|
return ItemTool.GetCurrWeaponID(UE.GetLocalPawn());
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ItemTool.GetCurrWeaponID(InPawn)
|
|
|
|
|
if UE.IsValidPawn(InPawn) then
|
|
|
|
|
local Weapon = UGCWeaponManagerSystem.GetCurrentWeapon(InPawn);
|
|
|
|
|
if Weapon and UE.IsValid(Weapon) then return Weapon:GetWeaponItemID() end
|
|
|
|
|
end
|
|
|
|
|
return -1;
|
|
|
|
|
end
|