This commit is contained in:
Leon Friedrich
2022-03-17 20:13:31 +13:00
committed by GitHub
parent 7b84362901
commit bfd95c493b
94 changed files with 1454 additions and 2185 deletions

View File

@@ -5,6 +5,7 @@ using Content.Server.DoAfter;
using Content.Server.Hands.Components;
using Content.Shared.Alert;
using Content.Shared.Cuffs.Components;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Helpers;
using Content.Shared.Popups;
@@ -26,6 +27,7 @@ namespace Content.Server.Cuffs.Components
public sealed class CuffableComponent : SharedCuffableComponent
{
[Dependency] private readonly IEntityManager _entMan = default!;
[Dependency] private readonly IEntitySystemManager _sysMan = default!;
/// <summary>
/// How many of this entity's hands are currently cuffed.
@@ -103,15 +105,13 @@ namespace Content.Server.Cuffs.Components
return true;
}
var sys = _sysMan.GetEntitySystem<SharedHandsSystem>();
// Success!
if (_entMan.TryGetComponent(user, out HandsComponent? handsComponent) && handsComponent.IsHolding(handcuff))
{
// Good lord handscomponent is scuffed, I hope some smug person will fix it someday
handsComponent.Drop(handcuff);
}
sys.TryDrop(user, handcuff);
Container.Insert(handcuff);
CanStillInteract = _entMan.TryGetComponent(Owner, out HandsComponent? ownerHands) && ownerHands.HandNames.Count() > CuffedHandCount;
CanStillInteract = _entMan.TryGetComponent(Owner, out HandsComponent? ownerHands) && ownerHands.Hands.Count() > CuffedHandCount;
OnCuffedStateChanged?.Invoke();
UpdateAlert();
@@ -133,23 +133,22 @@ namespace Content.Server.Cuffs.Components
{
if (!_entMan.TryGetComponent(Owner, out HandsComponent? handsComponent)) return;
var itemCount = handsComponent.GetAllHeldItems().Count();
var freeHandCount = handsComponent.HandNames.Count() - CuffedHandCount;
var sys = _sysMan.GetEntitySystem<SharedHandsSystem>();
if (freeHandCount < itemCount)
var freeHandCount = handsComponent.Hands.Count() - CuffedHandCount;
foreach (var hand in handsComponent.Hands.Values)
{
foreach (var item in handsComponent.GetAllHeldItems())
if (hand.IsEmpty)
continue;
if (freeHandCount > 0)
{
if (freeHandCount < itemCount)
{
freeHandCount++;
handsComponent.Drop(item.Owner, false);
}
else
{
break;
}
freeHandCount--;
continue;
}
sys.TryDrop(Owner, hand, checkActionBlocker: false, handsComp: handsComponent);
}
}
@@ -267,7 +266,7 @@ namespace Content.Server.Cuffs.Components
}
}
CanStillInteract = _entMan.TryGetComponent(Owner, out HandsComponent? handsComponent) && handsComponent.HandNames.Count() > CuffedHandCount;
CanStillInteract = _entMan.TryGetComponent(Owner, out HandsComponent? handsComponent) && handsComponent.SortedHands.Count() > CuffedHandCount;
OnCuffedStateChanged?.Invoke();
UpdateAlert();
Dirty();