Fix zombie uncuffing (#30321)
* Fix zombie uncuffing * PlaceNextTo() and rename vars
This commit is contained in:
@@ -58,7 +58,7 @@ namespace Content.Shared.Cuffs
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<HandCountChangedEvent>(OnHandCountChanged);
|
||||
SubscribeLocalEvent<CuffableComponent, HandCountChangedEvent>(OnHandCountChanged);
|
||||
SubscribeLocalEvent<UncuffAttemptEvent>(OnUncuffAttempt);
|
||||
|
||||
SubscribeLocalEvent<CuffableComponent, EntRemovedFromContainerMessage>(OnCuffsRemovedFromContainer);
|
||||
@@ -380,33 +380,24 @@ namespace Content.Shared.Cuffs
|
||||
/// <summary>
|
||||
/// Check the current amount of hands the owner has, and if there's less hands than active cuffs we remove some cuffs.
|
||||
/// </summary>
|
||||
private void OnHandCountChanged(HandCountChangedEvent message)
|
||||
private void OnHandCountChanged(Entity<CuffableComponent> ent, ref HandCountChangedEvent message)
|
||||
{
|
||||
var owner = message.Sender;
|
||||
|
||||
if (!TryComp(owner, out CuffableComponent? cuffable) ||
|
||||
!cuffable.Initialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var dirty = false;
|
||||
var handCount = CompOrNull<HandsComponent>(owner)?.Count ?? 0;
|
||||
var handCount = CompOrNull<HandsComponent>(ent.Owner)?.Count ?? 0;
|
||||
|
||||
while (cuffable.CuffedHandCount > handCount && cuffable.CuffedHandCount > 0)
|
||||
while (ent.Comp.CuffedHandCount > handCount && ent.Comp.CuffedHandCount > 0)
|
||||
{
|
||||
dirty = true;
|
||||
|
||||
var container = cuffable.Container;
|
||||
var entity = container.ContainedEntities[^1];
|
||||
var handcuffContainer = ent.Comp.Container;
|
||||
var handcuffEntity = handcuffContainer.ContainedEntities[^1];
|
||||
|
||||
_container.Remove(entity, container);
|
||||
_transform.SetWorldPosition(entity, _transform.GetWorldPosition(owner));
|
||||
_transform.PlaceNextTo(handcuffEntity, ent.Owner);
|
||||
}
|
||||
|
||||
if (dirty)
|
||||
{
|
||||
UpdateCuffState(owner, cuffable);
|
||||
UpdateCuffState(ent.Owner, ent.Comp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user