]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Anomaly Generator Tweaks (#13856)
authorNemanja <98561806+EmoGarbage404@users.noreply.github.com>
Mon, 6 Feb 2023 19:53:59 +0000 (14:53 -0500)
committerGitHub <noreply@github.com>
Mon, 6 Feb 2023 19:53:59 +0000 (15:53 -0400)
13 files changed:
Content.Client/Anomaly/Ui/AnomalyGeneratorWindow.xaml.cs
Content.Server/Anomaly/AnomalySystem.Generator.cs
Content.Server/Anomaly/AnomalySystem.cs
Content.Server/Anomaly/Components/AnomalyGeneratorComponent.cs
Content.Server/Anomaly/Components/GeneratingAnomalyGeneratorComponent.cs [new file with mode: 0644]
Content.Shared/Anomaly/SharedAnomaly.cs
Resources/Audio/Machines/anomaly_generate.ogg [new file with mode: 0644]
Resources/Audio/Machines/attributions.yml
Resources/Audio/Machines/beep.ogg [new file with mode: 0644]
Resources/Locale/en-US/anomaly/anomaly.ftl
Resources/Prototypes/Entities/Structures/Machines/anomaly_equipment.yml
Resources/Textures/Structures/Machines/Anomaly/anomaly_generator.rsi/generating.png [new file with mode: 0644]
Resources/Textures/Structures/Machines/Anomaly/anomaly_generator.rsi/meta.json

index cf46f0f8fdd2ab96857c647148fad885f152e7e6..cda9c21239410b8dfd511cf24cbf9c8b9859eab9 100644 (file)
@@ -37,7 +37,9 @@ public sealed partial class AnomalyGeneratorWindow : FancyWindow
         var fuelCompletion = Math.Clamp((float) state.FuelAmount / state.FuelCost, 0f, 1f);
 
         FuelBar.Value = fuelCompletion;
-        FuelText.Text = $"{fuelCompletion:P}";
+
+        var charges = state.FuelAmount / state.FuelCost;
+        FuelText.Text = Loc.GetString("anomaly-generator-charges", ("charges", charges));
 
         UpdateTimer();
         UpdateReady(); // yes this can trigger twice. no i don't care
index 7a2deb86110baa74ed621a53f65f7620fad99a34..2b20ce75a24a03bf34e2d0360b405e86490fe325 100644 (file)
@@ -1,9 +1,11 @@
-using Content.Server.Anomaly.Components;
+using Content.Server.Anomaly.Components;
 using Content.Server.Power.Components;
 using Content.Server.Power.EntitySystems;
 using Content.Shared.Anomaly;
 using Content.Shared.CCVar;
 using Content.Shared.Materials;
+using Content.Shared.Radio;
+using Robust.Shared.Audio;
 using Content.Shared.Physics;
 using Robust.Shared.Map.Components;
 using Robust.Shared.Physics;
@@ -24,6 +26,9 @@ public sealed partial class AnomalySystem
         SubscribeLocalEvent<AnomalyGeneratorComponent, MaterialAmountChangedEvent>(OnGeneratorMaterialAmountChanged);
         SubscribeLocalEvent<AnomalyGeneratorComponent, AnomalyGeneratorGenerateButtonPressedEvent>(OnGenerateButtonPressed);
         SubscribeLocalEvent<AnomalyGeneratorComponent, PowerChangedEvent>(OnGeneratorPowerChanged);
+        SubscribeLocalEvent<AnomalyGeneratorComponent, EntityUnpausedEvent>(OnGeneratorUnpaused);
+        SubscribeLocalEvent<GeneratingAnomalyGeneratorComponent, ComponentStartup>(OnGeneratingStartup);
+        SubscribeLocalEvent<GeneratingAnomalyGeneratorComponent, EntityUnpausedEvent>(OnGeneratingUnpaused);
     }
 
     private void OnGeneratorPowerChanged(EntityUid uid, AnomalyGeneratorComponent component, ref PowerChangedEvent args)
@@ -46,6 +51,11 @@ public sealed partial class AnomalySystem
         TryGeneratorCreateAnomaly(uid, component);
     }
 
