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,19 +1,8 @@
using Content.Shared.Projectiles; using Content.Shared.Projectiles;
using Robust.Shared.GameObjects;
namespace Content.Client.Projectiles namespace Content.Client.Projectiles
{ {
[RegisterComponent] [RegisterComponent]
[ComponentReference(typeof(SharedProjectileComponent))] [ComponentReference(typeof(SharedProjectileComponent))]
public sealed class ProjectileComponent : SharedProjectileComponent public sealed class ProjectileComponent : SharedProjectileComponent {}
{
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
if (curState is ProjectileComponentState compState)
{
Shooter = compState.Shooter;
IgnoreShooter = compState.IgnoreShooter;
}
}
}
} }

View File

@@ -0,0 +1,61 @@
using Content.Shared.Projectiles;
using Content.Shared.Spawners.Components;
using Content.Shared.Weapons.Ranged.Systems;
using Robust.Client.Animations;
using Robust.Client.GameObjects;
using Robust.Shared.GameStates;
namespace Content.Client.Projectiles;
public sealed class ProjectileSystem : SharedProjectileSystem
{
[Dependency] private readonly AnimationPlayerSystem _player = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ProjectileComponent, ComponentHandleState>(OnHandleState);
SubscribeNetworkEvent<ImpactEffectEvent>(OnProjectileImpact);
}
private void OnProjectileImpact(ImpactEffectEvent ev)
{
var ent = Spawn(ev.Prototype, ev.Coordinates);
if (TryComp<SpriteComponent>(ent, out var sprite))
{
sprite[EffectLayers.Unshaded].AutoAnimated = false;
sprite.LayerMapTryGet(EffectLayers.Unshaded, out var layer);
var state = sprite.LayerGetState(layer);
var lifetime = 0.5f;
if (TryComp<TimedDespawnComponent>(ent, out var despawn))
lifetime = despawn.Lifetime;
var anim = new Animation()
{
Length = TimeSpan.FromSeconds(lifetime),
AnimationTracks =
{
new AnimationTrackSpriteFlick()
{
LayerKey = EffectLayers.Unshaded,
KeyFrames =
{
new AnimationTrackSpriteFlick.KeyFrame(state.Name, 0f),
}
}
}
};
_player.Play(ent, anim, "impact-effect");
}
}
private void OnHandleState(EntityUid uid, ProjectileComponent component, ref ComponentHandleState args)
{
if (args.Current is not ProjectileComponentState state) return;
component.Shooter = state.Shooter;
component.IgnoreShooter = state.IgnoreShooter;
}
}

View File

@@ -1,3 +1,4 @@
using Content.Server.Projectiles;
using Content.Server.Projectiles.Components; using Content.Server.Projectiles.Components;
using Content.Server.Singularity.Components; using Content.Server.Singularity.Components;
using Content.Shared.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"); Logger.Error("ParticleProjectile tried firing, but it was spawned without a ProjectileComponent");
return; return;
} }
projectileComponent.IgnoreEntity(firer);
_entMan.EntitySysManager.GetEntitySystem<ProjectileSystem>().SetShooter(projectileComponent, firer);
if (!_entMan.TryGetComponent<SinguloFoodComponent?>(Owner, out var singuloFoodComponent)) 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 ForceSound = false;
public bool DamagedEntity; 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.Administration.Logs;
using Content.Server.Projectiles.Components; 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.Camera;
using Content.Shared.Damage; using Content.Shared.Damage;
using Content.Shared.Database; using Content.Shared.Database;
using Content.Shared.Projectiles; using Content.Shared.Projectiles;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.Audio; using Robust.Shared.GameStates;
using Robust.Shared.Physics.Dynamics; using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using GunSystem = Content.Server.Weapon.Ranged.Systems.GunSystem; using GunSystem = Content.Server.Weapon.Ranged.Systems.GunSystem;
namespace Content.Server.Projectiles namespace Content.Server.Projectiles
@@ -29,16 +23,20 @@ namespace Content.Server.Projectiles
public override void Initialize() public override void Initialize()
{ {
base.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. // This is so entities that shouldn't get a collision are ignored.
if (args.OurFixture.ID != ProjectileFixture || !args.OtherFixture.Hard || component.DamagedEntity) if (args.OurFixture.ID != ProjectileFixture || !args.OtherFixture.Hard || component.DamagedEntity)
{
return; return;
}
var otherEntity = args.OtherFixture.Body.Owner; var otherEntity = args.OtherFixture.Body.Owner;
@@ -62,20 +60,12 @@ namespace Content.Server.Projectiles
} }
if (component.DeleteOnCollide) if (component.DeleteOnCollide)
{
QueueDel(uid); QueueDel(uid);
}
public override void Update(float frameTime) if (component.ImpactEffect != null && TryComp<TransformComponent>(uid, out var xform))
{ {
base.Update(frameTime); RaiseNetworkEvent(new ImpactEffectEvent(component.ImpactEffect, xform.Coordinates));
foreach (var component in EntityManager.EntityQuery<ProjectileComponent>())
{
component.TimeLeft -= frameTime;
if (component.TimeLeft <= 0)
{
EntityManager.DeleteEntity(component.Owner);
} }
} }
} }

