@@ -1,5 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Content.Shared.Collections;
|
||||||
using Content.Shared.Hands.Components;
|
using Content.Shared.Hands.Components;
|
||||||
using Content.Shared.Physics;
|
using Content.Shared.Physics;
|
||||||
using Content.Shared.Physics.Pull;
|
using Content.Shared.Physics.Pull;
|
||||||
@@ -7,6 +8,7 @@ using Robust.Shared.Containers;
|
|||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Log;
|
using Robust.Shared.Log;
|
||||||
|
using Robust.Shared.Maths;
|
||||||
using Robust.Shared.Physics;
|
using Robust.Shared.Physics;
|
||||||
using Robust.Shared.Physics.Dynamics;
|
using Robust.Shared.Physics.Dynamics;
|
||||||
|
|
||||||
@@ -28,21 +30,28 @@ namespace Content.Shared.Throwing
|
|||||||
SubscribeLocalEvent<ThrownItemComponent, StartCollideEvent>(HandleCollision);
|
SubscribeLocalEvent<ThrownItemComponent, StartCollideEvent>(HandleCollision);
|
||||||
SubscribeLocalEvent<ThrownItemComponent, PreventCollideEvent>(PreventCollision);
|
SubscribeLocalEvent<ThrownItemComponent, PreventCollideEvent>(PreventCollision);
|
||||||
SubscribeLocalEvent<ThrownItemComponent, ThrownEvent>(ThrowItem);
|
SubscribeLocalEvent<ThrownItemComponent, ThrownEvent>(ThrowItem);
|
||||||
SubscribeLocalEvent<ThrownItemComponent, LandEvent>(LandItem);
|
|
||||||
SubscribeLocalEvent<PullStartedMessage>(HandlePullStarted);
|
SubscribeLocalEvent<PullStartedMessage>(HandlePullStarted);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LandItem(EntityUid uid, ThrownItemComponent component, LandEvent args)
|
public override void Update(float frameTime)
|
||||||
{
|
{
|
||||||
if (!component.Owner.TryGetComponent(out PhysicsComponent? physicsComponent)) return;
|
base.Update(frameTime);
|
||||||
|
|
||||||
var fixture = physicsComponent.GetFixture(ThrowingFixture);
|
var toRemove = new RemQueue<ThrownItemComponent>();
|
||||||
if (fixture == null)
|
|
||||||
|
// We can't just use sleeping unfortunately because there's a delay of the sleep timer. ThrownItemComponent
|
||||||
|
// is transient while the entity is thrown so this shouldn't be too bad.
|
||||||
|
foreach (var (thrown, physics) in ComponentManager.EntityQuery<ThrownItemComponent, PhysicsComponent>())
|
||||||
{
|
{
|
||||||
return;
|
if (!physics.LinearVelocity.Equals(Vector2.Zero)) continue;
|
||||||
|
toRemove.Add(thrown);
|
||||||
}
|
}
|
||||||
|
|
||||||
_broadphaseSystem.DestroyFixture(physicsComponent, fixture);
|
foreach (var comp in toRemove)
|
||||||
|
{
|
||||||
|
if (comp.Deleted) continue;
|
||||||
|
LandComponent(comp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ThrowItem(EntityUid uid, ThrownItemComponent component, ThrownEvent args)
|
private void ThrowItem(EntityUid uid, ThrownItemComponent component, ThrownEvent args)
|
||||||
@@ -79,10 +88,6 @@ namespace Content.Shared.Throwing
|
|||||||
|
|
||||||
private void HandleSleep(EntityUid uid, ThrownItemComponent thrownItem, PhysicsSleepMessage message)
|
private void HandleSleep(EntityUid uid, ThrownItemComponent thrownItem, PhysicsSleepMessage message)
|
||||||
{
|
{
|
||||||
// Unfortunately we can't check for hands containers as they have specific names.
|
|
||||||
if (EntityManager.GetEntity(uid).TryGetContainerMan(out var manager) &&
|
|
||||||
manager.Owner.HasComponent<SharedHandsComponent>()) return;
|
|
||||||
|
|
||||||
LandComponent(thrownItem);
|
LandComponent(thrownItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,8 +102,26 @@ namespace Content.Shared.Throwing
|
|||||||
{
|
{
|
||||||
if (thrownItem.Owner.Deleted) return;
|
if (thrownItem.Owner.Deleted) return;
|
||||||
|
|
||||||
var user = thrownItem.Thrower;
|
|
||||||
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.
|
||||||
|
if (thrownItem.Owner.TryGetContainerMan(out var containerManager) &&
|
||||||
|
containerManager.Owner.HasComponent<SharedHandsComponent>())
|
||||||
|
{
|
||||||
|
ComponentManager.RemoveComponent(landing.Uid, thrownItem);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var user = thrownItem.Thrower;
|
||||||
var coordinates = landing.Transform.Coordinates;
|
var coordinates = landing.Transform.Coordinates;
|
||||||
|
|
||||||
// LandInteraction
|
// LandInteraction
|
||||||
|
|||||||
Reference in New Issue
Block a user