]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix cargo product groups (#24212)
authorNemanja <98561806+EmoGarbage404@users.noreply.github.com>
Sat, 20 Jan 2024 03:47:08 +0000 (22:47 -0500)
committerGitHub <noreply@github.com>
Sat, 20 Jan 2024 03:47:08 +0000 (14:47 +1100)
Content.Client/Cargo/BUI/CargoOrderConsoleBoundUserInterface.cs
Content.Client/Cargo/UI/CargoConsoleMenu.xaml.cs
Content.IntegrationTests/Tests/CargoTest.cs
Content.Server/Cargo/Components/CargoOrderConsoleComponent.cs [deleted file]
Content.Server/Cargo/Systems/CargoSystem.Orders.cs
Content.Server/Cargo/Systems/CargoSystem.cs
Content.Server/StationEvents/Events/CargoGiftsRule.cs
Content.Shared/Cargo/Components/CargoOrderConsoleComponent.cs [new file with mode: 0644]
Content.Shared/Cargo/Prototypes/CargoProductPrototype.cs

index 6c9af85a2c614bd475419010a9f8561637f0e573..ce12d16cb58845551a30025182cc17a9398796b7 100644 (file)
@@ -50,7 +50,7 @@ namespace Content.Client.Cargo.BUI
             base.Open();
 
             var spriteSystem = EntMan.System<SpriteSystem>();
-            _menu = new CargoConsoleMenu(IoCManager.Resolve<IPrototypeManager>(), spriteSystem);
+            _menu = new CargoConsoleMenu(Owner, IoCManager.Resolve<EntityManager>(), IoCManager.Resolve<IPrototypeManager>(), spriteSystem);
             var localPlayer = IoCManager.Resolve<IPlayerManager>()?.LocalPlayer?.ControlledEntity;
             var description = new FormattedMessage();
 
index 0cc17a624696f2a3637a6a0db956581440129046..5402a24667686c9202ac72415439f776929becff 100644 (file)
@@ -1,6 +1,7 @@
 using System.Linq;
 using Content.Client.UserInterface.Controls;
 using Content.Shared.Cargo;
+using Content.Shared.Cargo.Components;
 using Content.Shared.Cargo.Prototypes;
 using Robust.Client.AutoGenerated;
 using Robust.Client.GameObjects;
@@ -14,8 +15,10 @@ namespace Content.Client.Cargo.UI
     [GenerateTypedNameReferences]
     public sealed partial class CargoConsoleMenu : FancyWindow
     {
+        private IEntityManager _entityManager;
         private IPrototypeManager _protoManager;
         private SpriteSystem _spriteSystem;
+        private EntityUid _owner;
 
         public event Action<ButtonEventArgs>? OnItemSelected;
         public event Action<ButtonEventArgs>? OnOrderApproved;
@@ -24,11 +27,13 @@ namespace Content.Client.Cargo.UI
         private readonly List<string> _categoryStrings = new();
         private string? _category;
 
-        public CargoConsoleMenu(IPrototypeManager protoManager, SpriteSystem spriteSystem)
+        public CargoConsoleMenu(EntityUid owner, IEntityManager entMan, IPrototypeManager protoManager, SpriteSystem spriteSystem)
         {
             RobustXamlLoader.Load(this);
+            _entityManager = entMan;
             _protoManager = protoManager;
             _spriteSystem = spriteSystem;
+            _owner = owner;
 
             Title = Loc.GetString("cargo-console-menu-title");
 
@@ -53,7 +58,21 @@ namespace Content.Client.Cargo.UI
             Categories.SelectId(id);
         }
 
-        public IEnumerable<CargoProductPrototype> ProductPrototypes => _protoManager.EnumeratePrototypes<CargoProductPrototype>();
+        public IEnumerable<CargoProductPrototype> ProductPrototypes
+        {
+            get
+            {
+                var allowedGroups = _entityManager.GetComponentOrNull<CargoOrderConsoleComponent>(_owner)?.AllowedGroups;
+
+                foreach (var cargoPrototype in _protoManager.EnumeratePrototypes<CargoProductPrototype>())
+                {
+                    if (!allowedGroups?.Contains(cargoPrototype.Group) ?? false)
+                        continue;
+
+                    yield return cargoPrototype;
+                }
+            }
+        }
 
         /// <summary>
         ///     Populates the list of products that will actually be shown, using the current filters.
@@ -80,7 +99,7 @@ namespace Content.Client.Cargo.UI
                         Product = prototype,
                         ProductName = { Text = prototype.Name },
                         MainButton = { ToolTip = prototype.Description },
-                        PointCost = { Text = Loc.GetString("cargo-console-menu-points-amount", ("amount", prototype.PointCost.ToString())) },
+                        PointCost = { Text = Loc.GetString("cargo-console-menu-points-amount", ("amount", prototype.Cost.ToString())) },
                         Icon = { Texture = _spriteSystem.Frame0(prototype.Icon) },
                     };
                     button.MainButton.OnPressed += args =>
index 8bb07cfd96720ae81035b507b92e1a58db5c1510..e49f2e996ba8d0eb2eeff7b685b061391e5fb2e0 100644 (file)
@@ -44,7 +44,7 @@ public sealed class CargoTest
                     var ent = entManager.SpawnEntity(proto.Product, testMap.MapCoords);
                     var price = pricing.GetPrice(ent);
 
-                    Assert.That(price, Is.AtMost(proto.PointCost), $"Found arbitrage on {proto.ID} cargo product! Cost is {proto.PointCost} but sell is {price}!");
+                    Assert.That(price, Is.AtMost(proto.Cost), $"Found arbitrage on {proto.ID} cargo product! Cost is {proto.Cost} but sell is {price}!");
                     entManager.DeleteEntity(ent);
                 }
             });
