2022-06-30 03:44:53 -04:00
|
|
|
using Content.Server.Actions;
|
|
|
|
|
using Content.Server.Atmos.Components;
|
2022-07-25 14:42:25 +10:00
|
|
|
using Content.Server.Atmos.EntitySystems;
|
2022-06-30 03:44:53 -04:00
|
|
|
using Content.Server.Body.Components;
|
2022-07-25 14:42:25 +10:00
|
|
|
using Content.Server.Body.Systems;
|
2022-06-30 03:44:53 -04:00
|
|
|
using Content.Server.Clothing.Components;
|
2022-07-13 22:23:55 -07:00
|
|
|
using Content.Server.IdentityManagement;
|
2022-06-30 03:44:53 -04:00
|
|
|
using Content.Server.Nutrition.EntitySystems;
|
|
|
|
|
using Content.Server.Popups;
|
2022-09-28 19:22:27 -07:00
|
|
|
using Content.Server.VoiceMask;
|
2022-10-23 11:30:37 +13:00
|
|
|
using Content.Shared.Actions;
|
|
|
|
|
using Content.Shared.Clothing.Components;
|
2022-07-27 03:53:47 -07:00
|
|
|
using Content.Shared.Clothing.EntitySystems;
|
2022-07-13 22:23:55 -07:00
|
|
|
using Content.Shared.IdentityManagement.Components;
|
2022-10-23 11:30:37 +13:00
|
|
|
using Content.Shared.Inventory;
|
|
|
|
|
using Content.Shared.Inventory.Events;
|
2022-06-30 03:44:53 -04:00
|
|
|
|
|
|
|
|
namespace Content.Server.Clothing
|
|
|
|
|
{
|
|
|
|
|
public sealed class MaskSystem : EntitySystem
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly ActionsSystem _actionSystem = default!;
|
2022-07-25 14:42:25 +10:00
|
|
|
[Dependency] private readonly AtmosphereSystem _atmos = default!;
|
|
|
|
|
[Dependency] private readonly InternalsSystem _internals = default!;
|
|
|
|
|
[Dependency] private readonly InventorySystem _inventorySystem = default!;
|
|
|
|
|
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
2022-07-13 22:23:55 -07:00
|
|
|
[Dependency] private readonly IdentitySystem _identity = default!;
|
2022-07-27 03:53:47 -07:00
|
|
|
[Dependency] private readonly ClothingSystem _clothing = default!;
|
2022-07-13 22:23:55 -07:00
|
|
|
|
2022-06-30 03:44:53 -04:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<MaskComponent, ToggleMaskEvent>(OnToggleMask);
|
|
|
|
|
SubscribeLocalEvent<MaskComponent, GetItemActionsEvent>(OnGetActions);
|
|
|
|
|
SubscribeLocalEvent<MaskComponent, GotUnequippedEvent>(OnGotUnequipped);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnGetActions(EntityUid uid, MaskComponent component, GetItemActionsEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (component.ToggleAction != null && !args.InHands)
|
|
|
|
|
args.Actions.Add(component.ToggleAction);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnToggleMask(EntityUid uid, MaskComponent mask, ToggleMaskEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (mask.ToggleAction == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!_inventorySystem.TryGetSlotEntity(args.Performer, "mask", out var existing) || !mask.Owner.Equals(existing))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
mask.IsToggled ^= true;
|
|
|
|
|
_actionSystem.SetToggled(mask.ToggleAction, mask.IsToggled);
|
|
|
|
|
|
2022-07-13 22:23:55 -07:00
|
|
|
// Pulling mask down can change identity, so we want to update that
|
|
|
|
|
_identity.QueueIdentityUpdate(args.Performer);
|
|
|
|
|
|
2022-06-30 03:44:53 -04:00
|
|
|
if (mask.IsToggled)
|
2022-12-19 10:41:47 +13:00
|
|
|
_popupSystem.PopupEntity(Loc.GetString("action-mask-pull-down-popup-message", ("mask", mask.Owner)), args.Performer, args.Performer);
|
2022-06-30 03:44:53 -04:00
|
|
|
else
|
2022-12-19 10:41:47 +13:00
|
|
|
_popupSystem.PopupEntity(Loc.GetString("action-mask-pull-up-popup-message", ("mask", mask.Owner)), args.Performer, args.Performer);
|
2022-06-30 03:44:53 -04:00
|
|
|
|
|
|
|
|
ToggleMaskComponents(uid, mask, args.Performer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// set to untoggled when unequipped, so it isn't left in a 'pulled down' state
|
|
|
|
|
private void OnGotUnequipped(EntityUid uid, MaskComponent mask, GotUnequippedEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (mask.ToggleAction == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
mask.IsToggled = false;
|
|
|
|
|
_actionSystem.SetToggled(mask.ToggleAction, mask.IsToggled);
|
|
|
|
|
|
|
|
|
|
ToggleMaskComponents(uid, mask, args.Equipee, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ToggleMaskComponents(EntityUid uid, MaskComponent mask, EntityUid wearer, bool isEquip = false)
|
|
|
|
|
{
|
2023-05-07 17:50:37 +10:00
|
|
|
// toggle visuals
|
|
|
|
|
if (TryComp<ClothingComponent>(uid, out var clothing))
|
2022-06-30 03:44:53 -04:00
|
|
|
{
|
|
|
|
|
//TODO: sprites for 'pulled down' state. defaults to invisible due to no sprite with this prefix
|
2022-07-27 03:53:47 -07:00
|
|
|
_clothing.SetEquippedPrefix(uid, mask.IsToggled ? "toggled" : null, clothing);
|
2022-06-30 03:44:53 -04:00
|
|
|
}
|
|
|
|
|
|
2022-09-28 19:22:27 -07:00
|
|
|
// shouldn't this be an event?
|
|
|
|
|
|
2022-07-13 22:23:55 -07:00
|
|
|
// toggle ingestion blocking
|
2022-06-30 03:44:53 -04:00
|
|
|
if (TryComp<IngestionBlockerComponent>(uid, out var blocker))
|
|
|
|
|
blocker.Enabled = !mask.IsToggled;
|
|
|
|
|
|
2022-07-13 22:23:55 -07:00
|
|
|
// toggle identity
|
|
|
|
|
if (TryComp<IdentityBlockerComponent>(uid, out var identity))
|
|
|
|
|
identity.Enabled = !mask.IsToggled;
|
|
|
|
|
|
2022-09-28 19:22:27 -07:00
|
|
|
// toggle voice masking
|
2022-10-03 18:14:07 -07:00
|
|
|
if (TryComp<VoiceMaskComponent>(wearer, out var voiceMask))
|
2022-09-28 19:22:27 -07:00
|
|
|
voiceMask.Enabled = !mask.IsToggled;
|
|
|
|
|
|
2022-07-13 22:23:55 -07:00
|
|
|
// toggle breath tool connection (skip during equip since that is handled in LungSystem)
|
2022-06-30 03:44:53 -04:00
|
|
|
if (isEquip || !TryComp<BreathToolComponent>(uid, out var breathTool))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (mask.IsToggled)
|
|
|
|
|
{
|
2022-07-25 14:42:25 +10:00
|
|
|
_atmos.DisconnectInternals(breathTool);
|
2022-06-30 03:44:53 -04:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
breathTool.IsFunctional = true;
|
|
|
|
|
|
|
|
|
|
if (TryComp(wearer, out InternalsComponent? internals))
|
|
|
|
|
{
|
|
|
|
|
breathTool.ConnectedInternalsEntity = wearer;
|
2022-07-25 14:42:25 +10:00
|
|
|
_internals.ConnectBreathTool(internals, uid);
|
2022-06-30 03:44:53 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|