Cargo Console Limit (#1095)
Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
This commit is contained in:
@@ -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; }
|
||||
|
||||
/// <summary>
|
||||
/// Removes all orders from the database.
|
||||
@@ -86,9 +91,18 @@ namespace Content.Server.Cargo
|
||||
/// <param name="order">The order to be approved.</param>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -100,5 +114,13 @@ namespace Content.Server.Cargo
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user