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>
|
||||
|
||||
@@ -29,6 +29,7 @@ using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using Content.Server.GameObjects.Components.ActionBlocking;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.GUI
|
||||
{
|
||||
@@ -444,6 +445,7 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
ActiveHand ??= name;
|
||||
|
||||
OnItemChanged?.Invoke();
|
||||
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new HandCountChangedEvent(Owner));
|
||||
|
||||
Dirty();
|
||||
}
|
||||
@@ -466,6 +468,7 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
}
|
||||
|
||||
OnItemChanged?.Invoke();
|
||||
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new HandCountChangedEvent(Owner));
|
||||
|
||||
Dirty();
|
||||
}
|
||||
@@ -791,4 +794,14 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
return new SharedHand(index, Name, Entity?.Uid, location);
|
||||
}
|
||||
}
|
||||
|
||||
public class HandCountChangedEvent : EntitySystemMessage
|
||||
{
|
||||
public HandCountChangedEvent(IEntity sender)
|
||||
{
|
||||
Sender = sender;
|
||||
}
|
||||
|
||||
public IEntity Sender { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
using Content.Server.GameObjects.Components.ActionBlocking;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
|
||||
namespace Content.Server.GameObjects.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
internal sealed class CuffSystem : EntitySystem
|
||||
{
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
foreach (var comp in ComponentManager.EntityQuery<CuffableComponent>())
|
||||
{
|
||||
comp.Update(frameTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,6 +94,7 @@
|
||||
color: "#ffffff"
|
||||
sprite: Objects/Misc/handcuffs.rsi
|
||||
state: body-overlay-2
|
||||
visible: false
|
||||
- map: ["enum.Slots.IDCARD"]
|
||||
- map: ["enum.Slots.GLOVES"]
|
||||
- map: ["enum.Slots.SHOES"]
|
||||
@@ -231,6 +232,7 @@
|
||||
color: "#ffffff"
|
||||
sprite: Objects/Misc/handcuffs.rsi
|
||||
state: body-overlay-2
|
||||
visible: false
|
||||
- map: ["enum.Slots.IDCARD"]
|
||||
- map: ["enum.Slots.GLOVES"]
|
||||
- map: ["enum.Slots.SHOES"]
|
||||
|
||||
Reference in New Issue
Block a user