using Content.Shared.Cargo.Events;
using Content.Shared.Cargo.Prototypes;
using Content.Shared.CCVar;
-using JetBrains.Annotations;
using Robust.Shared.Audio;
using Robust.Shared.Prototypes;
{
SubscribeLocalEvent<TradeStationComponent, GridSplitEvent>(OnTradeSplit);
- SubscribeLocalEvent<CargoShuttleConsoleComponent, ComponentStartup>(OnCargoShuttleConsoleStartup);
-
SubscribeLocalEvent<CargoPalletConsoleComponent, CargoPalletSellMessage>(OnPalletSale);
SubscribeLocalEvent<CargoPalletConsoleComponent, CargoPalletAppraiseMessage>(OnPalletAppraise);
SubscribeLocalEvent<CargoPalletConsoleComponent, BoundUIOpenedEvent>(OnPalletUIOpen);
}
#region Console
-
- [PublicAPI]
- private void UpdateCargoShuttleConsoles(EntityUid shuttleUid, CargoShuttleComponent _)
- {
- // Update pilot consoles that are already open.
- _console.RefreshDroneConsoles();
-
- // Update order consoles.
- var shuttleConsoleQuery = AllEntityQuery<CargoShuttleConsoleComponent>();
-
- while (shuttleConsoleQuery.MoveNext(out var uid, out var _))
- {
- var stationUid = _station.GetOwningStation(uid);
- if (stationUid != shuttleUid)
- continue;
-
- UpdateShuttleState(uid, stationUid);
- }
- }
-
private void UpdatePalletConsoleInterface(EntityUid uid)
{
if (Transform(uid).GridUid is not { } gridUid)
UpdatePalletConsoleInterface(uid);
}
- private void OnCargoShuttleConsoleStartup(EntityUid uid, CargoShuttleConsoleComponent component, ComponentStartup args)
- {
- var station = _station.GetOwningStation(uid);
- UpdateShuttleState(uid, station);
- }
-
- private void UpdateShuttleState(EntityUid uid, EntityUid? station = null)
- {
- TryComp<StationCargoOrderDatabaseComponent>(station, out var orderDatabase);
- TryComp<CargoShuttleComponent>(orderDatabase?.Shuttle, out var shuttle);
-
- var orders = GetProjectedOrders(station ?? EntityUid.Invalid, orderDatabase, shuttle);
- var shuttleName = orderDatabase?.Shuttle != null ? MetaData(orderDatabase.Shuttle.Value).EntityName : string.Empty;
-
- if (_uiSystem.HasUi(uid, CargoConsoleUiKey.Shuttle))
- {
- _uiSystem.SetUiState(uid,
- CargoConsoleUiKey.Shuttle,
- new CargoShuttleConsoleBoundUserInterfaceState(
- station != null ? MetaData(station.Value).EntityName : Loc.GetString("cargo-shuttle-console-station-unknown"),
- string.IsNullOrEmpty(shuttleName) ? Loc.GetString("cargo-shuttle-console-shuttle-not-found") : shuttleName,
- orders
- ));
- }
- }
-
#endregion
private void OnTradeSplit(EntityUid uid, TradeStationComponent component, ref GridSplitEvent args)
}
#region Shuttle
-
- /// <summary>
- /// Returns the orders that can fit on the cargo shuttle.
- /// </summary>
- private List<CargoOrderData> GetProjectedOrders(
- EntityUid shuttleUid,
- StationCargoOrderDatabaseComponent? component = null,
- CargoShuttleComponent? shuttle = null)
- {
- var orders = new List<CargoOrderData>();
-
- if (component == null || shuttle == null || component.Orders.Count == 0)
- return orders;
-
- var spaceRemaining = GetCargoSpace(shuttleUid);
- var allOrders = component.AllOrders.ToList();
- for (var i = 0; i < allOrders.Count && spaceRemaining > 0; i++)
- {
- var order = allOrders[i];
- if (order.Approved)
- {
- var numToShip = order.OrderQuantity - order.NumDispatched;
- if (numToShip > spaceRemaining)
- {
- // We won't be able to fit the whole order on, so make one
- // which represents the space we do have left:
- var reducedOrder = new CargoOrderData(
- order.OrderId,
- order.ProductId,
- order.ProductName,
- order.Price,
- spaceRemaining,
- order.Requester,
- order.Reason);
- orders.Add(reducedOrder);
- }
- else
- {
- orders.Add(order);
- }
- spaceRemaining -= numToShip;
- }
- }
-
- return orders;
- }
-
- /// <summary>
- /// Get the amount of space the cargo shuttle can fit for orders.
- /// </summary>
- private int GetCargoSpace(EntityUid gridUid)
- {
- var space = GetCargoPallets(gridUid, BuySellType.Buy).Count;
- return space;
- }
-
/// GetCargoPallets(gridUid, BuySellType.Sell) to return only Sell pads
/// GetCargoPallets(gridUid, BuySellType.Buy) to return only Buy pads
private List<(EntityUid Entity, CargoPalletComponent Component, TransformComponent PalletXform)> GetCargoPallets(EntityUid gridUid, BuySellType requestType = BuySellType.All)
energy: 1.6
color: "#e6e227"
-- type: entity
- id: ComputerCargoShuttle
- parent: BaseComputerAiAccess
- name: cargo shuttle computer
- description: Used to order the shuttle.
- components:
- - type: Sprite
- layers:
- - map: ["computerLayerBody"]
- state: computer
- - map: ["computerLayerKeyboard"]
- state: generic_keyboard
- - map: ["computerLayerScreen"]
- state: supply
- - map: ["computerLayerKeys"]
- state: tech_key
- - map: [ "enum.WiresVisualLayers.MaintenancePanel" ]
- state: generic_panel_open
- - type: CargoShuttleConsole
- - type: ActivatableUI
- key: enum.CargoConsoleUiKey.Shuttle
- - type: UserInterface
- interfaces:
- enum.CargoConsoleUiKey.Shuttle:
- type: CargoShuttleConsoleBoundUserInterface
- enum.WiresUiKey.Key:
- type: WiresBoundUserInterface
- - type: Computer
- board: CargoShuttleComputerCircuitboard
- - type: PointLight
- radius: 1.5
- energy: 1.6
- color: "#b89f25"
- - type: AccessReader
- access: [["Cargo"]]
- - type: GuideHelp
- guides:
- - Cargo
-
- type: entity
id: ComputerCargoOrders
parent: BaseComputerAiAccess