2020-09-13 14:23:52 +02:00
|
|
|
using System.Text;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Disposal.Unit.Components;
|
|
|
|
|
using Content.Server.UserInterface;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Server.GameObjects;
|
2020-08-19 15:50:06 +02:00
|
|
|
using Robust.Shared.Audio;
|
2021-03-08 04:09:59 +11:00
|
|
|
using Robust.Shared.Physics;
|
2021-03-21 09:12:03 -07:00
|
|
|
using Robust.Shared.Player;
|
2021-06-09 22:19:39 +02:00
|
|
|
using static Content.Shared.Disposal.Components.SharedDisposalRouterComponent;
|
2020-08-19 15:50:06 +02:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Disposal.Tube.Components
|
2020-08-19 15:50:06 +02:00
|
|
|
{
|
|
|
|
|
[RegisterComponent]
|
|
|
|
|
[ComponentReference(typeof(IDisposalTubeComponent))]
|
2022-05-28 16:29:12 +02:00
|
|
|
[ComponentReference(typeof(DisposalTubeComponent))]
|
2022-03-12 13:26:06 -05:00
|
|
|
public sealed class DisposalRouterComponent : DisposalJunctionComponent
|
2020-08-19 15:50:06 +02:00
|
|
|
{
|
2022-08-17 14:17:32 +12:00
|
|
|
public override string ContainerId => "DisposalRouter";
|
|
|
|
|
|
2021-12-08 17:17:12 +01:00
|
|
|
[Dependency] private readonly IEntityManager _entMan = default!;
|
|
|
|
|
|
2022-09-13 21:14:21 +02:00
|
|
|
[DataField("tags")]
|
|
|
|
|
public HashSet<string> Tags = new();
|
2020-08-19 15:50:06 +02:00
|
|
|
|
|
|
|
|
[ViewVariables]
|
|
|
|
|
public bool Anchored =>
|
2021-12-08 17:17:12 +01:00
|
|
|
!_entMan.TryGetComponent(Owner, out IPhysBody? physics) ||
|
2021-03-08 04:09:59 +11:00
|
|
|
physics.BodyType == BodyType.Static;
|
2020-08-19 15:50:06 +02:00
|
|
|
|
2022-08-18 23:48:00 +02:00
|
|
|
[ViewVariables] public BoundUserInterface? UserInterface => Owner.GetUIOrNull(DisposalRouterUiKey.Key);
|
2020-08-22 22:29:20 +02:00
|
|
|
|
2021-07-10 17:35:33 +02:00
|
|
|
[DataField("clickSound")] private SoundSpecifier _clickSound = new SoundPathSpecifier("/Audio/Machines/machine_switch.ogg");
|
|
|
|
|
|
2020-08-19 15:50:06 +02:00
|
|
|
public override Direction NextDirection(DisposalHolderComponent holder)
|
|
|
|
|
{
|
|
|
|
|
var directions = ConnectableDirections();
|
|
|
|
|
|
2022-08-18 23:48:00 +02:00
|
|
|
if (holder.Tags.Overlaps(Tags))
|
2020-08-19 15:50:06 +02:00
|
|
|
{
|
|
|
|
|
return directions[1];
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-08 17:17:12 +01:00
|
|
|
return _entMan.GetComponent<TransformComponent>(Owner).LocalRotation.GetDir();
|
2020-08-19 15:50:06 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-19 19:41:26 -07:00
|
|
|
protected override void Initialize()
|
2020-08-19 15:50:06 +02:00
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
2020-08-22 22:29:20 +02:00
|
|
|
if (UserInterface != null)
|
|
|
|
|
{
|
|
|
|
|
UserInterface.OnReceiveMessage += OnUiReceiveMessage;
|
|
|
|
|
}
|
2020-08-19 15:50:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handles ui messages from the client. For things such as button presses
|
|
|
|
|
/// which interact with the world and require server action.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="obj">A user interface message from the client.</param>
|
|
|
|
|
private void OnUiReceiveMessage(ServerBoundUserInterfaceMessage obj)
|
|
|
|
|
{
|
2020-08-22 22:29:20 +02:00
|
|
|
if (obj.Session.AttachedEntity == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-19 15:50:06 +02:00
|
|
|
var msg = (UiActionMessage) obj.Message;
|
|
|
|
|
|
2022-02-15 17:06:52 +13:00
|
|
|
if (!Anchored)
|
2020-08-19 15:50:06 +02:00
|
|
|
return;
|
|
|
|
|
|
2020-08-19 20:43:56 +02:00
|
|
|
//Check for correct message and ignore maleformed strings
|
|
|
|
|
if (msg.Action == UiAction.Ok && TagRegex.IsMatch(msg.Tags))
|
2020-08-19 15:50:06 +02:00
|
|
|
{
|
2022-08-18 23:48:00 +02:00
|
|
|
Tags.Clear();
|
2020-08-19 15:50:06 +02:00
|
|
|
foreach (var tag in msg.Tags.Split(',', StringSplitOptions.RemoveEmptyEntries))
|
|
|
|
|
{
|
2022-08-18 23:48:00 +02:00
|
|
|
Tags.Add(tag.Trim());
|
2020-08-19 20:43:56 +02:00
|
|
|
ClickSound();
|
2020-08-19 15:50:06 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ClickSound()
|
|
|
|
|
{
|
2022-06-12 19:45:47 -04:00
|
|
|
SoundSystem.Play(_clickSound.GetSound(), Filter.Pvs(Owner), Owner, AudioParams.Default.WithVolume(-2f));
|
2020-08-19 15:50:06 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-19 19:41:26 -07:00
|
|
|
protected override void OnRemove()
|
2020-08-19 15:50:06 +02:00
|
|
|
{
|
2020-08-22 22:29:20 +02:00
|
|
|
UserInterface?.CloseAll();
|
2020-08-19 15:50:06 +02:00
|
|
|
base.OnRemove();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|