Throwing tweaks (#4705)
* Throwing tweaks Landing is when the timer stops, throwing stops when it stops moving. * Review
This commit is contained in:
@@ -5,31 +5,19 @@ using Robust.Shared.Map;
|
||||
namespace Content.Shared.Throwing
|
||||
{
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public sealed class LandEvent : EntityEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// Entity that threw the item.
|
||||
/// </summary>
|
||||
public IEntity? User { get; }
|
||||
public EntityUid? User;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Item that was thrown.
|
||||
/// </summary>
|
||||
public IEntity Thrown { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Location where the item landed.
|
||||
/// </summary>
|
||||
public EntityCoordinates LandLocation { get; }
|
||||
|
||||
public LandEvent(IEntity? user, IEntity thrown, EntityCoordinates landLocation)
|
||||
{
|
||||
User = user;
|
||||
Thrown = thrown;
|
||||
LandLocation = landLocation;
|
||||
}
|
||||
/// <summary>
|
||||
/// Raised when a thrown entity is no longer moving.
|
||||
/// </summary>
|
||||
public sealed class StopThrowEvent : EntityEventArgs
|
||||
{
|
||||
public EntityUid? User;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ namespace Content.Shared.Throwing
|
||||
/// </summary>
|
||||
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<ThrownItemComponent>(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<SharedHandsComponent>())
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user