Skip to content

Commit

Permalink
Fix whatever the fuck is going on in storage system slightly (#28236)
Browse files Browse the repository at this point in the history
* Fix whatever the fuck is going on in storage system slightly

* Fix inverted check

* h

* Add silent bool

* Silent
  • Loading branch information
DrSmugleaf authored and sleepyyapril committed Nov 30, 2024
1 parent 0aeb6ce commit 7199df1
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using Robust.Shared.GameStates;

namespace Content.Shared.Interaction.Components;

[RegisterComponent, NetworkedComponent]
public sealed partial class BypassInteractionChecksComponent : Component;
2 changes: 1 addition & 1 deletion Content.Shared/Inventory/InventorySystem.Slots.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private void OnOpenSlotStorage(OpenSlotStorageNetworkMessage ev, EntitySessionEv

if (TryGetSlotEntity(uid, ev.Slot, out var entityUid) && TryComp<StorageComponent>(entityUid, out var storageComponent))
{
_storageSystem.OpenStorageUI(entityUid.Value, uid, storageComponent);
_storageSystem.OpenStorageUI(entityUid.Value, uid, storageComponent, false);
}
}

Expand Down
9 changes: 9 additions & 0 deletions Content.Shared/Lock/LockSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Content.Shared.IdentityManagement;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using Content.Shared.Storage;
using Content.Shared.Storage.Components;
using Content.Shared.Verbs;
using Content.Shared.Wires;
Expand Down Expand Up @@ -42,11 +43,13 @@ public override void Initialize()
SubscribeLocalEvent<LockComponent, GotEmaggedEvent>(OnEmagged);
SubscribeLocalEvent<LockComponent, LockDoAfter>(OnDoAfterLock);
SubscribeLocalEvent<LockComponent, UnlockDoAfter>(OnDoAfterUnlock);
SubscribeLocalEvent<LockComponent, StorageInteractAttemptEvent>(OnStorageInteractAttempt);

SubscribeLocalEvent<LockedWiresPanelComponent, LockToggleAttemptEvent>(OnLockToggleAttempt);
SubscribeLocalEvent<LockedWiresPanelComponent, AttemptChangePanelEvent>(OnAttemptChangePanel);
SubscribeLocalEvent<LockedAnchorableComponent, UnanchorAttemptEvent>(OnUnanchorAttempt);
}

