]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add pointlight to flashbangs (#15785)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Wed, 26 Apr 2023 03:51:48 +0000 (13:51 +1000)
committerGitHub <noreply@github.com>
Wed, 26 Apr 2023 03:51:48 +0000 (13:51 +1000)
Content.Client/Light/Components/LightFadeComponent.cs [new file with mode: 0644]
Content.Client/Light/EntitySystems/LightFadeSystem.cs [new file with mode: 0644]
Content.Server/Entry/IgnoredComponents.cs
Content.Server/Explosion/Components/SpawnOnTriggerComponent.cs [new file with mode: 0644]
Content.Server/Explosion/EntitySystems/TriggerSystem.cs
Resources/Prototypes/Entities/Objects/Weapons/Throwable/grenades.yml

diff --git a/Content.Client/Light/Components/LightFadeComponent.cs b/Content.Client/Light/Components/LightFadeComponent.cs
new file mode 100644 (file)
index 0000000..3327c94
--- /dev/null
@@ -0,0 +1,11 @@
+namespace Content.Client.Light.Components;
+
+/// <summary>
+/// Fades out the <see cref="SharedPointLightComponent"/> attached to this entity.
+/// </summary>
+[RegisterComponent]
+public sealed class LightFadeComponent : Component
+{
+    [ViewVariables(VVAccess.ReadWrite), DataField("duration")]
+    public float Duration = 0.5f;
+}
diff --git a/Content.Client/Light/EntitySystems/LightFadeSystem.cs b/Content.Client/Light/EntitySystems/LightFadeSystem.cs
new file mode 100644 (file)
index 0000000..c4e4fff
--- /dev/null
@@ -0,0 +1,46 @@
+using Content.Client.Light.Components;
+using Robust.Client.Animations;
+using Robust.Client.GameObjects;
+using Robust.Shared.Animations;
+
+namespace Content.Client.Light.EntitySystems;
+
+public sealed class LightFadeSystem : EntitySystem
+{
+    [Dependency] private readonly AnimationPlayerSystem _player = default!;
+
+    private const string FadeTrack = "light-fade";
+
+    public override void Initialize()
+    {
+        base.Initialize();
+        SubscribeLocalEvent<LightFadeComponent, ComponentStartup>(OnFadeStartup);
+    }
+
+    private void OnFadeStartup(EntityUid uid, LightFadeComponent component, ComponentStartup args)
+    {
+        if (!TryComp<PointLightComponent>(uid, out var light))
+            return;
+
+        var animation = new Animation()
+        {
+            Length = TimeSpan.FromSeconds(component.Duration),
+            AnimationTracks =
+            {
+                new AnimationTrackComponentProperty()
+                {
+                    Property = nameof(PointLightComponent.Energy),
+                    ComponentType = typeof(PointLightComponent),
+                    InterpolationMode = AnimationInterpolationMode.Cubic,
+                    KeyFrames =
+                    {
+                        new AnimationTrackProperty.KeyFrame(light.Energy, 0f),
+                        new AnimationTrackProperty.KeyFrame(0f, component.Duration)
+                    }
+                }
+            }
+        };
+
+        _player.Play(uid, animation, FadeTrack);
+    }
+}
index eae00c7502e344bfdc3f28e08c7024a4b092adff..a1db7163a003b00618de6aa064b94755c0bdfdbb 100644 (file)
@@ -20,6 +20,7 @@ namespace Content.Server.Entry
             "UIFragment",
             "PDABorderColor",
             "InventorySlots",
+            "LightFade",
         };
     }
 }
diff --git a/Content.Server/Explosion/Components/SpawnOnTriggerComponent.cs b/Content.Server/Explosion/Components/SpawnOnTriggerComponent.cs
new file mode 100644 (file)
index 0000000..0821d30
--- /dev/null
@@ -0,0 +1,12 @@
+using Content.Server.Explosion.EntitySystems;
+using Robust.Shared.Prototypes;
+using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
+
+namespace Content.Server.Explosion.Components;
+
+[RegisterComponent, Access(typeof(TriggerSystem))]
+public sealed class SpawnOnTriggerComponent : Component
+{
+    [ViewVariables(VVAccess.ReadWrite), DataField("proto", required: true, customTypeSerializer:typeof(PrototypeIdSerializer<EntityPrototype>))]
+    public string Proto = string.Empty;
+}
index 6e4360b5f8e1c86eeba21a901d8f6f8c0b5d20a9..4fbd6465851892b29515097b0103b4ac12da7239 100644 (file)
@@ -70,12 +70,25 @@ namespace Content.Server.Explosion.EntitySystems
             SubscribeLocalEvent<TriggerOnStepTriggerComponent, StepTriggeredEvent>(OnStepTriggered);
             SubscribeLocalEvent<TriggerOnSlipComponent, SlipEvent>(OnSlipTriggered);
 
+            SubscribeLocalEvent<SpawnOnTriggerComponent, TriggerEvent>(OnSpawnTrigger);
             SubscribeLocalEvent<DeleteOnTriggerComponent, TriggerEvent>(HandleDeleteTrigger);
             SubscribeLocalEvent<ExplodeOnTriggerComponent, TriggerEvent>(HandleExplodeTrigger);
             SubscribeLocalEvent<FlashOnTriggerComponent, TriggerEvent>(HandleFlashTrigger);
             SubscribeLocalEvent<GibOnTriggerComponent, TriggerEvent>(HandleGibTrigger);
         }
 
+        private void OnSpawnTrigger(EntityUid uid, SpawnOnTriggerComponent component, TriggerEvent args)
+        {
+            var xform = Transform(uid);
+
+            var coords = xform.Coordinates;
+
+            if (!coords.IsValid(EntityManager))
+                return;
+
+            Spawn(component.Proto, coords);
+        }
+
         private void HandleExplodeTrigger(EntityUid uid, ExplodeOnTriggerComponent component, TriggerEvent args)
         {
             _explosions.TriggerExplosive(uid, user: args.User);
index 85e35faff141fbbd20040cfbc191e46fad3e4931..638855646d5bcc252955c732278cdaa3e2f5ee9d 100644 (file)
     sound:
       path: "/Audio/Effects/flash_bang.ogg"
   - type: DeleteOnTrigger
+  - type: SpawnOnTrigger
+    proto: GrenadeFlashEffect
   - type: Appearance
     visuals:
     - type: TimerTriggerVisualizer
       countdown_sound:
         path: /Audio/Effects/countdown.ogg
 
+- type: entity
+  id: GrenadeFlashEffect
+  noSpawn: true
+  components:
+    - type: PointLight
+      enabled: true
+      netsync: false
+      radius: 5
+      energy: 8
+    - type: LightFade
+      duration: 0.5
+    - type: TimedDespawn
+      lifetime: 0.5
+
 - type: entity
   name: Syndicate minibomb
   description: A precision sabotage explosive for quickly destroying a machine, dead body, or whatever else needs to go.