Fix throwing.
This commit is contained in:
@@ -1,26 +1,27 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.GameObjects.Components.Projectiles;
|
||||
using Content.Server.GameObjects.Components.Projectiles;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.Physics;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Physics;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Timers;
|
||||
|
||||
namespace Content.Server.GameObjects.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
internal class ThrownItemComponent : ProjectileComponent, ICollideBehavior
|
||||
{
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly IEntitySystemManager _entitySystemManager;
|
||||
#pragma warning restore 649
|
||||
public const float DefaultThrowTime = 0.25f;
|
||||
|
||||
private bool _shouldCollide = true;
|
||||
|
||||
public override string Name => "ThrownItem";
|
||||
public override uint? NetID => ContentNetIDs.THROWN_ITEM;
|
||||
|
||||
/// <summary>
|
||||
/// User who threw the item.
|
||||
@@ -34,6 +35,7 @@ namespace Content.Server.GameObjects.Components
|
||||
{
|
||||
damage.TakeDamage(DamageType.Brute, 10, Owner, User);
|
||||
}
|
||||
|
||||
// Stop colliding with mobs, this mimics not having enough velocity to do damage
|
||||
// after impacting the first object.
|
||||
// For realism this should actually be changed when the velocity of the object is less than a threshold.
|
||||
@@ -44,20 +46,56 @@ namespace Content.Server.GameObjects.Components
|
||||
}
|
||||
}
|
||||
|
||||
public void PostCollide(int collideCount)
|
||||
private void StopThrow()
|
||||
{
|
||||
|
||||
if (collideCount > 0 && Owner.TryGetComponent(out CollidableComponent body) && body.PhysicsShapes.Count >= 1)
|
||||
if (Owner.TryGetComponent(out CollidableComponent body) && body.PhysicsShapes.Count >= 1)
|
||||
{
|
||||
body.PhysicsShapes[0].CollisionMask &= (int)~CollisionGroup.MobImpassable;
|
||||
body.PhysicsShapes[0].CollisionMask &= (int) ~CollisionGroup.ThrownItem;
|
||||
|
||||
// KYS, your job is finished. Trigger ILand as well.
|
||||
var physics = Owner.GetComponent<PhysicsComponent>();
|
||||
(physics.Controller as ThrowController).StopThrow();
|
||||
physics.RemoveController();
|
||||
physics.LinearVelocity = Vector2.Zero;
|
||||
physics.Status = BodyStatus.OnGround;
|
||||
body.Status = BodyStatus.OnGround;
|
||||
Owner.RemoveComponent<ThrownItemComponent>();
|
||||
_entitySystemManager.GetEntitySystem<InteractionSystem>().LandInteraction(User, Owner, Owner.Transform.GridPosition);
|
||||
EntitySystem.Get<InteractionSystem>().LandInteraction(User, Owner, Owner.Transform.GridPosition);
|
||||
}
|
||||
}
|
||||
|
||||
void ICollideBehavior.PostCollide(int collideCount)
|
||||
{
|
||||
if (collideCount > 0)
|
||||
{
|
||||
StopThrow();
|
||||
}
|
||||
}
|
||||
|
||||
public void StartThrow(Vector2 initialImpulse)
|
||||
{
|
||||
var comp = Owner.GetComponent<PhysicsComponent>();
|
||||
comp.Status = BodyStatus.InAir;
|
||||
comp.Momentum = initialImpulse;
|
||||
StartStopTimer();
|
||||
}
|
||||
|
||||
private void StartStopTimer()
|
||||
{
|
||||
Timer.Spawn((int) (DefaultThrowTime * 1000), MaybeStopThrow);
|
||||
}
|
||||
|
||||
private void MaybeStopThrow()
|
||||
{
|
||||
if (Deleted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (IoCManager.Resolve<IPhysicsManager>().IsWeightless(Owner.Transform.GridPosition))
|
||||
{
|
||||
StartStopTimer();
|
||||
return;
|
||||
}
|
||||
|
||||
StopThrow();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user