]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Give stores the ability to check for owner only (#26573)
authorkeronshb <54602815+keronshb@users.noreply.github.com>
Sat, 30 Mar 2024 23:25:36 +0000 (19:25 -0400)
committerGitHub <noreply@github.com>
Sat, 30 Mar 2024 23:25:36 +0000 (19:25 -0400)
adds a check if the store belongs to the user

Content.Server/Store/Components/StoreComponent.cs
Content.Server/Store/Systems/StoreSystem.cs
Resources/Locale/en-US/store/store.ftl

index 063e25fbf9fec8dcc3f35b307cde81b872c9f9b2..0b7dbbea0942a9d063867ac819ea3eb0032b56a1 100644 (file)
@@ -78,6 +78,13 @@ public sealed partial class StoreComponent : Component
     [ViewVariables, DataField]
     public bool RefundAllowed;
 
+    /// <summary>
+    ///     Checks if store can be opened by the account owner only.
+    ///     Not meant to be used with uplinks.
+    /// </summary>
+    [ViewVariables(VVAccess.ReadWrite), DataField]
+    public bool OwnerOnly;
+
     /// <summary>
     ///     The map the store was originally from, used to block refunds if the map is changed
     /// </summary>
index 8ce1f9bb83a09520eddfaed17e7aa81301aac007..56426e04045f230a799726d23a676b864f6cb3b5 100644 (file)
@@ -10,6 +10,7 @@ using JetBrains.Annotations;
 using Robust.Server.GameObjects;
 using Robust.Shared.Prototypes;
 using System.Linq;
+using Robust.Shared.Utility;
 
 namespace Content.Server.Store.Systems;
 
@@ -26,6 +27,7 @@ public sealed partial class StoreSystem : EntitySystem
     {
         base.Initialize();
 
+        SubscribeLocalEvent<StoreComponent, ActivatableUIOpenAttemptEvent>(OnStoreOpenAttempt);
         SubscribeLocalEvent<CurrencyComponent, AfterInteractEvent>(OnAfterInteract);
         SubscribeLocalEvent<StoreComponent, BeforeActivatableUIOpenEvent>(BeforeActivatableUiOpen);
 
@@ -65,6 +67,21 @@ public sealed partial class StoreSystem : EntitySystem
         RaiseLocalEvent(uid, ref ev, true);
     }
 
+    private void OnStoreOpenAttempt(EntityUid uid, StoreComponent component, ActivatableUIOpenAttemptEvent args)
+    {
+        if (!component.OwnerOnly)
+            return;
+
+        component.AccountOwner ??= args.User;
+        DebugTools.Assert(component.AccountOwner != null);
+
+        if (component.AccountOwner == args.User)
+            return;
+
+        _popup.PopupEntity(Loc.GetString("store-not-account-owner", ("store", uid)), uid, args.User);
+        args.Cancel();
+    }
+
     private void OnAfterInteract(EntityUid uid, CurrencyComponent component, AfterInteractEvent args)
     {
         if (args.Handled || !args.CanReach)
index 7af2b0553380c74cdacdf1518f8315c10fb35ece..d663cc61f71e551c665d339c33943fe2ee01fb22 100644 (file)
@@ -6,3 +6,5 @@ store-ui-traitor-flavor = Copyright (C) NT -30643
 store-ui-traitor-warning = Operatives must lock their uplinks after use to avoid detection.
 
 store-withdraw-button-ui = Withdraw {$currency}
+
+store-not-account-owner = This {$store} is not bound to you!