Files
OldThink/Content.Server/Explosion/Components/ExplosionLaunchedComponent.cs

41 lines
1.2 KiB
C#
Raw Normal View History

2021-06-09 22:19:39 +02:00
using Content.Server.Throwing;
using Content.Shared.Acts;
using Robust.Shared.GameObjects;
2021-12-03 11:11:52 +01:00
using Robust.Shared.IoC;
using Robust.Shared.Maths;
2021-06-09 22:19:39 +02:00
namespace Content.Server.Explosion.Components
{
[RegisterComponent]
public sealed class ExplosionLaunchedComponent : Component, IExAct
{
2021-12-08 17:17:12 +01:00
[Dependency] private readonly IEntityManager _entMan = default!;
void IExAct.OnExplosion(ExplosionEventArgs eventArgs)
{
2021-12-08 17:17:12 +01:00
if (_entMan.Deleted(Owner))
return;
var sourceLocation = eventArgs.Source;
2021-12-08 17:17:12 +01:00
var targetLocation = _entMan.GetComponent<TransformComponent>(eventArgs.Target).Coordinates;
if (sourceLocation.Equals(targetLocation)) return;
2021-12-08 17:17:12 +01:00
var offset = (targetLocation.ToMapPos(_entMan) - sourceLocation.ToMapPos(_entMan));
//Don't throw if the direction is center (0,0)
if (offset == Vector2.Zero) return;
var direction = offset.Normalized;
var throwForce = eventArgs.Severity switch
{
ExplosionSeverity.Heavy => 30,
ExplosionSeverity.Light => 20,
_ => 0,
};
Owner.TryThrow(direction, throwForce);
}
}
}