Get rid of CuffSystem, make CuffableComponent update its hand count properly (#1927)
* Merge branch 'master' of https://github.com/space-wizards/space-station-14 into cuff-fix * yml * event bus
This commit is contained in:
@@ -22,7 +22,7 @@ using Content.Shared.GameObjects.Components.Mobs;
|
||||
using Robust.Shared.Maths;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Serilog;
|
||||
using Content.Server.GameObjects.Components.GUI;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.ActionBlocking
|
||||
{
|
||||
@@ -48,7 +48,6 @@ namespace Content.Server.GameObjects.Components.ActionBlocking
|
||||
[ViewVariables(VVAccess.ReadOnly)]
|
||||
private Container _container = default!;
|
||||
|
||||
private bool _dirtyThisFrame = false;
|
||||
private float _interactRange;
|
||||
private IHandsComponent _hands;
|
||||
|
||||
@@ -61,6 +60,8 @@ namespace Content.Server.GameObjects.Components.ActionBlocking
|
||||
_container = ContainerManagerComponent.Ensure<Container>(Name, Owner);
|
||||
_interactRange = SharedInteractionSystem.InteractionRange / 2;
|
||||
|
||||
Owner.EntityManager.EventBus.SubscribeEvent<HandCountChangedEvent>(EventSource.Local, this, HandleHandCountChange);
|
||||
|
||||
if (!Owner.TryGetComponent(out _hands))
|
||||
{
|
||||
Logger.Warning("Player does not have an IHandsComponent!");
|
||||
@@ -127,29 +128,24 @@ namespace Content.Server.GameObjects.Components.ActionBlocking
|
||||
Dirty();
|
||||
}
|
||||
|
||||
public void Update(float frameTime)
|
||||
{
|
||||
UpdateHandCount();
|
||||
}
|
||||
|
||||
/// <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 UpdateHandCount()
|
||||
{
|
||||
_dirtyThisFrame = false;
|
||||
var dirty = false;
|
||||
var handCount = _hands.Hands.Count();
|
||||
|
||||
while (CuffedHandCount > handCount && CuffedHandCount > 0)
|
||||
{
|
||||
_dirtyThisFrame = true;
|
||||
dirty = true;
|
||||
|
||||
var entity = _container.ContainedEntities[_container.ContainedEntities.Count - 1];
|
||||
_container.Remove(entity);
|
||||
entity.Transform.WorldPosition = Owner.Transform.GridPosition.Position;
|
||||
}
|
||||
|
||||
if (_dirtyThisFrame)
|
||||
if (dirty)
|
||||
{
|
||||
CanStillInteract = handCount > CuffedHandCount;
|
||||
OnCuffedStateChanged.Invoke();
|
||||
@@ -157,6 +153,14 @@ namespace Content.Server.GameObjects.Components.ActionBlocking
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleHandCountChange(HandCountChangedEvent message)
|
||||
{
|
||||
if (message.Sender == Owner)
|
||||
{
|
||||
UpdateHandCount();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check how many items the user is holding and if it's more than the number of cuffed hands, drop some items.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user