2023-12-16 20:45:18 -05:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2023-05-05 21:50:09 -04:00
|
|
|
using Content.Shared.Inventory;
|
|
|
|
|
using Content.Shared.Weapons.Ranged.Components;
|
|
|
|
|
using Content.Shared.Weapons.Ranged.Events;
|
|
|
|
|
|
|
|
|
|
namespace Content.Shared.Weapons.Ranged.Systems;
|
|
|
|
|
|
|
|
|
|
public partial class SharedGunSystem
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly InventorySystem _inventory = default!;
|
|
|
|
|
|
|
|
|
|
private void InitializeClothing()
|
|
|
|
|
{
|
|
|
|
|
SubscribeLocalEvent<ClothingSlotAmmoProviderComponent, TakeAmmoEvent>(OnClothingTakeAmmo);
|
|
|
|
|
SubscribeLocalEvent<ClothingSlotAmmoProviderComponent, GetAmmoCountEvent>(OnClothingAmmoCount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnClothingTakeAmmo(EntityUid uid, ClothingSlotAmmoProviderComponent component, TakeAmmoEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (!TryGetClothingSlotEntity(uid, component, out var entity))
|
|
|
|
|
return;
|
|
|
|
|
RaiseLocalEvent(entity.Value, args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnClothingAmmoCount(EntityUid uid, ClothingSlotAmmoProviderComponent component, ref GetAmmoCountEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (!TryGetClothingSlotEntity(uid, component, out var entity))
|
|
|
|
|
return;
|
|
|
|
|
RaiseLocalEvent(entity.Value, ref args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool TryGetClothingSlotEntity(EntityUid uid, ClothingSlotAmmoProviderComponent component, [NotNullWhen(true)] out EntityUid? slotEntity)
|
|
|
|
|
{
|
|
|
|
|
slotEntity = null;
|
|
|
|
|
|
2024-08-04 07:38:53 +02:00
|
|
|
if (!Containers.TryGetContainingContainer((uid, null, null), out var container))
|
2023-12-14 15:49:40 -05:00
|
|
|
return false;
|
|
|
|
|
var user = container.Owner;
|
|
|
|
|
|
|
|
|
|
if (!_inventory.TryGetContainerSlotEnumerator(user, out var enumerator, component.TargetSlot))
|
2023-05-05 21:50:09 -04:00
|
|
|
return false;
|
2023-12-07 16:20:51 -05:00
|
|
|
|
|
|
|
|
while (enumerator.NextItem(out var item))
|
2023-05-05 21:50:09 -04:00
|
|
|
{
|
2024-06-03 14:40:03 -07:00
|
|
|
if (_whitelistSystem.IsWhitelistFailOrNull(component.ProviderWhitelist, item))
|
2023-05-05 21:50:09 -04:00
|
|
|
continue;
|
2023-12-07 16:20:51 -05:00
|
|
|
|
|
|
|
|
slotEntity = item;
|
|
|
|
|
return true;
|
2023-05-05 21:50:09 -04:00
|
|
|
}
|
|
|
|
|
|
2023-12-07 16:20:51 -05:00
|
|
|
return false;
|
2023-05-05 21:50:09 -04:00
|
|
|
}
|
|
|
|
|
}
|