2020-12-20 04:31:39 +01:00
|
|
|
|
using System.Collections.Generic;
|
2021-06-09 22:19:39 +02:00
|
|
|
|
using Content.Server.Body.Surgery.Messages;
|
|
|
|
|
|
using Content.Shared.ActionBlocker;
|
2020-12-20 04:31:39 +01:00
|
|
|
|
using Content.Shared.GameTicking;
|
2021-06-19 10:03:24 +02:00
|
|
|
|
using Content.Shared.Interaction.Events;
|
2021-06-09 22:19:39 +02:00
|
|
|
|
using Content.Shared.Interaction.Helpers;
|
2020-12-20 04:31:39 +01:00
|
|
|
|
using JetBrains.Annotations;
|
2021-02-11 01:13:03 -08:00
|
|
|
|
using Robust.Shared.GameObjects;
|
2021-07-26 12:58:17 +02:00
|
|
|
|
using Robust.Shared.IoC;
|
2020-12-20 04:31:39 +01:00
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
|
namespace Content.Server.Body.Surgery.Components
|
2020-12-20 04:31:39 +01:00
|
|
|
|
{
|
|
|
|
|
|
[UsedImplicitly]
|
2021-06-29 15:56:07 +02:00
|
|
|
|
public class SurgeryToolSystem : EntitySystem
|
2020-12-20 04:31:39 +01:00
|
|
|
|
{
|
2021-07-26 12:58:17 +02:00
|
|
|
|
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
|
|
|
|
|
|
2020-12-20 04:31:39 +01:00
|
|
|
|
private readonly HashSet<SurgeryToolComponent> _openSurgeryUIs = new();
|
|
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
2021-06-29 15:56:07 +02:00
|
|
|
|
SubscribeLocalEvent<RoundRestartCleanupEvent>(Reset);
|
2020-12-20 04:31:39 +01:00
|
|
|
|
SubscribeLocalEvent<SurgeryWindowOpenMessage>(OnSurgeryWindowOpen);
|
|
|
|
|
|
SubscribeLocalEvent<SurgeryWindowCloseMessage>(OnSurgeryWindowClose);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-06-29 15:56:07 +02:00
|
|
|
|
public void Reset(RoundRestartCleanupEvent ev)
|
2020-12-20 04:31:39 +01:00
|
|
|
|
{
|
|
|
|
|
|
_openSurgeryUIs.Clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnSurgeryWindowOpen(SurgeryWindowOpenMessage ev)
|
|
|
|
|
|
{
|
|
|
|
|
|
_openSurgeryUIs.Add(ev.Tool);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnSurgeryWindowClose(SurgeryWindowCloseMessage ev)
|
|
|
|
|
|
{
|
|
|
|
|
|
_openSurgeryUIs.Remove(ev.Tool);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void Update(float frameTime)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Update(frameTime);
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var tool in _openSurgeryUIs)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (tool.PerformerCache == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (tool.BodyCache == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-11-09 14:54:00 +01:00
|
|
|
|
if (!_actionBlockerSystem.CanInteract(tool.PerformerCache.Uid) ||
|
2020-12-20 04:31:39 +01:00
|
|
|
|
!tool.PerformerCache.InRangeUnobstructed(tool.BodyCache))
|
|
|
|
|
|
{
|
|
|
|
|
|
tool.CloseAllSurgeryUIs();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|