Allow cargo request computers to send orders to the primary account (#37943)
This commit is contained in:
committed by
GitHub
parent
b1ab5bd059
commit
3d40bebbef
@@ -203,6 +203,9 @@ namespace Content.Client.Cargo.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void PopulateOrders(IEnumerable<CargoOrderData> orders)
|
public void PopulateOrders(IEnumerable<CargoOrderData> orders)
|
||||||
{
|
{
|
||||||
|
if (!_orderConsoleQuery.TryComp(_owner, out var orderConsole))
|
||||||
|
return;
|
||||||
|
|
||||||
Requests.DisposeAllChildren();
|
Requests.DisposeAllChildren();
|
||||||
|
|
||||||
foreach (var order in orders)
|
foreach (var order in orders)
|
||||||
@@ -237,6 +240,7 @@ namespace Content.Client.Cargo.UI
|
|||||||
row.Cancel.OnPressed += (args) => { OnOrderCanceled?.Invoke(args); };
|
row.Cancel.OnPressed += (args) => { OnOrderCanceled?.Invoke(args); };
|
||||||
|
|
||||||
// TODO: Disable based on access.
|
// TODO: Disable based on access.
|
||||||
|
row.SetApproveVisible(orderConsole.Mode != CargoOrderConsoleMode.SendToPrimary);
|
||||||
row.Approve.OnPressed += (args) => { OnOrderApproved?.Invoke(args); };
|
row.Approve.OnPressed += (args) => { OnOrderApproved?.Invoke(args); };
|
||||||
Requests.AddChild(row);
|
Requests.AddChild(row);
|
||||||
}
|
}
|
||||||
@@ -290,8 +294,8 @@ namespace Content.Client.Cargo.UI
|
|||||||
TransferSpinBox.Value > bankAccount.Accounts[orderConsole.Account] * orderConsole.TransferLimit ||
|
TransferSpinBox.Value > bankAccount.Accounts[orderConsole.Account] * orderConsole.TransferLimit ||
|
||||||
_timing.CurTime < orderConsole.NextAccountActionTime;
|
_timing.CurTime < orderConsole.NextAccountActionTime;
|
||||||
|
|
||||||
OrdersSpacer.Visible = !orderConsole.SlipPrinter;
|
OrdersSpacer.Visible = orderConsole.Mode != CargoOrderConsoleMode.PrintSlip;
|
||||||
Orders.Visible = !orderConsole.SlipPrinter;
|
Orders.Visible = orderConsole.Mode != CargoOrderConsoleMode.PrintSlip;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,5 +14,15 @@ namespace Content.Client.Cargo.UI
|
|||||||
{
|
{
|
||||||
RobustXamlLoader.Load(this);
|
RobustXamlLoader.Load(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetApproveVisible(bool visible)
|
||||||
|
{
|
||||||
|
Approve.Visible = visible;
|
||||||
|
|
||||||
|
if (visible)
|
||||||
|
Cancel.AddStyleClass("OpenLeft");
|
||||||
|
else
|
||||||
|
Cancel.RemoveStyleClass("OpenLeft");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ namespace Content.Server.Cargo.Systems
|
|||||||
{
|
{
|
||||||
OnInteractUsingCash(uid, component, ref args);
|
OnInteractUsingCash(uid, component, ref args);
|
||||||
}
|
}
|
||||||
else if (TryComp<CargoSlipComponent>(args.Used, out var slip) && !component.SlipPrinter)
|
else if (TryComp<CargoSlipComponent>(args.Used, out var slip) && component.Mode == CargoOrderConsoleMode.DirectOrder)
|
||||||
{
|
{
|
||||||
OnInteractUsingSlip((uid, component), ref args, slip);
|
OnInteractUsingSlip((uid, component), ref args, slip);
|
||||||
}
|
}
|
||||||
@@ -144,7 +144,7 @@ namespace Content.Server.Cargo.Systems
|
|||||||
if (args.Actor is not { Valid: true } player)
|
if (args.Actor is not { Valid: true } player)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (component.SlipPrinter)
|
if (component.Mode != CargoOrderConsoleMode.DirectOrder)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!_accessReaderSystem.IsAllowed(player, uid))
|
if (!_accessReaderSystem.IsAllowed(player, uid))
|
||||||
@@ -181,7 +181,7 @@ namespace Content.Server.Cargo.Systems
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var amount = GetOutstandingOrderCount(orderDatabase, order.Account);
|
var amount = GetOutstandingOrderCount((station.Value, orderDatabase), order.Account);
|
||||||
var capacity = orderDatabase.Capacity;
|
var capacity = orderDatabase.Capacity;
|
||||||
|
|
||||||
// Too many orders, avoid them getting spammed in the UI.
|
// Too many orders, avoid them getting spammed in the UI.
|
||||||
@@ -312,7 +312,7 @@ namespace Content.Server.Cargo.Systems
|
|||||||
{
|
{
|
||||||
var station = _station.GetOwningStation(uid);
|
var station = _station.GetOwningStation(uid);
|
||||||
|
|
||||||
if (component.SlipPrinter)
|
if (component.Mode != CargoOrderConsoleMode.DirectOrder)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!TryGetOrderDatabase(station, out var orderDatabase))
|
if (!TryGetOrderDatabase(station, out var orderDatabase))
|
||||||
@@ -367,6 +367,9 @@ namespace Content.Server.Cargo.Systems
|
|||||||
if (!TryGetOrderDatabase(stationUid, out var orderDatabase))
|
if (!TryGetOrderDatabase(stationUid, out var orderDatabase))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!TryComp<StationBankAccountComponent>(stationUid, out var bank))
|
||||||
|
return;
|
||||||
|
|
||||||
if (!_protoMan.TryIndex<CargoProductPrototype>(args.CargoProductId, out var product))
|
if (!_protoMan.TryIndex<CargoProductPrototype>(args.CargoProductId, out var product))
|
||||||
{
|
{
|
||||||
Log.Error($"Tried to add invalid cargo product {args.CargoProductId} as order!");
|
Log.Error($"Tried to add invalid cargo product {args.CargoProductId} as order!");
|
||||||
@@ -376,15 +379,17 @@ namespace Content.Server.Cargo.Systems
|
|||||||
if (!GetAvailableProducts((uid, component)).Contains(args.CargoProductId))
|
if (!GetAvailableProducts((uid, component)).Contains(args.CargoProductId))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (component.SlipPrinter)
|
if (component.Mode == CargoOrderConsoleMode.PrintSlip)
|
||||||
{
|
{
|
||||||
OnAddOrderMessageSlipPrinter(uid, component, args, product);
|
OnAddOrderMessageSlipPrinter(uid, component, args, product);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var targetAccount = component.Mode == CargoOrderConsoleMode.SendToPrimary ? bank.PrimaryAccount : component.Account;
|
||||||
|
|
||||||
var data = GetOrderData(args, product, GenerateOrderId(orderDatabase), component.Account);
|
var data = GetOrderData(args, product, GenerateOrderId(orderDatabase), component.Account);
|
||||||
|
|
||||||
if (!TryAddOrder(stationUid.Value, component.Account, data, orderDatabase))
|
if (!TryAddOrder(stationUid.Value, targetAccount, data, orderDatabase))
|
||||||
{
|
{
|
||||||
PlayDenySound(uid, component);
|
PlayDenySound(uid, component);
|
||||||
return;
|
return;
|
||||||
@@ -419,15 +424,33 @@ namespace Content.Server.Cargo.Systems
|
|||||||
CargoConsoleUiKey.Orders,
|
CargoConsoleUiKey.Orders,
|
||||||
new CargoConsoleInterfaceState(
|
new CargoConsoleInterfaceState(
|
||||||
MetaData(station.Value).EntityName,
|
MetaData(station.Value).EntityName,
|
||||||
GetOutstandingOrderCount(orderDatabase, console.Account),
|
GetOutstandingOrderCount((station!.Value, orderDatabase), console.Account),
|
||||||
orderDatabase.Capacity,
|
orderDatabase.Capacity,
|
||||||
GetNetEntity(station.Value),
|
GetNetEntity(station.Value),
|
||||||
orderDatabase.Orders[console.Account],
|
RelevantOrders((station!.Value, orderDatabase), (consoleUid, console)),
|
||||||
GetAvailableProducts((consoleUid, console))
|
GetAvailableProducts((consoleUid, console))
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets orders relevant to this account, i.e. orders on the account directly or orders on behalf of the account in the primary account.
|
||||||
|
/// </summary>
|
||||||
|
private List<CargoOrderData> RelevantOrders(Entity<StationCargoOrderDatabaseComponent> station, Entity<CargoOrderConsoleComponent> console)
|
||||||
|
{
|
||||||
|
if (!TryComp<StationBankAccountComponent>(station, out var bank))
|
||||||
|
return [];
|
||||||
|
|
||||||
|
var ourOrders = station.Comp.Orders[console.Comp.Account];
|
||||||
|
|
||||||
|
if (console.Comp.Account == bank.PrimaryAccount)
|
||||||
|
return ourOrders;
|
||||||
|
|
||||||
|
var otherOrders = station.Comp.Orders[bank.PrimaryAccount].Where(order => order.Account == console.Comp.Account);
|
||||||
|
|
||||||
|
return ourOrders.Concat(otherOrders).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
private void ConsolePopup(EntityUid actor, string text)
|
private void ConsolePopup(EntityUid actor, string text)
|
||||||
{
|
{
|
||||||
_popup.PopupCursor(text, actor);
|
_popup.PopupCursor(text, actor);
|
||||||
@@ -447,17 +470,32 @@ namespace Content.Server.Cargo.Systems
|
|||||||
return new CargoOrderData(id, cargoProduct.Product, cargoProduct.Name, cargoProduct.Cost, args.Amount, args.Requester, args.Reason, account);
|
return new CargoOrderData(id, cargoProduct.Product, cargoProduct.Name, cargoProduct.Cost, args.Amount, args.Requester, args.Reason, account);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int GetOutstandingOrderCount(StationCargoOrderDatabaseComponent component, ProtoId<CargoAccountPrototype> account)
|
public int GetOutstandingOrderCount(Entity<StationCargoOrderDatabaseComponent> station, ProtoId<CargoAccountPrototype> account)
|
||||||
{
|
{
|
||||||
var amount = 0;
|
var amount = 0;
|
||||||
|
|
||||||
foreach (var order in component.Orders[account])
|
if (!TryComp<StationBankAccountComponent>(station, out var bank))
|
||||||
|
return amount;
|
||||||
|
|
||||||
|
foreach (var order in station.Comp.Orders[account])
|
||||||
{
|
{
|
||||||
if (!order.Approved)
|
if (!order.Approved)
|
||||||
continue;
|
continue;
|
||||||
amount += order.OrderQuantity - order.NumDispatched;
|
amount += order.OrderQuantity - order.NumDispatched;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (account == bank.PrimaryAccount)
|
||||||
|
return amount;
|
||||||
|
|
||||||
|
foreach (var order in station.Comp.Orders[bank.PrimaryAccount])
|
||||||
|
{
|
||||||
|
if (order.Account != account)
|
||||||
|
continue;
|
||||||
|
if (!order.Approved)
|
||||||
|
continue;
|
||||||
|
amount += order.OrderQuantity - order.NumDispatched;
|
||||||
|
}
|
||||||
|
|
||||||
return amount;
|
return amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public sealed class CargoGiftsRule : StationEventSystem<CargoGiftsRuleComponent>
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add some presents
|
// Add some presents
|
||||||
var outstanding = CargoSystem.GetOutstandingOrderCount(cargoDb, component.Account);
|
var outstanding = _cargoSystem.GetOutstandingOrderCount((station.Value, cargoDb), component.Account);
|
||||||
while (outstanding < cargoDb.Capacity - component.OrderSpaceToLeave && component.Gifts.Count > 0)
|
while (outstanding < cargoDb.Capacity - component.OrderSpaceToLeave && component.Gifts.Count > 0)
|
||||||
{
|
{
|
||||||
// I wish there was a nice way to pop this
|
// I wish there was a nice way to pop this
|
||||||
|
|||||||
@@ -104,10 +104,10 @@ public sealed partial class CargoOrderConsoleComponent : Component
|
|||||||
public static readonly ProtoId<RadioChannelPrototype> BaseAnnouncementChannel = "Supply";
|
public static readonly ProtoId<RadioChannelPrototype> BaseAnnouncementChannel = "Supply";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// If set to true, restricts this console from ordering and has it print slips instead
|
/// The behaviour of the cargo console regarding orders
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField]
|
[DataField]
|
||||||
public bool SlipPrinter;
|
public CargoOrderConsoleMode Mode = CargoOrderConsoleMode.DirectOrder;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The time at which the console will be able to print a slip again.
|
/// The time at which the console will be able to print a slip again.
|
||||||
@@ -146,6 +146,26 @@ public sealed partial class CargoOrderConsoleComponent : Component
|
|||||||
public TimeSpan DenySoundDelay = TimeSpan.FromSeconds(2);
|
public TimeSpan DenySoundDelay = TimeSpan.FromSeconds(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The behaviour of the cargo order console
|
||||||
|
/// </summary>
|
||||||
|
[Serializable, NetSerializable]
|
||||||
|
public enum CargoOrderConsoleMode : byte
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Place orders directly
|
||||||
|
/// </summary>
|
||||||
|
DirectOrder,
|
||||||
|
/// <summary>
|
||||||
|
/// Print a slip to be inserted into a DirectOrder console
|
||||||
|
/// </summary>
|
||||||
|
PrintSlip,
|
||||||
|
/// <summary>
|
||||||
|
/// Transfers the order to the primary account
|
||||||
|
/// </summary>
|
||||||
|
SendToPrimary,
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Withdraw funds from an account
|
/// Withdraw funds from an account
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -931,7 +931,7 @@
|
|||||||
account: Engineering
|
account: Engineering
|
||||||
announcementChannel: Engineering
|
announcementChannel: Engineering
|
||||||
removeLimitAccess: [ "ChiefEngineer" ]
|
removeLimitAccess: [ "ChiefEngineer" ]
|
||||||
slipPrinter: true
|
mode: SendToPrimary
|
||||||
- type: ActiveRadio
|
- type: ActiveRadio
|
||||||
channels:
|
channels:
|
||||||
- Engineering
|
- Engineering
|
||||||
@@ -964,7 +964,7 @@
|
|||||||
account: Medical
|
account: Medical
|
||||||
announcementChannel: Medical
|
announcementChannel: Medical
|
||||||
removeLimitAccess: [ "ChiefMedicalOfficer" ]
|
removeLimitAccess: [ "ChiefMedicalOfficer" ]
|
||||||
slipPrinter: true
|
mode: SendToPrimary
|
||||||
- type: ActiveRadio
|
- type: ActiveRadio
|
||||||
channels:
|
channels:
|
||||||
- Medical
|
- Medical
|
||||||
@@ -997,7 +997,7 @@
|
|||||||
account: Science
|
account: Science
|
||||||
announcementChannel: Science
|
announcementChannel: Science
|
||||||
removeLimitAccess: [ "ResearchDirector" ]
|
removeLimitAccess: [ "ResearchDirector" ]
|
||||||
slipPrinter: true
|
mode: SendToPrimary
|
||||||
- type: ActiveRadio
|
- type: ActiveRadio
|
||||||
channels:
|
channels:
|
||||||
- Science
|
- Science
|
||||||
@@ -1030,7 +1030,7 @@
|
|||||||
account: Security
|
account: Security
|
||||||
announcementChannel: Security
|
announcementChannel: Security
|
||||||
removeLimitAccess: [ "HeadOfSecurity" ]
|
removeLimitAccess: [ "HeadOfSecurity" ]
|
||||||
slipPrinter: true
|
mode: SendToPrimary
|
||||||
- type: ActiveRadio
|
- type: ActiveRadio
|
||||||
channels:
|
channels:
|
||||||
- Security
|
- Security
|
||||||
@@ -1063,7 +1063,7 @@
|
|||||||
account: Service
|
account: Service
|
||||||
announcementChannel: Service
|
announcementChannel: Service
|
||||||
removeLimitAccess: [ "HeadOfPersonnel" ]
|
removeLimitAccess: [ "HeadOfPersonnel" ]
|
||||||
slipPrinter: true
|
mode: SendToPrimary
|
||||||
- type: ActiveRadio
|
- type: ActiveRadio
|
||||||
channels:
|
channels:
|
||||||
- Service
|
- Service
|
||||||
|
|||||||
Reference in New Issue
Block a user