(mostly) ECS projectiles (#4317)
* (mostly) ECS projectiles * a * Actual queue
This commit is contained in:
@@ -1,13 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Content.Server.Camera;
|
|
||||||
using Content.Shared.Damage;
|
using Content.Shared.Damage;
|
||||||
using Content.Shared.Damage.Components;
|
|
||||||
using Content.Shared.Projectiles;
|
using Content.Shared.Projectiles;
|
||||||
using Robust.Shared.Audio;
|
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.Physics.Collision;
|
|
||||||
using Robust.Shared.Physics.Dynamics;
|
|
||||||
using Robust.Shared.Player;
|
|
||||||
using Robust.Shared.Players;
|
using Robust.Shared.Players;
|
||||||
using Robust.Shared.Serialization.Manager.Attributes;
|
using Robust.Shared.Serialization.Manager.Attributes;
|
||||||
using Robust.Shared.ViewVariables;
|
using Robust.Shared.ViewVariables;
|
||||||
@@ -16,9 +10,8 @@ namespace Content.Server.Projectiles.Components
|
|||||||
{
|
{
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
[ComponentReference(typeof(SharedProjectileComponent))]
|
[ComponentReference(typeof(SharedProjectileComponent))]
|
||||||
public class ProjectileComponent : SharedProjectileComponent, IStartCollide
|
public class ProjectileComponent : SharedProjectileComponent
|
||||||
{
|
{
|
||||||
|
|
||||||
[DataField("damages")] private Dictionary<DamageType, int> _damages = new();
|
[DataField("damages")] private Dictionary<DamageType, int> _damages = new();
|
||||||
|
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
@@ -32,12 +25,10 @@ namespace Content.Server.Projectiles.Components
|
|||||||
public bool DeleteOnCollide { get; } = true;
|
public bool DeleteOnCollide { get; } = true;
|
||||||
|
|
||||||
// Get that juicy FPS hit sound
|
// Get that juicy FPS hit sound
|
||||||
[DataField("soundHit")]
|
[DataField("soundHit")] public string? SoundHit = default;
|
||||||
private string? _soundHit = default;
|
[DataField("soundHitSpecies")] public string? SoundHitSpecies = default;
|
||||||
[DataField("soundHitSpecies")]
|
|
||||||
private string? _soundHitSpecies = default;
|
|
||||||
|
|
||||||
private bool _damagedEntity;
|
public bool DamagedEntity;
|
||||||
|
|
||||||
public float TimeLeft { get; set; } = 10;
|
public float TimeLeft { get; set; } = 10;
|
||||||
|
|
||||||
@@ -51,51 +42,6 @@ namespace Content.Server.Projectiles.Components
|
|||||||
Dirty();
|
Dirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Applies the damage when our projectile collides with its victim
|
|
||||||
/// </summary>
|
|
||||||
void IStartCollide.CollideWith(Fixture ourFixture, Fixture otherFixture, in Manifold manifold)
|
|
||||||
{
|
|
||||||
// This is so entities that shouldn't get a collision are ignored.
|
|
||||||
if (!otherFixture.Hard || _damagedEntity)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var coordinates = otherFixture.Body.Owner.Transform.Coordinates;
|
|
||||||
var playerFilter = Filter.Pvs(coordinates);
|
|
||||||
if (otherFixture.Body.Owner.TryGetComponent(out IDamageableComponent? damage) && _soundHitSpecies != null)
|
|
||||||
{
|
|
||||||
SoundSystem.Play(playerFilter, _soundHitSpecies, coordinates);
|
|
||||||
}
|
|
||||||
else if (_soundHit != null)
|
|
||||||
{
|
|
||||||
SoundSystem.Play(playerFilter, _soundHit, coordinates);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (damage != null)
|
|
||||||
{
|
|
||||||
Owner.EntityManager.TryGetEntity(Shooter, out var shooter);
|
|
||||||
|
|
||||||
foreach (var (damageType, amount) in _damages)
|
|
||||||
{
|
|
||||||
damage.ChangeDamage(damageType, amount, false, shooter);
|
|
||||||
}
|
|
||||||
|
|
||||||
_damagedEntity = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Damaging it can delete it
|
|
||||||
if (!otherFixture.Body.Deleted && otherFixture.Body.Owner.TryGetComponent(out CameraRecoilComponent? recoilComponent))
|
|
||||||
{
|
|
||||||
var direction = ourFixture.Body.LinearVelocity.Normalized;
|
|
||||||
recoilComponent.Kick(direction);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(DeleteOnCollide)
|
|
||||||
Owner.QueueDelete();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override ComponentState GetComponentState(ICommonSession player)
|
public override ComponentState GetComponentState(ICommonSession player)
|
||||||
{
|
{
|
||||||
return new ProjectileComponentState(Shooter, IgnoreShooter);
|
return new ProjectileComponentState(Shooter, IgnoreShooter);
|
||||||
|
|||||||
@@ -1,17 +1,70 @@
|
|||||||
|
using Content.Server.Camera;
|
||||||
using Content.Server.Projectiles.Components;
|
using Content.Server.Projectiles.Components;
|
||||||
|
using Content.Shared.Damage.Components;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
using Robust.Shared.Audio;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Physics.Dynamics;
|
||||||
|
using Robust.Shared.Player;
|
||||||
|
|
||||||
namespace Content.Server.Projectiles
|
namespace Content.Server.Projectiles
|
||||||
{
|
{
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
internal sealed class ProjectileSystem : EntitySystem
|
internal sealed class ProjectileSystem : EntitySystem
|
||||||
{
|
{
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
SubscribeLocalEvent<ProjectileComponent, StartCollideEvent>(HandleCollide);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleCollide(EntityUid uid, ProjectileComponent component, StartCollideEvent args)
|
||||||
|
{
|
||||||
|
// This is so entities that shouldn't get a collision are ignored.
|
||||||
|
if (!args.OtherFixture.Hard || component.DamagedEntity)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var coordinates = args.OtherFixture.Body.Owner.Transform.Coordinates;
|
||||||
|
var playerFilter = Filter.Pvs(coordinates);
|
||||||
|
if (args.OtherFixture.Body.Owner.TryGetComponent(out IDamageableComponent? damage) && component.SoundHitSpecies != null)
|
||||||
|
{
|
||||||
|
SoundSystem.Play(playerFilter, component.SoundHitSpecies, coordinates);
|
||||||
|
}
|
||||||
|
else if (component.SoundHit != null)
|
||||||
|
{
|
||||||
|
SoundSystem.Play(playerFilter, component.SoundHit, coordinates);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (damage != null)
|
||||||
|
{
|
||||||
|
EntityManager.TryGetEntity(component.Shooter, out var shooter);
|
||||||
|
|
||||||
|
foreach (var (damageType, amount) in component.Damages)
|
||||||
|
{
|
||||||
|
damage.ChangeDamage(damageType, amount, false, shooter);
|
||||||
|
}
|
||||||
|
|
||||||
|
component.DamagedEntity = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Damaging it can delete it
|
||||||
|
if (!args.OtherFixture.Body.Deleted && args.OtherFixture.Body.Owner.TryGetComponent(out CameraRecoilComponent? recoilComponent))
|
||||||
|
{
|
||||||
|
var direction = args.OurFixture.Body.LinearVelocity.Normalized;
|
||||||
|
recoilComponent.Kick(direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (component.DeleteOnCollide)
|
||||||
|
EntityManager.QueueDeleteEntity(uid);
|
||||||
|
}
|
||||||
|
|
||||||
public override void Update(float frameTime)
|
public override void Update(float frameTime)
|
||||||
{
|
{
|
||||||
base.Update(frameTime);
|
base.Update(frameTime);
|
||||||
|
|
||||||
foreach (var component in ComponentManager.EntityQuery<ProjectileComponent>(true))
|
foreach (var component in ComponentManager.EntityQuery<ProjectileComponent>())
|
||||||
{
|
{
|
||||||
component.TimeLeft -= frameTime;
|
component.TimeLeft -= frameTime;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user