From fcf01cc6efb6b95e9f454846fd5f08e706661fa9 Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Tue, 18 Jul 2023 21:44:00 +1000 Subject: [PATCH] Trashbag stuff (#18096) --- .../Animations/ReusableAnimations.cs | 14 ++++++------- .../Disposal/DisposalUnitComponent.cs | 1 + Content.Client/Hands/Systems/HandsSystem.cs | 10 +++++----- .../Storage/ClientStorageComponent.cs | 19 ------------------ .../Storage/Systems/StorageSystem.cs | 2 +- .../Unit/Components/DisposalUnitComponent.cs | 1 + Content.Server/Hands/Systems/HandsSystem.cs | 4 ++-- .../Storage/EntitySystems/StorageSystem.cs | 9 +++++++-- .../EntitySystems/SharedHandsSystem.Pickup.cs | 7 ++++--- Content.Shared/Hands/HandEvents.cs | 4 +++- .../Storage/Components/DumpableComponent.cs | 4 ++++ .../Storage/EntitySystems/DumpableSystem.cs | 20 ++++++++++++++++--- .../Storage/SharedStorageComponent.cs | 4 +++- 13 files changed, 55 insertions(+), 44 deletions(-) diff --git a/Content.Client/Animations/ReusableAnimations.cs b/Content.Client/Animations/ReusableAnimations.cs index b061cfd05f..504b81e734 100644 --- a/Content.Client/Animations/ReusableAnimations.cs +++ b/Content.Client/Animations/ReusableAnimations.cs @@ -1,19 +1,15 @@ -using System; using System.Numerics; +using Content.Shared.Spawners.Components; using Robust.Client.Animations; using Robust.Client.GameObjects; using Robust.Shared.Animations; -using Robust.Shared.GameObjects; -using Robust.Shared.IoC; -using Robust.Shared.Log; using Robust.Shared.Map; -using Robust.Shared.Maths; namespace Content.Client.Animations { public static class ReusableAnimations { - public static void AnimateEntityPickup(EntityUid entity, EntityCoordinates initialPosition, Vector2 finalPosition, IEntityManager? entMan = null) + public static void AnimateEntityPickup(EntityUid entity, EntityCoordinates initialPosition, Vector2 finalPosition, Angle initialAngle, IEntityManager? entMan = null) { IoCManager.Resolve(ref entMan); @@ -38,6 +34,10 @@ namespace Content.Client.Animations entMan.DeleteEntity(animatableClone); }; + var despawn = entMan.EnsureComponent(animatableClone); + despawn.Lifetime = 0.25f; + entMan.System().SetLocalRotationNoLerp(animatableClone, initialAngle); + animations.Play(new Animation { Length = TimeSpan.FromMilliseconds(125), @@ -53,7 +53,7 @@ namespace Content.Client.Animations new AnimationTrackProperty.KeyFrame(initialPosition.Position, 0), new AnimationTrackProperty.KeyFrame(finalPosition, 0.125f) } - } + }, } }, "fancy_pickup_anim"); } diff --git a/Content.Client/Disposal/DisposalUnitComponent.cs b/Content.Client/Disposal/DisposalUnitComponent.cs index 1ca18bedeb..5466ea59dd 100644 --- a/Content.Client/Disposal/DisposalUnitComponent.cs +++ b/Content.Client/Disposal/DisposalUnitComponent.cs @@ -3,6 +3,7 @@ using Content.Shared.Disposal.Components; namespace Content.Client.Disposal; [RegisterComponent] +[ComponentReference(typeof(SharedDisposalUnitComponent))] public sealed class DisposalUnitComponent : SharedDisposalUnitComponent { diff --git a/Content.Client/Hands/Systems/HandsSystem.cs b/Content.Client/Hands/Systems/HandsSystem.cs index 0d56d4617b..f87f75892e 100644 --- a/Content.Client/Hands/Systems/HandsSystem.cs +++ b/Content.Client/Hands/Systems/HandsSystem.cs @@ -110,16 +110,16 @@ namespace Content.Client.Hands.Systems #region PickupAnimation private void HandlePickupAnimation(PickupAnimationEvent msg) { - PickupAnimation(msg.ItemUid, msg.InitialPosition, msg.FinalPosition); + PickupAnimation(msg.ItemUid, msg.InitialPosition, msg.FinalPosition, msg.InitialAngle); } - public override void PickupAnimation(EntityUid item, EntityCoordinates initialPosition, Vector2 finalPosition, + public override void PickupAnimation(EntityUid item, EntityCoordinates initialPosition, Vector2 finalPosition, Angle initialAngle, EntityUid? exclude) { - PickupAnimation(item, initialPosition, finalPosition); + PickupAnimation(item, initialPosition, finalPosition, initialAngle); } - public void PickupAnimation(EntityUid item, EntityCoordinates initialPosition, Vector2 finalPosition) + public void PickupAnimation(EntityUid item, EntityCoordinates initialPosition, Vector2 finalPosition, Angle initialAngle) { if (!_gameTiming.IsFirstTimePredicted) return; @@ -127,7 +127,7 @@ namespace Content.Client.Hands.Systems if (finalPosition.EqualsApprox(initialPosition.Position, tolerance: 0.1f)) return; - ReusableAnimations.AnimateEntityPickup(item, initialPosition, finalPosition); + ReusableAnimations.AnimateEntityPickup(item, initialPosition, finalPosition, initialAngle); } #endregion diff --git a/Content.Client/Storage/ClientStorageComponent.cs b/Content.Client/Storage/ClientStorageComponent.cs index dfd0f26c1a..8f1697510a 100644 --- a/Content.Client/Storage/ClientStorageComponent.cs +++ b/Content.Client/Storage/ClientStorageComponent.cs @@ -11,28 +11,9 @@ namespace Content.Client.Storage [ComponentReference(typeof(SharedStorageComponent))] public sealed class ClientStorageComponent : SharedStorageComponent { - [Dependency] private readonly IEntityManager _entityManager = default!; private List _storedEntities = new(); public override IReadOnlyList StoredEntities => _storedEntities; - /// - /// Animate the newly stored entities in flying towards this storage's position - /// - /// - public void HandleAnimatingInsertingEntities(AnimateInsertingEntitiesEvent msg) - { - for (var i = 0; msg.StoredEntities.Count > i; i++) - { - var entity = msg.StoredEntities[i]; - var initialPosition = msg.EntityPositions[i]; - - if (_entityManager.EntityExists(entity)) - { - ReusableAnimations.AnimateEntityPickup(entity, initialPosition, _entityManager.GetComponent(Owner).LocalPosition, _entityManager); - } - } - } - public override bool Remove(EntityUid entity) { return false; diff --git a/Content.Client/Storage/Systems/StorageSystem.cs b/Content.Client/Storage/Systems/StorageSystem.cs index 37dc7a94ec..145a7dd9f0 100644 --- a/Content.Client/Storage/Systems/StorageSystem.cs +++ b/Content.Client/Storage/Systems/StorageSystem.cs @@ -30,7 +30,7 @@ public sealed class StorageSystem : EntitySystem var initialPosition = msg.EntityPositions[i]; if (EntityManager.EntityExists(entity) && transformComp != null) { - ReusableAnimations.AnimateEntityPickup(entity, initialPosition, transformComp.LocalPosition, EntityManager); + ReusableAnimations.AnimateEntityPickup(entity, initialPosition, transformComp.LocalPosition, msg.EntityAngles[i], EntityManager); } } } diff --git a/Content.Server/Disposal/Unit/Components/DisposalUnitComponent.cs b/Content.Server/Disposal/Unit/Components/DisposalUnitComponent.cs index 67495d9b34..c9608dfba4 100644 --- a/Content.Server/Disposal/Unit/Components/DisposalUnitComponent.cs +++ b/Content.Server/Disposal/Unit/Components/DisposalUnitComponent.cs @@ -6,6 +6,7 @@ namespace Content.Server.Disposal.Unit.Components; // GasMixture life. [RegisterComponent] +[ComponentReference(typeof(SharedDisposalUnitComponent))] public sealed class DisposalUnitComponent : SharedDisposalUnitComponent { [DataField("air")] diff --git a/Content.Server/Hands/Systems/HandsSystem.cs b/Content.Server/Hands/Systems/HandsSystem.cs index a792b27c71..9a72d31207 100644 --- a/Content.Server/Hands/Systems/HandsSystem.cs +++ b/Content.Server/Hands/Systems/HandsSystem.cs @@ -94,7 +94,7 @@ namespace Content.Server.Hands.Systems args.Handled = true; // no shove/stun. } - public override void PickupAnimation(EntityUid item, EntityCoordinates initialPosition, Vector2 finalPosition, + public override void PickupAnimation(EntityUid item, EntityCoordinates initialPosition, Vector2 finalPosition, Angle initialAngle, EntityUid? exclude) { if (finalPosition.EqualsApprox(initialPosition.Position, tolerance: 0.1f)) @@ -105,7 +105,7 @@ namespace Content.Server.Hands.Systems if (exclude != null) filter = filter.RemoveWhereAttachedEntity(entity => entity == exclude); - RaiseNetworkEvent(new PickupAnimationEvent(item, initialPosition, finalPosition), filter); + RaiseNetworkEvent(new PickupAnimationEvent(item, initialPosition, finalPosition, initialAngle), filter); } protected override void HandleEntityRemoved(EntityUid uid, HandsComponent hands, EntRemovedFromContainerMessage args) diff --git a/Content.Server/Storage/EntitySystems/StorageSystem.cs b/Content.Server/Storage/EntitySystems/StorageSystem.cs index 300e0af9f5..0322af11fa 100644 --- a/Content.Server/Storage/EntitySystems/StorageSystem.cs +++ b/Content.Server/Storage/EntitySystems/StorageSystem.cs @@ -275,7 +275,8 @@ namespace Content.Server.Storage.EntitySystems { RaiseNetworkEvent(new AnimateInsertingEntitiesEvent(uid, new List { target }, - new List { position })); + new List { position }, + new List { transformOwner.LocalRotation })); } } } @@ -288,6 +289,7 @@ namespace Content.Server.Storage.EntitySystems var successfullyInserted = new List(); var successfullyInsertedPositions = new List(); + var successfullyInsertedAngles = new List(); var itemQuery = GetEntityQuery(); var xformQuery = GetEntityQuery(); xformQuery.TryGetComponent(uid, out var xform); @@ -313,10 +315,13 @@ namespace Content.Server.Storage.EntitySystems _transform ); + var angle = targetXform.LocalRotation; + if (PlayerInsertEntityInWorld(uid, args.Args.User, entity, component)) { successfullyInserted.Add(entity); successfullyInsertedPositions.Add(position); + successfullyInsertedAngles.Add(angle); } } @@ -324,7 +329,7 @@ namespace Content.Server.Storage.EntitySystems if (successfullyInserted.Count > 0) { _audio.PlayPvs(component.StorageInsertSound, uid); - RaiseNetworkEvent(new AnimateInsertingEntitiesEvent(uid, successfullyInserted, successfullyInsertedPositions)); + RaiseNetworkEvent(new AnimateInsertingEntitiesEvent(uid, successfullyInserted, successfullyInsertedPositions, successfullyInsertedAngles)); } args.Handled = true; diff --git a/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Pickup.cs b/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Pickup.cs index b5c8aea415..eaa10ed077 100644 --- a/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Pickup.cs +++ b/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Pickup.cs @@ -109,14 +109,15 @@ public abstract partial class SharedHandsSystem : EntitySystem { var xform = Transform(uid); var coordinateEntity = xform.ParentUid.IsValid() ? xform.ParentUid : uid; - var itemPos = Transform(entity).MapPosition; + var itemXform = Transform(entity); + var itemPos = itemXform.MapPosition; if (itemPos.MapId == xform.MapID && (itemPos.Position - xform.MapPosition.Position).Length() <= MaxAnimationRange && MetaData(entity).VisibilityMask == MetaData(uid).VisibilityMask) // Don't animate aghost pickups. { var initialPosition = EntityCoordinates.FromMap(coordinateEntity, itemPos, EntityManager); - PickupAnimation(entity, initialPosition, xform.LocalPosition, animateUser ? null : uid); + PickupAnimation(entity, initialPosition, xform.LocalPosition, itemXform.LocalRotation, animateUser ? null : uid); } } DoPickup(uid, hand, entity, handsComp); @@ -232,6 +233,6 @@ public abstract partial class SharedHandsSystem : EntitySystem RaiseLocalEvent(entity, new HandSelectedEvent(uid), false); } - public abstract void PickupAnimation(EntityUid item, EntityCoordinates initialPosition, Vector2 finalPosition, + public abstract void PickupAnimation(EntityUid item, EntityCoordinates initialPosition, Vector2 finalPosition, Angle initialAngle, EntityUid? exclude); } diff --git a/Content.Shared/Hands/HandEvents.cs b/Content.Shared/Hands/HandEvents.cs index b5068d34c3..5541c2e439 100644 --- a/Content.Shared/Hands/HandEvents.cs +++ b/Content.Shared/Hands/HandEvents.cs @@ -120,13 +120,15 @@ namespace Content.Shared.Hands public EntityUid ItemUid { get; } public EntityCoordinates InitialPosition { get; } public Vector2 FinalPosition { get; } + public Angle InitialAngle { get; } public PickupAnimationEvent(EntityUid itemUid, EntityCoordinates initialPosition, - Vector2 finalPosition) + Vector2 finalPosition, Angle initialAngle) { ItemUid = itemUid; FinalPosition = finalPosition; InitialPosition = initialPosition; + InitialAngle = initialAngle; } } diff --git a/Content.Shared/Storage/Components/DumpableComponent.cs b/Content.Shared/Storage/Components/DumpableComponent.cs index 8ef14e1bb6..10470fd2f3 100644 --- a/Content.Shared/Storage/Components/DumpableComponent.cs +++ b/Content.Shared/Storage/Components/DumpableComponent.cs @@ -1,4 +1,5 @@ using Content.Shared.DoAfter; +using Robust.Shared.Audio; using Robust.Shared.GameStates; using Robust.Shared.Serialization; @@ -16,6 +17,9 @@ public sealed class DumpableDoAfterEvent : SimpleDoAfterEvent [RegisterComponent, NetworkedComponent, AutoGenerateComponentState] public sealed partial class DumpableComponent : Component { + [ViewVariables(VVAccess.ReadWrite), DataField("soundDump"), AutoNetworkedField] + public SoundSpecifier? DumpSound = new SoundCollectionSpecifier("storageRustle"); + /// /// How long each item adds to the doafter. /// diff --git a/Content.Shared/Storage/EntitySystems/DumpableSystem.cs b/Content.Shared/Storage/EntitySystems/DumpableSystem.cs index 8cb68d97c4..0e5a4fd796 100644 --- a/Content.Shared/Storage/EntitySystems/DumpableSystem.cs +++ b/Content.Shared/Storage/EntitySystems/DumpableSystem.cs @@ -14,6 +14,7 @@ namespace Content.Shared.Storage.EntitySystems; public sealed class DumpableSystem : EntitySystem { [Dependency] private readonly IRobustRandom _random = default!; + [Dependency] private readonly SharedAudioSystem _audio = default!; [Dependency] private readonly SharedContainerSystem _container = default!; [Dependency] private readonly SharedDisposalUnitSystem _disposalUnitSystem = default!; [Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!; @@ -126,6 +127,9 @@ public sealed class DumpableSystem : EntitySystem dumpQueue.Enqueue(entity); } + if (dumpQueue.Count == 0) + return; + foreach (var entity in dumpQueue) { var transform = Transform(entity); @@ -136,17 +140,21 @@ public sealed class DumpableSystem : EntitySystem if (args.Args.Target == null) return; + var dumped = false; + if (HasComp(args.Args.Target.Value)) { + dumped = true; + foreach (var entity in dumpQueue) { _disposalUnitSystem.DoInsertDisposalUnit(args.Args.Target.Value, entity, args.Args.User); } - return; } - - if (HasComp(args.Args.Target.Value)) + else if (HasComp(args.Args.Target.Value)) { + dumped = true; + var targetPos = _xformQuery.GetComponent(args.Args.Target.Value).LocalPosition; foreach (var entity in dumpQueue) @@ -154,5 +162,11 @@ public sealed class DumpableSystem : EntitySystem _transformSystem.SetLocalPosition(entity, targetPos + _random.NextVector2Box() / 4); } } + + if (dumped) + { + // TODO: Predicted when above predicted + _audio.PlayPvs(component.DumpSound, uid); + } } } diff --git a/Content.Shared/Storage/SharedStorageComponent.cs b/Content.Shared/Storage/SharedStorageComponent.cs index 14c4123c6a..7034d1e138 100644 --- a/Content.Shared/Storage/SharedStorageComponent.cs +++ b/Content.Shared/Storage/SharedStorageComponent.cs @@ -62,12 +62,14 @@ namespace Content.Shared.Storage public readonly EntityUid Storage; public readonly List StoredEntities; public readonly List EntityPositions; + public readonly List EntityAngles; - public AnimateInsertingEntitiesEvent(EntityUid storage, List storedEntities, List entityPositions) + public AnimateInsertingEntitiesEvent(EntityUid storage, List storedEntities, List entityPositions, List entityAngles) { Storage = storage; StoredEntities = storedEntities; EntityPositions = entityPositions; + EntityAngles = entityAngles; } }