From dc53a91b682eedb250eb5862c3cd1ee4436f8211 Mon Sep 17 00:00:00 2001 From: Dvir Date: Fri, 29 Sep 2023 00:17:51 +0300 Subject: [PATCH 1/8] Lathe Magnet --- .../Components/LatheMagnetPickupComponent.cs | 30 +++++++ .../EntitySystems/LatheMagnetPickupSystem.cs | 82 +++++++++++++++++++ .../Entities/Structures/Machines/lathe.yml | 6 ++ 3 files changed, 118 insertions(+) create mode 100644 Content.Shared/Storage/Components/LatheMagnetPickupComponent.cs create mode 100644 Content.Shared/Storage/EntitySystems/LatheMagnetPickupSystem.cs diff --git a/Content.Shared/Storage/Components/LatheMagnetPickupComponent.cs b/Content.Shared/Storage/Components/LatheMagnetPickupComponent.cs new file mode 100644 index 00000000000..334e8a6dd3a --- /dev/null +++ b/Content.Shared/Storage/Components/LatheMagnetPickupComponent.cs @@ -0,0 +1,30 @@ +using Content.Shared.Inventory; +using Content.Shared.Tag; +using Content.Shared.Whitelist; + +namespace Content.Server.Storage.Components; + +/// +/// Applies an ongoing pickup area around the attached entity. +/// +[RegisterComponent] +public sealed partial class LatheMagnetPickupComponent : Component +{ + [ViewVariables(VVAccess.ReadWrite), DataField("nextScan")] + public TimeSpan NextScan = TimeSpan.Zero; + + [ViewVariables(VVAccess.ReadWrite), DataField("range")] + public float Range = 1f; + + [ValidatePrototypeId] + private const string DefaultTag = "Ore"; + + [ViewVariables(VVAccess.ReadWrite), DataField("whitelist")] + public EntityWhitelist? Whitelist = new() + { + Tags = new List() + { + DefaultTag, + } + }; +} diff --git a/Content.Shared/Storage/EntitySystems/LatheMagnetPickupSystem.cs b/Content.Shared/Storage/EntitySystems/LatheMagnetPickupSystem.cs new file mode 100644 index 00000000000..005718794c2 --- /dev/null +++ b/Content.Shared/Storage/EntitySystems/LatheMagnetPickupSystem.cs @@ -0,0 +1,82 @@ +using Content.Server.Storage.Components; +using Content.Shared.Inventory; +using Content.Shared.Materials; +using Robust.Shared.Map; +using Robust.Shared.Physics.Components; +using Robust.Shared.Player; +using Robust.Shared.Timing; + +namespace Content.Shared.Storage.EntitySystems; + +/// +/// +/// +public sealed class LatheMagnetPickupSystem : EntitySystem +{ + [Dependency] private readonly IGameTiming _timing = default!; + [Dependency] private readonly EntityLookupSystem _lookup = default!; + [Dependency] private readonly SharedTransformSystem _transform = default!; + [Dependency] private readonly SharedMaterialStorageSystem _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, LatheMagnetPickupComponent component, ref EntityUnpausedEvent args) + { + component.NextScan += args.PausedTime; + } + + private void OnMagnetMapInit(EntityUid uid, LatheMagnetPickupComponent component, MapInitEvent args) + { + component.NextScan = _timing.CurTime; + } + + public override void Update(float frameTime) + { + base.Update(frameTime); + var currentTime = _timing.CurTime; + var query = EntityQueryEnumerator(); + + while (query.MoveNext(out var uid, out var comp, out var storage, out var xform)) + { + if (comp.NextScan < currentTime) + continue; + + comp.NextScan += ScanDelay; + + var parentUid = xform.ParentUid; + var moverCoords = _transform.GetMoverCoordinates(uid, xform); + + foreach (var near in _lookup.GetEntitiesInRange(uid, comp.Range, LookupFlags.Dynamic | LookupFlags.Sundries)) + { + if (comp.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; + + if (!_storage.TryInsertMaterialEntity(uid, near, uid, storage)) + continue; + } + } + } +} diff --git a/Resources/Prototypes/Entities/Structures/Machines/lathe.yml b/Resources/Prototypes/Entities/Structures/Machines/lathe.yml index fa72e2f66fe..debcc70642d 100644 --- a/Resources/Prototypes/Entities/Structures/Machines/lathe.yml +++ b/Resources/Prototypes/Entities/Structures/Machines/lathe.yml @@ -17,6 +17,7 @@ - MachineMask layer: - MachineLayer +# - FullTileLayer - type: Lathe - type: MaterialStorage - type: Destructible @@ -841,6 +842,11 @@ - IngotGold30 - IngotSilver30 - MaterialBananium10 + - type: LatheMagnetPickup + range: 0.5 + whitelist: + tags: + - Ore - type: entity parent: BaseLathe From 9f150a577f0259e50f78acfdca0c27295005e960 Mon Sep 17 00:00:00 2001 From: Dvir <39403717+dvir001@users.noreply.github.com> Date: Fri, 29 Sep 2023 00:22:12 +0300 Subject: [PATCH 2/8] Update lathe.yml --- Resources/Prototypes/Entities/Structures/Machines/lathe.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/Resources/Prototypes/Entities/Structures/Machines/lathe.yml b/Resources/Prototypes/Entities/Structures/Machines/lathe.yml index debcc70642d..ac7b81857a8 100644 --- a/Resources/Prototypes/Entities/Structures/Machines/lathe.yml +++ b/Resources/Prototypes/Entities/Structures/Machines/lathe.yml @@ -17,7 +17,6 @@ - MachineMask layer: - MachineLayer -# - FullTileLayer - type: Lathe - type: MaterialStorage - type: Destructible From 1a81c06770d1d3f1dabd5b0102652a57c6dea901 Mon Sep 17 00:00:00 2001 From: Dvir <39403717+dvir001@users.noreply.github.com> Date: Fri, 29 Sep 2023 00:28:21 +0300 Subject: [PATCH 3/8] Up range --- Resources/Prototypes/Entities/Structures/Machines/lathe.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/Prototypes/Entities/Structures/Machines/lathe.yml b/Resources/Prototypes/Entities/Structures/Machines/lathe.yml index ac7b81857a8..474530cdb42 100644 --- a/Resources/Prototypes/Entities/Structures/Machines/lathe.yml +++ b/Resources/Prototypes/Entities/Structures/Machines/lathe.yml @@ -842,7 +842,7 @@ - IngotSilver30 - MaterialBananium10 - type: LatheMagnetPickup - range: 0.5 + range: 0.75 whitelist: tags: - Ore From 282ef166ffc548fd6defd08fc8ab6e64ce9c84c7 Mon Sep 17 00:00:00 2001 From: Dvir Date: Sat, 30 Sep 2023 13:00:11 +0300 Subject: [PATCH 4/8] CleanUp MaterialStorageMagnetPickup --- ... => MaterialStorageMagnetPickupComponent.cs} | 2 +- ....cs => MaterialStorageMagnetPickupSystem.cs} | 17 +++++++---------- .../Entities/Structures/Machines/lathe.yml | 2 +- 3 files changed, 9 insertions(+), 12 deletions(-) rename Content.Shared/Storage/Components/{LatheMagnetPickupComponent.cs => MaterialStorageMagnetPickupComponent.cs} (90%) rename Content.Shared/Storage/EntitySystems/{LatheMagnetPickupSystem.cs => MaterialStorageMagnetPickupSystem.cs} (77%) diff --git a/Content.Shared/Storage/Components/LatheMagnetPickupComponent.cs b/Content.Shared/Storage/Components/MaterialStorageMagnetPickupComponent.cs similarity index 90% rename from Content.Shared/Storage/Components/LatheMagnetPickupComponent.cs rename to Content.Shared/Storage/Components/MaterialStorageMagnetPickupComponent.cs index 334e8a6dd3a..eef29f2fced 100644 --- a/Content.Shared/Storage/Components/LatheMagnetPickupComponent.cs +++ b/Content.Shared/Storage/Components/MaterialStorageMagnetPickupComponent.cs @@ -8,7 +8,7 @@ namespace Content.Server.Storage.Components; /// Applies an ongoing pickup area around the attached entity. /// [RegisterComponent] -public sealed partial class LatheMagnetPickupComponent : Component +public sealed partial class MaterialStorageMagnetPickupComponent : Component { [ViewVariables(VVAccess.ReadWrite), DataField("nextScan")] public TimeSpan NextScan = TimeSpan.Zero; diff --git a/Content.Shared/Storage/EntitySystems/LatheMagnetPickupSystem.cs b/Content.Shared/Storage/EntitySystems/MaterialStorageMagnetPickupSystem.cs similarity index 77% rename from Content.Shared/Storage/EntitySystems/LatheMagnetPickupSystem.cs rename to Content.Shared/Storage/EntitySystems/MaterialStorageMagnetPickupSystem.cs index 005718794c2..6ed3678ef45 100644 --- a/Content.Shared/Storage/EntitySystems/LatheMagnetPickupSystem.cs +++ b/Content.Shared/Storage/EntitySystems/MaterialStorageMagnetPickupSystem.cs @@ -1,17 +1,14 @@ using Content.Server.Storage.Components; -using Content.Shared.Inventory; using Content.Shared.Materials; -using Robust.Shared.Map; using Robust.Shared.Physics.Components; -using Robust.Shared.Player; using Robust.Shared.Timing; namespace Content.Shared.Storage.EntitySystems; /// -/// +/// /// -public sealed class LatheMagnetPickupSystem : EntitySystem +public sealed class MaterialStorageMagnetPickupSystem : EntitySystem { [Dependency] private readonly IGameTiming _timing = default!; [Dependency] private readonly EntityLookupSystem _lookup = default!; @@ -26,16 +23,16 @@ public override void Initialize() { base.Initialize(); _physicsQuery = GetEntityQuery(); - SubscribeLocalEvent(OnMagnetMapInit); - SubscribeLocalEvent(OnMagnetUnpaused); + SubscribeLocalEvent(OnMagnetMapInit); + SubscribeLocalEvent(OnMagnetUnpaused); } - private void OnMagnetUnpaused(EntityUid uid, LatheMagnetPickupComponent component, ref EntityUnpausedEvent args) + private void OnMagnetUnpaused(EntityUid uid, MaterialStorageMagnetPickupComponent component, ref EntityUnpausedEvent args) { component.NextScan += args.PausedTime; } - private void OnMagnetMapInit(EntityUid uid, LatheMagnetPickupComponent component, MapInitEvent args) + private void OnMagnetMapInit(EntityUid uid, MaterialStorageMagnetPickupComponent component, MapInitEvent args) { component.NextScan = _timing.CurTime; } @@ -44,7 +41,7 @@ public override void Update(float frameTime) { base.Update(frameTime); var currentTime = _timing.CurTime; - var query = EntityQueryEnumerator(); + var query = EntityQueryEnumerator(); while (query.MoveNext(out var uid, out var comp, out var storage, out var xform)) { diff --git a/Resources/Prototypes/Entities/Structures/Machines/lathe.yml b/Resources/Prototypes/Entities/Structures/Machines/lathe.yml index 474530cdb42..60329f3a77a 100644 --- a/Resources/Prototypes/Entities/Structures/Machines/lathe.yml +++ b/Resources/Prototypes/Entities/Structures/Machines/lathe.yml @@ -841,7 +841,7 @@ - IngotGold30 - IngotSilver30 - MaterialBananium10 - - type: LatheMagnetPickup + - type: MaterialStorageMagnetPickup range: 0.75 whitelist: tags: From 0d3453e449490c80d703ab8086b1d21978107b41 Mon Sep 17 00:00:00 2001 From: Dvir Date: Sat, 30 Sep 2023 13:14:13 +0300 Subject: [PATCH 5/8] Update MaterialStorageMagnetPickupComponent.cs --- .../Storage/Components/MaterialStorageMagnetPickupComponent.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Content.Shared/Storage/Components/MaterialStorageMagnetPickupComponent.cs b/Content.Shared/Storage/Components/MaterialStorageMagnetPickupComponent.cs index eef29f2fced..a9cacec436a 100644 --- a/Content.Shared/Storage/Components/MaterialStorageMagnetPickupComponent.cs +++ b/Content.Shared/Storage/Components/MaterialStorageMagnetPickupComponent.cs @@ -1,4 +1,3 @@ -using Content.Shared.Inventory; using Content.Shared.Tag; using Content.Shared.Whitelist; From 3205884e166ba23a0ae4b12941b76375a439a35c Mon Sep 17 00:00:00 2001 From: Dvir Date: Sat, 30 Sep 2023 14:21:44 +0300 Subject: [PATCH 6/8] CodeClean --- .../MaterialStorageMagnetPickupComponent.cs | 14 ++++---------- .../MaterialStorageMagnetPickupSystem.cs | 7 ++++--- .../Entities/Structures/Machines/lathe.yml | 2 +- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/Content.Shared/Storage/Components/MaterialStorageMagnetPickupComponent.cs b/Content.Shared/Storage/Components/MaterialStorageMagnetPickupComponent.cs index a9cacec436a..e2ced955e8d 100644 --- a/Content.Shared/Storage/Components/MaterialStorageMagnetPickupComponent.cs +++ b/Content.Shared/Storage/Components/MaterialStorageMagnetPickupComponent.cs @@ -15,15 +15,9 @@ public sealed partial class MaterialStorageMagnetPickupComponent : Component [ViewVariables(VVAccess.ReadWrite), DataField("range")] public float Range = 1f; - [ValidatePrototypeId] - private const string DefaultTag = "Ore"; - [ViewVariables(VVAccess.ReadWrite), DataField("whitelist")] - public EntityWhitelist? Whitelist = new() - { - Tags = new List() - { - DefaultTag, - } - }; + public EntityWhitelist? Whitelist; + + [ViewVariables(VVAccess.ReadWrite), DataField("blacklist")] + public EntityWhitelist? Blacklist; } diff --git a/Content.Shared/Storage/EntitySystems/MaterialStorageMagnetPickupSystem.cs b/Content.Shared/Storage/EntitySystems/MaterialStorageMagnetPickupSystem.cs index 6ed3678ef45..2dec6164838 100644 --- a/Content.Shared/Storage/EntitySystems/MaterialStorageMagnetPickupSystem.cs +++ b/Content.Shared/Storage/EntitySystems/MaterialStorageMagnetPickupSystem.cs @@ -51,11 +51,13 @@ public override void Update(float frameTime) comp.NextScan += ScanDelay; var parentUid = xform.ParentUid; - var moverCoords = _transform.GetMoverCoordinates(uid, xform); foreach (var near in _lookup.GetEntitiesInRange(uid, comp.Range, LookupFlags.Dynamic | LookupFlags.Sundries)) { - if (comp.Whitelist?.IsValid(near, EntityManager) == false) + if (comp.Blacklist is { } blacklist && blacklist.IsValid(near, EntityManager) == true) + continue; + + if (comp.Whitelist is { } whitelist && whitelist.IsValid(near, EntityManager) == false) continue; if (!_physicsQuery.TryGetComponent(near, out var physics) || physics.BodyStatus != BodyStatus.OnGround) @@ -69,7 +71,6 @@ public override void Update(float frameTime) // 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; if (!_storage.TryInsertMaterialEntity(uid, near, uid, storage)) continue; diff --git a/Resources/Prototypes/Entities/Structures/Machines/lathe.yml b/Resources/Prototypes/Entities/Structures/Machines/lathe.yml index 60329f3a77a..cd7a6c0be71 100644 --- a/Resources/Prototypes/Entities/Structures/Machines/lathe.yml +++ b/Resources/Prototypes/Entities/Structures/Machines/lathe.yml @@ -842,7 +842,7 @@ - IngotSilver30 - MaterialBananium10 - type: MaterialStorageMagnetPickup - range: 0.75 + range: 0.60 whitelist: tags: - Ore From 0eb415409fd7e86542691c685e6247949a832e40 Mon Sep 17 00:00:00 2001 From: Dvir Date: Sat, 30 Sep 2023 14:27:10 +0300 Subject: [PATCH 7/8] CleanUp --- .../EntitySystems/MaterialStorageMagnetPickupSystem.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Content.Shared/Storage/EntitySystems/MaterialStorageMagnetPickupSystem.cs b/Content.Shared/Storage/EntitySystems/MaterialStorageMagnetPickupSystem.cs index 2dec6164838..9931592c1eb 100644 --- a/Content.Shared/Storage/EntitySystems/MaterialStorageMagnetPickupSystem.cs +++ b/Content.Shared/Storage/EntitySystems/MaterialStorageMagnetPickupSystem.cs @@ -66,12 +66,6 @@ public override void Update(float frameTime) 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); - if (!_storage.TryInsertMaterialEntity(uid, near, uid, storage)) continue; } From dd254208dcae795e516b9f14197312e941737dba Mon Sep 17 00:00:00 2001 From: Dvir Date: Sat, 30 Sep 2023 14:43:54 +0300 Subject: [PATCH 8/8] MaterialReclaimer Added --- .../MaterialReclaimerMagnetPickupComponent.cs | 23 ++++++ .../MaterialReclaimerMagnetPickupSystem.cs | 74 +++++++++++++++++++ .../Entities/Structures/Machines/lathe.yml | 2 +- .../Machines/material_reclaimer.yml | 16 ++++ 4 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 Content.Shared/Storage/Components/MaterialReclaimerMagnetPickupComponent.cs create mode 100644 Content.Shared/Storage/EntitySystems/MaterialReclaimerMagnetPickupSystem.cs diff --git a/Content.Shared/Storage/Components/MaterialReclaimerMagnetPickupComponent.cs b/Content.Shared/Storage/Components/MaterialReclaimerMagnetPickupComponent.cs new file mode 100644 index 00000000000..86c3bb83fb8 --- /dev/null +++ b/Content.Shared/Storage/Components/MaterialReclaimerMagnetPickupComponent.cs @@ -0,0 +1,23 @@ +using Content.Shared.Tag; +using Content.Shared.Whitelist; + +namespace Content.Server.Storage.Components; + +/// +/// Applies an ongoing pickup area around the attached entity. +/// +[RegisterComponent] +public sealed partial class MaterialReclaimerMagnetPickupComponent : Component +{ + [ViewVariables(VVAccess.ReadWrite), DataField("nextScan")] + public TimeSpan NextScan = TimeSpan.Zero; + + [ViewVariables(VVAccess.ReadWrite), DataField("range")] + public float Range = 1f; + + [ViewVariables(VVAccess.ReadWrite), DataField("whitelist")] + public EntityWhitelist? Whitelist; + + [ViewVariables(VVAccess.ReadWrite), DataField("blacklist")] + public EntityWhitelist? Blacklist; +} diff --git a/Content.Shared/Storage/EntitySystems/MaterialReclaimerMagnetPickupSystem.cs b/Content.Shared/Storage/EntitySystems/MaterialReclaimerMagnetPickupSystem.cs new file mode 100644 index 00000000000..59002fd998a --- /dev/null +++ b/Content.Shared/Storage/EntitySystems/MaterialReclaimerMagnetPickupSystem.cs @@ -0,0 +1,74 @@ +using Content.Server.Storage.Components; +using Content.Shared.Materials; +using Robust.Shared.Physics.Components; +using Robust.Shared.Timing; + +namespace Content.Shared.Storage.EntitySystems; + +/// +/// +/// +public sealed class MaterialReclaimerMagnetPickupSystem : EntitySystem +{ + [Dependency] private readonly IGameTiming _timing = default!; + [Dependency] private readonly EntityLookupSystem _lookup = default!; + [Dependency] private readonly SharedTransformSystem _transform = default!; + [Dependency] private readonly SharedMaterialReclaimerSystem _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, MaterialReclaimerMagnetPickupComponent component, ref EntityUnpausedEvent args) + { + component.NextScan += args.PausedTime; + } + + private void OnMagnetMapInit(EntityUid uid, MaterialReclaimerMagnetPickupComponent component, MapInitEvent args) + { + component.NextScan = _timing.CurTime; + } + + public override void Update(float frameTime) + { + base.Update(frameTime); + var currentTime = _timing.CurTime; + var query = EntityQueryEnumerator(); + + while (query.MoveNext(out var uid, out var comp, out var storage, out var xform)) + { + if (comp.NextScan < currentTime) + continue; + + comp.NextScan += ScanDelay; + + var parentUid = xform.ParentUid; + + foreach (var near in _lookup.GetEntitiesInRange(uid, comp.Range, LookupFlags.Dynamic | LookupFlags.Sundries)) + { + if (comp.Blacklist is { } blacklist && blacklist.IsValid(near, EntityManager) == true) + continue; + + if (comp.Whitelist is { } whitelist && whitelist.IsValid(near, EntityManager) == false) + continue; + + if (!_physicsQuery.TryGetComponent(near, out var physics) || physics.BodyStatus != BodyStatus.OnGround) + continue; + + if (near == parentUid) + continue; + + if (!_storage.TryStartProcessItem(uid, near)) + continue; + } + } + } +} diff --git a/Resources/Prototypes/Entities/Structures/Machines/lathe.yml b/Resources/Prototypes/Entities/Structures/Machines/lathe.yml index cd7a6c0be71..7f6abe1df9f 100644 --- a/Resources/Prototypes/Entities/Structures/Machines/lathe.yml +++ b/Resources/Prototypes/Entities/Structures/Machines/lathe.yml @@ -842,7 +842,7 @@ - IngotSilver30 - MaterialBananium10 - type: MaterialStorageMagnetPickup - range: 0.60 + range: 0.30 whitelist: tags: - Ore diff --git a/Resources/Prototypes/Entities/Structures/Machines/material_reclaimer.yml b/Resources/Prototypes/Entities/Structures/Machines/material_reclaimer.yml index bb8f6d200b7..934ee3c58c2 100644 --- a/Resources/Prototypes/Entities/Structures/Machines/material_reclaimer.yml +++ b/Resources/Prototypes/Entities/Structures/Machines/material_reclaimer.yml @@ -100,3 +100,19 @@ solution: output - type: StaticPrice price: 500 + - type: MaterialReclaimerMagnetPickup + range: 0.30 + whitelist: + components: + - PhysicalComposition + - SpaceGarbage + tags: + - Trash + - Recyclable + blacklist: + components: + - Material + - Pda + - IdCard + tags: + - HighRiskItem