private void OnStartup(EntityUid uid, LockComponent lockComp, ComponentStartup args)
{
_appearanceSystem.SetData(uid, LockVisuals.Locked, lockComp.Locked);
Expand Down Expand Up @@ -295,6 +298,12 @@ private void OnDoAfterUnlock(EntityUid uid, LockComponent component, UnlockDoAft
TryUnlock(uid, args.User, skipDoAfter: true);
}

private void OnStorageInteractAttempt(Entity<LockComponent> ent, ref StorageInteractAttemptEvent args)
{
if (ent.Comp.Locked)
args.Cancelled = true;
}

private void OnLockToggleAttempt(Entity<LockedWiresPanelComponent> ent, ref LockToggleAttemptEvent args)
{
if (args.Cancelled)
Expand Down
69 changes: 37 additions & 32 deletions Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Shared.ActionBlocker;
using Content.Shared.Administration;
using Content.Shared.Administration.Managers;
using Content.Shared.Containers.ItemSlots;
using Content.Shared.Destructible;
using Content.Shared.DoAfter;
using Content.Shared.Ghost;
using Content.Shared.Hands.Components;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Implants.Components;
using Content.Shared.Input;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Components;
using Content.Shared.Inventory;
using Content.Shared.Item;
using Content.Shared.Lock;
Expand Down Expand Up @@ -41,7 +39,6 @@ public abstract class SharedStorageSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] protected readonly IRobustRandom Random = default!;
[Dependency] private readonly ISharedAdminManager _admin = default!;
[Dependency] protected readonly ActionBlockerSystem ActionBlocker = default!;
[Dependency] private readonly EntityLookupSystem _entityLookupSystem = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
Expand Down Expand Up @@ -250,17 +247,8 @@ private void OnBoundUIClosed(EntityUid uid, StorageComponent storageComp, BoundU

private void AddUiVerb(EntityUid uid, StorageComponent component, GetVerbsEvent<ActivationVerb> args)
{
var silent = false;
if (!args.CanAccess || !args.CanInteract || TryComp<LockComponent>(uid, out var lockComponent) && lockComponent.Locked)
{
// we allow admins to open the storage anyways
if (!_admin.HasAdminFlag(args.User, AdminFlags.Admin))
return;

silent = true;
}

silent |= HasComp<GhostComponent>(args.User);
if (!CanInteract(args.User, (uid, component), args.CanAccess && args.CanInteract))
return;

// Does this player currently have the storage UI open?
var uiOpen = _ui.IsUiOpen(uid, StorageComponent.StorageUiKey.Key, args.User);
Expand All @@ -275,7 +263,7 @@ private void AddUiVerb(EntityUid uid, StorageComponent component, GetVerbsEvent<
}
else
{
OpenStorageUI(uid, args.User, component, silent);
OpenStorageUI(uid, args.User, component);
}
}
};
Expand All @@ -299,20 +287,23 @@ private void AddUiVerb(EntityUid uid, StorageComponent component, GetVerbsEvent<
/// Opens the storage UI for an entity
/// </summary>
/// <param name="entity">The entity to open the UI for</param>
public void OpenStorageUI(EntityUid uid, EntityUid entity, StorageComponent? storageComp = null, bool silent = false)
public void OpenStorageUI(EntityUid uid, EntityUid entity, StorageComponent? storageComp = null, bool silent = true)
{
if (!Resolve(uid, ref storageComp, false))
return;

// prevent spamming bag open / honkerton honk sound
silent |= TryComp<UseDelayComponent>(uid, out var useDelay) && UseDelay.IsDelayed((uid, useDelay));
silent |= TryComp<UseDelayComponent>(uid, out var useDelay) && UseDelay.IsDelayed((uid, useDelay), id: OpenUiUseDelayID);
if (!CanInteract(entity, (uid, storageComp), silent: silent))
return;

if (!silent)
{
if (!_ui.IsUiOpen(uid, StorageComponent.StorageUiKey.Key))
Audio.PlayPredicted(storageComp.StorageOpenSound, uid, entity);

if (useDelay != null)
UseDelay.TryResetDelay((uid, useDelay));
UseDelay.TryResetDelay((uid, useDelay), id: OpenUiUseDelayID);
}

_ui.OpenUi(uid, StorageComponent.StorageUiKey.Key, entity);
Expand All @@ -327,7 +318,7 @@ private void AddTransferVerbs(EntityUid uid, StorageComponent component, GetVerb

var entities = component.Container.ContainedEntities;

if (entities.Count == 0 || TryComp(uid, out LockComponent? lockComponent) && lockComponent.Locked)
if (entities.Count == 0 || !CanInteract(args.User, (uid, component)))
return;

// if the target is storage, add a verb to transfer storage.
Expand All @@ -338,7 +329,7 @@ private void AddTransferVerbs(EntityUid uid, StorageComponent component, GetVerb
{
Text = Loc.GetString("storage-component-transfer-verb"),
IconEntity = GetNetEntity(args.Using),
Act = () => TransferEntities(uid, args.Target, args.User, component, lockComponent, targetStorage, targetLock)
Act = () => TransferEntities(uid, args.Target, args.User, component, null, targetStorage, targetLock)
};

args.Verbs.Add(verb);
Expand All @@ -351,7 +342,7 @@ private void AddTransferVerbs(EntityUid uid, StorageComponent component, GetVerb
/// <returns>true if inserted, false otherwise</returns>
private void OnInteractUsing(EntityUid uid, StorageComponent storageComp, InteractUsingEvent args)
{
if (args.Handled || !storageComp.ClickInsert || TryComp(uid, out LockComponent? lockComponent) && lockComponent.Locked)
if (args.Handled || !CanInteract(args.User, (uid, storageComp), storageComp.ClickInsert, false))
return;

if (HasComp<PlaceableSurfaceComponent>(uid))
Expand All @@ -369,14 +360,14 @@ private void OnInteractUsing(EntityUid uid, StorageComponent storageComp, Intera
/// </summary>
private void OnActivate(EntityUid uid, StorageComponent storageComp, ActivateInWorldEvent args)
{
if (args.Handled || !args.Complex || !CanInteract(args.User, (uid, storageComp), storageComp.ClickInsert))
if (args.Handled || !CanInteract(args.User, (uid, storageComp), storageComp.ClickInsert))
return;

// Toggle
if (_ui.IsUiOpen(uid, StorageComponent.StorageUiKey.Key, args.User))
_ui.CloseUi(uid, StorageComponent.StorageUiKey.Key, args.User);
else
OpenStorageUI(uid, args.User, storageComp);
OpenStorageUI(uid, args.User, storageComp, false);

args.Handled = true;
}
Expand All @@ -389,7 +380,7 @@ private void OnImplantActivate(EntityUid uid, StorageComponent storageComp, Open
if (args.Handled)
return;

OpenStorageUI(uid, args.Performer, storageComp);
OpenStorageUI(uid, args.Performer, storageComp, false);
args.Handled = true;
}

Expand Down Expand Up @@ -1403,7 +1394,7 @@ public ItemSizePrototype GetMaxItemSize(Entity<StorageComponent?> uid)
}

/// <summary>
/// Checks if a storage's UI is open by anyone when locked, and closes it unless they're an admin.
/// Checks if a storage's UI is open by anyone when locked, and closes it.
/// </summary>
private void OnLockToggled(EntityUid uid, StorageComponent component, ref LockToggledEvent args)
{
Expand All @@ -1413,11 +1404,8 @@ private void OnLockToggled(EntityUid uid, StorageComponent component, ref LockTo
// Gets everyone looking at the UI
foreach (var actor in _ui.GetActors(uid, StorageComponent.StorageUiKey.Key).ToList())
{
if (_admin.HasAdminFlag(actor, AdminFlags.Admin))
continue;

// And closes it unless they're an admin
_ui.CloseUi(uid, StorageComponent.StorageUiKey.Key, actor);
if (!CanInteract(actor, (uid, component)))
_ui.CloseUi(uid, StorageComponent.StorageUiKey.Key, actor);
}
}

Expand Down Expand Up @@ -1455,7 +1443,10 @@ private void HandleOpenSlotUI(ICommonSession? session, string slot)
if (!ActionBlocker.CanInteract(playerEnt, storageEnt))
return;

OpenStorageUI(storageEnt.Value, playerEnt);
if (!_ui.IsUiOpen(storageEnt.Value, StorageComponent.StorageUiKey.Key, playerEnt))
OpenStorageUI(storageEnt.Value, playerEnt, silent: false);
else
_ui.CloseUi(storageEnt.Value, StorageComponent.StorageUiKey.Key, playerEnt);
}

protected void ClearCantFillReasons()
Expand All @@ -1465,6 +1456,20 @@ protected void ClearCantFillReasons()
#endif
}

private bool CanInteract(EntityUid user, Entity<StorageComponent> storage, bool canInteract = true, bool silent = true)
{
if (HasComp<BypassInteractionChecksComponent>(user))
return true;

if (!canInteract)
return false;

var ev = new StorageInteractAttemptEvent(silent);
RaiseLocalEvent(storage, ref ev);

return !ev.Cancelled;
}

/// <summary>
/// Plays a clientside pickup animation for the specified uid.
/// </summary>
Expand Down
4 changes: 3 additions & 1 deletion Content.Shared/Storage/StorageComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Robust.Shared.Containers;
using Robust.Shared.GameStates;
using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;

Expand Down Expand Up @@ -228,6 +227,9 @@ public AnimateInsertingEntitiesEvent(NetEntity storage, List<NetEntity> storedEn
}
}

[ByRefEvent]
public record struct StorageInteractAttemptEvent(bool Silent, bool Cancelled = false);

[NetSerializable]
[Serializable]
public enum StorageVisuals : byte
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/Entities/Mobs/Player/admin_ghost.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
- type: Loadout
prototypes: [ MobAghostGear ]
- type: SupermatterImmune
- type: BypassInteractionChecks

- type: entity
id: ActionAGhostShowSolar
Expand Down

0 comments on commit 7199df1

Please sign in to comment.