+    private void OnGeneratorUnpaused(EntityUid uid, AnomalyGeneratorComponent component, ref EntityUnpausedEvent args)
+    {
+        component.CooldownEndTime += args.PausedTime;
+    }
+
     public void UpdateGeneratorUi(EntityUid uid, AnomalyGeneratorComponent component)
     {
         var materialAmount = _material.GetMaterialAmount(uid, component.RequiredMaterial);
@@ -65,14 +75,12 @@ public sealed partial class AnomalySystem
         if (Timing.CurTime < component.CooldownEndTime)
             return;
 
-        var grid = Transform(uid).GridUid;
-        if (grid == null)
-            return;
-
         if (!_material.TryChangeMaterialAmount(uid, component.RequiredMaterial, -component.MaterialPerAnomaly))
             return;
 
-        SpawnOnRandomGridLocation(grid.Value, component.SpawnerPrototype);
+        var generating = EnsureComp<GeneratingAnomalyGeneratorComponent>(uid);
+        generating.EndTime = Timing.CurTime + component.GenerationLength;
+        generating.AudioStream = Audio.PlayPvs(component.GeneratingSound, uid, AudioParams.Default.WithLoop(true));
         component.CooldownEndTime = Timing.CurTime + component.CooldownLength;
         UpdateGeneratorUi(uid, component);
     }
@@ -126,4 +134,42 @@ public sealed partial class AnomalySystem
 
         Spawn(toSpawn, targetCoords);
     }
+
+    private void OnGeneratingStartup(EntityUid uid, GeneratingAnomalyGeneratorComponent component, ComponentStartup args)
+    {
+        Appearance.SetData(uid, AnomalyGeneratorVisuals.Generating, true);
+    }
+
+    private void OnGeneratingUnpaused(EntityUid uid, GeneratingAnomalyGeneratorComponent component, ref EntityUnpausedEvent args)
+    {
+        component.EndTime += args.PausedTime;
+    }
+
+    private void OnGeneratingFinished(EntityUid uid, AnomalyGeneratorComponent component)
+    {
+        var grid = Transform(uid).GridUid;
+        if (grid == null)
+            return;
+
+        SpawnOnRandomGridLocation(grid.Value, component.SpawnerPrototype);
+        RemComp<GeneratingAnomalyGeneratorComponent>(uid);
+        Appearance.SetData(uid, AnomalyGeneratorVisuals.Generating, false);
+        Audio.PlayPvs(component.GeneratingFinishedSound, uid);
+
+        var message = Loc.GetString("anomaly-generator-announcement");
+        _radio.SendRadioMessage(uid, message, _prototype.Index<RadioChannelPrototype>(component.ScienceChannel));
+    }
+
+    private void UpdateGenerator()
+    {
+        foreach (var (active, gen) in EntityQuery<GeneratingAnomalyGeneratorComponent, AnomalyGeneratorComponent>())
+        {
+            var ent = active.Owner;
+
+            if (Timing.CurTime < active.EndTime)
+                continue;
+            active.AudioStream?.Stop();
+            OnGeneratingFinished(ent, gen);
+        }
+    }
 }
index e48fc328c48f68b4485c12c21b3adeb35502a5d0..3de46afb46b423e043337e9f9331409ba185465f 100644 (file)
@@ -4,12 +4,15 @@ using Content.Server.Audio;
 using Content.Server.DoAfter;
 using Content.Server.Explosion.EntitySystems;
 using Content.Server.Materials;
+using Content.Server.Radio.EntitySystems;
 using Content.Shared.Anomaly;
 using Content.Shared.Anomaly.Components;
 using Robust.Server.GameObjects;
 using Robust.Shared.Configuration;
 using Robust.Shared.Physics.Events;
+using Robust.Shared.Prototypes;
 using Robust.Shared.Random;
+
 namespace Content.Server.Anomaly;
 
 /// <summary>
@@ -18,11 +21,13 @@ namespace Content.Server.Anomaly;
 public sealed partial class AnomalySystem : SharedAnomalySystem
 {
     [Dependency] private readonly IConfigurationManager _configuration = default!;
+    [Dependency] private readonly IPrototypeManager _prototype = default!;
     [Dependency] private readonly AmbientSoundSystem _ambient = default!;
     [Dependency] private readonly AtmosphereSystem _atmosphere = default!;
     [Dependency] private readonly DoAfterSystem _doAfter = default!;
     [Dependency] private readonly ExplosionSystem _explosion = default!;
     [Dependency] private readonly MaterialStorageSystem _material = default!;
+    [Dependency] private readonly RadioSystem _radio = default!;
     [Dependency] private readonly UserInterfaceSystem _ui = default!;
 
     public const float MinParticleVariation = 0.8f;
@@ -128,6 +133,7 @@ public sealed partial class AnomalySystem : SharedAnomalySystem
     {
         base.Update(frameTime);
 
+        UpdateGenerator();
         UpdateVessels();
     }
 }
