Don't sell non-dead mobs on cargo (#15228)
This commit is contained in:
@@ -281,7 +281,7 @@ namespace Content.Server.Cargo.Systems
|
|||||||
if (station != component.Owner)
|
if (station != component.Owner)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
UpdateShuttleState(uid, comp, station);
|
UpdateShuttleState(uid, station);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Content.Server.Cargo.Components;
|
using Content.Server.Cargo.Components;
|
||||||
using Content.Server.Labels.Components;
|
|
||||||
using Content.Server.Shuttles.Components;
|
using Content.Server.Shuttles.Components;
|
||||||
using Content.Server.Shuttles.Events;
|
using Content.Server.Shuttles.Events;
|
||||||
using Content.Server.UserInterface;
|
using Content.Server.UserInterface;
|
||||||
using Content.Server.Paper;
|
|
||||||
using Content.Server.Shuttles.Systems;
|
using Content.Server.Shuttles.Systems;
|
||||||
using Content.Server.Station.Components;
|
|
||||||
using Content.Server.Stack;
|
using Content.Server.Stack;
|
||||||
using Content.Shared.Stacks;
|
using Content.Shared.Stacks;
|
||||||
using Content.Shared.Cargo;
|
using Content.Shared.Cargo;
|
||||||
@@ -25,8 +22,8 @@ using Robust.Shared.Random;
|
|||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using Content.Shared.Coordinates;
|
using Content.Shared.Coordinates;
|
||||||
|
using Content.Shared.Mobs;
|
||||||
using Content.Shared.Mobs.Components;
|
using Content.Shared.Mobs.Components;
|
||||||
using Robust.Shared.Map.Components;
|
|
||||||
|
|
||||||
namespace Content.Server.Cargo.Systems;
|
namespace Content.Server.Cargo.Systems;
|
||||||
|
|
||||||
@@ -44,8 +41,8 @@ public sealed partial class CargoSystem
|
|||||||
[Dependency] private readonly EntityLookupSystem _lookup = default!;
|
[Dependency] private readonly EntityLookupSystem _lookup = default!;
|
||||||
[Dependency] private readonly MapLoaderSystem _map = default!;
|
[Dependency] private readonly MapLoaderSystem _map = default!;
|
||||||
[Dependency] private readonly PricingSystem _pricing = default!;
|
[Dependency] private readonly PricingSystem _pricing = default!;
|
||||||
|
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||||
[Dependency] private readonly ShuttleConsoleSystem _console = default!;
|
[Dependency] private readonly ShuttleConsoleSystem _console = default!;
|
||||||
[Dependency] private readonly ShuttleSystem _shuttle = default!;
|
|
||||||
[Dependency] private readonly StackSystem _stack = default!;
|
[Dependency] private readonly StackSystem _stack = default!;
|
||||||
public MapId? CargoMap { get; private set; }
|
public MapId? CargoMap { get; private set; }
|
||||||
|
|
||||||
@@ -107,9 +104,11 @@ public sealed partial class CargoSystem
|
|||||||
{
|
{
|
||||||
Setup();
|
Setup();
|
||||||
|
|
||||||
foreach (var station in EntityQuery<StationCargoOrderDatabaseComponent>(true))
|
var query = AllEntityQuery<StationCargoOrderDatabaseComponent>();
|
||||||
|
|
||||||
|
while (query.MoveNext(out var stationUid, out var station))
|
||||||
{
|
{
|
||||||
AddShuttle(station);
|
AddShuttle(stationUid, station);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -175,13 +174,13 @@ public sealed partial class CargoSystem
|
|||||||
if (stationUid != component.Station)
|
if (stationUid != component.Station)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
UpdateShuttleState(uid, console, stationUid);
|
UpdateShuttleState(uid, stationUid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdatePalletConsoleInterface(EntityUid uid, CargoPalletConsoleComponent component)
|
private void UpdatePalletConsoleInterface(EntityUid uid)
|
||||||
{
|
{
|
||||||
var bui = _uiSystem.GetUi(component.Owner, CargoPalletConsoleUiKey.Sale);
|
var bui = _uiSystem.GetUi(uid, CargoPalletConsoleUiKey.Sale);
|
||||||
if (Transform(uid).GridUid is not EntityUid gridUid)
|
if (Transform(uid).GridUid is not EntityUid gridUid)
|
||||||
{
|
{
|
||||||
_uiSystem.SetUiState(bui,
|
_uiSystem.SetUiState(bui,
|
||||||
@@ -200,7 +199,7 @@ public sealed partial class CargoSystem
|
|||||||
if (player == null)
|
if (player == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
UpdatePalletConsoleInterface(uid, component);
|
UpdatePalletConsoleInterface(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -218,21 +217,21 @@ public sealed partial class CargoSystem
|
|||||||
if (player == null)
|
if (player == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
UpdatePalletConsoleInterface(uid, component);
|
UpdatePalletConsoleInterface(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnCargoShuttleConsoleStartup(EntityUid uid, CargoShuttleConsoleComponent component, ComponentStartup args)
|
private void OnCargoShuttleConsoleStartup(EntityUid uid, CargoShuttleConsoleComponent component, ComponentStartup args)
|
||||||
{
|
{
|
||||||
var station = _station.GetOwningStation(uid);
|
var station = _station.GetOwningStation(uid);
|
||||||
UpdateShuttleState(uid, component, station);
|
UpdateShuttleState(uid, station);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateShuttleState(EntityUid uid, CargoShuttleConsoleComponent component, EntityUid? station = null)
|
private void UpdateShuttleState(EntityUid uid, EntityUid? station = null)
|
||||||
{
|
{
|
||||||
TryComp<StationCargoOrderDatabaseComponent>(station, out var orderDatabase);
|
TryComp<StationCargoOrderDatabaseComponent>(station, out var orderDatabase);
|
||||||
TryComp<CargoShuttleComponent>(orderDatabase?.Shuttle, out var shuttle);
|
TryComp<CargoShuttleComponent>(orderDatabase?.Shuttle, out var shuttle);
|
||||||
|
|
||||||
var orders = GetProjectedOrders(orderDatabase, shuttle);
|
var orders = GetProjectedOrders(station ?? EntityUid.Invalid, orderDatabase, shuttle);
|
||||||
var shuttleName = orderDatabase?.Shuttle != null ? MetaData(orderDatabase.Shuttle.Value).EntityName : string.Empty;
|
var shuttleName = orderDatabase?.Shuttle != null ? MetaData(orderDatabase.Shuttle.Value).EntityName : string.Empty;
|
||||||
|
|
||||||
_uiSystem.GetUiOrNull(uid, CargoConsoleUiKey.Shuttle)?.SetState(
|
_uiSystem.GetUiOrNull(uid, CargoConsoleUiKey.Shuttle)?.SetState(
|
||||||
@@ -265,6 +264,7 @@ public sealed partial class CargoSystem
|
|||||||
/// Returns the orders that can fit on the cargo shuttle.
|
/// Returns the orders that can fit on the cargo shuttle.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private List<CargoOrderData> GetProjectedOrders(
|
private List<CargoOrderData> GetProjectedOrders(
|
||||||
|
EntityUid shuttleUid,
|
||||||
StationCargoOrderDatabaseComponent? component = null,
|
StationCargoOrderDatabaseComponent? component = null,
|
||||||
CargoShuttleComponent? shuttle = null)
|
CargoShuttleComponent? shuttle = null)
|
||||||
{
|
{
|
||||||
@@ -273,7 +273,7 @@ public sealed partial class CargoSystem
|
|||||||
if (component == null || shuttle == null || component.Orders.Count == 0)
|
if (component == null || shuttle == null || component.Orders.Count == 0)
|
||||||
return orders;
|
return orders;
|
||||||
|
|
||||||
var spaceRemaining = GetCargoSpace(shuttle.Owner);
|
var spaceRemaining = GetCargoSpace(shuttleUid);
|
||||||
for( var i = 0; i < component.Orders.Count && spaceRemaining > 0; i++)
|
for( var i = 0; i < component.Orders.Count && spaceRemaining > 0; i++)
|
||||||
{
|
{
|
||||||
var order = component.Orders[i];
|
var order = component.Orders[i];
|
||||||
@@ -308,16 +308,20 @@ public sealed partial class CargoSystem
|
|||||||
return space;
|
return space;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<CargoPalletComponent> GetCargoPallets(EntityUid gridUid)
|
private List<(EntityUid Entity, CargoPalletComponent Component)> GetCargoPallets(EntityUid gridUid)
|
||||||
{
|
{
|
||||||
var pads = new List<CargoPalletComponent>();
|
var pads = new List<(EntityUid, CargoPalletComponent)>();
|
||||||
|
var query = AllEntityQuery<CargoPalletComponent, TransformComponent>();
|
||||||
|
|
||||||
foreach (var (comp, compXform) in EntityQuery<CargoPalletComponent, TransformComponent>(true))
|
while (query.MoveNext(out var uid, out var comp, out var compXform))
|
||||||
{
|
{
|
||||||
if (compXform.ParentUid != gridUid ||
|
if (compXform.ParentUid != gridUid ||
|
||||||
!compXform.Anchored) continue;
|
!compXform.Anchored)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
pads.Add(comp);
|
pads.Add((uid, comp));
|
||||||
}
|
}
|
||||||
|
|
||||||
return pads;
|
return pads;
|
||||||
@@ -333,10 +337,10 @@ public sealed partial class CargoSystem
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Stations get created first but if any are added at runtime then do this.
|
// Stations get created first but if any are added at runtime then do this.
|
||||||
AddShuttle(component);
|
AddShuttle(uid, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddShuttle(StationCargoOrderDatabaseComponent component)
|
private void AddShuttle(EntityUid stationUid, StationCargoOrderDatabaseComponent component)
|
||||||
{
|
{
|
||||||
Setup();
|
Setup();
|
||||||
|
|
||||||
@@ -361,9 +365,9 @@ public sealed partial class CargoSystem
|
|||||||
MetaData(shuttleUid).EntityName = name;
|
MetaData(shuttleUid).EntityName = name;
|
||||||
|
|
||||||
// TODO: Something better like a bounds check.
|
// TODO: Something better like a bounds check.
|
||||||
xform.LocalPosition += 100 * _index;
|
_transform.SetLocalPosition(xform, xform.LocalPosition + 100 * _index);
|
||||||
var comp = EnsureComp<CargoShuttleComponent>(shuttleUid);
|
var comp = EnsureComp<CargoShuttleComponent>(shuttleUid);
|
||||||
comp.Station = component.Owner;
|
comp.Station = stationUid;
|
||||||
|
|
||||||
component.Shuttle = shuttleUid;
|
component.Shuttle = shuttleUid;
|
||||||
UpdateCargoShuttleConsoles(comp);
|
UpdateCargoShuttleConsoles(comp);
|
||||||
@@ -388,19 +392,24 @@ public sealed partial class CargoSystem
|
|||||||
amount = 0;
|
amount = 0;
|
||||||
var xformQuery = GetEntityQuery<TransformComponent>();
|
var xformQuery = GetEntityQuery<TransformComponent>();
|
||||||
var blacklistQuery = GetEntityQuery<CargoSellBlacklistComponent>();
|
var blacklistQuery = GetEntityQuery<CargoSellBlacklistComponent>();
|
||||||
|
var mobStateQuery = GetEntityQuery<MobStateComponent>();
|
||||||
toSell = new HashSet<EntityUid>();
|
toSell = new HashSet<EntityUid>();
|
||||||
foreach (var pallet in GetCargoPallets(gridUid))
|
|
||||||
|
foreach (var (palletUid, _) in GetCargoPallets(gridUid))
|
||||||
{
|
{
|
||||||
// Containers should already get the sell price of their children so can skip those.
|
// Containers should already get the sell price of their children so can skip those.
|
||||||
foreach (var ent in _lookup.GetEntitiesIntersecting(pallet.Owner, LookupFlags.Dynamic | LookupFlags.Sundries | LookupFlags.Approximate))
|
foreach (var ent in _lookup.GetEntitiesIntersecting(palletUid, LookupFlags.Dynamic | LookupFlags.Sundries | LookupFlags.Approximate))
|
||||||
{
|
{
|
||||||
// Dont sell:
|
// Dont sell:
|
||||||
// - anything already being sold
|
// - anything already being sold
|
||||||
// - anything anchored (e.g. light fixtures)
|
// - anything anchored (e.g. light fixtures)
|
||||||
// - anything blacklisted (e.g. players).
|
// - anything blacklisted (e.g. players).
|
||||||
if (toSell.Contains(ent) ||
|
if (toSell.Contains(ent) ||
|
||||||
(xformQuery.TryGetComponent(ent, out var xform) && xform.Anchored))
|
(xformQuery.TryGetComponent(ent, out var xform) && xform.Anchored) ||
|
||||||
|
!CanSell(ent, mobStateQuery))
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (blacklistQuery.HasComponent(ent))
|
if (blacklistQuery.HasComponent(ent))
|
||||||
continue;
|
continue;
|
||||||
@@ -414,14 +423,25 @@ public sealed partial class CargoSystem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddCargoContents(CargoShuttleComponent shuttle, StationCargoOrderDatabaseComponent orderDatabase)
|
private bool CanSell(EntityUid uid, EntityQuery<MobStateComponent> mobStateQuery)
|
||||||
|
{
|
||||||
|
if (mobStateQuery.TryGetComponent(uid, out var mobState) &&
|
||||||
|
mobState.CurrentState != MobState.Dead)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddCargoContents(EntityUid shuttleUid, CargoShuttleComponent shuttle, StationCargoOrderDatabaseComponent orderDatabase)
|
||||||
{
|
{
|
||||||
var xformQuery = GetEntityQuery<TransformComponent>();
|
var xformQuery = GetEntityQuery<TransformComponent>();
|
||||||
|
|
||||||
var pads = GetCargoPallets(shuttle.Owner);
|
var pads = GetCargoPallets(shuttleUid);
|
||||||
while (pads.Count > 0)
|
while (pads.Count > 0)
|
||||||
{
|
{
|
||||||
var coordinates = new EntityCoordinates(shuttle.Owner, xformQuery.GetComponent(_random.PickAndTake(pads).Owner).LocalPosition);
|
var coordinates = new EntityCoordinates(shuttleUid, xformQuery.GetComponent(_random.PickAndTake(pads).Entity).LocalPosition);
|
||||||
if(!FulfillOrder(orderDatabase, coordinates, shuttle.PrinterOutput))
|
if(!FulfillOrder(orderDatabase, coordinates, shuttle.PrinterOutput))
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
@@ -436,7 +456,7 @@ public sealed partial class CargoSystem
|
|||||||
if (player == null)
|
if (player == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var bui = _uiSystem.GetUi(component.Owner, CargoPalletConsoleUiKey.Sale);
|
var bui = _uiSystem.GetUi(uid, CargoPalletConsoleUiKey.Sale);
|
||||||
if (Transform(uid).GridUid is not EntityUid gridUid)
|
if (Transform(uid).GridUid is not EntityUid gridUid)
|
||||||
{
|
{
|
||||||
_uiSystem.SetUiState(bui,
|
_uiSystem.SetUiState(bui,
|
||||||
@@ -447,7 +467,7 @@ public sealed partial class CargoSystem
|
|||||||
SellPallets(gridUid, out var price);
|
SellPallets(gridUid, out var price);
|
||||||
var stackPrototype = _prototypeManager.Index<StackPrototype>(component.CashType);
|
var stackPrototype = _prototypeManager.Index<StackPrototype>(component.CashType);
|
||||||
_stack.Spawn((int)price, stackPrototype, uid.ToCoordinates());
|
_stack.Spawn((int)price, stackPrototype, uid.ToCoordinates());
|
||||||
UpdatePalletConsoleInterface(uid, component);
|
UpdatePalletConsoleInterface(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnCargoFTLStarted(EntityUid uid, CargoShuttleComponent component, ref FTLStartedEvent args)
|
private void OnCargoFTLStarted(EntityUid uid, CargoShuttleComponent component, ref FTLStartedEvent args)
|
||||||
@@ -462,7 +482,7 @@ public sealed partial class CargoSystem
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
AddCargoContents(component, orderDatabase);
|
AddCargoContents(uid, component, orderDatabase);
|
||||||
UpdateOrders(orderDatabase);
|
UpdateOrders(orderDatabase);
|
||||||
UpdateCargoShuttleConsoles(component);
|
UpdateCargoShuttleConsoles(component);
|
||||||
}
|
}
|
||||||
@@ -536,9 +556,11 @@ public sealed partial class CargoSystem
|
|||||||
|
|
||||||
MetaData(mapUid).EntityName = $"Trading post {_random.Next(1000):000}";
|
MetaData(mapUid).EntityName = $"Trading post {_random.Next(1000):000}";
|
||||||
|
|
||||||
foreach (var comp in EntityQuery<StationCargoOrderDatabaseComponent>(true))
|
var query = AllEntityQuery<StationCargoOrderDatabaseComponent>();
|
||||||
|
|
||||||
|
while (query.MoveNext(out var uid, out var comp))
|
||||||
{
|
{
|
||||||
AddShuttle(comp);
|
AddShuttle(uid, comp);
|
||||||
}
|
}
|
||||||
|
|
||||||
_console.RefreshShuttleConsoles();
|
_console.RefreshShuttleConsoles();
|
||||||
|
|||||||
Reference in New Issue
Block a user