Cargo Console Limit (#1095)

Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
This commit is contained in:
windarkata
2020-07-02 07:45:40 -05:00
committed by GitHub
parent 7e061b5968
commit 6775ae8153
7 changed files with 81 additions and 18 deletions

View File

@@ -27,6 +27,8 @@ namespace Content.Client.GameObjects.Components.Cargo
public string BankName { get; private set; } public string BankName { get; private set; }
[ViewVariables] [ViewVariables]
public int BankBalance { get; private set; } public int BankBalance { get; private set; }
[ViewVariables]
public (int CurrentCapacity, int MaxCapacity) ShuttleCapacity { get; private set; }
private CargoProductPrototype _product; private CargoProductPrototype _product;
@@ -95,6 +97,8 @@ namespace Content.Client.GameObjects.Components.Cargo
BankId = cstate.BankId; BankId = cstate.BankId;
BankName = cstate.BankName; BankName = cstate.BankName;
BankBalance = cstate.BankBalance; BankBalance = cstate.BankBalance;
ShuttleCapacity = cstate.ShuttleCapacity;
_menu.UpdateCargoCapacity();
_menu.UpdateBankData(); _menu.UpdateBankData();
} }
@@ -126,7 +130,10 @@ namespace Content.Client.GameObjects.Components.Cargo
{ {
if (!(args.Button.Parent.Parent is CargoOrderRow row)) if (!(args.Button.Parent.Parent is CargoOrderRow row))
return; return;
if (ShuttleCapacity.CurrentCapacity == ShuttleCapacity.MaxCapacity)
return;
SendMessage(new SharedCargoConsoleComponent.CargoConsoleApproveOrderMessage(row.Order.OrderNumber)); SendMessage(new SharedCargoConsoleComponent.CargoConsoleApproveOrderMessage(row.Order.OrderNumber));
_menu?.UpdateCargoCapacity();
} }
} }
} }

View File

@@ -32,6 +32,7 @@ namespace Content.Client.UserInterface.Cargo
private Label _accountNameLabel { get; set; } private Label _accountNameLabel { get; set; }
private Label _pointsLabel { get; set; } private Label _pointsLabel { get; set; }
private Label _shuttleStatusLabel { get; set; } private Label _shuttleStatusLabel { get; set; }
private Label _shuttleCapacityLabel { get; set; }
private VBoxContainer _requests { get; set; } private VBoxContainer _requests { get; set; }
private VBoxContainer _orders { get; set; } private VBoxContainer _orders { get; set; }
private OptionButton _categories { get; set; } private OptionButton _categories { get; set; }
@@ -95,6 +96,20 @@ namespace Content.Client.UserInterface.Cargo
shuttleStatus.AddChild(_shuttleStatusLabel); shuttleStatus.AddChild(_shuttleStatusLabel);
rows.AddChild(shuttleStatus); 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(); var buttons = new HBoxContainer();
CallShuttleButton = new Button() CallShuttleButton = new Button()
{ {
@@ -273,7 +288,6 @@ namespace Content.Client.UserInterface.Cargo
{ {
_orders.RemoveAllChildren(); _orders.RemoveAllChildren();
_requests.RemoveAllChildren(); _requests.RemoveAllChildren();
foreach (var order in Owner.Orders.Orders) foreach (var order in Owner.Orders.Orders)
{ {
var row = new CargoOrderRow(); var row = new CargoOrderRow();
@@ -306,6 +320,11 @@ namespace Content.Client.UserInterface.Cargo
PopulateOrders(); PopulateOrders();
} }
public void UpdateCargoCapacity()
{
_shuttleCapacityLabel.Text = $"{Owner.ShuttleCapacity.CurrentCapacity}/{Owner.ShuttleCapacity.MaxCapacity}";
}
public void UpdateBankData() public void UpdateBankData()
{ {
_accountNameLabel.Text = Owner.BankName; _accountNameLabel.Text = Owner.BankName;

View File

@@ -95,5 +95,11 @@ namespace Content.Server.Cargo
return null; return null;
return account.GetOrders(); return account.GetOrders();
} }
public (int CurrentCapacity, int MaxCapacity) GetCapacity(int id)
{
TryGetAccount(id, out var account);
return (account.CurrentOrderSize, account.MaxOrderSize);
}
} }
} }

View File