index 4c9fc39442aad9dce0d5ebe6740bc14d7e9be14a..0b27ee7d1b170d5af11c7bf9c9c50d5ce1ebc928 100644 (file)
@@ -1,4 +1,6 @@
 using Content.Shared.Materials;
+using Content.Shared.Radio;
+using Robust.Shared.Audio;
 using Robust.Shared.Prototypes;
 using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
 using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
@@ -24,6 +26,12 @@ public sealed class AnomalyGeneratorComponent : Component
     [DataField("cooldownLength"), ViewVariables(VVAccess.ReadWrite)]
     public TimeSpan CooldownLength = TimeSpan.FromMinutes(5);
 
+    /// <summary>
+    /// How long it takes to generate an anomaly after pushing the button.
+    /// </summary>
+    [DataField("generationLength"), ViewVariables(VVAccess.ReadWrite)]
+    public TimeSpan GenerationLength = TimeSpan.FromSeconds(8);
+
     /// <summary>
     /// The material needed to generate an anomaly
     /// </summary>
@@ -41,4 +49,22 @@ public sealed class AnomalyGeneratorComponent : Component
     /// </summary>
     [DataField("spawnerPrototype", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>)), ViewVariables(VVAccess.ReadWrite)]
     public string SpawnerPrototype = "RandomAnomalySpawner";
+
+    /// <summary>
+    /// The radio channel for science
+    /// </summary>
+    [DataField("scienceChannel", customTypeSerializer: typeof(PrototypeIdSerializer<RadioChannelPrototype>))]
+    public string ScienceChannel = "Science";
+
+    /// <summary>
+    /// The sound looped while an anomaly generates
+    /// </summary>
+    [DataField("generatingSound")]
+    public SoundSpecifier? GeneratingSound;
+
+    /// <summary>
+    /// Sound played on generation completion.
+    /// </summary>
+    [DataField("generatingFinishedSound")]
+    public SoundSpecifier? GeneratingFinishedSound;
 }
diff --git a/Content.Server/Anomaly/Components/GeneratingAnomalyGeneratorComponent.cs b/Content.Server/Anomaly/Components/GeneratingAnomalyGeneratorComponent.cs
new file mode 100644 (file)
index 0000000..9e30d66
--- /dev/null
@@ -0,0 +1,16 @@
+using Robust.Shared.Audio;
+using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
+
+namespace Content.Server.Anomaly.Components;
+
+[RegisterComponent]
+public sealed class GeneratingAnomalyGeneratorComponent : Component
+{
+    /// <summary>
+    /// When the generating period will end.
+    /// </summary>
+    [DataField("endTime", customTypeSerializer: typeof(TimeOffsetSerializer))]
+    public TimeSpan EndTime = TimeSpan.Zero;
+
+    public IPlayingAudioStream? AudioStream;
+}
index 9ee1f847a95d5fd7dcb39e2d308c48262299d53d..cf94e2c6b10f5cc61af8bc46d17177a0c52dc7fd 100644 (file)
@@ -48,6 +48,18 @@ public enum AnomalyVesselVisualLayers : byte
     Base
 }
 
