--- /dev/null
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Containers.ItemSlots;
+
+/// <summary>
+/// Updates the relevant ItemSlots locks based on <see cref="LockComponent"/>
+/// </summary>
+[RegisterComponent, NetworkedComponent]
+public sealed partial class ItemSlotsLockComponent : Component
+{
+ [DataField(required: true)]
+ public List<string> Slots = new();
+}
--- /dev/null
+using Content.Shared.Lock;
+
+namespace Content.Shared.Containers.ItemSlots;
+
+public sealed partial class ItemSlotsSystem
+{
+ private void InitializeLock()
+ {
+ SubscribeLocalEvent<ItemSlotsLockComponent, MapInitEvent>(OnLockMapInit);
+ SubscribeLocalEvent<ItemSlotsLockComponent, LockToggledEvent>(OnLockToggled);
+ }
+
+ private void OnLockMapInit(Entity<ItemSlotsLockComponent> ent, ref MapInitEvent args)
+ {
+ if (!TryComp(ent.Owner, out LockComponent? lockComp))
+ return;
+
+ UpdateLocks(ent, lockComp.Locked);
+ }
+
+ private void OnLockToggled(Entity<ItemSlotsLockComponent> ent, ref LockToggledEvent args)
+ {
+ UpdateLocks(ent, args.Locked);
+ }
+
+ private void UpdateLocks(Entity<ItemSlotsLockComponent> ent, bool value)
+ {
+ foreach (var slot in ent.Comp.Slots)
+ {
+ if (!TryGetSlot(ent.Owner, slot, out var itemSlot))
+ continue;
+
+ SetLock(ent.Owner, itemSlot, value);
+ }
+ }
+}
/// Note when using popups on entities with many slots with InsertOnInteract, EjectOnInteract or EjectOnUse:
/// A single use will try to insert to/eject from every slot and generate a popup for each that fails.
/// </remarks>
- public sealed class ItemSlotsSystem : EntitySystem
+ public sealed partial class ItemSlotsSystem : EntitySystem
{
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
{
base.Initialize();
+ InitializeLock();
+
SubscribeLocalEvent<ItemSlotsComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<ItemSlotsComponent, ComponentInit>(Oninitialize);
[DataField, AutoNetworkedField]
public bool Activated = false;
+ /// <summary>
+ /// Can the entity be activated in the world.
+ /// </summary>
+ [DataField]
+ public bool OnActivate = true;
+
/// <summary>
/// If this is set to false then the item can't be toggled by pressing Z.
/// Use another system to do it then.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
public SoundSpecifier? SoundFailToActivate;
-
- /// <summary>
- /// Whether or not to toggle the entity's lights on or off.
- /// </summary>
- [ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
- public bool ToggleLight = true;
}
/// <summary>
+using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.Item.ItemToggle.Components;
using Content.Shared.Popups;
using Content.Shared.Temperature;
using Content.Shared.Toggleable;
+using Content.Shared.Verbs;
using Content.Shared.Wieldable;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
[Dependency] private readonly INetManager _netManager = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
- [Dependency] private readonly SharedPointLightSystem _light = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
private EntityQuery<ItemToggleComponent> _query;
SubscribeLocalEvent<ItemToggleComponent, ItemUnwieldedEvent>(TurnOffOnUnwielded);
SubscribeLocalEvent<ItemToggleComponent, ItemWieldedEvent>(TurnOnOnWielded);
SubscribeLocalEvent<ItemToggleComponent, UseInHandEvent>(OnUseInHand);
+ SubscribeLocalEvent<ItemToggleComponent, GetVerbsEvent<ActivationVerb>>(OnActivateVerb);
+ SubscribeLocalEvent<ItemToggleComponent, ActivateInWorldEvent>(OnActivate);
SubscribeLocalEvent<ItemToggleHotComponent, IsHotEvent>(OnIsHotEvent);
Toggle((ent, ent.Comp), args.User, predicted: ent.Comp.Predictable);
}
+ private void OnActivateVerb(Entity<ItemToggleComponent> ent, ref GetVerbsEvent<ActivationVerb> args)
+ {
+ if (!args.CanAccess || !args.CanInteract)
+ return;
+
+ var user = args.User;
+
+ args.Verbs.Add(new ActivationVerb()
+ {
+ Text = !ent.Comp.Activated ? Loc.GetString("item-toggle-activate") : Loc.GetString("item-toggle-deactivate"),
+ Act = () =>
+ {
+ Toggle((ent.Owner, ent.Comp), user, predicted: ent.Comp.Predictable);
+ }
+ });
+ }
+
+ private void OnActivate(Entity<ItemToggleComponent> ent, ref ActivateInWorldEvent args)
+ {
+ if (args.Handled || !ent.Comp.OnActivate)
+ return;
+
+ args.Handled = true;
+ Toggle((ent.Owner, ent.Comp), args.User, predicted: ent.Comp.Predictable);
+ }
+
/// <summary>
/// Used when an item is attempted to be toggled.
/// Sets its state to the opposite of what it is.
if (TryComp(ent, out AppearanceComponent? appearance))
{
_appearance.SetData(ent, ToggleVisuals.Toggled, ent.Comp.Activated, appearance);
-
- if (ent.Comp.ToggleLight)
- _appearance.SetData(ent, ToggleableLightVisuals.Enabled, ent.Comp.Activated, appearance);
}
-
- if (!ent.Comp.ToggleLight)
- return;
-
- if (_light.TryGetLight(ent, out var light))
- _light.SetEnabled(ent, ent.Comp.Activated, light);
}
/// <summary>
--- /dev/null
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Light.Components;
+
+/// <summary>
+/// Toggles point light on an entity whenever ItemToggle hits.
+/// </summary>
+[RegisterComponent, NetworkedComponent]
+public sealed partial class ItemTogglePointLightComponent : Component
+{
+
+}
--- /dev/null
+using Content.Shared.Item.ItemToggle.Components;
+using Content.Shared.Toggleable;
+using ItemTogglePointLightComponent = Content.Shared.Light.Components.ItemTogglePointLightComponent;
+
+namespace Content.Shared.Light.EntitySystems;
+
+/// <summary>
+/// Handles ItemToggle for PointLight
+/// </summary>
+public sealed class ItemTogglePointLightSystem : EntitySystem
+{
+ [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
+ [Dependency] private readonly SharedPointLightSystem _light = default!;
+
+ public override void Initialize()
+ {
+ base.Initialize();
+ SubscribeLocalEvent<ItemTogglePointLightComponent, ItemToggledEvent>(OnLightToggled);
+ }
+
+ private void OnLightToggled(Entity<ItemTogglePointLightComponent> ent, ref ItemToggledEvent args)
+ {
+ if (!_light.TryGetLight(ent.Owner, out var light))
+ return;
+
+ _appearance.SetData(ent, ToggleableLightVisuals.Enabled, args.Activated);
+ _light.SetEnabled(ent.Owner, args.Activated, comp: light);
+ }
+}
--- /dev/null
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Power.Components;
+
+[RegisterComponent, NetworkedComponent]
+public sealed partial class ItemSlotRequiresPowerComponent : Component
+{
+
+}
--- /dev/null
+using Content.Shared.Containers.ItemSlots;
+using Content.Shared.Power.Components;
+
+namespace Content.Shared.Power.EntitySystems;
+
+public sealed class ItemSlotRequiresPowerSystem : EntitySystem
+{
+ [Dependency] private readonly SharedPowerReceiverSystem _receiver = default!;
+
+ public override void Initialize()
+ {
+ base.Initialize();
+ SubscribeLocalEvent<ItemSlotRequiresPowerComponent, ItemSlotInsertAttemptEvent>(OnInsertAttempt);
+ }
+
+ private void OnInsertAttempt(Entity<ItemSlotRequiresPowerComponent> ent, ref ItemSlotInsertAttemptEvent args)
+ {
+ if (!_receiver.IsPowered(ent.Owner))
+ {
+ args.Cancelled = true;
+ }
+ }
+}
--- /dev/null
+item-toggle-activate = Activate
+item-toggle-deactivate = Deactivate