CatStation/Content.Client/Projectiles/ProjectileSystem.cs
Pieter-Jan Briers 5168b5f3d4
IoC source gen compatibility (#43863)
* IoC source gen compatibility

Can be merged before or after https://github.com/space-wizards/RobustToolbox/pull/6549 doesn't really matter.

* Missed a spot
2026-05-09 03:29:58 +00:00

58 lines
1.8 KiB
C#

using Content.Shared.Projectiles;
using Content.Shared.Weapons.Ranged.Systems;
using Robust.Client.Animations;
using Robust.Client.GameObjects;
using TimedDespawnComponent = Robust.Shared.Spawners.TimedDespawnComponent;
namespace Content.Client.Projectiles;
public sealed partial class ProjectileSystem : SharedProjectileSystem
{
[Dependency] private AnimationPlayerSystem _player = default!;
[Dependency] private SpriteSystem _sprite = default!;
public override void Initialize()
{
base.Initialize();
SubscribeNetworkEvent<ImpactEffectEvent>(OnProjectileImpact);
}
private void OnProjectileImpact(ImpactEffectEvent ev)
{
var coords = GetCoordinates(ev.Coordinates);
if (Deleted(coords.EntityId))
return;
var ent = Spawn(ev.Prototype, coords);
if (TryComp<SpriteComponent>(ent, out var sprite))
{
sprite[EffectLayers.Unshaded].AutoAnimated = false;
_sprite.LayerMapTryGet((ent, sprite), EffectLayers.Unshaded, out var layer, false);
var state = _sprite.LayerGetRsiState((ent, sprite), 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");
}
}
}