@@ -1,4 +1,5 @@
using Content.Shared.Prototypes.Cargo; using Content.Shared.Prototypes.Cargo;
using Robust.Shared.Localization;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -12,9 +13,13 @@ namespace Content.Server.Cargo
public CargoOrderDatabase(int id) public CargoOrderDatabase(int id)
{ {
Id = id; Id = id;
CurrentOrderSize = 0;
MaxOrderSize = 20;
} }
public int Id { get; private set; } public int Id { get; private set; }
public int CurrentOrderSize { get; private set; }
public int MaxOrderSize { get; private set; }
/// <summary> /// <summary>
/// Removes all orders from the database. /// Removes all orders from the database.
@@ -86,9 +91,18 @@ namespace Content.Server.Cargo
/// <param name="order">The order to be approved.</param> /// <param name="order">The order to be approved.</param>
public void ApproveOrder(int orderNumber) public void ApproveOrder(int orderNumber)
{ {
if (CurrentOrderSize == MaxOrderSize)
return;
if (!_orders.TryGetValue(orderNumber, out var order)) if (!_orders.TryGetValue(orderNumber, out var order))
return; 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; order.Approved = true;
CurrentOrderSize += order.Amount;
} }
/// <summary> /// <summary>
@@ -100,5 +114,13 @@ namespace Content.Server.Cargo
{ {
return _orders.ContainsValue(order); return _orders.ContainsValue(order);
} }
/// <summary>
/// Clears the current order capacity. This allows more orders to be processed and is invoked after an order is dispatched.
/// </summary>
public void ClearOrderCapacity()
{
CurrentOrderSize = 0;
}
} }
} }

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using Content.Server.GameObjects.Components.Cargo; using Content.Server.GameObjects.Components.Cargo;
using Content.Shared.Prototypes.Cargo; using Content.Shared.Prototypes.Cargo;
@@ -13,5 +14,6 @@ namespace Content.Server.Cargo
void AddComponent(CargoOrderDatabaseComponent component); void AddComponent(CargoOrderDatabaseComponent component);
List<CargoOrderData> GetOrdersFromAccount(int accountId); List<CargoOrderData> GetOrdersFromAccount(int accountId);
List<CargoOrderData> RemoveAndGetApprovedFrom(CargoOrderDatabase database); List<CargoOrderData> RemoveAndGetApprovedFrom(CargoOrderDatabase database);
(int CurrentCapacity, int MaxCapacity) GetCapacity(int id);
} }
} }

View File

@@ -1,5 +1,4 @@
using Content.Server.Cargo; using Content.Server.Cargo;
using Content.Server.GameObjects.Components.Power;
using Content.Server.GameObjects.Components.Power.ApcNetComponents; using Content.Server.GameObjects.Components.Power.ApcNetComponents;
using Content.Server.GameObjects.EntitySystems; using Content.Server.GameObjects.EntitySystems;
using Content.Shared.GameObjects.Components.Cargo; using Content.Shared.GameObjects.Components.Cargo;
@@ -46,24 +45,19 @@ namespace Content.Server.GameObjects.Components.Cargo
return; return;
if (_bankAccount != null) if (_bankAccount != null)
{ {
_bankAccount.OnBalanceChange -= OnBankAccountChange; _bankAccount.OnBalanceChange -= UpdateUIState;
} }
_bankAccount = value; _bankAccount = value;
if (value != null) 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 bool _requestOnly = false;
private PowerReceiverComponent _powerReceiver; private PowerReceiverComponent _powerReceiver;
@@ -121,14 +115,19 @@ namespace Content.Server.GameObjects.Components.Cargo
_prototypeManager.TryIndex(order.ProductId, out CargoProductPrototype product); _prototypeManager.TryIndex(order.ProductId, out CargoProductPrototype product);
if (product == null) if (product == null)
break; break;
var capacity = _cargoOrderDataManager.GetCapacity(Orders.Database.Id);
if (capacity.CurrentCapacity == capacity.MaxCapacity)
break;
if (!_cargoConsoleSystem.ChangeBalance(_bankAccount.Id, (-product.PointCost) * order.Amount)) if (!_cargoConsoleSystem.ChangeBalance(_bankAccount.Id, (-product.PointCost) * order.Amount))
break; break;
_cargoOrderDataManager.ApproveOrder(Orders.Database.Id, msg.OrderNumber); _cargoOrderDataManager.ApproveOrder(Orders.Database.Id, msg.OrderNumber);
UpdateUIState();
break; break;
} }
case CargoConsoleShuttleMessage _: case CargoConsoleShuttleMessage _:
{ {
var approvedOrders = _cargoOrderDataManager.RemoveAndGetApprovedFrom(Orders.Database); var approvedOrders = _cargoOrderDataManager.RemoveAndGetApprovedFrom(Orders.Database);
Orders.Database.ClearOrderCapacity();
// TODO replace with shuttle code // TODO replace with shuttle code
// TEMPORARY loop for spawning stuff on top of console // TEMPORARY loop for spawning stuff on top of console
@@ -158,12 +157,18 @@ namespace Content.Server.GameObjects.Components.Cargo
_userInterface.Open(actor.playerSession); _userInterface.Open(actor.playerSession);
} }
/// <summary> private void UpdateUIState()
/// Sync bank account information
/// </summary>
public void SetState(int id, string name, int balance)
{ {
_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));
} }
} }
} }

View File

@@ -94,13 +94,15 @@ namespace Content.Shared.GameObjects.Components.Cargo
public readonly int BankId; public readonly int BankId;
public readonly string BankName; public readonly string BankName;
public readonly int BankBalance; 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; RequestOnly = requestOnly;
BankId = bankId; BankId = bankId;
BankName = bankName; BankName = bankName;
BankBalance = bankBalance; BankBalance = bankBalance;
ShuttleCapacity = shuttleCapacity;
} }
} }
} }