+[Serializable, NetSerializable]
+public enum AnomalyGeneratorVisuals : byte
+{
+    Generating
+}
+
+[Serializable, NetSerializable]
+public enum AnomalyGeneratorVisualLayers : byte
+{
+    Base
+}
+
 [Serializable, NetSerializable]
 public enum AnomalyScannerUiKey : byte
 {
diff --git a/Resources/Audio/Machines/anomaly_generate.ogg b/Resources/Audio/Machines/anomaly_generate.ogg
new file mode 100644 (file)
index 0000000..fd5384a
Binary files /dev/null and b/Resources/Audio/Machines/anomaly_generate.ogg differ
index 4ac0ac9cfbfa5139401a5aba2b08ce7d5b8d5700..4f47ff53be59eab0d8fbceef75c20d7fa12aa416 100644 (file)
@@ -1,3 +1,13 @@
+- files: ["anomaly_generate.ogg"]
+  license: "CC0-1.0"
+  copyright: "Created by szegvari, converted to mono and .ogg by EmoGarbage404 (github)."
+  source: "https://freesound.org/people/szegvari/sounds/536794/"
+
+- files: ["beep.ogg"]
+  license: "CC0-1.0"
+  copyright: "Created by dotY21."
+  source: "https://freesound.org/people/dotY21/sounds/330726/"
+
 - files: ["vending_restock_start.ogg"]
   license: "CC0-1.0"
   copyright: "https://freesound.org/people/Defaultv/"
diff --git a/Resources/Audio/Machines/beep.ogg b/Resources/Audio/Machines/beep.ogg
new file mode 100644 (file)
index 0000000..820f550
Binary files /dev/null and b/Resources/Audio/Machines/beep.ogg differ
index ae982071158993b378fe0483314d96d54a18a341..f9fa6d06398d2854b8fe4f5be55de3470e96fcfa 100644 (file)
@@ -30,4 +30,9 @@ anomaly-generator-cooldown = Cooldown: [color=gray]{$time}[/color]
 anomaly-generator-no-cooldown = Cooldown: [color=gray]Complete[/color]
 anomaly-generator-yes-fire = Status: [color=forestgreen]Ready[/color]
 anomaly-generator-no-fire = Status: [color=crimson]Not ready[/color]
-anomaly-generator-generate = Generate Anomaly
\ No newline at end of file
+anomaly-generator-generate = Generate Anomaly
+anomaly-generator-charges = {$charges -> 
+    [one] {$charges} charge
+    *[other] {$charges} charges
+}
+anomaly-generator-announcement = An anomaly has been generated!
\ No newline at end of file
index cfce5ca910a2e942ce406a464b53c0dafd72fae1..acc32a51955f03b2a0b1a1cc3a8c6b1aaf68346d 100644 (file)
     - state: inserting
       visible: false
       map: ["enum.MaterialStorageVisualLayers.Inserting"]
+    - state: generating
+      visible: false
+      shader: unshaded
+      map: ["enum.AnomalyGeneratorVisualLayers.Base"]
   - type: Transform
     anchored: true
   - type: ApcPowerReceiver
   - type: ExtensionCableReceiver
   - type: AmbientSound
     range: 5
-    volume: -3
+    volume: -6
     sound:
       path: /Audio/Ambience/Objects/anomaly_generator.ogg
   - type: Physics
     bodyType: Static
   - type: AnomalyGenerator
+    generatingSound:
+      path: /Audio/Machines/anomaly_generate.ogg
+    generatingFinishedSound:
+      path: /Audio/Machines/beep.ogg
   - type: MaterialStorage
     whitelist:
       tags:
       - key: enum.AnomalyGeneratorUiKey.Key
         type: AnomalyGeneratorBoundUserInterface
   - type: Appearance
+  - type: ActiveRadio
+    channels:
+    - Science
   - type: GenericVisualizer
     visuals:
       enum.PowerDeviceVisuals.Powered:
         enum.PowerDeviceVisualLayers.Powered:
           True: { visible: true }
           False: { visible: false }
+      enum.AnomalyGeneratorVisuals.Generating:
+        enum.AnomalyGeneratorVisualLayers.Base:
+          True: { visible: true }
+          False: { visible: false }
   - type: WiresVisuals
   - type: StaticPrice
     price: 5000
diff --git a/Resources/Textures/Structures/Machines/Anomaly/anomaly_generator.rsi/generating.png b/Resources/Textures/Structures/Machines/Anomaly/anomaly_generator.rsi/generating.png
new file mode 100644 (file)
index 0000000..e530750
Binary files /dev/null and b/Resources/Textures/Structures/Machines/Anomaly/anomaly_generator.rsi/generating.png differ
index cd4793cdd2e6e77e732e7af1d718826f0d478689..a70802f01795dd64ad4c44d16495926b380727d7 100644 (file)
@@ -7,6 +7,21 @@
   "license":"CC0-1.0",
   "copyright":"Created by EmoGarbage",
   "states":[
+    {
+      "name": "generating",
+      "delays": [
+        [
+          0.1,
+          0.1,
+          0.1,
+          0.1,
+          0.1,
+          0.1,
+          0.1,
+          0.1
+        ]
+      ]
+    },
     {
       "name":"base"
     },