2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Throwing;
|
|
|
|
|
using Content.Shared.Acts;
|
2021-04-02 04:01:03 -06:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-11-26 03:32:22 -08:00
|
|
|
using Robust.Shared.Maths;
|
2021-04-02 04:01:03 -06:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Explosion.Components
|
2021-04-02 04:01:03 -06:00
|
|
|
{
|
|
|
|
|
[RegisterComponent]
|
|
|
|
|
public class ExplosionLaunchedComponent : Component, IExAct
|
|
|
|
|
{
|
|
|
|
|
public override string Name => "ExplosionLaunched";
|
|
|
|
|
|
|
|
|
|
void IExAct.OnExplosion(ExplosionEventArgs eventArgs)
|
|
|
|
|
{
|
|
|
|
|
if (Owner.Deleted)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var sourceLocation = eventArgs.Source;
|
2021-11-09 21:24:35 +01:00
|
|
|
var targetLocation = Owner.EntityManager.GetComponent<TransformComponent>(eventArgs.Target).Coordinates;
|
2021-07-25 16:58:02 +10:00
|
|
|
|
|
|
|
|
if (sourceLocation.Equals(targetLocation)) return;
|
|
|
|
|
|
2021-11-26 03:32:22 -08:00
|
|
|
var offset = (targetLocation.ToMapPos(Owner.EntityManager) - sourceLocation.ToMapPos(Owner.EntityManager));
|
|
|
|
|
|
|
|
|
|
//Don't throw if the direction is center (0,0)
|
|
|
|
|
if (offset == Vector2.Zero) return;
|
|
|
|
|
|
|
|
|
|
var direction = offset.Normalized;
|
2021-04-02 04:01:03 -06:00
|
|
|
|
|
|
|
|
var throwForce = eventArgs.Severity switch
|
|
|
|
|
{
|
|
|
|
|
ExplosionSeverity.Heavy => 30,
|
|
|
|
|
ExplosionSeverity.Light => 20,
|
|
|
|
|
_ => 0,
|
|
|
|
|
};
|
2021-11-09 21:24:35 +01:00
|
|
|
|
2021-07-25 16:58:02 +10:00
|
|
|
Owner.TryThrow(direction, throwForce);
|
2021-04-02 04:01:03 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|