Muzzle flash enhancements (#9527)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Content.Client.Items;
|
||||
using Content.Client.Weapons.Ranged.Components;
|
||||
using Content.Shared.Camera;
|
||||
using Content.Shared.Spawners.Components;
|
||||
using Content.Shared.Weapons.Ranged;
|
||||
using Content.Shared.Weapons.Ranged.Components;
|
||||
using Content.Shared.Weapons.Ranged.Events;
|
||||
@@ -10,11 +11,11 @@ using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Input;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Shared.Animations;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
using SharedGunSystem = Content.Shared.Weapons.Ranged.Systems.SharedGunSystem;
|
||||
|
||||
@@ -26,7 +27,6 @@ public sealed partial class GunSystem : SharedGunSystem
|
||||
[Dependency] private readonly IInputManager _inputManager = default!;
|
||||
[Dependency] private readonly IPlayerManager _player = default!;
|
||||
[Dependency] private readonly AnimationPlayerSystem _animPlayer = default!;
|
||||
[Dependency] private readonly EffectSystem _effects = default!;
|
||||
[Dependency] private readonly InputSystem _inputSystem = default!;
|
||||
[Dependency] private readonly SharedCameraRecoilSystem _recoil = default!;
|
||||
|
||||
@@ -43,10 +43,10 @@ public sealed partial class GunSystem : SharedGunSystem
|
||||
{
|
||||
overlayManager.AddOverlay(new GunSpreadOverlay(
|
||||
EntityManager,
|
||||
IoCManager.Resolve<IEyeManager>(),
|
||||
IoCManager.Resolve<IGameTiming>(),
|
||||
IoCManager.Resolve<IInputManager>(),
|
||||
IoCManager.Resolve<IPlayerManager>(),
|
||||
_eyeManager,
|
||||
Timing,
|
||||
_inputManager,
|
||||
_player,
|
||||
this));
|
||||
}
|
||||
else
|
||||
@@ -63,6 +63,7 @@ public sealed partial class GunSystem : SharedGunSystem
|
||||
base.Initialize();
|
||||
UpdatesOutsidePrediction = true;
|
||||
SubscribeLocalEvent<AmmoCounterComponent, ItemStatusCollectMessage>(OnAmmoCounterCollect);
|
||||
SubscribeLocalEvent<GunComponent, MuzzleFlashEvent>(OnMuzzleFlash);
|
||||
|
||||
// Plays animated effects on the client.
|
||||
SubscribeNetworkEvent<HitscanEvent>(OnHitscan);
|
||||
@@ -71,6 +72,11 @@ public sealed partial class GunSystem : SharedGunSystem
|
||||
InitializeSpentAmmo();
|
||||
}
|
||||
|
||||
private void OnMuzzleFlash(EntityUid uid, GunComponent component, MuzzleFlashEvent args)
|
||||
{
|
||||
CreateEffect(uid, args);
|
||||
}
|
||||
|
||||
private void OnHitscan(HitscanEvent ev)
|
||||
{
|
||||
// ALL I WANT IS AN ANIMATED EFFECT
|
||||
@@ -227,8 +233,82 @@ public sealed partial class GunSystem : SharedGunSystem
|
||||
PopupSystem.PopupEntity(message, uid.Value, Filter.Entities(user.Value));
|
||||
}
|
||||
|
||||
protected override void CreateEffect(EffectSystemMessage message, EntityUid? user = null)
|
||||
protected override void CreateEffect(EntityUid uid, MuzzleFlashEvent message, EntityUid? user = null)
|
||||
{
|
||||
_effects.CreateEffect(message);
|
||||
if (!Timing.IsFirstTimePredicted || !TryComp<TransformComponent>(uid, out var xform)) return;
|
||||
var ent = Spawn(message.Prototype, xform.Coordinates);
|
||||
|
||||
var effectXform = Transform(ent);
|
||||
effectXform.LocalRotation -= MathF.PI / 2;
|
||||
effectXform.LocalPosition += new Vector2(0f, -0.5f);
|
||||
|
||||
var lifetime = 0.4f;
|
||||
|
||||
if (TryComp<TimedDespawnComponent>(uid, out var despawn))
|
||||
{
|
||||
lifetime = despawn.Lifetime;
|
||||
}
|
||||
|
||||
var anim = new Animation()
|
||||
{
|
||||
Length = TimeSpan.FromSeconds(lifetime),
|
||||
AnimationTracks =
|
||||
{
|
||||
new AnimationTrackComponentProperty
|
||||
{
|
||||
ComponentType = typeof(SpriteComponent),
|
||||
Property = nameof(SpriteComponent.Color),
|
||||
InterpolationMode = AnimationInterpolationMode.Linear,
|
||||
KeyFrames =
|
||||
{
|
||||
new AnimationTrackProperty.KeyFrame(Color.White.WithAlpha(1f), 0),
|
||||
new AnimationTrackProperty.KeyFrame(Color.White.WithAlpha(0f), lifetime)
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_animPlayer.Play(ent, anim, "muzzle-flash");
|
||||
var light = EnsureComp<PointLightComponent>(uid);
|
||||
|
||||
light.Enabled = true;
|
||||
light.Color = Color.FromHex("#cc8e2b");
|
||||
light.Radius = 2f;
|
||||
light.Energy = 5f;
|
||||
|
||||
var animTwo = new Animation()
|
||||
{
|
||||
Length = TimeSpan.FromSeconds(lifetime),
|
||||
AnimationTracks =
|
||||
{
|
||||
new AnimationTrackComponentProperty
|
||||
{
|
||||
ComponentType = typeof(PointLightComponent),
|
||||
Property = nameof(PointLightComponent.Energy),
|
||||
InterpolationMode = AnimationInterpolationMode.Linear,
|
||||
KeyFrames =
|
||||
{
|
||||
new AnimationTrackProperty.KeyFrame(5f, 0),
|
||||
new AnimationTrackProperty.KeyFrame(0f, lifetime)
|
||||
}
|
||||
},
|
||||
new AnimationTrackComponentProperty
|
||||
{
|
||||
ComponentType = typeof(PointLightComponent),
|
||||
Property = nameof(PointLightComponent.Enabled),
|
||||
InterpolationMode = AnimationInterpolationMode.Linear,
|
||||
KeyFrames =
|
||||
{
|
||||
new AnimationTrackProperty.KeyFrame(true, 0),
|
||||
new AnimationTrackProperty.KeyFrame(false, lifetime)
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var uidPlayer = EnsureComp<AnimationPlayerComponent>(uid);
|
||||
|
||||
_animPlayer.Stop(uid, uidPlayer, "muzzle-flash-light");
|
||||
_animPlayer.Play(uid, uidPlayer, animTwo,"muzzle-flash-light");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user