Add trade stations (#23863)
* puters * Start on fulfillment * weh * Smol update * FTL sound fixes or smth iunno * Add consoles * More tweaks * Make it unanchorable * final wehs * weh * Fix 1 test * Shrimply bump the distance * cat
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Content.Shared.Cargo;
|
||||
using Content.Shared.Cargo.Prototypes;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Server.Cargo.Components;
|
||||
@@ -30,4 +31,10 @@ public sealed partial class StationCargoOrderDatabaseComponent : Component
|
||||
/// </summary>
|
||||
[DataField("shuttle")]
|
||||
public EntityUid? Shuttle;
|
||||
|
||||
/// <summary>
|
||||
/// The paper-type prototype to spawn with the order information.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public EntProtoId PrinterOutput = "PaperCargoInvoice";
|
||||
}
|
||||
|
||||
10
Content.Server/Cargo/Components/TradeStationComponent.cs
Normal file
10
Content.Server/Cargo/Components/TradeStationComponent.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Content.Server.Cargo.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Target for approved orders to spawn at.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed partial class TradeStationComponent : Component
|
||||
{
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Server.Cargo.Components;
|
||||
using Content.Server.Labels.Components;
|
||||
using Content.Server.Paper;
|
||||
using Content.Server.Station.Components;
|
||||
using Content.Shared.Cargo;
|
||||
using Content.Shared.Cargo.BUI;
|
||||
using Content.Shared.Cargo.Events;
|
||||
@@ -10,6 +11,7 @@ using Content.Shared.Database;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Cargo.Systems
|
||||
@@ -87,10 +89,12 @@ namespace Content.Server.Cargo.Systems
|
||||
return;
|
||||
}
|
||||
|
||||
var bankAccount = GetBankAccount(uid, component);
|
||||
var station = _station.GetOwningStation(uid);
|
||||
|
||||
// No station to deduct from.
|
||||
if (!TryGetOrderDatabase(uid, out var dbUid, out var orderDatabase, component) || bankAccount == null)
|
||||
if (!TryComp(station, out StationBankAccountComponent? bank) ||
|
||||
!TryComp(station, out StationDataComponent? stationData) ||
|
||||
!TryGetOrderDatabase(station, out var orderDatabase))
|
||||
{
|
||||
ConsolePopup(args.Session, Loc.GetString("cargo-console-station-not-found"));
|
||||
PlayDenySound(uid, component);
|
||||
@@ -136,32 +140,82 @@ namespace Content.Server.Cargo.Systems
|
||||
var cost = order.Price * order.OrderQuantity;
|
||||
|
||||
// Not enough balance
|
||||
if (cost > bankAccount.Balance)
|
||||
if (cost > bank.Balance)
|
||||
{
|
||||
ConsolePopup(args.Session, Loc.GetString("cargo-console-insufficient-funds", ("cost", cost)));
|
||||
PlayDenySound(uid, component);
|
||||
return;
|
||||
}
|
||||
|
||||
// No slots at the trade station
|
||||
_listEnts.Clear();
|
||||
GetTradeStations(stationData, ref _listEnts);
|
||||
EntityUid? tradeDestination = null;
|
||||
|
||||
// Try to fulfill from any station where possible, if the pad is not occupied.
|
||||
foreach (var trade in _listEnts)
|
||||
{
|
||||
var tradePads = GetCargoPallets(trade);
|
||||
_random.Shuffle(tradePads);
|
||||
|
||||
var freePads = GetFreeCargoPallets(trade, tradePads);
|
||||
|
||||
foreach (var pad in freePads)
|
||||
{
|
||||
var coordinates = new EntityCoordinates(trade, pad.Transform.LocalPosition);
|
||||
|
||||
if (FulfillOrder(order, coordinates, orderDatabase.PrinterOutput))
|
||||
{
|
||||
tradeDestination = trade;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (tradeDestination != null)
|
||||
break;
|
||||
}
|
||||
|
||||
if (tradeDestination == null)
|
||||
{
|
||||
ConsolePopup(args.Session, Loc.GetString("cargo-console-unfulfilled"));
|
||||
PlayDenySound(uid, component);
|
||||
return;
|
||||
}
|
||||
|
||||
_idCardSystem.TryFindIdCard(player, out var idCard);
|
||||
// ReSharper disable once ConditionalAccessQualifierIsNonNullableAccordingToAPIContract
|
||||
order.SetApproverData(idCard.Comp?.FullName, idCard.Comp?.JobTitle);
|
||||
_audio.PlayPvs(_audio.GetSound(component.ConfirmSound), uid);
|
||||
_audio.PlayPvs(component.ConfirmSound, uid);
|
||||
|
||||
ConsolePopup(args.Session, Loc.GetString("cargo-console-trade-station", ("destination", MetaData(tradeDestination.Value).EntityName)));
|
||||
|
||||
// Log order approval
|
||||
_adminLogger.Add(LogType.Action, LogImpact.Low,
|
||||
$"{ToPrettyString(player):user} approved order [orderId:{order.OrderId}, quantity:{order.OrderQuantity}, product:{order.ProductId}, requester:{order.Requester}, reason:{order.Reason}] with balance at {bankAccount.Balance}");
|
||||
$"{ToPrettyString(player):user} approved order [orderId:{order.OrderId}, quantity:{order.OrderQuantity}, product:{order.ProductId}, requester:{order.Requester}, reason:{order.Reason}] with balance at {bank.Balance}");
|
||||
|
||||
DeductFunds(bankAccount, cost);
|
||||
UpdateOrders(dbUid!.Value, orderDatabase);
|
||||
DeductFunds(bank, cost);
|
||||
UpdateOrders(station.Value, orderDatabase);
|
||||
}
|
||||
|
||||
private void GetTradeStations(StationDataComponent data, ref List<EntityUid> ents)
|
||||
{
|
||||
foreach (var gridUid in data.Grids)
|
||||
{
|
||||
if (!_tradeQuery.HasComponent(gridUid))
|
||||
continue;
|
||||
|
||||
ents.Add(gridUid);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRemoveOrderMessage(EntityUid uid, CargoOrderConsoleComponent component, CargoConsoleRemoveOrderMessage args)
|
||||
{
|
||||
if (!TryGetOrderDatabase(uid, out var dbUid, out var orderDatabase, component))
|
||||
var station = _station.GetOwningStation(uid);
|
||||
|
||||
if (!TryGetOrderDatabase(station, out var orderDatabase))
|
||||
return;
|
||||
|
||||
RemoveOrder(dbUid!.Value, args.OrderId, orderDatabase);
|
||||
RemoveOrder(station.Value, args.OrderId, orderDatabase);
|
||||
}
|
||||
|
||||
private void OnAddOrderMessage(EntityUid uid, CargoOrderConsoleComponent component, CargoConsoleAddOrderMessage args)
|
||||
@@ -172,11 +226,9 @@ namespace Content.Server.Cargo.Systems
|
||||
if (args.Amount <= 0)
|
||||
return;
|
||||
|
||||
var bank = GetBankAccount(uid, component);
|
||||
if (bank == null)
|
||||
return;
|
||||
var stationUid = _station.GetOwningStation(uid);
|
||||
|
||||
if (!TryGetOrderDatabase(uid, out var dbUid, out var orderDatabase, component))
|
||||
if (!TryGetOrderDatabase(stationUid, out var orderDatabase))
|
||||
return;
|
||||
|
||||
if (!_protoMan.TryIndex<CargoProductPrototype>(args.CargoProductId, out var product))
|
||||
@@ -187,7 +239,7 @@ namespace Content.Server.Cargo.Systems
|
||||
|
||||
var data = GetOrderData(args, product, GenerateOrderId(orderDatabase));
|
||||
|
||||
if (!TryAddOrder(dbUid!.Value, data, orderDatabase))
|
||||
if (!TryAddOrder(stationUid.Value, data, orderDatabase))
|
||||
{
|
||||
PlayDenySound(uid, component);
|
||||
return;
|
||||
@@ -336,10 +388,10 @@ namespace Content.Server.Cargo.Systems
|
||||
|
||||
public void ClearOrders(StationCargoOrderDatabaseComponent component)
|
||||
{
|
||||
if (component.Orders.Count == 0) return;
|
||||
if (component.Orders.Count == 0)
|
||||
return;
|
||||
|
||||
component.Orders.Clear();
|
||||
Dirty(component);
|
||||
}
|
||||
|
||||
private static bool PopFrontOrder(StationCargoOrderDatabaseComponent orderDB, [NotNullWhen(true)] out CargoOrderData? orderOut)
|
||||
@@ -362,64 +414,63 @@ namespace Content.Server.Cargo.Systems
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool FulfillOrder(StationCargoOrderDatabaseComponent orderDB, EntityCoordinates whereToPutIt,
|
||||
string? paperPrototypeToPrint)
|
||||
/// <summary>
|
||||
/// Tries to fulfill the next outstanding order.
|
||||
/// </summary>
|
||||
private bool FulfillNextOrder(StationCargoOrderDatabaseComponent orderDB, EntityCoordinates spawn, string? paperProto)
|
||||
{
|
||||
if (PopFrontOrder(orderDB, out var order))
|
||||
if (!PopFrontOrder(orderDB, out var order))
|
||||
return false;
|
||||
|
||||
return FulfillOrder(order, spawn, paperProto);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fulfills the specified cargo order and spawns paper attached to it.
|
||||
/// </summary>
|
||||
private bool FulfillOrder(CargoOrderData order, EntityCoordinates spawn, string? paperProto)
|
||||
{
|
||||
// Create the item itself
|
||||
var item = Spawn(order.ProductId, spawn);
|
||||
|
||||
// Create a sheet of paper to write the order details on
|
||||
var printed = EntityManager.SpawnEntity(paperProto, spawn);
|
||||
if (TryComp<PaperComponent>(printed, out var paper))
|
||||
{
|
||||
// Create the item itself
|
||||
var item = Spawn(order.ProductId, whereToPutIt);
|
||||
// fill in the order data
|
||||
var val = Loc.GetString("cargo-console-paper-print-name", ("orderNumber", order.OrderId));
|
||||
_metaSystem.SetEntityName(printed, val);
|
||||
|
||||
// Create a sheet of paper to write the order details on
|
||||
var printed = EntityManager.SpawnEntity(paperPrototypeToPrint, whereToPutIt);
|
||||
if (TryComp<PaperComponent>(printed, out var paper))
|
||||
_paperSystem.SetContent(printed, Loc.GetString(
|
||||
"cargo-console-paper-print-text",
|
||||
("orderNumber", order.OrderId),
|
||||
("itemName", MetaData(item).EntityName),
|
||||
("requester", order.Requester),
|
||||
("reason", order.Reason),
|
||||
("approver", order.Approver ?? string.Empty)),
|
||||
paper);
|
||||
|
||||
// attempt to attach the label to the item
|
||||
if (TryComp<PaperLabelComponent>(item, out var label))
|
||||
{
|
||||
// fill in the order data
|
||||
var val = Loc.GetString("cargo-console-paper-print-name", ("orderNumber", order.OrderId));
|
||||
_metaSystem.SetEntityName(printed, val);
|
||||
|
||||
_paperSystem.SetContent(printed, Loc.GetString(
|
||||
"cargo-console-paper-print-text",
|
||||
("orderNumber", order.OrderId),
|
||||
("itemName", MetaData(item).EntityName),
|
||||
("requester", order.Requester),
|
||||
("reason", order.Reason),
|
||||
("approver", order.Approver ?? string.Empty)),
|
||||
paper);
|
||||
|
||||
// attempt to attach the label to the item
|
||||
if (TryComp<PaperLabelComponent>(item, out var label))
|
||||
{
|
||||
_slots.TryInsert(item, label.LabelSlot, printed, null);
|
||||
}
|
||||
_slots.TryInsert(item, label.LabelSlot, printed, null);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
private void DeductFunds(StationBankAccountComponent component, int amount)
|
||||
{
|
||||
component.Balance = Math.Max(0, component.Balance - amount);
|
||||
Dirty(component);
|
||||
}
|
||||
|
||||
#region Station
|
||||
|
||||
private StationBankAccountComponent? GetBankAccount(EntityUid uid, CargoOrderConsoleComponent _)
|
||||
private bool TryGetOrderDatabase([NotNullWhen(true)] EntityUid? stationUid, [MaybeNullWhen(false)] out StationCargoOrderDatabaseComponent dbComp)
|
||||
{
|
||||
var station = _station.GetOwningStation(uid);
|
||||
|
||||
TryComp<StationBankAccountComponent>(station, out var bankComponent);
|
||||
return bankComponent;
|
||||
}
|
||||
|
||||
private bool TryGetOrderDatabase(EntityUid uid, [MaybeNullWhen(false)] out EntityUid? dbUid, [MaybeNullWhen(false)] out StationCargoOrderDatabaseComponent dbComp, CargoOrderConsoleComponent _)
|
||||
{
|
||||
dbUid = _station.GetOwningStation(uid);
|
||||
return TryComp(dbUid, out dbComp);
|
||||
return TryComp(stationUid, out dbComp);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -1,39 +1,27 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Cargo.Components;
|
||||
using Content.Server.GameTicking.Events;
|
||||
using Content.Server.Shuttles.Components;
|
||||
using Content.Server.Shuttles.Events;
|
||||
using Content.Shared.Stacks;
|
||||
using Content.Shared.Cargo;
|
||||
using Content.Shared.Cargo.BUI;
|
||||
using Content.Shared.Cargo.Components;
|
||||
using Content.Shared.Cargo.Events;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.GameTicking;
|
||||
using Content.Shared.Whitelist;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Utility;
|
||||
using Content.Shared.Coordinates;
|
||||
using Content.Shared.Mobs;
|
||||
using Content.Shared.Mobs.Components;
|
||||
using Robust.Shared.Audio;
|
||||
|
||||
namespace Content.Server.Cargo.Systems;
|
||||
|
||||
public sealed partial class CargoSystem
|
||||
{
|
||||
/*
|
||||
* Handles cargo shuttle mechanics.
|
||||
* Handles cargo shuttle / trade mechanics.
|
||||
*/
|
||||
|
||||
public MapId? CargoMap { get; private set; }
|
||||
private static readonly SoundPathSpecifier ApproveSound = new("/Audio/Effects/Cargo/ping.ogg");
|
||||
|
||||
private void InitializeShuttle()
|
||||
{
|
||||
SubscribeLocalEvent<CargoShuttleComponent, FTLStartedEvent>(OnCargoFTLStarted);
|
||||
SubscribeLocalEvent<CargoShuttleComponent, FTLCompletedEvent>(OnCargoFTLCompleted);
|
||||
SubscribeLocalEvent<CargoShuttleComponent, FTLTagEvent>(OnCargoFTLTag);
|
||||
SubscribeLocalEvent<TradeStationComponent, GridSplitEvent>(OnTradeSplit);
|
||||
|
||||
SubscribeLocalEvent<CargoShuttleConsoleComponent, ComponentStartup>(OnCargoShuttleConsoleStartup);
|
||||
|
||||
@@ -42,32 +30,6 @@ public sealed partial class CargoSystem
|
||||
SubscribeLocalEvent<CargoPalletConsoleComponent, BoundUIOpenedEvent>(OnPalletUIOpen);
|
||||
|
||||
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRoundRestart);
|
||||
SubscribeLocalEvent<RoundStartingEvent>(OnRoundStart);
|
||||
|
||||
_cfgManager.OnValueChanged(CCVars.GridFill, SetGridFill);
|
||||
}
|
||||
|
||||
private void ShutdownShuttle()
|
||||
{
|
||||
_cfgManager.UnsubValueChanged(CCVars.GridFill, SetGridFill);
|
||||
}
|
||||
|
||||
private void SetGridFill(bool obj)
|
||||
{
|
||||
if (obj)
|
||||
{
|
||||
SetupCargoShuttle();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCargoFTLTag(EntityUid uid, CargoShuttleComponent component, ref FTLTagEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
// Just saves mappers forgetting.
|
||||
args.Handled = true;
|
||||
args.Tag = "DockCargo";
|
||||
}
|
||||
|
||||
#region Console
|
||||
@@ -156,6 +118,15 @@ public sealed partial class CargoSystem
|
||||
|
||||
#endregion
|
||||
|
||||
private void OnTradeSplit(EntityUid uid, TradeStationComponent component, ref GridSplitEvent args)
|
||||
{
|
||||
// If the trade station gets bombed it's still a trade station.
|
||||
foreach (var gridUid in args.NewGrids)
|
||||
{
|
||||
EnsureComp<TradeStationComponent>(gridUid);
|
||||
}
|
||||
}
|
||||
|
||||
#region Shuttle
|
||||
|
||||
/// <summary>
|
||||
@@ -206,9 +177,9 @@ public sealed partial class CargoSystem
|
||||
return space;
|
||||
}
|
||||
|
||||
private List<(EntityUid Entity, CargoPalletComponent Component)> GetCargoPallets(EntityUid gridUid)
|
||||
private List<(EntityUid Entity, CargoPalletComponent Component, TransformComponent PalletXform)> GetCargoPallets(EntityUid gridUid)
|
||||
{
|
||||
var pads = new List<(EntityUid, CargoPalletComponent)>();
|
||||
_pads.Clear();
|
||||
var query = AllEntityQuery<CargoPalletComponent, TransformComponent>();
|
||||
|
||||
while (query.MoveNext(out var uid, out var comp, out var compXform))
|
||||
@@ -219,23 +190,43 @@ public sealed partial class CargoSystem
|
||||
continue;
|
||||
}
|
||||
|
||||
pads.Add((uid, comp));
|
||||
_pads.Add((uid, comp, compXform));
|
||||
}
|
||||
|
||||
return pads;
|
||||
return _pads;
|
||||
}
|
||||
|
||||
private IEnumerable<(EntityUid Entity, CargoPalletComponent Component, TransformComponent Transform)>
|
||||
GetFreeCargoPallets(EntityUid gridUid,
|
||||
List<(EntityUid Entity, CargoPalletComponent Component, TransformComponent Transform)> pallets)
|
||||
{
|
||||
_setEnts.Clear();
|
||||
|
||||
foreach (var pallet in pallets)
|
||||
{
|
||||
var aabb = _lookup.GetAABBNoContainer(pallet.Entity, pallet.Transform.LocalPosition, pallet.Transform.LocalRotation);
|
||||
|
||||
if (_lookup.AnyLocalEntitiesIntersecting(gridUid, aabb, LookupFlags.Dynamic))
|
||||
continue;
|
||||
|
||||
yield return pallet;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Station
|
||||
|
||||
private void SellPallets(EntityUid gridUid, EntityUid? station, out double amount)
|
||||
private bool SellPallets(EntityUid gridUid, EntityUid? station, out double amount)
|
||||
{
|
||||
station ??= _station.GetOwningStation(gridUid);
|
||||
GetPalletGoods(gridUid, out var toSell, out amount);
|
||||
|
||||
Log.Debug($"Cargo sold {toSell.Count} entities for {amount}");
|
||||
|
||||
if (toSell.Count == 0)
|
||||
return false;
|
||||
|
||||
if (station != null)
|
||||
{
|
||||
var ev = new EntitySoldEvent(station.Value, toSell);
|
||||
@@ -246,6 +237,8 @@ public sealed partial class CargoSystem
|
||||
{
|
||||
Del(ent);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void GetPalletGoods(EntityUid gridUid, out HashSet<EntityUid> toSell, out double amount)
|
||||
@@ -253,10 +246,15 @@ public sealed partial class CargoSystem
|
||||
amount = 0;
|
||||
toSell = new HashSet<EntityUid>();
|
||||
|
||||
foreach (var (palletUid, _) in GetCargoPallets(gridUid))
|
||||
foreach (var (palletUid, _, _) in GetCargoPallets(gridUid))
|
||||
{
|
||||
// Containers should already get the sell price of their children so can skip those.
|
||||
foreach (var ent in _lookup.GetEntitiesIntersecting(palletUid, LookupFlags.Dynamic | LookupFlags.Sundries | LookupFlags.Approximate))
|
||||
_setEnts.Clear();
|
||||
|
||||
_lookup.GetEntitiesIntersecting(palletUid, _setEnts,
|
||||
LookupFlags.Dynamic | LookupFlags.Sundries);
|
||||
|
||||
foreach (var ent in _setEnts)
|
||||
{
|
||||
// Dont sell:
|
||||
// - anything already being sold
|
||||
@@ -304,21 +302,6 @@ public sealed partial class CargoSystem
|
||||
return true;
|
||||
}
|
||||
|
||||
private void AddCargoContents(EntityUid shuttleUid, CargoShuttleComponent shuttle, StationCargoOrderDatabaseComponent orderDatabase)
|
||||
{
|
||||
var xformQuery = GetEntityQuery<TransformComponent>();
|
||||
|
||||
var pads = GetCargoPallets(shuttleUid);
|
||||
while (pads.Count > 0)
|
||||
{
|
||||
var coordinates = new EntityCoordinates(shuttleUid, xformQuery.GetComponent(_random.PickAndTake(pads).Entity).LocalPosition);
|
||||
if (!FulfillOrder(orderDatabase, coordinates, shuttle.PrinterOutput))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPalletSale(EntityUid uid, CargoPalletConsoleComponent component, CargoPalletSellMessage args)
|
||||
{
|
||||
var player = args.Session.AttachedEntity;
|
||||
@@ -327,114 +310,29 @@ public sealed partial class CargoSystem
|
||||
return;
|
||||
|
||||
var bui = _uiSystem.GetUi(uid, CargoPalletConsoleUiKey.Sale);
|
||||
if (Transform(uid).GridUid is not EntityUid gridUid)
|
||||
var xform = Transform(uid);
|
||||
|
||||
if (xform.GridUid is not EntityUid gridUid)
|
||||
{
|
||||
_uiSystem.SetUiState(bui,
|
||||
new CargoPalletConsoleInterfaceState(0, 0, false));
|
||||
return;
|
||||
}
|
||||
|
||||
SellPallets(gridUid, null, out var price);
|
||||
if (!SellPallets(gridUid, null, out var price))
|
||||
return;
|
||||
|
||||
var stackPrototype = _protoMan.Index<StackPrototype>(component.CashType);
|
||||
_stack.Spawn((int) price, stackPrototype, uid.ToCoordinates());
|
||||
_stack.Spawn((int) price, stackPrototype, xform.Coordinates);
|
||||
_audio.PlayPvs(ApproveSound, uid);
|
||||
UpdatePalletConsoleInterface(uid);
|
||||
}
|
||||
|
||||
private void OnCargoFTLStarted(EntityUid uid, CargoShuttleComponent component, ref FTLStartedEvent args)
|
||||
{
|
||||
var stationUid = _station.GetOwningStation(uid);
|
||||
|
||||
// Called
|
||||
if (CargoMap == null ||
|
||||
args.FromMapUid != _mapManager.GetMapEntityId(CargoMap.Value) ||
|
||||
!TryComp<StationCargoOrderDatabaseComponent>(stationUid, out var orderDatabase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
AddCargoContents(uid, component, orderDatabase);
|
||||
UpdateOrders(stationUid!.Value, orderDatabase);
|
||||
UpdateCargoShuttleConsoles(uid, component);
|
||||
}
|
||||
|
||||
private void OnCargoFTLCompleted(EntityUid uid, CargoShuttleComponent component, ref FTLCompletedEvent args)
|
||||
{
|
||||
var xform = Transform(uid);
|
||||
// Recalled
|
||||
if (xform.MapID != CargoMap)
|
||||
return;
|
||||
|
||||
var stationUid = _station.GetOwningStation(uid);
|
||||
|
||||
if (TryComp<StationBankAccountComponent>(stationUid, out var bank))
|
||||
{
|
||||
SellPallets(uid, stationUid, out var amount);
|
||||
bank.Balance += (int) amount;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void OnRoundRestart(RoundRestartCleanupEvent ev)
|
||||
{
|
||||
Reset();
|
||||
CleanupCargoShuttle();
|
||||
}
|
||||
|
||||
private void OnRoundStart(RoundStartingEvent ev)
|
||||
{
|
||||
if (_cfgManager.GetCVar(CCVars.GridFill))
|
||||
SetupCargoShuttle();
|
||||
}
|
||||
|
||||
private void CleanupCargoShuttle()
|
||||
{
|
||||
if (CargoMap == null || !_mapManager.MapExists(CargoMap.Value))
|
||||
{
|
||||
CargoMap = null;
|
||||
DebugTools.Assert(!EntityQuery<CargoShuttleComponent>().Any());
|
||||
return;
|
||||
}
|
||||
|
||||
_mapManager.DeleteMap(CargoMap.Value);
|
||||
CargoMap = null;
|
||||
|
||||
// Shuttle may not have been in the cargo dimension (e.g. on the station map) so need to delete.
|
||||
var query = AllEntityQuery<CargoShuttleComponent>();
|
||||
|
||||
while (query.MoveNext(out var uid, out var _))
|
||||
{
|
||||
if (TryComp<StationCargoOrderDatabaseComponent>(uid, out var station))
|
||||
{
|
||||
station.Shuttle = null;
|
||||
}
|
||||
|
||||
QueueDel(uid);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupCargoShuttle()
|
||||
{
|
||||
if (CargoMap != null && _mapManager.MapExists(CargoMap.Value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// It gets mapinit which is okay... buuutt we still want it paused to avoid power draining.
|
||||
CargoMap = _mapManager.CreateMap();
|
||||
var mapUid = _mapManager.GetMapEntityId(CargoMap.Value);
|
||||
var ftl = EnsureComp<FTLDestinationComponent>(_mapManager.GetMapEntityId(CargoMap.Value));
|
||||
ftl.Whitelist = new EntityWhitelist()
|
||||
{
|
||||
Components = new[]
|
||||
{
|
||||
_factory.GetComponentName(typeof(CargoShuttleComponent))
|
||||
}
|
||||
};
|
||||
|
||||
_metaSystem.SetEntityName(mapUid, $"Trading post {_random.Next(1000):000}");
|
||||
|
||||
_console.RefreshShuttleConsoles();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,10 +65,10 @@ public sealed partial class CargoSystem
|
||||
}
|
||||
|
||||
var xform = Transform(uid);
|
||||
if (FulfillOrder(orderDatabase, xform.Coordinates, comp.PrinterOutput))
|
||||
if (FulfillNextOrder(orderDatabase, xform.Coordinates, comp.PrinterOutput))
|
||||
{
|
||||
_audio.PlayPvs(_audio.GetSound(comp.TeleportSound), uid, AudioParams.Default.WithVolume(-8f));
|
||||
UpdateOrders(station!.Value, orderDatabase);
|
||||
UpdateOrders(station.Value, orderDatabase);
|
||||
|
||||
comp.CurrentState = CargoTelepadState.Teleporting;
|
||||
_appearance.SetData(uid, CargoTelepadVisuals.State, CargoTelepadState.Teleporting, appearance);
|
||||
|
||||
@@ -14,8 +14,6 @@ using Content.Shared.Mobs.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Random;
|
||||
@@ -25,9 +23,6 @@ namespace Content.Server.Cargo.Systems;
|
||||
public sealed partial class CargoSystem : SharedCargoSystem
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly IComponentFactory _factory = default!;
|
||||
[Dependency] private readonly IConfigurationManager _cfgManager = default!;
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly IPrototypeManager _protoMan = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
|
||||
@@ -41,6 +36,7 @@ public sealed partial class CargoSystem : SharedCargoSystem
|
||||
[Dependency] private readonly PricingSystem _pricing = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _xformSystem = default!;
|
||||
[Dependency] private readonly ShuttleConsoleSystem _console = default!;
|
||||
[Dependency] private readonly StackSystem _stack = default!;
|
||||
[Dependency] private readonly StationSystem _station = default!;
|
||||
@@ -50,6 +46,11 @@ public sealed partial class CargoSystem : SharedCargoSystem
|
||||
private EntityQuery<TransformComponent> _xformQuery;
|
||||
private EntityQuery<CargoSellBlacklistComponent> _blacklistQuery;
|
||||
private EntityQuery<MobStateComponent> _mobQuery;
|
||||
private EntityQuery<TradeStationComponent> _tradeQuery;
|
||||
|
||||
private HashSet<EntityUid> _setEnts = new();
|
||||
private List<EntityUid> _listEnts = new();
|
||||
private List<(EntityUid, CargoPalletComponent, TransformComponent)> _pads = new();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -58,6 +59,7 @@ public sealed partial class CargoSystem : SharedCargoSystem
|
||||
_xformQuery = GetEntityQuery<TransformComponent>();
|
||||
_blacklistQuery = GetEntityQuery<CargoSellBlacklistComponent>();
|
||||
_mobQuery = GetEntityQuery<MobStateComponent>();
|
||||
_tradeQuery = GetEntityQuery<TradeStationComponent>();
|
||||
|
||||
InitializeConsole();
|
||||
InitializeShuttle();
|
||||
@@ -65,13 +67,6 @@ public sealed partial class CargoSystem : SharedCargoSystem
|
||||
InitializeBounty();
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
base.Shutdown();
|
||||
ShutdownShuttle();
|
||||
CleanupCargoShuttle();
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
Reference in New Issue
Block a user