@@ -80,7 +80,7 @@ public sealed class CargoTest
                     foreach (var bounty in bounties)
                     {
                         if (cargo.IsBountyComplete(ent, bounty))
-                            Assert.That(proto.PointCost, Is.GreaterThanOrEqualTo(bounty.Reward), $"Found arbitrage on {bounty.ID} cargo bounty! Product {proto.ID} costs {proto.PointCost} but fulfills bounty {bounty.ID} with reward {bounty.Reward}!");
+                            Assert.That(proto.Cost, Is.GreaterThanOrEqualTo(bounty.Reward), $"Found arbitrage on {bounty.ID} cargo bounty! Product {proto.ID} costs {proto.Cost} but fulfills bounty {bounty.ID} with reward {bounty.Reward}!");
                     }
 
                     entManager.DeleteEntity(ent);
diff --git a/Content.Server/Cargo/Components/CargoOrderConsoleComponent.cs b/Content.Server/Cargo/Components/CargoOrderConsoleComponent.cs
deleted file mode 100644 (file)
index 1c418c9..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-using Robust.Shared.Audio;
-
-namespace Content.Server.Cargo.Components
-{
-    /// <summary>
-    /// Handles sending order requests to cargo. Doesn't handle orders themselves via shuttle or telepads.
-    /// </summary>
-    [RegisterComponent]
-    public sealed partial class CargoOrderConsoleComponent : Component
-    {
-        [DataField("soundError")] public SoundSpecifier ErrorSound =
-            new SoundPathSpecifier("/Audio/Effects/Cargo/buzz_sigh.ogg");
-
-        [DataField("soundConfirm")]
-        public SoundSpecifier ConfirmSound = new SoundPathSpecifier("/Audio/Effects/Cargo/ping.ogg");
-    }
-}
index 9a547bb578a14bdfc65b207816ec4e0bbaa6cd69..5985bbb484cfc18dca61eab19c8ecf342a25e227 100644 (file)
@@ -261,6 +261,9 @@ namespace Content.Server.Cargo.Systems
                 return;
             }
 
+            if (!component.AllowedGroups.Contains(product.Group))
+                return;
+
             var data = GetOrderData(args, product, GenerateOrderId(orderDatabase));
 
             if (!TryAddOrder(stationUid.Value, data, orderDatabase))
@@ -313,7 +316,7 @@ namespace Content.Server.Cargo.Systems
 
         private static CargoOrderData GetOrderData(CargoConsoleAddOrderMessage args, CargoProductPrototype cargoProduct, int id)
         {
-            return new CargoOrderData(id, cargoProduct.Product, cargoProduct.PointCost, args.Amount, args.Requester, args.Reason);
+            return new CargoOrderData(id, cargoProduct.Product, cargoProduct.Cost, args.Amount, args.Requester, args.Reason);
         }
 
         public static int GetOutstandingOrderCount(StationCargoOrderDatabaseComponent component)
index c39ffb186a1bcda7383ee34d933e1bdfe8164067..d4be68efc85631a491ed04884e25c8b4ce2f563d 100644 (file)
@@ -9,6 +9,7 @@ using Content.Server.Station.Systems;
 using Content.Shared.Access.Systems;
 using Content.Shared.Administration.Logs;
 using Content.Shared.Cargo;
