diff --git a/Content.Client/GameObjects/Components/Cargo/CargoConsoleBoundUserInterface.cs b/Content.Client/GameObjects/Components/Cargo/CargoConsoleBoundUserInterface.cs index 8ffac19330..f875091bb4 100644 --- a/Content.Client/GameObjects/Components/Cargo/CargoConsoleBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Cargo/CargoConsoleBoundUserInterface.cs @@ -1,4 +1,5 @@ -using Content.Client.UserInterface.Cargo; +using System; +using Content.Client.UserInterface.Cargo; using Content.Shared.GameObjects.Components.Cargo; using Content.Shared.Prototypes.Cargo; using Robust.Client.GameObjects; @@ -83,8 +84,10 @@ namespace Content.Client.GameObjects.Components.Cargo _menu.OnOrderCanceled += RemoveOrder; _orderMenu.SubmitButton.OnPressed += (_) => { - AddOrder(); - _orderMenu.Close(); + if (AddOrder()) + { + _orderMenu.Close(); + } }; _menu.OpenCentered(); @@ -131,13 +134,21 @@ namespace Content.Client.GameObjects.Components.Cargo _orderMenu?.Dispose(); } - private void AddOrder() + private bool AddOrder() { + int orderAmt = _orderMenu?.Amount.Value ?? 0; + if (orderAmt < 1 || orderAmt > ShuttleCapacity.MaxCapacity) + { + return false; + } + SendMessage(new CargoConsoleAddOrderMessage( _orderMenu?.Requester.Text ?? "", _orderMenu?.Reason.Text ?? "", _product?.ID ?? "", - _orderMenu?.Amount.Value ?? 0)); + orderAmt)); + + return true; } private void RemoveOrder(ButtonEventArgs args) diff --git a/Content.Server/GameObjects/Components/Cargo/CargoConsoleComponent.cs b/Content.Server/GameObjects/Components/Cargo/CargoConsoleComponent.cs index 999bb293c9..a8a31e87a8 100644 --- a/Content.Server/GameObjects/Components/Cargo/CargoConsoleComponent.cs +++ b/Content.Server/GameObjects/Components/Cargo/CargoConsoleComponent.cs @@ -8,10 +8,12 @@ using Content.Shared.GameObjects.Components.Cargo; using Content.Shared.Interfaces.GameObjects.Components; using Content.Shared.Prototypes.Cargo; using Robust.Server.GameObjects; +using Robust.Shared.Audio; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Map; using Robust.Shared.Maths; +using Robust.Shared.Player; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; @@ -110,7 +112,11 @@ namespace Content.Server.GameObjects.Components.Cargo break; } - _cargoConsoleSystem.AddOrder(orders.Database.Id, msg.Requester, msg.Reason, msg.ProductId, msg.Amount, _bankAccount.Id); + if (!_cargoConsoleSystem.AddOrder(orders.Database.Id, msg.Requester, msg.Reason, msg.ProductId, + msg.Amount, _bankAccount.Id)) + { + SoundSystem.Play(Filter.Local(), "/Audio/Effects/error.ogg", Owner, AudioParams.Default); + } break; } case CargoConsoleRemoveOrderMessage msg: @@ -131,15 +137,17 @@ namespace Content.Server.GameObjects.Components.Cargo if (product == null!) break; var capacity = _cargoConsoleSystem.GetCapacity(orders.Database.Id); - if (capacity.CurrentCapacity == capacity.MaxCapacity) + if ( + capacity.CurrentCapacity == capacity.MaxCapacity + || capacity.CurrentCapacity + order.Amount > capacity.MaxCapacity + || !_cargoConsoleSystem.CheckBalance(_bankAccount.Id, (-product.PointCost) * order.Amount) + || !_cargoConsoleSystem.ApproveOrder(orders.Database.Id, msg.OrderNumber) + || !_cargoConsoleSystem.ChangeBalance(_bankAccount.Id, (-product.PointCost) * order.Amount) + ) + { + SoundSystem.Play(Filter.Local(), "/Audio/Effects/error.ogg", Owner, AudioParams.Default); break; - if (!_cargoConsoleSystem.CheckBalance(_bankAccount.Id, (-product.PointCost) * order.Amount)) - break; - if (!_cargoConsoleSystem.ApproveOrder(orders.Database.Id, msg.OrderNumber)) - break; - if (!_cargoConsoleSystem.ChangeBalance(_bankAccount.Id, (-product.PointCost) * order.Amount)) - break; - + } UpdateUIState(); break; } diff --git a/Content.Server/GameObjects/EntitySystems/CargoConsoleSystem.cs b/Content.Server/GameObjects/EntitySystems/CargoConsoleSystem.cs index eb2f5db375..747a1c2c25 100644 --- a/Content.Server/GameObjects/EntitySystems/CargoConsoleSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/CargoConsoleSystem.cs @@ -151,8 +151,11 @@ namespace Content.Server.GameObjects.EntitySystems public bool AddOrder(int id, string requester, string reason, string productId, int amount, int payingAccountId) { - if (amount < 1 || !TryGetOrderDatabase(id, out var database)) + if (amount < 1 || !TryGetOrderDatabase(id, out var database) || amount > database.MaxOrderSize) + { return false; + } + database.AddOrder(requester, reason, productId, amount, payingAccountId); SyncComponentsWithId(id); return true;