From a242b08230f469c0b24ae59491e1ceb182879364 Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Wed, 29 Sep 2021 00:16:00 +1000 Subject: [PATCH] Throwing tweaks (#4705) * Throwing tweaks Landing is when the timer stops, throwing stops when it stops moving. * Review --- Content.Shared/Throwing/LandEvent.cs | 30 +++++---------- Content.Shared/Throwing/ThrownItemSystem.cs | 42 +++++++++++---------- 2 files changed, 31 insertions(+), 41 deletions(-) diff --git a/Content.Shared/Throwing/LandEvent.cs b/Content.Shared/Throwing/LandEvent.cs index 550f4d0f61..198aeeb5a4 100644 --- a/Content.Shared/Throwing/LandEvent.cs +++ b/Content.Shared/Throwing/LandEvent.cs @@ -5,31 +5,19 @@ using Robust.Shared.Map; namespace Content.Shared.Throwing { /// - /// Raised when an entity that was thrown lands. + /// Raised when an entity that was thrown lands. This occurs before they stop moving and is when their tile-friction is reapplied. /// [PublicAPI] public sealed class LandEvent : EntityEventArgs { - /// - /// Entity that threw the item. - /// - public IEntity? User { get; } + public EntityUid? User; + } - /// - /// Item that was thrown. - /// - public IEntity Thrown { get; } - - /// - /// Location where the item landed. - /// - public EntityCoordinates LandLocation { get; } - - public LandEvent(IEntity? user, IEntity thrown, EntityCoordinates landLocation) - { - User = user; - Thrown = thrown; - LandLocation = landLocation; - } + /// + /// Raised when a thrown entity is no longer moving. + /// + public sealed class StopThrowEvent : EntityEventArgs + { + public EntityUid? User; } } diff --git a/Content.Shared/Throwing/ThrownItemSystem.cs b/Content.Shared/Throwing/ThrownItemSystem.cs index 51ed84842f..f1a0e21599 100644 --- a/Content.Shared/Throwing/ThrownItemSystem.cs +++ b/Content.Shared/Throwing/ThrownItemSystem.cs @@ -20,8 +20,8 @@ namespace Content.Shared.Throwing /// public class ThrownItemSystem : EntitySystem { - [Dependency] private readonly IConfigurationManager _cfg = default!; [Dependency] private readonly SharedBroadphaseSystem _broadphaseSystem = default!; + [Dependency] private readonly SharedContainerSystem _containerSystem = default!; private const string ThrowingFixture = "throw-fixture"; @@ -69,31 +69,38 @@ namespace Content.Shared.Throwing private void HandleSleep(EntityUid uid, ThrownItemComponent thrownItem, PhysicsSleepMessage message) { - LandComponent(thrownItem); + StopThrow(uid, thrownItem); } private void HandlePullStarted(PullStartedMessage message) { // TODO: this isn't directed so things have to be done the bad way - if (message.Pulled.Owner.TryGetComponent(out ThrownItemComponent? thrownItem)) - LandComponent(thrownItem); + if (EntityManager.TryGetComponent(message.Pulled.Owner.Uid, out ThrownItemComponent? thrownItemComponent)) + StopThrow(message.Pulled.Owner.Uid, thrownItemComponent); + } + + private void StopThrow(EntityUid uid, ThrownItemComponent thrownItemComponent) + { + if (EntityManager.TryGetComponent(uid, out PhysicsComponent? physicsComponent)) + { + var fixture = physicsComponent.GetFixture(ThrowingFixture); + + if (fixture != null) + { + _broadphaseSystem.DestroyFixture(physicsComponent, fixture); + } + } + + EntityManager.EventBus.RaiseLocalEvent(uid, new StopThrowEvent {User = thrownItemComponent.Thrower?.Uid}); + EntityManager.RemoveComponent(uid); } public void LandComponent(ThrownItemComponent thrownItem) { - if (thrownItem.Owner.Deleted) return; + if (thrownItem.Deleted || thrownItem.Owner.Deleted || _containerSystem.IsEntityInContainer(thrownItem.Owner.Uid)) return; var landing = thrownItem.Owner; - if (!thrownItem.Owner.TryGetComponent(out PhysicsComponent? physicsComponent)) return; - - var fixture = physicsComponent.GetFixture(ThrowingFixture); - - if (fixture != null) - { - _broadphaseSystem.DestroyFixture(physicsComponent, fixture); - } - // Unfortunately we can't check for hands containers as they have specific names. if (thrownItem.Owner.TryGetContainerMan(out var containerManager) && containerManager.Owner.HasComponent()) @@ -102,13 +109,8 @@ namespace Content.Shared.Throwing return; } - var user = thrownItem.Thrower; - var coordinates = landing.Transform.Coordinates; - - var landMsg = new LandEvent(user, landing, coordinates); + var landMsg = new LandEvent {User = thrownItem.Thrower?.Uid}; RaiseLocalEvent(landing.Uid, landMsg, false); - - EntityManager.RemoveComponent(landing.Uid, thrownItem); } ///