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();
|
base.Initialize();
|
||||||
|
|
||||||
SubscribeLocalEvent<HandCountChangedEvent>(OnHandCountChanged);
|
SubscribeLocalEvent<CuffableComponent, HandCountChangedEvent>(OnHandCountChanged);
|
||||||
SubscribeLocalEvent<UncuffAttemptEvent>(OnUncuffAttempt);
|
SubscribeLocalEvent<UncuffAttemptEvent>(OnUncuffAttempt);
|
||||||
|
|
||||||
SubscribeLocalEvent<CuffableComponent, EntRemovedFromContainerMessage>(OnCuffsRemovedFromContainer);
|
SubscribeLocalEvent<CuffableComponent, EntRemovedFromContainerMessage>(OnCuffsRemovedFromContainer);
|
||||||
@@ -380,33 +380,24 @@ namespace Content.Shared.Cuffs
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check the current amount of hands the owner has, and if there's less hands than active cuffs we remove some cuffs.
|
/// Check the current amount of hands the owner has, and if there's less hands than active cuffs we remove some cuffs.
|
||||||
/// </summary>
|
/// </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 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;
|
dirty = true;
|
||||||
|
|
||||||
var container = cuffable.Container;
|
var handcuffContainer = ent.Comp.Container;
|
||||||
var entity = container.ContainedEntities[^1];
|
var handcuffEntity = handcuffContainer.ContainedEntities[^1];
|
||||||
|
|
||||||
_container.Remove(entity, container);
|
_transform.PlaceNextTo(handcuffEntity, ent.Owner);
|
||||||
_transform.SetWorldPosition(entity, _transform.GetWorldPosition(owner));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dirty)
|
if (dirty)
|
||||||
{
|
{
|
||||||
UpdateCuffState(owner, cuffable);
|
UpdateCuffState(ent.Owner, ent.Comp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user