]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Predict appraisal tool verb! (#32496)
authorbeck-thompson <107373427+beck-thompson@users.noreply.github.com>
Sat, 28 Sep 2024 04:40:24 +0000 (21:40 -0700)
committerGitHub <noreply@github.com>
Sat, 28 Sep 2024 04:40:24 +0000 (14:40 +1000)
* First commit

* Network :(

Content.Client/Cargo/Systems/ClientPriceGunSystem.cs [new file with mode: 0644]
Content.Server/Cargo/Components/PriceGunComponent.cs [deleted file]
Content.Server/Cargo/Systems/PriceGunSystem.cs
Content.Shared/Cargo/Components/PriceGunComponent.cs [new file with mode: 0644]
Content.Shared/Cargo/SharedPriceGunSystem.cs [new file with mode: 0644]

diff --git a/Content.Client/Cargo/Systems/ClientPriceGunSystem.cs b/Content.Client/Cargo/Systems/ClientPriceGunSystem.cs
new file mode 100644 (file)
index 0000000..f173932
--- /dev/null
@@ -0,0 +1,21 @@
+using Content.Shared.Timing;
+using Content.Shared.Cargo.Systems;
+
+namespace Content.Client.Cargo.Systems;
+
+/// <summary>
+/// This handles...
+/// </summary>
+public sealed class ClientPriceGunSystem : SharedPriceGunSystem
+{
+    [Dependency] private readonly UseDelaySystem _useDelay = default!;
+
+    protected override bool GetPriceOrBounty(EntityUid priceGunUid, EntityUid target, EntityUid user)
+    {
+        if (!TryComp(priceGunUid, out UseDelayComponent? useDelay) || _useDelay.IsDelayed((priceGunUid, useDelay)))
+            return false;
+
+        // It feels worse if the cooldown is predicted but the popup isn't! So only do the cooldown reset on the server.
+        return true;
+    }
+}
diff --git a/Content.Server/Cargo/Components/PriceGunComponent.cs b/Content.Server/Cargo/Components/PriceGunComponent.cs
deleted file mode 100644 (file)
index 7207bea..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-namespace Content.Server.Cargo.Components;
-
-/// <summary>
-/// This is used for the price gun, which calculates the price of any object it appraises.
-/// </summary>
-[RegisterComponent]
-public sealed partial class PriceGunComponent : Component
-{
-
-}
index 19fe07bd253a28b7e19c1bac0918723d6f3871dc..94f9f9cba9edcc505f93d5dd09c56a69372284db 100644 (file)
@@ -1,73 +1,34 @@
-using Content.Server.Cargo.Components;
 using Content.Server.Popups;
 using Content.Shared.IdentityManagement;
-using Content.Shared.Interaction;
 using Content.Shared.Timing;
-using Content.Shared.Verbs;
+using Content.Shared.Cargo.Systems;
 
 namespace Content.Server.Cargo.Systems;
 
-/// <summary>
-/// This handles...
-/// </summary>
-public sealed class PriceGunSystem : EntitySystem
+public sealed class PriceGunSystem : SharedPriceGunSystem
 {
     [Dependency] private readonly UseDelaySystem _useDelay = default!;
     [Dependency] private readonly PricingSystem _pricingSystem = default!;
     [Dependency] private readonly PopupSystem _popupSystem = default!;
     [Dependency] private readonly CargoSystem _bountySystem = default!;
 
-    /// <inheritdoc/>
-    public override void Initialize()
+    protected override bool GetPriceOrBounty(EntityUid priceGunUid, EntityUid target, EntityUid user)
     {
-        SubscribeLocalEvent<PriceGunComponent, AfterInteractEvent>(OnAfterInteract);
-        SubscribeLocalEvent<PriceGunComponent, GetVerbsEvent<UtilityVerb>>(OnUtilityVerb);
-    }
-
-    private void OnUtilityVerb(EntityUid uid, PriceGunComponent component, GetVerbsEvent<UtilityVerb> args)
-    {
-        if (!args.CanAccess || !args.CanInteract || args.Using == null)
-            return;
-
-        if (!TryComp(uid, out UseDelayComponent? useDelay) || _useDelay.IsDelayed((uid, useDelay)))
-            return;
-
-        var price = _pricingSystem.GetPrice(args.Target);
-
-        var verb = new UtilityVerb()
-        {
-            Act = () =>
-            {
-                _popupSystem.PopupEntity(Loc.GetString("price-gun-pricing-result", ("object", Identity.Entity(args.Target, EntityManager)), ("price", $"{price:F2}")), args.User, args.User);
-                _useDelay.TryResetDelay((uid, useDelay));
-            },
-            Text = Loc.GetString("price-gun-verb-text"),
-            Message = Loc.GetString("price-gun-verb-message", ("object", Identity.Entity(args.Target, EntityManager)))
-        };
-
-        args.Verbs.Add(verb);
-    }
-
-    private void OnAfterInteract(EntityUid uid, PriceGunComponent component, AfterInteractEvent args)
-    {
-        if (!args.CanReach || args.Target == null || args.Handled)
-            return;
-
-        if (!TryComp(uid, out UseDelayComponent? useDelay) || _useDelay.IsDelayed((uid, useDelay)))
-            return;
+        if (!TryComp(priceGunUid, out UseDelayComponent? useDelay) || _useDelay.IsDelayed((priceGunUid, useDelay)))
+            return false;
 
         // Check if we're scanning a bounty crate
-        if (_bountySystem.IsBountyComplete(args.Target.Value, out _))
+        if (_bountySystem.IsBountyComplete(target, out _))
         {
-            _popupSystem.PopupEntity(Loc.GetString("price-gun-bounty-complete"), args.User, args.User);
+            _popupSystem.PopupEntity(Loc.GetString("price-gun-bounty-complete"), user, user);
         }
         else // Otherwise appraise the price
         {
-            double price = _pricingSystem.GetPrice(args.Target.Value);
-            _popupSystem.PopupEntity(Loc.GetString("price-gun-pricing-result", ("object", Identity.Entity(args.Target.Value, EntityManager)), ("price", $"{price:F2}")), args.User, args.User);
+            var price = _pricingSystem.GetPrice(target);
+            _popupSystem.PopupEntity(Loc.GetString("price-gun-pricing-result", ("object", Identity.Entity(target, EntityManager)), ("price", $"{price:F2}")), user, user);
         }
 
-        _useDelay.TryResetDelay((uid, useDelay));
-        args.Handled = true;
+        _useDelay.TryResetDelay((priceGunUid, useDelay));
+        return true;
     }
 }
diff --git a/Content.Shared/Cargo/Components/PriceGunComponent.cs b/Content.Shared/Cargo/Components/PriceGunComponent.cs
new file mode 100644 (file)
index 0000000..7024f11
--- /dev/null
@@ -0,0 +1,11 @@
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Cargo.Components;
+
+/// <summary>
+///     This is used for the price gun, which calculates the price of any object it appraises.
+/// </summary>
+[RegisterComponent, NetworkedComponent]
+public sealed partial class PriceGunComponent : Component
+{
+}
diff --git a/Content.Shared/Cargo/SharedPriceGunSystem.cs b/Content.Shared/Cargo/SharedPriceGunSystem.cs
new file mode 100644 (file)
index 0000000..779d550
--- /dev/null
@@ -0,0 +1,55 @@
+using Content.Shared.Cargo.Components;
+using Content.Shared.IdentityManagement;
+using Content.Shared.Interaction;
+using Content.Shared.Verbs;
+
+namespace Content.Shared.Cargo.Systems;
+
+/// <summary>
+///     The price gun system! If this component is on an entity, you can scan objects (Click or use verb) to see their price.
+/// </summary>
+public abstract class SharedPriceGunSystem : EntitySystem
+{
+    public override void Initialize()
+    {
+        base.Initialize();
+        SubscribeLocalEvent<PriceGunComponent, GetVerbsEvent<UtilityVerb>>(OnUtilityVerb);
+        SubscribeLocalEvent<PriceGunComponent, AfterInteractEvent>(OnAfterInteract);
+    }
+
+    private void OnUtilityVerb(EntityUid uid, PriceGunComponent component, GetVerbsEvent<UtilityVerb> args)
+    {
+        if (!args.CanAccess || !args.CanInteract || args.Using == null)
+            return;
+
+        var verb = new UtilityVerb()
+        {
+            Act = () =>
+            {
+                GetPriceOrBounty(uid, args.Target, args.User);
+            },
+            Text = Loc.GetString("price-gun-verb-text"),
+            Message = Loc.GetString("price-gun-verb-message", ("object", Identity.Entity(args.Target, EntityManager)))
+        };
+
+        args.Verbs.Add(verb);
+    }
+
+    private void OnAfterInteract(Entity<PriceGunComponent> entity, ref AfterInteractEvent args)
+    {
+        if (!args.CanReach || args.Target == null || args.Handled)
+            return;
+
+        args.Handled |= GetPriceOrBounty(entity, args.Target.Value, args.User);
+    }
+
+    /// <summary>
+    ///     Find the price or confirm if the item is a bounty. Will give a popup of the result to the passed user.
+    /// </summary>
+    /// <returns></returns>
+    /// <remarks>
+    ///     This is abstract for prediction. When the bounty system / cargo systems that are necessary are moved to shared,
+    ///     combine all the server, client, and shared stuff into one non abstract file.
+    /// </remarks>
+    protected abstract bool GetPriceOrBounty(EntityUid priceGunUid, EntityUid target, EntityUid user);
+}