+using Content.Shared.Cargo.Components;
 using Content.Shared.Containers.ItemSlots;
 using Content.Shared.Mobs.Components;
 using JetBrains.Annotations;
index f0f9586ad33e4f7fff043b465fe24d72665e0d2f..4d3ffa005d780e471a7698ff60c1e68c0b0240b3 100644 (file)
@@ -60,7 +60,7 @@ public sealed class CargoGiftsRule : StationEventSystem<CargoGiftsRuleComponent>
             if (!_cargoSystem.AddAndApproveOrder(
                     station!.Value,
                     product.Product,
-                    product.PointCost,
+                    product.Cost,
                     qty,
                     Loc.GetString(component.Sender),
                     Loc.GetString(component.Description),
diff --git a/Content.Shared/Cargo/Components/CargoOrderConsoleComponent.cs b/Content.Shared/Cargo/Components/CargoOrderConsoleComponent.cs
new file mode 100644 (file)
index 0000000..a7d1f53
--- /dev/null
@@ -0,0 +1,25 @@
+using Content.Shared.Cargo.Prototypes;
+using Robust.Shared.Audio;
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Cargo.Components;
+
+/// <summary>
+/// Handles sending order requests to cargo. Doesn't handle orders themselves via shuttle or telepads.
+/// </summary>
+[RegisterComponent, NetworkedComponent]
+public sealed partial class CargoOrderConsoleComponent : Component
+{
+    [DataField("soundError")] public SoundSpecifier ErrorSound =
+        new SoundPathSpecifier("/Audio/Effects/Cargo/buzz_sigh.ogg");
+
+    [DataField("soundConfirm")]
+    public SoundSpecifier ConfirmSound = new SoundPathSpecifier("/Audio/Effects/Cargo/ping.ogg");
+
+    /// <summary>
+    /// All of the <see cref="CargoProductPrototype.Group"/>s that are supported.
+    /// </summary>
+    [DataField, ViewVariables(VVAccess.ReadWrite)]
+    public List<string> AllowedGroups = new() { "market" };
+}
+
index 54876183094af94fab6050e42a88c141949181cf..1d0ca8abdb47354987a0cfe2217b9dadd8656e9a 100644 (file)
@@ -1,12 +1,22 @@
 using Robust.Shared.Prototypes;
 using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
+using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Array;
 using Robust.Shared.Utility;
 
 namespace Content.Shared.Cargo.Prototypes
 {
-    [Prototype("cargoProduct")]
-    public sealed partial class CargoProductPrototype : IPrototype
+    [Prototype]
+    public sealed partial class CargoProductPrototype : IPrototype, IInheritingPrototype
     {
+        /// <inheritdoc />
+        [ParentDataField(typeof(AbstractPrototypeIdArraySerializer<CargoProductPrototype>))]
+        public string[]? Parents { get; }
+
+        /// <inheritdoc />
+        [NeverPushInheritance]
+        [AbstractDataField]
+        public bool Abstract { get; }
+
         [DataField("name")] private string _name = string.Empty;
 
         [DataField("description")] private string _description = string.Empty;
@@ -58,31 +68,31 @@ namespace Content.Shared.Cargo.Prototypes
         /// <summary>
         ///     Texture path used in the CargoConsole GUI.
         /// </summary>
-        [DataField("icon")]
+        [DataField]
         public SpriteSpecifier Icon { get; private set; } = SpriteSpecifier.Invalid;
 
         /// <summary>
-        ///     The prototype name of the product.
+        ///     The entity prototype ID of the product.
         /// </summary>
-        [DataField("product", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
-        public string Product { get; private set; } = string.Empty;
+        [DataField]
+        public EntProtoId Product { get; private set; } = string.Empty;
 
         /// <summary>
         ///     The point cost of the product.
         /// </summary>
-        [DataField("cost")]
-        public int PointCost { get; private set; }
+        [DataField]
+        public int Cost { get; private set; }
 
         /// <summary>
         ///     The prototype category of the product. (e.g. Engineering, Medical)
         /// </summary>
-        [DataField("category")]
+        [DataField]
         public string Category { get; private set; } = string.Empty;
 
         /// <summary>
         ///     The prototype group of the product. (e.g. Contraband)
         /// </summary>
-        [DataField("group")]
-        public string Group { get; private set; } = string.Empty;
+        [DataField]
+        public string Group { get; private set; } = "market";
     }
 }