* Fix TransformComponent.MapPosition warnings in Content.Client * Fix TransformComponent.MapPosition warnings in Content.IntegrationTests * Fix TransformComponent.MapPosition warnings in Content.Shared * Fix TransformComponent.MapPosition warnings in Content.Server * Fix TransformComponent.WorldPosition warnings in Content.Shared * Fix TransformComponent.WorldPosition warnings in Content.Client Excepts ClickableComponent b/c that needs to be ECS'd entirely later * Fix TransformComponent.WorldPosition warnings in Content.Server * Fix TransformComponent.WorldRotation warnings in Content.* * Fix TransformComponent.MapPosition warnings I missed * Fix TransformComponent.WorldMatrix warnings in Content.* * Fix TransformComponent.InvWorldMatrix warnings in Content.* * Fix TransformComponent.GetWorldPositionRotationMatrixWithInv warnings in Content.* * Fix TransformComponent.GetWorldPositionRotationMatrix warnings in Content.* * Fix TransformComponent.GetWorldPositionRotation warnings in Content.* * Fix TransformComponent.Anchored.set warnings in Content.* * Fix TransformComponent.Coordinates.set warnings in Content.* * Fix TransformComponent.LocalPosition.set warnings in Content.* * Fix TransformComponent.AttachToGridOrMap warnings in Content.* * Fix TransformComponent.AttachParent warnings in Content.* * Preempt TransformComponent.LocalRotation.set warnings in Content.Shared * Preempt TransformComponent.LocalRotation.set warnings in Content.Client * Preempt TransformComponent.LocalRotation.set warnings in Content.IntegrationTests * Preempt TransformComponent.LocalRotation.set warnings in Content.Server * Fix/Preempt the remaining obsolete TransformComponent properties/methods in Content.* * ECS ClickableComponent * Fix obsolete SharedTransformSystem methods in Content.* * Fix ExplosionOverlay `SharedTransformSystem` dependency * Maybe fix null eye position breaking tests * MGS requested changes
97 lines
3.8 KiB
C#
97 lines
3.8 KiB
C#
using Content.Server.Storage.Components;
|
|
using Content.Shared.Inventory;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Physics.Components;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Shared.Storage.EntitySystems;
|
|
|
|
/// <summary>
|
|
/// <see cref="MagnetPickupComponent"/>
|
|
/// </summary>
|
|
public sealed class MagnetPickupSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IGameTiming _timing = default!;
|
|
[Dependency] private readonly EntityLookupSystem _lookup = default!;
|
|
[Dependency] private readonly InventorySystem _inventory = default!;
|
|
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
|
[Dependency] private readonly SharedStorageSystem _storage = default!;
|
|
|
|
private static readonly TimeSpan ScanDelay = TimeSpan.FromSeconds(1);
|
|
|
|
private EntityQuery<PhysicsComponent> _physicsQuery;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
_physicsQuery = GetEntityQuery<PhysicsComponent>();
|
|
SubscribeLocalEvent<MagnetPickupComponent, MapInitEvent>(OnMagnetMapInit);
|
|
}
|
|
|
|
private void OnMagnetMapInit(EntityUid uid, MagnetPickupComponent component, MapInitEvent args)
|
|
{
|
|
component.NextScan = _timing.CurTime;
|
|
}
|
|
|
|
public override void Update(float frameTime)
|
|
{
|
|
base.Update(frameTime);
|
|
var query = EntityQueryEnumerator<MagnetPickupComponent, StorageComponent, TransformComponent, MetaDataComponent>();
|
|
var currentTime = _timing.CurTime;
|
|
|
|
while (query.MoveNext(out var uid, out var comp, out var storage, out var xform, out var meta))
|
|
{
|
|
if (comp.NextScan > currentTime)
|
|
continue;
|
|
|
|
comp.NextScan += ScanDelay;
|
|
|
|
if (!_inventory.TryGetContainingSlot((uid, xform, meta), out var slotDef))
|
|
continue;
|
|
|
|
if ((slotDef.SlotFlags & comp.SlotFlags) == 0x0)
|
|
continue;
|
|
|
|
// No space
|
|
if (!_storage.HasSpace((uid, storage)))
|
|
continue;
|
|
|
|
var parentUid = xform.ParentUid;
|
|
var playedSound = false;
|
|
var finalCoords = xform.Coordinates;
|
|
var moverCoords = _transform.GetMoverCoordinates(uid, xform);
|
|
|
|
foreach (var near in _lookup.GetEntitiesInRange(uid, comp.Range, LookupFlags.Dynamic | LookupFlags.Sundries))
|
|
{
|
|
if (storage.Whitelist?.IsValid(near, EntityManager) == false)
|
|
continue;
|
|
|
|
if (!_physicsQuery.TryGetComponent(near, out var physics) || physics.BodyStatus != BodyStatus.OnGround)
|
|
continue;
|
|
|
|
if (near == parentUid)
|
|
continue;
|
|
|
|
// TODO: Probably move this to storage somewhere when it gets cleaned up
|
|
// TODO: This sucks but you need to fix a lot of stuff to make it better
|
|
// the problem is that stack pickups delete the original entity, which is fine, but due to
|
|
// game state handling we can't show a lerp animation for it.
|
|
var nearXform = Transform(near);
|
|
var nearMap = _transform.GetMapCoordinates(nearXform);
|
|
var nearCoords = EntityCoordinates.FromMap(moverCoords.EntityId, nearMap, _transform, EntityManager);
|
|
|
|
if (!_storage.Insert(uid, near, out var stacked, storageComp: storage, playSound: !playedSound))
|
|
continue;
|
|
|
|
// Play pickup animation for either the stack entity or the original entity.
|
|
if (stacked != null)
|
|
_storage.PlayPickupAnimation(stacked.Value, nearCoords, finalCoords, nearXform.LocalRotation);
|
|
else
|
|
_storage.PlayPickupAnimation(near, nearCoords, finalCoords, nearXform.LocalRotation);
|
|
|
|
playedSound = true;
|
|
}
|
|
}
|
|
}
|
|
}
|