{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly AnimationPlayerSystem _animation = default!;
+ [Dependency] private readonly IComponentFactory _factory = default!;
/// <summary>
/// It's a little on the long side but given we use multiple colours denoting what happened it makes it easier to register.
continue;
}
- var player = EnsureComp<AnimationPlayerComponent>(ent);
- player.NetSyncEnabled = false;
+ if (!TryComp(ent, out AnimationPlayerComponent? player))
+ {
+ player = (AnimationPlayerComponent) _factory.GetComponent(typeof(AnimationPlayerComponent));
+ player.Owner = ent;
+ player.NetSyncEnabled = false;
+ AddComp(ent, player);
+ }
// Need to stop the existing animation first to ensure the sprite color is fixed.
// Otherwise we might lerp to a red colour instead.
if (animation == null)
continue;
- var comp = EnsureComp<ColorFlashEffectComponent>(ent);
- comp.NetSyncEnabled = false;
+ if (!TryComp(ent, out ColorFlashEffectComponent? comp))
+ {
+ comp = (ColorFlashEffectComponent) _factory.GetComponent(typeof(ColorFlashEffectComponent));
+ comp.Owner = ent;
+ comp.NetSyncEnabled = false;
+ AddComp(ent, comp);
+ }
+
comp.Color = sprite.Color;
_animation.Play((ent, player), animation, AnimationKey);
}
[Dependency] private readonly AnimationPlayerSystem _animPlayer = default!;
[Dependency] private readonly InputSystem _inputSystem = default!;
[Dependency] private readonly SharedCameraRecoilSystem _recoil = default!;
+ [Dependency] private readonly IComponentFactory _factory = default!;
[ValidatePrototypeId<EntityPrototype>]
public const string HitscanProto = "HitscanEffect";
};
_animPlayer.Play(ent, anim, "muzzle-flash");
- var light = EnsureComp<PointLightComponent>(uid);
- light.NetSyncEnabled = false;
+ if (!TryComp(uid, out PointLightComponent? light))
+ {
+ light = (PointLightComponent) _factory.GetComponent(typeof(PointLightComponent));
+ light.Owner = uid;
+ light.NetSyncEnabled = false;
+ AddComp(uid, light);
+ }
+
Lights.SetEnabled(uid, true, light);
Lights.SetRadius(uid, 2f, light);
Lights.SetColor(uid, Color.FromHex("#cc8e2b"), light);