2021-06-08 19:10:29 -07:00
|
|
|
using Content.Shared.Audio;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Cabinet;
|
2021-10-06 08:55:45 +11:00
|
|
|
using Content.Shared.Containers.ItemSlots;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Interaction;
|
2021-10-05 14:29:03 +11:00
|
|
|
using Content.Shared.Verbs;
|
2021-06-08 19:10:29 -07:00
|
|
|
using Robust.Shared.Audio;
|
2021-11-20 18:26:01 +13:00
|
|
|
using Robust.Shared.Containers;
|
2021-06-08 19:10:29 -07:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-10-05 14:29:03 +11:00
|
|
|
using Robust.Shared.IoC;
|
2021-06-08 19:10:29 -07:00
|
|
|
using Robust.Shared.Localization;
|
|
|
|
|
using Robust.Shared.Player;
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Cabinet
|
2021-06-08 19:10:29 -07:00
|
|
|
{
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class ItemCabinetSystem : EntitySystem
|
2021-06-08 19:10:29 -07:00
|
|
|
{
|
2021-11-20 18:26:01 +13:00
|
|
|
[Dependency] private readonly ItemSlotsSystem _itemSlotsSystem = default!;
|
2021-10-05 14:29:03 +11:00
|
|
|
|
2021-06-08 19:10:29 -07:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
2021-11-20 18:26:01 +13:00
|
|
|
SubscribeLocalEvent<ItemCabinetComponent, ComponentInit>(OnComponentInit);
|
|
|
|
|
SubscribeLocalEvent<ItemCabinetComponent, ComponentRemove>(OnComponentRemove);
|
|
|
|
|
SubscribeLocalEvent<ItemCabinetComponent, ComponentStartup>(OnComponentStartup);
|
|
|
|
|
|
2021-06-08 19:10:29 -07:00
|
|
|
SubscribeLocalEvent<ItemCabinetComponent, ActivateInWorldEvent>(OnActivateInWorld);
|
2022-02-10 15:30:59 +13:00
|
|
|
SubscribeLocalEvent<ItemCabinetComponent, GetVerbsEvent<ActivationVerb>>(AddToggleOpenVerb);
|
2021-11-20 18:26:01 +13:00
|
|
|
|
|
|
|
|
SubscribeLocalEvent<ItemCabinetComponent, EntInsertedIntoContainerMessage>(OnContainerModified);
|
|
|
|
|
SubscribeLocalEvent<ItemCabinetComponent, EntRemovedFromContainerMessage>(OnContainerModified);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnComponentInit(EntityUid uid, ItemCabinetComponent cabinet, ComponentInit args)
|
|
|
|
|
{
|
|
|
|
|
_itemSlotsSystem.AddItemSlot(uid, cabinet.Name, cabinet.CabinetSlot);
|
|
|
|
|
}
|
|
|
|
|
private void OnComponentRemove(EntityUid uid, ItemCabinetComponent cabinet, ComponentRemove args)
|
|
|
|
|
{
|
|
|
|
|
_itemSlotsSystem.RemoveItemSlot(uid, cabinet.CabinetSlot);
|
2021-10-06 08:55:45 +11:00
|
|
|
}
|
2021-06-08 19:10:29 -07:00
|
|
|
|
2021-11-20 18:26:01 +13:00
|
|
|
private void OnComponentStartup(EntityUid uid, ItemCabinetComponent cabinet, ComponentStartup args)
|
2021-10-06 08:55:45 +11:00
|
|
|
{
|
2021-11-20 18:26:01 +13:00
|
|
|
UpdateAppearance(uid, cabinet);
|
2022-01-18 08:22:35 +13:00
|
|
|
_itemSlotsSystem.SetLock(uid, cabinet.CabinetSlot, !cabinet.Opened);
|
2021-10-06 08:55:45 +11:00
|
|
|
}
|
2021-10-05 14:29:03 +11:00
|
|
|
|
2021-10-06 08:55:45 +11:00
|
|
|
private void UpdateAppearance(EntityUid uid,
|
|
|
|
|
ItemCabinetComponent? cabinet = null,
|
2021-11-22 23:22:59 -08:00
|
|
|
AppearanceComponent? appearance = null)
|
2021-10-06 08:55:45 +11:00
|
|
|
{
|
2021-11-20 18:26:01 +13:00
|
|
|
if (!Resolve(uid, ref cabinet, ref appearance, false))
|
2021-10-06 08:55:45 +11:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
appearance.SetData(ItemCabinetVisuals.IsOpen, cabinet.Opened);
|
2021-11-20 18:26:01 +13:00
|
|
|
appearance.SetData(ItemCabinetVisuals.ContainsItem, cabinet.CabinetSlot.HasItem);
|
2021-10-05 14:29:03 +11:00
|
|
|
}
|
|
|
|
|
|
2021-11-20 18:26:01 +13:00
|
|
|
private void OnContainerModified(EntityUid uid, ItemCabinetComponent cabinet, ContainerModifiedMessage args)
|
2021-10-06 08:55:45 +11:00
|
|
|
{
|
2021-12-16 23:42:02 +13:00
|
|
|
if (!cabinet.Initialized) return;
|
|
|
|
|
|
2021-11-20 18:26:01 +13:00
|
|
|
if (args.Container.ID == cabinet.CabinetSlot.ID)
|
|
|
|
|
UpdateAppearance(uid, cabinet);
|
2021-10-06 08:55:45 +11:00
|
|
|
}
|
|
|
|
|
|
2022-02-10 15:30:59 +13:00
|
|
|
private void AddToggleOpenVerb(EntityUid uid, ItemCabinetComponent cabinet, GetVerbsEvent<ActivationVerb> args)
|
2021-10-05 14:29:03 +11:00
|
|
|
{
|
|
|
|
|
if (args.Hands == null || !args.CanAccess || !args.CanInteract)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Toggle open verb
|
2022-02-10 15:30:59 +13:00
|
|
|
ActivationVerb toggleVerb = new();
|
2021-10-06 08:55:45 +11:00
|
|
|
toggleVerb.Act = () => ToggleItemCabinet(uid, cabinet);
|
|
|
|
|
if (cabinet.Opened)
|
2021-10-05 14:29:03 +11:00
|
|
|
{
|
2021-10-28 18:21:19 +13:00
|
|
|
toggleVerb.Text = Loc.GetString("verb-common-close");
|
2021-10-05 14:29:03 +11:00
|
|
|
toggleVerb.IconTexture = "/Textures/Interface/VerbIcons/close.svg.192dpi.png";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-10-28 18:21:19 +13:00
|
|
|
toggleVerb.Text = Loc.GetString("verb-common-open");
|
2021-10-05 14:29:03 +11:00
|
|
|
toggleVerb.IconTexture = "/Textures/Interface/VerbIcons/open.svg.192dpi.png";
|
|
|
|
|
}
|
|
|
|
|
args.Verbs.Add(toggleVerb);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-06 08:55:45 +11:00
|
|
|
private void OnActivateInWorld(EntityUid uid, ItemCabinetComponent comp, ActivateInWorldEvent args)
|
2021-06-08 19:10:29 -07:00
|
|
|
{
|
2021-10-06 08:55:45 +11:00
|
|
|
if (args.Handled)
|
|
|
|
|
return;
|
2021-06-08 19:10:29 -07:00
|
|
|
|
2021-10-06 08:55:45 +11:00
|
|
|
args.Handled = true;
|
|
|
|
|
ToggleItemCabinet(uid, comp);
|
2021-06-08 19:10:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2021-10-06 08:55:45 +11:00
|
|
|
/// Toggles the ItemCabinet's state.
|
2021-06-08 19:10:29 -07:00
|
|
|
/// </summary>
|
2021-10-06 08:55:45 +11:00
|
|
|
private void ToggleItemCabinet(EntityUid uid, ItemCabinetComponent? cabinet = null)
|
2021-06-08 19:10:29 -07:00
|
|
|
{
|
2021-10-06 08:55:45 +11:00
|
|
|
if (!Resolve(uid, ref cabinet))
|
|
|
|
|
return;
|
2021-06-08 19:10:29 -07:00
|
|
|
|
2021-10-06 08:55:45 +11:00
|
|
|
cabinet.Opened = !cabinet.Opened;
|
|
|
|
|
SoundSystem.Play(Filter.Pvs(uid), cabinet.DoorSound.GetSound(), uid, AudioHelpers.WithVariation(0.15f));
|
2022-01-18 08:22:35 +13:00
|
|
|
_itemSlotsSystem.SetLock(uid, cabinet.CabinetSlot, !cabinet.Opened);
|
2021-06-08 19:10:29 -07:00
|
|
|
|
2021-10-06 08:55:45 +11:00
|
|
|
UpdateAppearance(uid, cabinet);
|
2021-06-08 19:10:29 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|