diff --git a/Content.Client/GameObjects/Components/Cargo/CargoConsoleBoundUserInterface.cs b/Content.Client/GameObjects/Components/Cargo/CargoConsoleBoundUserInterface.cs index d98a89173b..aef4cd1403 100644 --- a/Content.Client/GameObjects/Components/Cargo/CargoConsoleBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Cargo/CargoConsoleBoundUserInterface.cs @@ -27,6 +27,8 @@ namespace Content.Client.GameObjects.Components.Cargo public string BankName { get; private set; } [ViewVariables] public int BankBalance { get; private set; } + [ViewVariables] + public (int CurrentCapacity, int MaxCapacity) ShuttleCapacity { get; private set; } private CargoProductPrototype _product; @@ -95,6 +97,8 @@ namespace Content.Client.GameObjects.Components.Cargo BankId = cstate.BankId; BankName = cstate.BankName; BankBalance = cstate.BankBalance; + ShuttleCapacity = cstate.ShuttleCapacity; + _menu.UpdateCargoCapacity(); _menu.UpdateBankData(); } @@ -126,7 +130,10 @@ namespace Content.Client.GameObjects.Components.Cargo { if (!(args.Button.Parent.Parent is CargoOrderRow row)) return; + if (ShuttleCapacity.CurrentCapacity == ShuttleCapacity.MaxCapacity) + return; SendMessage(new SharedCargoConsoleComponent.CargoConsoleApproveOrderMessage(row.Order.OrderNumber)); + _menu?.UpdateCargoCapacity(); } } } diff --git a/Content.Client/UserInterface/Cargo/CargoConsoleMenu.cs b/Content.Client/UserInterface/Cargo/CargoConsoleMenu.cs index 9de68993e6..3626f72faa 100644 --- a/Content.Client/UserInterface/Cargo/CargoConsoleMenu.cs +++ b/Content.Client/UserInterface/Cargo/CargoConsoleMenu.cs @@ -32,6 +32,7 @@ namespace Content.Client.UserInterface.Cargo private Label _accountNameLabel { get; set; } private Label _pointsLabel { get; set; } private Label _shuttleStatusLabel { get; set; } + private Label _shuttleCapacityLabel { get; set; } private VBoxContainer _requests { get; set; } private VBoxContainer _orders { get; set; } private OptionButton _categories { get; set; } @@ -95,6 +96,20 @@ namespace Content.Client.UserInterface.Cargo shuttleStatus.AddChild(_shuttleStatusLabel); rows.AddChild(shuttleStatus); + var shuttleCapacity = new HBoxContainer(); + var shuttleCapacityLabel = new Label + { + Text = _loc.GetString("Order Capacity: "), + StyleClasses = { StyleNano.StyleClassLabelKeyText } + }; + _shuttleCapacityLabel = new Label + { + Text = "0/20" + }; + shuttleCapacity.AddChild(shuttleCapacityLabel); + shuttleCapacity.AddChild(_shuttleCapacityLabel); + rows.AddChild(shuttleCapacity); + var buttons = new HBoxContainer(); CallShuttleButton = new Button() { @@ -272,8 +287,7 @@ namespace Content.Client.UserInterface.Cargo public void PopulateOrders() { _orders.RemoveAllChildren(); - _requests.RemoveAllChildren(); - + _requests.RemoveAllChildren(); foreach (var order in Owner.Orders.Orders) { var row = new CargoOrderRow(); @@ -306,6 +320,11 @@ namespace Content.Client.UserInterface.Cargo PopulateOrders(); } + public void UpdateCargoCapacity() + { + _shuttleCapacityLabel.Text = $"{Owner.ShuttleCapacity.CurrentCapacity}/{Owner.ShuttleCapacity.MaxCapacity}"; + } + public void UpdateBankData() { _accountNameLabel.Text = Owner.BankName; diff --git a/Content.Server/Cargo/CargoOrderDataManager.cs b/Content.Server/Cargo/CargoOrderDataManager.cs index a9b05dba06..35fed56a01 100644 --- a/Content.Server/Cargo/CargoOrderDataManager.cs +++ b/Content.Server/Cargo/CargoOrderDataManager.cs @@ -95,5 +95,11 @@ namespace Content.Server.Cargo return null; return account.GetOrders(); } + + public (int CurrentCapacity, int MaxCapacity) GetCapacity(int id) + { + TryGetAccount(id, out var account); + return (account.CurrentOrderSize, account.MaxOrderSize); + } } } diff --git a/Content.Server/Cargo/CargoOrderDatabase.cs b/Content.Server/Cargo/CargoOrderDatabase.cs index 9f8ee35ad5..3762822ef5 100644 --- a/Content.Server/Cargo/CargoOrderDatabase.cs +++ b/Content.Server/Cargo/CargoOrderDatabase.cs @@ -1,4 +1,5 @@ using Content.Shared.Prototypes.Cargo; +using Robust.Shared.Localization; using System.Collections.Generic; using System.Linq; @@ -12,9 +13,13 @@ namespace Content.Server.Cargo public CargoOrderDatabase(int id) { Id = id; + CurrentOrderSize = 0; + MaxOrderSize = 20; } public int Id { get; private set; } + public int CurrentOrderSize { get; private set; } + public int MaxOrderSize { get; private set; } /// /// Removes all orders from the database. @@ -86,9 +91,18 @@ namespace Content.Server.Cargo /// The order to be approved. public void ApproveOrder(int orderNumber) { + if (CurrentOrderSize == MaxOrderSize) + return; if (!_orders.TryGetValue(orderNumber, out var order)) return; + else if (CurrentOrderSize + order.Amount > MaxOrderSize) + { + AddOrder(order.Requester, Loc.GetString("{0} (Overflow)", order.Reason.Replace(" (Overflow)","")), order.ProductId, + order.Amount - MaxOrderSize - CurrentOrderSize, order.PayingAccountId); + order.Amount = MaxOrderSize - CurrentOrderSize; + } order.Approved = true; + CurrentOrderSize += order.Amount; } /// @@ -100,5 +114,13 @@ namespace Content.Server.Cargo { return _orders.ContainsValue(order); } + + /// + /// Clears the current order capacity. This allows more orders to be processed and is invoked after an order is dispatched. + /// + public void ClearOrderCapacity() + { + CurrentOrderSize = 0; + } } } diff --git a/Content.Server/Cargo/ICargoOrderDataManager.cs b/Content.Server/Cargo/ICargoOrderDataManager.cs index 4c4f5cbbe7..2eefea9f9d 100644 --- a/Content.Server/Cargo/ICargoOrderDataManager.cs +++ b/Content.Server/Cargo/ICargoOrderDataManager.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Content.Server.GameObjects.Components.Cargo; using Content.Shared.Prototypes.Cargo; @@ -13,5 +14,6 @@ namespace Content.Server.Cargo void AddComponent(CargoOrderDatabaseComponent component); List GetOrdersFromAccount(int accountId); List RemoveAndGetApprovedFrom(CargoOrderDatabase database); + (int CurrentCapacity, int MaxCapacity) GetCapacity(int id); } } diff --git a/Content.Server/GameObjects/Components/Cargo/CargoConsoleComponent.cs b/Content.Server/GameObjects/Components/Cargo/CargoConsoleComponent.cs index 11fc7e832f..b8be1cda01 100644 --- a/Content.Server/GameObjects/Components/Cargo/CargoConsoleComponent.cs +++ b/Content.Server/GameObjects/Components/Cargo/CargoConsoleComponent.cs @@ -1,5 +1,4 @@ using Content.Server.Cargo; -using Content.Server.GameObjects.Components.Power; using Content.Server.GameObjects.Components.Power.ApcNetComponents; using Content.Server.GameObjects.EntitySystems; using Content.Shared.GameObjects.Components.Cargo; @@ -46,24 +45,19 @@ namespace Content.Server.GameObjects.Components.Cargo return; if (_bankAccount != null) { - _bankAccount.OnBalanceChange -= OnBankAccountChange; + _bankAccount.OnBalanceChange -= UpdateUIState; } _bankAccount = value; if (value != null) { - _bankAccount.OnBalanceChange += OnBankAccountChange; + _bankAccount.OnBalanceChange += UpdateUIState; } - OnBankAccountChange(); + UpdateUIState(); } } - private void OnBankAccountChange() - { - SetState(_bankAccount.Id, _bankAccount.Name, _bankAccount.Balance); - } - private bool _requestOnly = false; private PowerReceiverComponent _powerReceiver; @@ -121,14 +115,19 @@ namespace Content.Server.GameObjects.Components.Cargo _prototypeManager.TryIndex(order.ProductId, out CargoProductPrototype product); if (product == null) break; + var capacity = _cargoOrderDataManager.GetCapacity(Orders.Database.Id); + if (capacity.CurrentCapacity == capacity.MaxCapacity) + break; if (!_cargoConsoleSystem.ChangeBalance(_bankAccount.Id, (-product.PointCost) * order.Amount)) break; _cargoOrderDataManager.ApproveOrder(Orders.Database.Id, msg.OrderNumber); + UpdateUIState(); break; } case CargoConsoleShuttleMessage _: { var approvedOrders = _cargoOrderDataManager.RemoveAndGetApprovedFrom(Orders.Database); + Orders.Database.ClearOrderCapacity(); // TODO replace with shuttle code // TEMPORARY loop for spawning stuff on top of console @@ -158,12 +157,18 @@ namespace Content.Server.GameObjects.Components.Cargo _userInterface.Open(actor.playerSession); } - /// - /// Sync bank account information - /// - public void SetState(int id, string name, int balance) + private void UpdateUIState() { - _userInterface.SetState(new CargoConsoleInterfaceState(_requestOnly, id, name, balance)); + if (_bankAccount == null) + { + return; + } + + var id = _bankAccount.Id; + var name = _bankAccount.Name; + var balance = _bankAccount.Balance; + var capacity = _cargoOrderDataManager.GetCapacity(id); + _userInterface.SetState(new CargoConsoleInterfaceState(_requestOnly, id, name, balance, capacity)); } } } diff --git a/Content.Shared/GameObjects/Components/Cargo/SharedCargoConsoleComponent.cs b/Content.Shared/GameObjects/Components/Cargo/SharedCargoConsoleComponent.cs index 887c94f4be..a2221bfb32 100644 --- a/Content.Shared/GameObjects/Components/Cargo/SharedCargoConsoleComponent.cs +++ b/Content.Shared/GameObjects/Components/Cargo/SharedCargoConsoleComponent.cs @@ -94,13 +94,15 @@ namespace Content.Shared.GameObjects.Components.Cargo public readonly int BankId; public readonly string BankName; public readonly int BankBalance; + public readonly (int CurrentCapacity, int MaxCapacity) ShuttleCapacity; - public CargoConsoleInterfaceState(bool requestOnly, int bankId, string bankName, int bankBalance) + public CargoConsoleInterfaceState(bool requestOnly, int bankId, string bankName, int bankBalance, (int CurrentCapacity, int MaxCapacity) shuttleCapacity) { RequestOnly = requestOnly; BankId = bankId; BankName = bankName; BankBalance = bankBalance; + ShuttleCapacity = shuttleCapacity; } } }