Bullet impact effects (#9530)

This commit is contained in:
metalgearsloth
2022-07-09 13:46:11 +10:00
committed by GitHub
parent 1b5f88e4d0
commit 5107bc3be7
14 changed files with 175 additions and 85 deletions

View File

@@ -1,3 +1,4 @@
using Content.Server.Projectiles;
using Content.Server.Projectiles.Components;
using Content.Server.Singularity.Components;
using Content.Shared.Singularity.Components;
@@ -29,7 +30,8 @@ namespace Content.Server.ParticleAccelerator.Components
Logger.Error("ParticleProjectile tried firing, but it was spawned without a ProjectileComponent");
return;
}
projectileComponent.IgnoreEntity(firer);
_entMan.EntitySysManager.GetEntitySystem<ProjectileSystem>().SetShooter(projectileComponent, firer);
if (!_entMan.TryGetComponent<SinguloFoodComponent?>(Owner, out var singuloFoodComponent))
{

View File

@@ -22,22 +22,5 @@ namespace Content.Server.Projectiles.Components
public bool ForceSound = false;
public bool DamagedEntity;
public float TimeLeft { get; set; } = 10;
/// <summary>
/// Function that makes the collision of this object ignore a specific entity so we don't collide with ourselves
/// </summary>
/// <param name="shooter"></param>
public void IgnoreEntity(EntityUid shooter)
{
Shooter = shooter;
Dirty();
}
public override ComponentState GetComponentState()
{
return new ProjectileComponentState(Shooter, IgnoreShooter);
}
}
}

View File

@@ -1,19 +1,13 @@
using Content.Server.Administration.Logs;
using Content.Server.Projectiles.Components;
using Content.Server.Weapon.Melee;
using Content.Server.Weapon.Ranged;
using Content.Shared.Audio;
using Content.Shared.Body.Components;
using Content.Shared.Camera;
using Content.Shared.Damage;
using Content.Shared.Database;
using Content.Shared.Projectiles;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using GunSystem = Content.Server.Weapon.Ranged.Systems.GunSystem;
namespace Content.Server.Projectiles
@@ -29,16 +23,20 @@ namespace Content.Server.Projectiles
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ProjectileComponent, StartCollideEvent>(HandleCollide);
SubscribeLocalEvent<ProjectileComponent, StartCollideEvent>(OnStartCollide);
SubscribeLocalEvent<ProjectileComponent, ComponentGetState>(OnGetState);
}
private void HandleCollide(EntityUid uid, ProjectileComponent component, StartCollideEvent args)
private void OnGetState(EntityUid uid, ProjectileComponent component, ref ComponentGetState args)
{
args.State = new ProjectileComponentState(component.Shooter, component.IgnoreShooter);
}
private void OnStartCollide(EntityUid uid, ProjectileComponent component, StartCollideEvent args)
{
// This is so entities that shouldn't get a collision are ignored.
if (args.OurFixture.ID != ProjectileFixture || !args.OtherFixture.Hard || component.DamagedEntity)
{
return;
}
var otherEntity = args.OtherFixture.Body.Owner;
@@ -62,20 +60,12 @@ namespace Content.Server.Projectiles
}
if (component.DeleteOnCollide)
QueueDel(uid);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
foreach (var component in EntityManager.EntityQuery<ProjectileComponent>())
{
component.TimeLeft -= frameTime;
QueueDel(uid);
if (component.TimeLeft <= 0)
if (component.ImpactEffect != null && TryComp<TransformComponent>(uid, out var xform))
{
EntityManager.DeleteEntity(component.Owner);
RaiseNetworkEvent(new ImpactEffectEvent(component.ImpactEffect, xform.Coordinates));
}
}
}

View File

@@ -2,6 +2,7 @@ using System.Threading;
using Content.Server.Administration.Logs;
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Server.Projectiles;
using Content.Server.Projectiles.Components;
using Content.Server.Singularity.Components;
using Content.Server.Storage.Components;
@@ -187,7 +188,7 @@ namespace Content.Server.Singularity.EntitySystems
return;
}
projectileComponent.IgnoreEntity(component.Owner);
Get<ProjectileSystem>().SetShooter(projectileComponent, component.Owner);
physicsComponent
.LinearVelocity = EntityManager.GetComponent<TransformComponent>(component.Owner).WorldRotation.ToWorldVec() * 20f;

View File

@@ -1,6 +1,7 @@
using Content.Server.GameTicking;
using Content.Server.Projectiles.Components;
using Content.Shared.Sound;
using Content.Shared.Spawners.Components;
using Robust.Shared.Map;
using Robust.Shared.Random;
@@ -116,7 +117,7 @@ namespace Content.Server.StationEvents.Events
physics.Mass * ((MaxAngularVelocity - MinAngularVelocity) * _robustRandom.NextFloat() +
MinAngularVelocity));
// TODO: God this disgusts me but projectile needs a refactor.
IoCManager.Resolve<IEntityManager>().GetComponent<ProjectileComponent>(meteor).TimeLeft = 120f;
IoCManager.Resolve<IEntityManager>().EnsureComponent<TimedDespawnComponent>(meteor).Lifetime = 120f;
}
}
}

View File

@@ -7,7 +7,6 @@ using Content.Shared.Audio;
using Content.Shared.Damage;
using Content.Shared.Database;
using Content.Shared.Sound;
using Content.Shared.Throwing;
using Content.Shared.Weapons.Ranged;
using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.Weapons.Ranged.Events;
@@ -16,7 +15,6 @@ using Robust.Shared.Audio;
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.Player;
using Robust.Shared.Random;
using Robust.Shared.Utility;
using SharedGunSystem = Content.Shared.Weapons.Ranged.Systems.SharedGunSystem;
@@ -168,7 +166,7 @@ public sealed partial class GunSystem : SharedGunSystem
if (user != null)
{
var projectile = EnsureComp<ProjectileComponent>(uid);
projectile.IgnoreEntity(user.Value);
Projectiles.SetShooter(projectile, user.Value);
}
Transform(uid).WorldRotation = direction.ToWorldAngle();