Skip to content

Commit

Permalink
Disable Quick Swap for Item Slots by Default (DeltaV-Station#856)
Browse files Browse the repository at this point in the history
# 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.
  • Loading branch information
Mnemotechnician authored Sep 8, 2024
1 parent 9dd569d commit 5c48a1e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Content.Shared/CCVar/CCVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,12 @@ public static readonly CVarDef<bool>
public static readonly CVarDef<bool> GamePressToSprint =
CVarDef.Create("game.press_to_sprint", true, CVar.REPLICATED);

/// <summary>
/// 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.
/// </summary>
public static readonly CVarDef<bool> AllowSlotQuickSwap =
CVarDef.Create("game.slot_quick_swap", false, CVar.REPLICATED);

#if EXCEPTION_TOLERANCE
/// <summary>
/// Amount of times round start must fail before the server is shut down.
Expand Down
3 changes: 2 additions & 1 deletion Content.Shared/Containers/ItemSlot/ItemSlotsComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,15 @@ public ItemSlot(ItemSlot other)

/// <summary>
/// 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.
/// </summary>
/// <remarks>
/// Useful for things like chem dispensers, but undesirable for things like the ID card console, where you
/// want to insert more than one item that matches the same whitelist.
/// </remarks>
[DataField]
[Access(typeof(ItemSlotsSystem), Other = AccessPermissions.ReadWriteExecute)]
public bool Swap = true;
public bool? Swap = null;

public string? ID => ContainerSlot?.ID;

Expand Down
9 changes: 8 additions & 1 deletion Content.Shared/Containers/ItemSlot/ItemSlotsSystem.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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();
Expand All @@ -53,6 +58,8 @@ public override void Initialize()
SubscribeLocalEvent<ItemSlotsComponent, ComponentHandleState>(HandleItemSlotsState);

SubscribeLocalEvent<ItemSlotsComponent, ItemSlotButtonPressedEvent>(HandleButtonPressed);

_config.OnValueChanged(CCVars.AllowSlotQuickSwap, b => _defaultQuickSwap = b, true);
}

#region ComponentManagement
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 5c48a1e

Please sign in to comment.