From 21caf4dea39a3d846955d46d894cbb0d8b26ea26 Mon Sep 17 00:00:00 2001 From: crystalHex Date: Sat, 9 Dec 2023 18:50:17 +0100 Subject: [PATCH] Ore bag and box now use same component --- .../ContainerMagnetPickupComponent.cs | 28 ----- .../Components/MagnetPickupComponent.cs | 24 +++- .../ContainerMagnetPickupSystem.cs | 106 ------------------ .../EntitySystems/MagnetPickupSystem.cs | 13 ++- .../Entities/Structures/Storage/ore_box.yml | 3 +- 5 files changed, 33 insertions(+), 141 deletions(-) delete mode 100644 Content.Shared/Storage/Components/ContainerMagnetPickupComponent.cs delete mode 100644 Content.Shared/Storage/EntitySystems/ContainerMagnetPickupSystem.cs diff --git a/Content.Shared/Storage/Components/ContainerMagnetPickupComponent.cs b/Content.Shared/Storage/Components/ContainerMagnetPickupComponent.cs deleted file mode 100644 index f240d276328..00000000000 --- a/Content.Shared/Storage/Components/ContainerMagnetPickupComponent.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Content.Shared.Inventory; - -namespace Content.Server.Storage.Components; - -/// -/// Applies an ongoing pickup area around the attached entity. -/// -[RegisterComponent] -public sealed partial class ContainerMagnetPickupComponent : Component -{ - [ViewVariables(VVAccess.ReadWrite), DataField("nextScan")] - public TimeSpan NextScan = TimeSpan.Zero; - - /// - /// Is magnet active, when container is anchored? - /// - [ViewVariables(VVAccess.ReadWrite), DataField("pickupWhenAnchored")] - public bool PickupWhenAnchored = true; - - /// - /// Is magnet active, when container is not anchored? - /// - [ViewVariables(VVAccess.ReadWrite), DataField("pickupWhenNotAnchored")] - public bool PickupWhenNotAnchored = true; - - [ViewVariables(VVAccess.ReadWrite), DataField("range")] - public float Range = 1f; -} diff --git a/Content.Shared/Storage/Components/MagnetPickupComponent.cs b/Content.Shared/Storage/Components/MagnetPickupComponent.cs index c57b7c4e85a..68d3029be82 100644 --- a/Content.Shared/Storage/Components/MagnetPickupComponent.cs +++ b/Content.Shared/Storage/Components/MagnetPickupComponent.cs @@ -11,12 +11,30 @@ public sealed partial class MagnetPickupComponent : Component [ViewVariables(VVAccess.ReadWrite), DataField("nextScan")] public TimeSpan NextScan = TimeSpan.Zero; + [ViewVariables(VVAccess.ReadWrite), DataField("range")] + public float Range = 1f; + /// - /// What container slot the magnet needs to be in to work. + /// Whether the magnet is attached to a fixture (e.g. ore box) or not (e.g. ore bag) + /// + [ViewVariables(VVAccess.ReadWrite), DataField("isFixture")] + public bool IsFixture = false; + + /// + /// What container slot the magnet needs to be in to work (if not a fixture) /// [ViewVariables(VVAccess.ReadWrite), DataField("slotFlags")] public SlotFlags SlotFlags = SlotFlags.BELT; - [ViewVariables(VVAccess.ReadWrite), DataField("range")] - public float Range = 1f; + /// + /// Is magnet active, when fixture is anchored? + /// + [ViewVariables(VVAccess.ReadWrite), DataField("pickupWhenAnchored")] + public bool PickupWhenAnchored = true; + + /// + /// Is magnet active, when fixture is not anchored? + /// + [ViewVariables(VVAccess.ReadWrite), DataField("pickupWhenNotAnchored")] + public bool PickupWhenNotAnchored = true; } diff --git a/Content.Shared/Storage/EntitySystems/ContainerMagnetPickupSystem.cs b/Content.Shared/Storage/EntitySystems/ContainerMagnetPickupSystem.cs deleted file mode 100644 index 24c758f2647..00000000000 --- a/Content.Shared/Storage/EntitySystems/ContainerMagnetPickupSystem.cs +++ /dev/null @@ -1,106 +0,0 @@ -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; - -/// -/// -/// -public sealed class ContainerMagnetPickupSystem : 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 _physicsQuery; - - public override void Initialize() - { - base.Initialize(); - _physicsQuery = GetEntityQuery(); - SubscribeLocalEvent(OnMagnetMapInit); - SubscribeLocalEvent(OnMagnetUnpaused); - } - - private void OnMagnetUnpaused(EntityUid uid, ContainerMagnetPickupComponent component, ref EntityUnpausedEvent args) - { - component.NextScan += args.PausedTime; - } - - private void OnMagnetMapInit(EntityUid uid, ContainerMagnetPickupComponent component, MapInitEvent args) - { - component.NextScan = _timing.CurTime; - } - - public override void Update(float frameTime) - { - base.Update(frameTime); - var query = EntityQueryEnumerator(); - var currentTime = _timing.CurTime; - - while (query.MoveNext(out var uid, out var comp, out var storage, out var xform)) - { - if (comp.NextScan > currentTime) - continue; - - comp.NextScan += ScanDelay; - - // No space - if (storage.StorageUsed >= storage.StorageCapacityMax) - continue; - - // Check if magnet should be active in current anchor state - if (xform.Anchored && !comp.PickupWhenAnchored || !xform.Anchored && !comp.PickupWhenNotAnchored) - continue; - - // if (!_inventory.TryGetContainingSlot(uid, out var slotDef)) - // continue; - - // if ((slotDef.SlotFlags & comp.SlotFlags) == 0x0) - // 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 = nearXform.MapPosition; - 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; - } - } - } -} diff --git a/Content.Shared/Storage/EntitySystems/MagnetPickupSystem.cs b/Content.Shared/Storage/EntitySystems/MagnetPickupSystem.cs index fe623fb1410..a038e16620d 100644 --- a/Content.Shared/Storage/EntitySystems/MagnetPickupSystem.cs +++ b/Content.Shared/Storage/EntitySystems/MagnetPickupSystem.cs @@ -56,10 +56,17 @@ public override void Update(float frameTime) if (storage.StorageUsed >= storage.StorageCapacityMax) continue; - if (!_inventory.TryGetContainingSlot(uid, out var slotDef)) - continue; - if ((slotDef.SlotFlags & comp.SlotFlags) == 0x0) + if (!comp.IsFixture) + { + if (!_inventory.TryGetContainingSlot(uid, out var slotDef)) + continue; + + if ((slotDef.SlotFlags & comp.SlotFlags) == 0x0) + continue; + } + // Magnet disabled in current fixture anchor state + else if (xform.Anchored && !comp.PickupWhenAnchored || !xform.Anchored && !comp.PickupWhenNotAnchored) continue; var parentUid = xform.ParentUid; diff --git a/Resources/Prototypes/Entities/Structures/Storage/ore_box.yml b/Resources/Prototypes/Entities/Structures/Storage/ore_box.yml index 136138775c6..f90993bd878 100644 --- a/Resources/Prototypes/Entities/Structures/Storage/ore_box.yml +++ b/Resources/Prototypes/Entities/Structures/Storage/ore_box.yml @@ -70,7 +70,8 @@ storagebase: !type:Container ents: [ ] - type: Dumpable # Frontier - - type: ContainerMagnetPickup # Frontier + - type: MagnetPickup # Frontier + isFixture: true pickupWhenNotAnchored: true pickupWhenAnchored: false range: 1.5 # Ore bag has a range of 1.0