From 5c48a1e48489939983feb9a03f5da75d6bcc029a Mon Sep 17 00:00:00 2001 From: Mnemotechnican <69920617+Mnemotechnician@users.noreply.github.com> Date: Sun, 8 Sep 2024 17:42:30 +0300 Subject: [PATCH] Disable Quick Swap for Item Slots by Default (#856) # Description As was discussed on discord, quick swap is a feature that makes certain things needlessly easy. You can instantly swap the magazine in a gun without even paying attention to it, you can quickly swap cells in IPCs/borgs, you can instantly swap the ID in your pda with that of someone else without anyone noticing, et cetera. In my opinion, this is unnecessary QOL that makes the game feel more bland and primitive. Besides, it used to lead to odd and unwanted behavior, such as IPCs being able to swap their own power cells. In addition to that, certain entities do not support quick swap. For instance, rechargers will stop working if you insert a power cell and then quick-swap it before it finishes charging. This PR makes quick swap disabled by default. It can still be re-enabled by setting `ItemSlotsComponent.Slots.[ItemSlot].Swap = true` on individual entities. # Changelog :cl: - remove: Quick swap has been disabled for most item slots. This primarily means you will have to eject power cells/magazines from items/weapons/borgs before replacing them with different ones. --- Content.Shared/CCVar/CCVars.cs | 6 ++++++ Content.Shared/Containers/ItemSlot/ItemSlotsComponent.cs | 3 ++- Content.Shared/Containers/ItemSlot/ItemSlotsSystem.cs | 9 ++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index 1501c92f88e..8fac5b3f636 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -402,6 +402,12 @@ public static readonly CVarDef public static readonly CVarDef GamePressToSprint = CVarDef.Create("game.press_to_sprint", true, CVar.REPLICATED); + /// + /// Whether item slots, such as power cell slots or AME fuel cell slots, should support quick swap if it is not otherwise specified in their YAML prototype. + /// + public static readonly CVarDef AllowSlotQuickSwap = + CVarDef.Create("game.slot_quick_swap", false, CVar.REPLICATED); + #if EXCEPTION_TOLERANCE /// /// Amount of times round start must fail before the server is shut down. diff --git a/Content.Shared/Containers/ItemSlot/ItemSlotsComponent.cs b/Content.Shared/Containers/ItemSlot/ItemSlotsComponent.cs index 42e7f721b3e..ba8a9a934e4 100644 --- a/Content.Shared/Containers/ItemSlot/ItemSlotsComponent.cs +++ b/Content.Shared/Containers/ItemSlot/ItemSlotsComponent.cs @@ -214,6 +214,7 @@ public ItemSlot(ItemSlot other) /// /// If the user interacts with an entity with an already-filled item slot, should they attempt to swap out the item? + /// If set to null, will be deduced based on the relevant config variable. /// /// /// Useful for things like chem dispensers, but undesirable for things like the ID card console, where you @@ -221,7 +222,7 @@ public ItemSlot(ItemSlot other) /// [DataField] [Access(typeof(ItemSlotsSystem), Other = AccessPermissions.ReadWriteExecute)] - public bool Swap = true; + public bool? Swap = null; public string? ID => ContainerSlot?.ID; diff --git a/Content.Shared/Containers/ItemSlot/ItemSlotsSystem.cs b/Content.Shared/Containers/ItemSlot/ItemSlotsSystem.cs index 9cb21e882e3..c7932ef8f75 100644 --- a/Content.Shared/Containers/ItemSlot/ItemSlotsSystem.cs +++ b/Content.Shared/Containers/ItemSlot/ItemSlotsSystem.cs @@ -1,6 +1,7 @@ using System.Diagnostics.CodeAnalysis; using Content.Shared.ActionBlocker; using Content.Shared.Administration.Logs; +using Content.Shared.CCVar; using Content.Shared.Database; using Content.Shared.Destructible; using Content.Shared.Hands.Components; @@ -10,6 +11,7 @@ using Content.Shared.Popups; using Content.Shared.Verbs; using Robust.Shared.Audio.Systems; +using Robust.Shared.Configuration; using Robust.Shared.Containers; using Robust.Shared.GameStates; using Robust.Shared.Utility; @@ -27,11 +29,14 @@ public sealed class ItemSlotsSystem : EntitySystem { [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!; [Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!; + [Dependency] private readonly IConfigurationManager _config = default!; [Dependency] private readonly SharedContainerSystem _containers = default!; [Dependency] private readonly SharedPopupSystem _popupSystem = default!; [Dependency] private readonly SharedHandsSystem _handsSystem = default!; [Dependency] private readonly SharedAudioSystem _audioSystem = default!; + private bool _defaultQuickSwap; + public override void Initialize() { base.Initialize(); @@ -53,6 +58,8 @@ public override void Initialize() SubscribeLocalEvent(HandleItemSlotsState); SubscribeLocalEvent(HandleButtonPressed); + + _config.OnValueChanged(CCVars.AllowSlotQuickSwap, b => _defaultQuickSwap = b, true); } #region ComponentManagement @@ -202,7 +209,7 @@ private void OnInteractUsing(EntityUid uid, ItemSlotsComponent itemSlots, Intera if (!slot.InsertOnInteract) continue; - if (!CanInsert(uid, args.Used, args.User, slot, swap: slot.Swap, popup: args.User)) + if (!CanInsert(uid, args.Used, args.User, slot, swap: slot.Swap ?? _defaultQuickSwap, popup: args.User)) continue; // Drop the held item onto the floor. Return if the user cannot drop.