{
base.Initialize();
- SubscribeLocalEvent<HandCountChangedEvent>(OnHandCountChanged);
+ SubscribeLocalEvent<CuffableComponent, HandCountChangedEvent>(OnHandCountChanged);
SubscribeLocalEvent<UncuffAttemptEvent>(OnUncuffAttempt);
SubscribeLocalEvent<CuffableComponent, EntRemovedFromContainerMessage>(OnCuffsRemovedFromContainer);
/// <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);
}
}