2021-12-30 18:27:15 -08:00
|
|
|
using Content.Server.Hands.Components;
|
2021-09-17 07:16:11 -07:00
|
|
|
using Content.Shared.Hands;
|
|
|
|
|
using Content.Shared.Hands.Components;
|
2022-03-17 20:13:31 +13:00
|
|
|
using Content.Shared.Hands.EntitySystems;
|
2021-09-17 07:16:11 -07:00
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.Hands.Systems
|
|
|
|
|
{
|
|
|
|
|
[UsedImplicitly]
|
2022-01-01 05:20:32 -08:00
|
|
|
public sealed class HandVirtualItemSystem : SharedHandVirtualItemSystem
|
2021-09-17 07:16:11 -07:00
|
|
|
{
|
2022-01-05 17:53:08 +13:00
|
|
|
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
|
|
|
|
|
|
2021-09-17 07:16:11 -07:00
|
|
|
public bool TrySpawnVirtualItemInHand(EntityUid blockingEnt, EntityUid user)
|
|
|
|
|
{
|
2022-03-17 20:13:31 +13:00
|
|
|
if (!_handsSystem.TryGetEmptyHand(user, out var hand))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
var pos = EntityManager.GetComponent<TransformComponent>(user).Coordinates;
|
|
|
|
|
var virtualItem = EntityManager.SpawnEntity("HandVirtualItem", pos);
|
|
|
|
|
var virtualItemComp = EntityManager.GetComponent<HandVirtualItemComponent>(virtualItem);
|
|
|
|
|
virtualItemComp.BlockingEntity = blockingEnt;
|
|
|
|
|
_handsSystem.DoPickup(user, hand, virtualItem);
|
|
|
|
|
return true;
|
2021-09-17 07:16:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Deletes all virtual items in a user's hands with
|
|
|
|
|
/// the specified blocked entity.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void DeleteInHandsMatching(EntityUid user, EntityUid matching)
|
|
|
|
|
{
|
2022-03-17 20:13:31 +13:00
|
|
|
foreach (var hand in _handsSystem.EnumerateHands(user))
|
2021-09-17 07:16:11 -07:00
|
|
|
{
|
2022-03-17 20:13:31 +13:00
|
|
|
if (TryComp(hand.HeldEntity, out HandVirtualItemComponent? virt) && virt.BlockingEntity == matching)
|
2021-12-05 18:09:01 +01:00
|
|
|
{
|
|
|
|
|
Delete(virt, user);
|
2022-03-17 20:13:31 +13:00
|
|
|
return;
|
2021-09-17 07:16:11 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|