View File

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

View File

@@ -1,6 +1,7 @@
using Content.Server.GameTicking; using Content.Server.GameTicking;
using Content.Server.Projectiles.Components; using Content.Server.Projectiles.Components;
using Content.Shared.Sound; using Content.Shared.Sound;
using Content.Shared.Spawners.Components;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Random; using Robust.Shared.Random;
@@ -116,7 +117,7 @@ namespace Content.Server.StationEvents.Events
physics.Mass * ((MaxAngularVelocity - MinAngularVelocity) * _robustRandom.NextFloat() + physics.Mass * ((MaxAngularVelocity - MinAngularVelocity) * _robustRandom.NextFloat() +
MinAngularVelocity)); MinAngularVelocity));
// TODO: God this disgusts me but projectile needs a refactor. // 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.Damage;
using Content.Shared.Database; using Content.Shared.Database;
using Content.Shared.Sound; using Content.Shared.Sound;
using Content.Shared.Throwing;
using Content.Shared.Weapons.Ranged; using Content.Shared.Weapons.Ranged;
using Content.Shared.Weapons.Ranged.Components; using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.Weapons.Ranged.Events; using Content.Shared.Weapons.Ranged.Events;
@@ -16,7 +15,6 @@ using Robust.Shared.Audio;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Physics; using Robust.Shared.Physics;
using Robust.Shared.Player; using Robust.Shared.Player;
using Robust.Shared.Random;
using Robust.Shared.Utility; using Robust.Shared.Utility;
using SharedGunSystem = Content.Shared.Weapons.Ranged.Systems.SharedGunSystem; using SharedGunSystem = Content.Shared.Weapons.Ranged.Systems.SharedGunSystem;
@@ -168,7 +166,7 @@ public sealed partial class GunSystem : SharedGunSystem
if (user != null) if (user != null)
{ {
var projectile = EnsureComp<ProjectileComponent>(uid); var projectile = EnsureComp<ProjectileComponent>(uid);
projectile.IgnoreEntity(user.Value); Projectiles.SetShooter(projectile, user.Value);
} }
Transform(uid).WorldRotation = direction.ToWorldAngle(); Transform(uid).WorldRotation = direction.ToWorldAngle();

View File

@@ -1,13 +1,17 @@
using Robust.Shared.GameStates; using Robust.Shared.GameStates;
using Robust.Shared.Serialization; using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Shared.Projectiles namespace Content.Shared.Projectiles
{ {
[NetworkedComponent()] [NetworkedComponent, Access(typeof(SharedProjectileSystem))]
public abstract class SharedProjectileComponent : Component public abstract class SharedProjectileComponent : Component
{ {
[ViewVariables(VVAccess.ReadWrite), DataField("impactEffect", customTypeSerializer:typeof(PrototypeIdSerializer<EntityPrototype>))]
public string? ImpactEffect;
private bool _ignoreShooter = true; private bool _ignoreShooter = true;
public EntityUid Shooter { get; protected set; } public EntityUid Shooter { get; set; }
public bool IgnoreShooter public bool IgnoreShooter
{ {
@@ -20,18 +24,5 @@ namespace Content.Shared.Projectiles
Dirty(); Dirty();
} }
} }
[NetSerializable, Serializable]
protected sealed class ProjectileComponentState : ComponentState
{
public ProjectileComponentState(EntityUid shooter, bool ignoreShooter)
{
Shooter = shooter;
IgnoreShooter = ignoreShooter;
}
public EntityUid Shooter { get; }
public bool IgnoreShooter { get; }
}
} }
} }

View File

@@ -1,4 +1,6 @@
using Robust.Shared.Map;
using Robust.Shared.Physics.Dynamics; using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Serialization;
namespace Content.Shared.Projectiles namespace Content.Shared.Projectiles
{ {
@@ -20,5 +22,39 @@ namespace Content.Shared.Projectiles
return; return;
} }
} }
public void SetShooter(SharedProjectileComponent component, EntityUid uid)
{
if (component.Shooter == uid) return;
component.Shooter = uid;
Dirty(component);
}
[NetSerializable, Serializable]
protected sealed class ProjectileComponentState : ComponentState
{
public ProjectileComponentState(EntityUid shooter, bool ignoreShooter)
{
Shooter = shooter;
IgnoreShooter = ignoreShooter;
}
public EntityUid Shooter { get; }
public bool IgnoreShooter { get; }
}
[Serializable, NetSerializable]
protected sealed class ImpactEffectEvent : EntityEventArgs
{
public string Prototype;
public EntityCoordinates Coordinates;
public ImpactEffectEvent(string prototype, EntityCoordinates coordinates)
{
Prototype = prototype;
Coordinates = coordinates;
}
}
} }
} }

