2021-11-11 16:10:57 -07:00
|
|
|
|
using Content.Server.Body.Components;
|
2021-06-09 22:19:39 +02:00
|
|
|
|
using Content.Shared.Inventory;
|
2020-10-27 20:53:44 +01:00
|
|
|
|
using Robust.Shared.GameObjects;
|
2021-12-03 14:17:01 +01:00
|
|
|
|
using Robust.Shared.IoC;
|
2021-03-05 01:08:38 +01:00
|
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2020-10-27 20:53:44 +01:00
|
|
|
|
|
2021-06-19 13:25:05 +02:00
|
|
|
|
namespace Content.Server.Atmos.Components
|
2020-10-27 20:53:44 +01:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Used in internals as breath tool.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[RegisterComponent]
|
|
|
|
|
|
public class BreathToolComponent : Component, IEquipped, IUnequipped
|
|
|
|
|
|
{
|
2021-12-05 18:09:01 +01:00
|
|
|
|
[Dependency] private readonly IEntityManager _entities = default!;
|
|
|
|
|
|
|
2020-10-27 20:53:44 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Tool is functional only in allowed slots
|
|
|
|
|
|
/// </summary>
|
2021-03-05 01:08:38 +01:00
|
|
|
|
[DataField("allowedSlots")]
|
|
|
|
|
|
private EquipmentSlotDefines.SlotFlags _allowedSlots = EquipmentSlotDefines.SlotFlags.MASK;
|
2020-10-27 20:53:44 +01:00
|
|
|
|
|
|
|
|
|
|
public override string Name => "BreathMask";
|
|
|
|
|
|
public bool IsFunctional { get; private set; }
|
2021-12-05 18:09:01 +01:00
|
|
|
|
public EntityUid ConnectedInternalsEntity { get; private set; }
|
2020-10-27 20:53:44 +01:00
|
|
|
|
|
|
|
|
|
|
protected override void Shutdown()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Shutdown();
|
|
|
|
|
|
DisconnectInternals();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-04 17:44:49 +01:00
|
|
|
|
void IEquipped.Equipped(EquippedEventArgs eventArgs)
|
2020-10-27 20:53:44 +01:00
|
|
|
|
{
|
|
|
|
|
|
if ((EquipmentSlotDefines.SlotMasks[eventArgs.Slot] & _allowedSlots) != _allowedSlots) return;
|
|
|
|
|
|
IsFunctional = true;
|
|
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
|
if (_entities.TryGetComponent(eventArgs.User, out InternalsComponent? internals))
|
2020-10-27 20:53:44 +01:00
|
|
|
|
{
|
|
|
|
|
|
ConnectedInternalsEntity = eventArgs.User;
|
|
|
|
|
|
internals.ConnectBreathTool(Owner);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-04 17:44:49 +01:00
|
|
|
|
void IUnequipped.Unequipped(UnequippedEventArgs eventArgs)
|
2020-10-27 20:53:44 +01:00
|
|
|
|
{
|
|
|
|
|
|
DisconnectInternals();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void DisconnectInternals()
|
|
|
|
|
|
{
|
|
|
|
|
|
var old = ConnectedInternalsEntity;
|
2021-12-05 18:09:01 +01:00
|
|
|
|
ConnectedInternalsEntity = default;
|
2020-10-27 20:53:44 +01:00
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
|
if (old != default && _entities.TryGetComponent<InternalsComponent?>(old, out var internalsComponent))
|
2020-10-27 20:53:44 +01:00
|
|
|
|
{
|
|
|
|
|
|
internalsComponent.DisconnectBreathTool();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
IsFunctional = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|