From: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Date: Sun, 5 Feb 2023 19:52:30 +0000 (-0500) Subject: Anomaly Vessel visuals + audio (#13927) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=440cd377ca9ae914be4b89b96490a5a43a1c1c3f;p=space-station-14.git Anomaly Vessel visuals + audio (#13927) --- diff --git a/Content.Server/Anomaly/AnomalySystem.Vessel.cs b/Content.Server/Anomaly/AnomalySystem.Vessel.cs index ce71cf4715..4809a613fd 100644 --- a/Content.Server/Anomaly/AnomalySystem.Vessel.cs +++ b/Content.Server/Anomaly/AnomalySystem.Vessel.cs @@ -25,7 +25,9 @@ public sealed partial class AnomalySystem SubscribeLocalEvent(OnVesselInteractUsing); SubscribeLocalEvent(OnExamined); SubscribeLocalEvent(OnVesselGetPointsPerSecond); + SubscribeLocalEvent(OnUnpaused); SubscribeLocalEvent(OnVesselAnomalyShutdown); + SubscribeLocalEvent(OnVesselAnomalyStabilityChanged); } private void OnExamined(EntityUid uid, AnomalyVesselComponent component, ExaminedEvent args) @@ -94,6 +96,11 @@ public sealed partial class AnomalySystem args.Points += (int) (GetAnomalyPointValue(anomaly) * component.PointMultiplier); } + private void OnUnpaused(EntityUid uid, AnomalyVesselComponent component, ref EntityUnpausedEvent args) + { + component.NextBeep += args.PausedTime; + } + private void OnVesselAnomalyShutdown(ref AnomalyShutdownEvent args) { foreach (var component in EntityQuery()) @@ -112,6 +119,18 @@ public sealed partial class AnomalySystem } } + private void OnVesselAnomalyStabilityChanged(ref AnomalyStabilityChangedEvent args) + { + foreach (var component in EntityQuery()) + { + var ent = component.Owner; + if (args.Anomaly != component.Anomaly) + continue; + + UpdateVesselAppearance(ent, component); + } + } + /// /// Updates the appearance of an anomaly vessel /// based on whether or not it has an anomaly @@ -125,11 +144,61 @@ public sealed partial class AnomalySystem var on = component.Anomaly != null; - Appearance.SetData(uid, AnomalyVesselVisuals.HasAnomaly, on); + if (!TryComp(uid, out var appearanceComponent)) + return; + + Appearance.SetData(uid, AnomalyVesselVisuals.HasAnomaly, on, appearanceComponent); if (TryComp(uid, out var pointLightComponent)) { pointLightComponent.Enabled = on; } + + // arbitrary value for the generic visualizer to use. + // i didn't feel like making an enum for this. + var value = 1; + if (TryComp(component.Anomaly, out var anomalyComp)) + { + if (anomalyComp.Stability <= anomalyComp.DecayThreshold) + { + value = 2; + } + else if (anomalyComp.Stability >= anomalyComp.GrowthThreshold) + { + value = 3; + } + } + Appearance.SetData(uid, AnomalyVesselVisuals.AnomalyState, value, appearanceComponent); + _ambient.SetAmbience(uid, on); } + + private void UpdateVessels() + { + foreach (var vessel in EntityQuery()) + { + var vesselEnt = vessel.Owner; + if (vessel.Anomaly is not { } anomUid) + continue; + + if (!TryComp(anomUid, out var anomaly)) + continue; + + if (Timing.CurTime < vessel.NextBeep) + continue; + + // a lerp between the max and min values for each threshold. + // longer beeps that get shorter as the anomaly gets more extreme + float timerPercentage; + if (anomaly.Stability <= anomaly.DecayThreshold) + timerPercentage = (anomaly.DecayThreshold - anomaly.Stability) / anomaly.DecayThreshold; + else if (anomaly.Stability >= anomaly.GrowthThreshold) + timerPercentage = (anomaly.Stability - anomaly.GrowthThreshold) / (1 - anomaly.GrowthThreshold); + else //it's not unstable + continue; + + Audio.PlayPvs(vessel.BeepSound, vesselEnt); + var beepInterval = (vessel.MaxBeepInterval - vessel.MinBeepInterval) * (1 - timerPercentage) + vessel.MinBeepInterval; + vessel.NextBeep = beepInterval + Timing.CurTime; + } + } } diff --git a/Content.Server/Anomaly/AnomalySystem.cs b/Content.Server/Anomaly/AnomalySystem.cs index f85ddbe990..8dce08c406 100644 --- a/Content.Server/Anomaly/AnomalySystem.cs +++ b/Content.Server/Anomaly/AnomalySystem.cs @@ -124,4 +124,11 @@ public sealed partial class AnomalySystem : SharedAnomalySystem _ => throw new ArgumentOutOfRangeException() }; } + + public override void Update(float frameTime) + { + base.Update(frameTime); + + UpdateVessels(); + } } diff --git a/Content.Server/Anomaly/Components/AnomalyVesselComponent.cs b/Content.Server/Anomaly/Components/AnomalyVesselComponent.cs index c833cf636b..2d502f0ea3 100644 --- a/Content.Server/Anomaly/Components/AnomalyVesselComponent.cs +++ b/Content.Server/Anomaly/Components/AnomalyVesselComponent.cs @@ -1,4 +1,6 @@ using Content.Shared.Construction.Prototypes; +using Robust.Shared.Audio; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; namespace Content.Server.Anomaly.Components; @@ -37,4 +39,28 @@ public sealed class AnomalyVesselComponent : Component /// [DataField("partRatingPointModifier")] public float PartRatingPointModifier = 1.5f; + + /// + /// The maximum time between each beep + /// + [DataField("maxBeepInterval")] + public TimeSpan MaxBeepInterval = TimeSpan.FromSeconds(2f); + + /// + /// The minimum time between each beep + /// + [DataField("minBeepInterval")] + public TimeSpan MinBeepInterval = TimeSpan.FromSeconds(0.75f); + + /// + /// When the next beep sound will play + /// + [DataField("nextBeep", customTypeSerializer:typeof(TimeOffsetSerializer))] + public TimeSpan NextBeep = TimeSpan.Zero; + + /// + /// The sound that is played repeatedly when the anomaly is destabilizing/decaying + /// + [DataField("beepSound")] + public SoundSpecifier BeepSound = new SoundPathSpecifier("/Audio/Machines/vessel_warning.ogg"); } diff --git a/Content.Shared/Anomaly/SharedAnomaly.cs b/Content.Shared/Anomaly/SharedAnomaly.cs index fe93cff117..9ee1f847a9 100644 --- a/Content.Shared/Anomaly/SharedAnomaly.cs +++ b/Content.Shared/Anomaly/SharedAnomaly.cs @@ -38,7 +38,8 @@ public enum AnomalousParticleType : byte [Serializable, NetSerializable] public enum AnomalyVesselVisuals : byte { - HasAnomaly + HasAnomaly, + AnomalyState } [Serializable, NetSerializable] diff --git a/Resources/Audio/Machines/attributions.yml b/Resources/Audio/Machines/attributions.yml index 64bb2793db..4ac0ac9cfb 100644 --- a/Resources/Audio/Machines/attributions.yml +++ b/Resources/Audio/Machines/attributions.yml @@ -12,3 +12,8 @@ license: "CC0-1.0" copyright: "receipt printing.wav by 13F_Panska_Tlolkova_Matilda. This version is cleaned up, shortened, and converted to OGG." source: "https://freesound.org/people/13F_Panska_Tlolkova_Matilda/sounds/378331" + +- files: ["vessel_warning.ogg"] + license: "CC-BY-4.0" + copyright: "Created by AUDACITIER (freesound), converted to MONO and .ogg and edited by EmoGarbage404 (github)." + source: "https://freesound.org/people/AUDACITIER/sounds/629196/" \ No newline at end of file diff --git a/Resources/Audio/Machines/vessel_warning.ogg b/Resources/Audio/Machines/vessel_warning.ogg new file mode 100644 index 0000000000..63431034c0 Binary files /dev/null and b/Resources/Audio/Machines/vessel_warning.ogg differ diff --git a/Resources/Prototypes/Entities/Structures/Machines/anomaly_equipment.yml b/Resources/Prototypes/Entities/Structures/Machines/anomaly_equipment.yml index 581e15e5f8..cfce5ca910 100644 --- a/Resources/Prototypes/Entities/Structures/Machines/anomaly_equipment.yml +++ b/Resources/Prototypes/Entities/Structures/Machines/anomaly_equipment.yml @@ -9,10 +9,11 @@ sprite: Structures/Machines/Anomaly/anomaly_vessel.rsi layers: - state: base - - state: powered + - state: powered-1 shader: unshaded map: ["enum.PowerDeviceVisualLayers.Powered"] - - state: anomaly + - state: anomaly-1 + visible: false shader: unshaded map: ["enum.AnomalyVesselVisualLayers.Base"] - state: panel @@ -54,6 +55,15 @@ enum.AnomalyVesselVisualLayers.Base: True: { visible: true } False: { visible: false } + enum.AnomalyVesselVisuals.AnomalyState: + enum.PowerDeviceVisualLayers.Powered: + 1: { state: powered-1 } + 2: { state: powered-2 } + 3: { state: powered-3 } + enum.AnomalyVesselVisualLayers.Base: + 1: { state: anomaly-1 } + 2: { state: anomaly-2 } + 3: { state: anomaly-3 } enum.WiresVisuals.MaintenancePanelState: enum.WiresVisualLayers.MaintenancePanel: True: { visible: false } diff --git a/Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/anomaly.png b/Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/anomaly-1.png similarity index 100% rename from Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/anomaly.png rename to Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/anomaly-1.png diff --git a/Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/anomaly-2.png b/Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/anomaly-2.png new file mode 100644 index 0000000000..2e4aebe536 Binary files /dev/null and b/Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/anomaly-2.png differ diff --git a/Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/anomaly-3.png b/Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/anomaly-3.png new file mode 100644 index 0000000000..da20f91182 Binary files /dev/null and b/Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/anomaly-3.png differ diff --git a/Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/meta.json b/Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/meta.json index 1a9a61933d..7a503b2cf8 100644 --- a/Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/meta.json +++ b/Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/meta.json @@ -1,14 +1,20 @@ { "version": 1, "license": "CC0-1.0", - "copyright": "Created by EmoGarbage404", + "copyright": "Created by EmoGarbage404 (github)", "size": { "x": 32, "y": 32 }, "states": [ { - "name": "anomaly" + "name": "anomaly-1" + }, + { + "name": "anomaly-2" + }, + { + "name": "anomaly-3" }, { "name": "base" @@ -17,7 +23,13 @@ "name": "panel" }, { - "name": "powered" + "name": "powered-1" + }, + { + "name": "powered-2" + }, + { + "name": "powered-3" } ] } diff --git a/Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/powered.png b/Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/powered-1.png similarity index 100% rename from Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/powered.png rename to Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/powered-1.png diff --git a/Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/powered-2.png b/Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/powered-2.png new file mode 100644 index 0000000000..b1f7b7c8ff Binary files /dev/null and b/Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/powered-2.png differ diff --git a/Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/powered-3.png b/Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/powered-3.png new file mode 100644 index 0000000000..59af1c9a33 Binary files /dev/null and b/Resources/Textures/Structures/Machines/Anomaly/anomaly_vessel.rsi/powered-3.png differ