View File

@@ -8,6 +8,7 @@ using Content.Shared.Examine;
using Content.Shared.Hands.Components; using Content.Shared.Hands.Components;
using Content.Shared.Interaction.Events; using Content.Shared.Interaction.Events;
using Content.Shared.Popups; using Content.Shared.Popups;
using Content.Shared.Projectiles;
using Content.Shared.Throwing; using Content.Shared.Throwing;
using Content.Shared.Verbs; using Content.Shared.Verbs;
using Content.Shared.Weapons.Ranged.Components; using Content.Shared.Weapons.Ranged.Components;
@@ -43,7 +44,8 @@ public abstract partial class SharedGunSystem : EntitySystem
[Dependency] protected readonly SharedPhysicsSystem Physics = default!; [Dependency] protected readonly SharedPhysicsSystem Physics = default!;
[Dependency] protected readonly SharedPopupSystem PopupSystem = default!; [Dependency] protected readonly SharedPopupSystem PopupSystem = default!;
[Dependency] protected readonly ThrowingSystem ThrowingSystem = default!; [Dependency] protected readonly ThrowingSystem ThrowingSystem = default!;
[Dependency] protected readonly TagSystem _tagSystem = default!; [Dependency] protected readonly TagSystem TagSystem = default!;
[Dependency] protected readonly SharedProjectileSystem Projectiles = default!;
protected ISawmill Sawmill = default!; protected ISawmill Sawmill = default!;
@@ -88,7 +90,7 @@ public abstract partial class SharedGunSystem : EntitySystem
private void OnGunMeleeAttempt(EntityUid uid, GunComponent component, ref MeleeAttackAttemptEvent args) private void OnGunMeleeAttempt(EntityUid uid, GunComponent component, ref MeleeAttackAttemptEvent args)
{ {
if (_tagSystem.HasTag(args.User, "GunsDisabled")) if (TagSystem.HasTag(args.User, "GunsDisabled"))
return; return;
args.Cancelled = true; args.Cancelled = true;
@@ -186,7 +188,7 @@ public abstract partial class SharedGunSystem : EntitySystem
if (toCoordinates == null) return; if (toCoordinates == null) return;
if (_tagSystem.HasTag(user, "GunsDisabled")) if (TagSystem.HasTag(user, "GunsDisabled"))
{ {
Popup(Loc.GetString("gun-disabled"), user, user); Popup(Loc.GetString("gun-disabled"), user, user);
return; return;

View File

@@ -0,0 +1,32 @@
- type: entity
id: BulletImpactEffect
noSpawn: true
components:
- type: TimedDespawn
lifetime: 0.25
- type: Sprite
netsync: false
drawdepth: Effects
layers:
- shader: unshaded
map: ["enum.EffectLayers.Unshaded"]
sprite: Objects/Weapons/Guns/Projectiles/projectiles_tg.rsi
state: impact_bullet
- type: EffectVisuals
- type: entity
id: BulletImpactEffectDisabler
noSpawn: true
components:
- type: TimedDespawn
lifetime: 0.2
- type: Sprite
netsync: false
drawdepth: Effects
layers:
- shader: unshaded
map: ["enum.EffectLayers.Unshaded"]
sprite: Objects/Weapons/Guns/Projectiles/projectiles_tg.rsi
state: impact_laser_blue
- type: EffectVisuals

View File

@@ -29,11 +29,14 @@
- Impassable - Impassable
- BulletImpassable - BulletImpassable
- type: Projectile - type: Projectile
impactEffect: BulletImpactEffect
damage: damage:
types: types:
Piercing: 14 Piercing: 14
soundHit: soundHit:
path: /Audio/Weapons/Guns/Hits/bullet_hit.ogg path: /Audio/Weapons/Guns/Hits/bullet_hit.ogg
- type: TimedDespawn
lifetime: 10
- type: entity - type: entity
id: BaseBulletTrigger # Trigger-on-collide bullets id: BaseBulletTrigger # Trigger-on-collide bullets
@@ -126,6 +129,7 @@
- type: StaminaDamageOnCollide - type: StaminaDamageOnCollide
damage: 30 damage: 30
- type: Projectile - type: Projectile
impactEffect: BulletImpactEffectDisabler
damage: damage:
types: types:
Heat: 5 Heat: 5

View File

@@ -14,11 +14,11 @@
"name": "impact_bullet", "name": "impact_bullet",
"delays": [ "delays": [
[ [
0.1, 0.05,
0.1, 0.05,
0.1, 0.05,
0.1, 0.05,
0.1 0.05
] ]
] ]
}, },
@@ -26,10 +26,10 @@
"name": "impact_laser_blue", "name": "impact_laser_blue",
"delays": [ "delays": [
[ [
0.1, 0.05,
0.1, 0.05,
0.1, 0.05,
0.1 0.05
] ]
] ]
} }