Files
OldThink/Content.Shared/Projectiles/SharedProjectileSystem.cs

74 lines
2.5 KiB
C#
Raw Normal View History

using Content.Shared.Projectiles;
2023-05-27 14:15:15 +10:00
using Content.Shared.Weapons.Ranged.Components;
2022-07-09 13:46:11 +10:00
using Robust.Shared.Map;
2023-05-27 14:15:15 +10:00
using Robust.Shared.Physics;
using Robust.Shared.Physics.Events;
2023-05-27 14:15:15 +10:00
using Robust.Shared.Physics.Systems;
2022-07-09 13:46:11 +10:00
using Robust.Shared.Serialization;
2021-06-09 22:19:39 +02:00
namespace Content.Shared.Projectiles
{
2022-05-21 18:04:47 +10:00
public abstract class SharedProjectileSystem : EntitySystem
{
2022-05-21 18:04:47 +10:00
public const string ProjectileFixture = "projectile";
2023-05-27 14:15:15 +10:00
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ProjectileComponent, PreventCollideEvent>(PreventCollision);
2023-05-27 14:15:15 +10:00
SubscribeLocalEvent<EmbeddableProjectileComponent, StartCollideEvent>(OnEmbedCollide);
}
private void OnEmbedCollide(EntityUid uid, EmbeddableProjectileComponent component, ref StartCollideEvent args)
{
if (!TryComp<ProjectileComponent>(uid, out var projectile))
return;
_physics.SetLinearVelocity(uid, Vector2.Zero, body: args.OurBody);
_physics.SetBodyType(uid, BodyType.Static, body: args.OurBody);
_transform.SetParent(uid, args.OtherEntity);
var ev = new ProjectileEmbedEvent(projectile.Shooter, projectile.Weapon, args.OtherEntity);
RaiseLocalEvent(uid, ref ev);
}
private void PreventCollision(EntityUid uid, ProjectileComponent component, ref PreventCollideEvent args)
{
2021-12-03 16:30:34 +01:00
if (component.IgnoreShooter && args.BodyB.Owner == component.Shooter)
{
args.Cancelled = true;
}
}
2022-07-09 13:46:11 +10:00
public void SetShooter(ProjectileComponent component, EntityUid uid)
2022-07-09 13:46:11 +10:00
{
2023-05-27 14:15:15 +10:00
if (component.Shooter == uid)
return;
2022-07-09 13:46:11 +10:00
component.Shooter = uid;
Dirty(component);
}
}
2022-07-09 13:46:11 +10:00
[Serializable, NetSerializable]
public sealed class ImpactEffectEvent : EntityEventArgs
{
public string Prototype;
public EntityCoordinates Coordinates;
2022-07-09 13:46:11 +10:00
public ImpactEffectEvent(string prototype, EntityCoordinates coordinates)
2022-07-09 13:46:11 +10:00
{
Prototype = prototype;
Coordinates = coordinates;
2022-07-09 13:46:11 +10:00
}
}
}
/// <summary>
/// Raised when entity is just about to be hit with projectile but can reflect it
/// </summary>
[ByRefEvent]
public record struct ProjectileReflectAttemptEvent(EntityUid ProjUid, ProjectileComponent Component, bool Cancelled);