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 Robust.Shared.Maths;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Serilog;
|
using Content.Server.GameObjects.Components.GUI;
|
||||||
|
|
||||||
namespace Content.Server.GameObjects.Components.ActionBlocking
|
namespace Content.Server.GameObjects.Components.ActionBlocking
|
||||||
{
|
{
|
||||||
@@ -48,7 +48,6 @@ namespace Content.Server.GameObjects.Components.ActionBlocking
|
|||||||
[ViewVariables(VVAccess.ReadOnly)]
|
[ViewVariables(VVAccess.ReadOnly)]
|
||||||
private Container _container = default!;
|
private Container _container = default!;
|
||||||
|
|
||||||
private bool _dirtyThisFrame = false;
|
|
||||||
private float _interactRange;
|
private float _interactRange;
|
||||||
private IHandsComponent _hands;
|
private IHandsComponent _hands;
|
||||||
|
|
||||||
@@ -61,6 +60,8 @@ namespace Content.Server.GameObjects.Components.ActionBlocking
|
|||||||
_container = ContainerManagerComponent.Ensure<Container>(Name, Owner);
|
_container = ContainerManagerComponent.Ensure<Container>(Name, Owner);
|
||||||
_interactRange = SharedInteractionSystem.InteractionRange / 2;
|
_interactRange = SharedInteractionSystem.InteractionRange / 2;
|
||||||
|
|
||||||
|
Owner.EntityManager.EventBus.SubscribeEvent<HandCountChangedEvent>(EventSource.Local, this, HandleHandCountChange);
|
||||||
|
|
||||||
if (!Owner.TryGetComponent(out _hands))
|
if (!Owner.TryGetComponent(out _hands))
|
||||||
{
|
{
|
||||||
Logger.Warning("Player does not have an IHandsComponent!");
|
Logger.Warning("Player does not have an IHandsComponent!");
|
||||||
@@ -127,29 +128,24 @@ namespace Content.Server.GameObjects.Components.ActionBlocking
|
|||||||
Dirty();
|
Dirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update(float frameTime)
|
|
||||||
{
|
|
||||||
UpdateHandCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <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 UpdateHandCount()
|
private void UpdateHandCount()
|
||||||
{
|
{
|
||||||
_dirtyThisFrame = false;
|
var dirty = false;
|
||||||
var handCount = _hands.Hands.Count();
|
var handCount = _hands.Hands.Count();
|
||||||
|
|
||||||
while (CuffedHandCount > handCount && CuffedHandCount > 0)
|
while (CuffedHandCount > handCount && CuffedHandCount > 0)
|
||||||
{
|
{
|
||||||
_dirtyThisFrame = true;
|
dirty = true;
|
||||||
|
|
||||||
var entity = _container.ContainedEntities[_container.ContainedEntities.Count - 1];
|
var entity = _container.ContainedEntities[_container.ContainedEntities.Count - 1];
|
||||||
_container.Remove(entity);
|
_container.Remove(entity);
|
||||||
entity.Transform.WorldPosition = Owner.Transform.GridPosition.Position;
|
entity.Transform.WorldPosition = Owner.Transform.GridPosition.Position;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_dirtyThisFrame)
|
if (dirty)
|
||||||
{
|
{
|
||||||
CanStillInteract = handCount > CuffedHandCount;
|
CanStillInteract = handCount > CuffedHandCount;
|
||||||
OnCuffedStateChanged.Invoke();
|
OnCuffedStateChanged.Invoke();
|
||||||
@@ -157,6 +153,14 @@ namespace Content.Server.GameObjects.Components.ActionBlocking
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void HandleHandCountChange(HandCountChangedEvent message)
|
||||||
|
{
|
||||||
|
if (message.Sender == Owner)
|
||||||
|
{
|
||||||
|
UpdateHandCount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check how many items the user is holding and if it's more than the number of cuffed hands, drop some items.
|
/// Check how many items the user is holding and if it's more than the number of cuffed hands, drop some items.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ using Robust.Shared.Map;
|
|||||||
using Robust.Shared.Maths;
|
using Robust.Shared.Maths;
|
||||||
using Robust.Shared.Players;
|
using Robust.Shared.Players;
|
||||||
using Robust.Shared.ViewVariables;
|
using Robust.Shared.ViewVariables;
|
||||||
|
using Content.Server.GameObjects.Components.ActionBlocking;
|
||||||
|
|
||||||
namespace Content.Server.GameObjects.Components.GUI
|
namespace Content.Server.GameObjects.Components.GUI
|
||||||
{
|
{
|
||||||
@@ -444,6 +445,7 @@ namespace Content.Server.GameObjects.Components.GUI
|
|||||||
ActiveHand ??= name;
|
ActiveHand ??= name;
|
||||||
|
|
||||||
OnItemChanged?.Invoke();
|
OnItemChanged?.Invoke();
|
||||||
|
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new HandCountChangedEvent(Owner));
|
||||||
|
|
||||||
Dirty();
|
Dirty();
|
||||||
}
|
}
|
||||||
@@ -466,6 +468,7 @@ namespace Content.Server.GameObjects.Components.GUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
OnItemChanged?.Invoke();
|
OnItemChanged?.Invoke();
|
||||||
|
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new HandCountChangedEvent(Owner));
|
||||||
|
|
||||||
Dirty();
|
Dirty();
|
||||||
}
|
}
|
||||||
@@ -791,4 +794,14 @@ namespace Content.Server.GameObjects.Components.GUI
|
|||||||
return new SharedHand(index, Name, Entity?.Uid, location);
|
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"
|
color: "#ffffff"
|
||||||
sprite: Objects/Misc/handcuffs.rsi
|
sprite: Objects/Misc/handcuffs.rsi
|
||||||
state: body-overlay-2
|
state: body-overlay-2
|
||||||
|
visible: false
|
||||||
- map: ["enum.Slots.IDCARD"]
|
- map: ["enum.Slots.IDCARD"]
|
||||||
- map: ["enum.Slots.GLOVES"]
|
- map: ["enum.Slots.GLOVES"]
|
||||||
- map: ["enum.Slots.SHOES"]
|
- map: ["enum.Slots.SHOES"]
|
||||||
@@ -231,6 +232,7 @@
|
|||||||
color: "#ffffff"
|
color: "#ffffff"
|
||||||
sprite: Objects/Misc/handcuffs.rsi
|
sprite: Objects/Misc/handcuffs.rsi
|
||||||
state: body-overlay-2
|
state: body-overlay-2
|
||||||
|
visible: false
|
||||||
- map: ["enum.Slots.IDCARD"]
|
- map: ["enum.Slots.IDCARD"]
|
||||||
- map: ["enum.Slots.GLOVES"]
|
- map: ["enum.Slots.GLOVES"]
|
||||||
- map: ["enum.Slots.SHOES"]
|
- map: ["enum.Slots.SHOES"]
|
||||||
|
|||||||
Reference in New Issue
Block a user