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
|
namespace Content.Shared.Throwing
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public sealed class LandEvent : EntityEventArgs
|
public sealed class LandEvent : EntityEventArgs
|
||||||
{
|
{
|
||||||
/// <summary>
|
public EntityUid? User;
|
||||||
/// Entity that threw the item.
|
}
|
||||||
/// </summary>
|
|
||||||
public IEntity? User { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Item that was thrown.
|
/// Raised when a thrown entity is no longer moving.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IEntity Thrown { get; }
|
public sealed class StopThrowEvent : EntityEventArgs
|
||||||
|
{
|
||||||
/// <summary>
|
public EntityUid? User;
|
||||||
/// Location where the item landed.
|
|
||||||
/// </summary>
|
|
||||||
public EntityCoordinates LandLocation { get; }
|
|
||||||
|
|
||||||
public LandEvent(IEntity? user, IEntity thrown, EntityCoordinates landLocation)
|
|
||||||
{
|
|
||||||
User = user;
|
|
||||||
Thrown = thrown;
|
|
||||||
LandLocation = landLocation;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ namespace Content.Shared.Throwing
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ThrownItemSystem : EntitySystem
|
public class ThrownItemSystem : EntitySystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
|
||||||
[Dependency] private readonly SharedBroadphaseSystem _broadphaseSystem = default!;
|
[Dependency] private readonly SharedBroadphaseSystem _broadphaseSystem = default!;
|
||||||
|
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
|
||||||
|
|
||||||
private const string ThrowingFixture = "throw-fixture";
|
private const string ThrowingFixture = "throw-fixture";
|
||||||
|
|
||||||
@@ -69,31 +69,38 @@ namespace Content.Shared.Throwing
|
|||||||
|
|
||||||
private void HandleSleep(EntityUid uid, ThrownItemComponent thrownItem, PhysicsSleepMessage message)
|
private void HandleSleep(EntityUid uid, ThrownItemComponent thrownItem, PhysicsSleepMessage message)
|
||||||
{
|
{
|
||||||
LandComponent(thrownItem);
|
StopThrow(uid, thrownItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandlePullStarted(PullStartedMessage message)
|
private void HandlePullStarted(PullStartedMessage message)
|
||||||
{
|
{
|
||||||
// TODO: this isn't directed so things have to be done the bad way
|
// TODO: this isn't directed so things have to be done the bad way
|
||||||
if (message.Pulled.Owner.TryGetComponent(out ThrownItemComponent? thrownItem))
|
if (EntityManager.TryGetComponent(message.Pulled.Owner.Uid, out ThrownItemComponent? thrownItemComponent))
|
||||||
LandComponent(thrownItem);
|
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)
|
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;
|
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.
|
// Unfortunately we can't check for hands containers as they have specific names.
|
||||||
if (thrownItem.Owner.TryGetContainerMan(out var containerManager) &&
|
if (thrownItem.Owner.TryGetContainerMan(out var containerManager) &&
|
||||||
containerManager.Owner.HasComponent<SharedHandsComponent>())
|
containerManager.Owner.HasComponent<SharedHandsComponent>())
|
||||||
@@ -102,13 +109,8 @@ namespace Content.Shared.Throwing
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var user = thrownItem.Thrower;
|
var landMsg = new LandEvent {User = thrownItem.Thrower?.Uid};
|
||||||
var coordinates = landing.Transform.Coordinates;
|
|
||||||
|
|
||||||
var landMsg = new LandEvent(user, landing, coordinates);
|
|
||||||
RaiseLocalEvent(landing.Uid, landMsg, false);
|
RaiseLocalEvent(landing.Uid, landMsg, false);
|
||||||
|
|
||||||
EntityManager.RemoveComponent(landing.Uid, thrownItem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user