2018-10-30 01:13:10 -07:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using Content.Server.GameObjects.Components.Projectiles;
|
2019-07-18 23:33:02 +02:00
|
|
|
|
using Content.Server.GameObjects.EntitySystems;
|
2018-12-13 07:47:19 -06:00
|
|
|
|
using Content.Shared.GameObjects;
|
2018-10-30 01:13:10 -07:00
|
|
|
|
using Content.Shared.Physics;
|
2019-04-17 23:26:00 +02:00
|
|
|
|
using Robust.Server.GameObjects;
|
2019-07-18 23:33:02 +02:00
|
|
|
|
using Robust.Shared.GameObjects;
|
2020-01-11 14:12:20 -08:00
|
|
|
|
using Robust.Shared.GameObjects.Components;
|
2019-04-15 21:11:38 -06:00
|
|
|
|
using Robust.Shared.Interfaces.GameObjects;
|
2019-07-18 23:33:02 +02:00
|
|
|
|
using Robust.Shared.IoC;
|
2018-10-30 01:13:10 -07:00
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.GameObjects.Components
|
|
|
|
|
|
{
|
2019-07-31 15:02:36 +02:00
|
|
|
|
[RegisterComponent]
|
2020-01-11 14:12:20 -08:00
|
|
|
|
internal class ThrownItemComponent : ProjectileComponent, ICollideBehavior
|
2018-10-30 01:13:10 -07:00
|
|
|
|
{
|
2019-07-18 23:33:02 +02:00
|
|
|
|
#pragma warning disable 649
|
|
|
|
|
|
[Dependency] private readonly IEntitySystemManager _entitySystemManager;
|
|
|
|
|
|
#pragma warning restore 649
|
|
|
|
|
|
|
2020-05-23 01:23:36 +02:00
|
|
|
|
private bool _shouldCollide = true;
|
|
|
|
|
|
|
2018-10-30 01:13:10 -07:00
|
|
|
|
public override string Name => "ThrownItem";
|
|
|
|
|
|
|
2019-07-18 23:33:02 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// User who threw the item.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public IEntity User;
|
|
|
|
|
|
|
2020-05-23 01:23:36 +02:00
|
|
|
|
void ICollideBehavior.CollideWith(IEntity entity)
|
2018-10-30 01:13:10 -07:00
|
|
|
|
{
|
2020-05-23 01:23:36 +02:00
|
|
|
|
if (!_shouldCollide) return;
|
|
|
|
|
|
if (entity.TryGetComponent(out DamageableComponent damage))
|
2018-10-30 01:13:10 -07:00
|
|
|
|
{
|
2020-05-23 01:23:36 +02:00
|
|
|
|
damage.TakeDamage(DamageType.Brute, 10, Owner, User);
|
2018-10-30 01:13:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
// 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.
|
|
|
|
|
|
// This would allow ricochets off walls, and weird gravity effects from slowing the object.
|
2020-05-23 01:23:36 +02:00
|
|
|
|
if (Owner.TryGetComponent(out CollidableComponent body) && body.PhysicsShapes.Count >= 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
_shouldCollide = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void PostCollide(int collideCount)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
if (collideCount > 0 && Owner.TryGetComponent(out CollidableComponent body) && body.PhysicsShapes.Count >= 1)
|
2018-10-30 01:13:10 -07:00
|
|
|
|
{
|
2019-12-01 09:20:50 -05:00
|
|
|
|
body.PhysicsShapes[0].CollisionMask &= (int)~CollisionGroup.MobImpassable;
|
2018-10-30 01:13:10 -07:00
|
|
|
|
|
2019-07-18 23:33:02 +02:00
|
|
|
|
// KYS, your job is finished. Trigger ILand as well.
|
2020-05-23 01:23:36 +02:00
|
|
|
|
var physics = Owner.GetComponent<PhysicsComponent>();
|
|
|
|
|
|
(physics.Controller as ThrowController).StopThrow();
|
|
|
|
|
|
physics.RemoveController();
|
2018-10-30 01:13:10 -07:00
|
|
|
|
Owner.RemoveComponent<ThrownItemComponent>();
|
2019-07-18 23:33:02 +02:00
|
|
|
|
_entitySystemManager.GetEntitySystem<InteractionSystem>().LandInteraction(User, Owner, Owner.Transform.GridPosition);
|
2018-10-30 01:13:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|