]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Radio jammer update! (#25912)
authorbeck-thompson <107373427+beck-thompson@users.noreply.github.com>
Thu, 25 Apr 2024 02:19:16 +0000 (19:19 -0700)
committerGitHub <noreply@github.com>
Thu, 25 Apr 2024 02:19:16 +0000 (12:19 +1000)
* Added selectable power level to radio jammer

* Cleaned up OnGetVerb

* Settings are now stored in the .yml file. Simplified stuff a lot!

* Minor fixes!

* Small little baby fix :)

* Added the power level switch to the examine menu and also removed the ftl file as it was in the incorrect location.

* Minor code cleanup

* Changed byte -> int

* Update sprite

* Fixed licence

* Added power LED that changes if the jammer is on low power.

* Removed tabs

* Changed github link to the commit

* Changed all the RemComp to RemComDeferred

* Moved NetworkedComponent to shared

* Changed radio jammer textures back with minor edits

* Added a space because it was annoying me

* Jammer now updates range for suit sensors properly! Thanks nikthechampiongr :)

* Removed useless comment

* Cleaned up code that updates the range of tracking devices.

* Fixed client namespace and removed newline

* Cleaned up ChangeLEDState and ChangeChargeLevel.

* Added comments

* Read only

* Fixed another comment

* Locked in

* Made server inherit shared

* Update Content.Shared/Radio/EntitySystems/SharedJammerSystem.cs

* Update Content.Shared/Radio/EntitySystems/SharedJammerSystem.cs

* review fixes

---------

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
14 files changed:
Content.Client/DeviceNetwork/JammerSystem.cs [new file with mode: 0644]
Content.Server/Radio/Components/RadioJammerComponent.cs [deleted file]
Content.Server/Radio/EntitySystems/JammerSystem.cs
Content.Shared/Radio/Components/SharedRadioJammerComponent.cs [new file with mode: 0644]
Content.Shared/Radio/EntitySystems/SharedJammerSystem.cs [new file with mode: 0644]
Content.Shared/Verbs/VerbCategory.cs
Resources/Locale/en-US/radio/components/radio-jammer-component.ftl
Resources/Locale/en-US/verbs/verb-system.ftl
Resources/Prototypes/Entities/Objects/Tools/jammer.yml
Resources/Textures/Objects/Devices/jammer.rsi/jammer.png
Resources/Textures/Objects/Devices/jammer.rsi/jammer_high_charge.png [new file with mode: 0644]
Resources/Textures/Objects/Devices/jammer.rsi/jammer_low_charge.png [new file with mode: 0644]
Resources/Textures/Objects/Devices/jammer.rsi/jammer_medium_charge.png [new file with mode: 0644]
Resources/Textures/Objects/Devices/jammer.rsi/meta.json

diff --git a/Content.Client/DeviceNetwork/JammerSystem.cs b/Content.Client/DeviceNetwork/JammerSystem.cs
new file mode 100644 (file)
index 0000000..c7dbf8c
--- /dev/null
@@ -0,0 +1,8 @@
+using Content.Shared.Radio.EntitySystems;
+
+namespace Content.Client.DeviceNetwork;
+
+public sealed class JammerSystem : SharedJammerSystem
+{
+
+}
diff --git a/Content.Server/Radio/Components/RadioJammerComponent.cs b/Content.Server/Radio/Components/RadioJammerComponent.cs
deleted file mode 100644 (file)
index 93504ef..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-using Content.Server.Radio.EntitySystems;
-
-namespace Content.Server.Radio.Components;
-
-/// <summary>
-/// When activated (<see cref="ActiveRadioJammerComponent"/>) prevents from sending messages in range
-/// </summary>
-[RegisterComponent]
-[Access(typeof(JammerSystem))]
-public sealed partial class RadioJammerComponent : Component
-{
-    [DataField("range"), ViewVariables(VVAccess.ReadWrite)]
-    public float Range = 8f;
-
-    /// <summary>
-    /// Power usage per second when enabled
-    /// </summary>
-    [DataField("wattage"), ViewVariables(VVAccess.ReadWrite)]
-    public float Wattage = 2f;
-}
index 5a2a854017bda63af5f615ecb3167505d9285576..4f58cb21e1d7ca727411c8fa5967efb27f904acf 100644 (file)
@@ -1,26 +1,22 @@
 using Content.Server.DeviceNetwork.Components;
-using Content.Server.DeviceNetwork.Systems;
-using Content.Server.Medical.CrewMonitoring;
 using Content.Server.Popups;
 using Content.Server.Power.EntitySystems;
 using Content.Server.PowerCell;
 using Content.Server.Radio.Components;
-using Content.Server.Station.Systems;
 using Content.Shared.DeviceNetwork.Components;
 using Content.Shared.Examine;
 using Content.Shared.Interaction;
 using Content.Shared.PowerCell.Components;
+using Content.Shared.RadioJammer;
+using Content.Shared.Radio.EntitySystems;
 
 namespace Content.Server.Radio.EntitySystems;
 
-public sealed class JammerSystem : EntitySystem
+public sealed class JammerSystem : SharedJammerSystem
 {
     [Dependency] private readonly PowerCellSystem _powerCell = default!;
     [Dependency] private readonly BatterySystem _battery = default!;
-    [Dependency] private readonly PopupSystem _popup = default!;
     [Dependency] private readonly SharedTransformSystem _transform = default!;
-    [Dependency] private readonly StationSystem _stationSystem = default!;
-    [Dependency] private readonly SingletonDeviceNetServerSystem _singletonServerSystem = default!;
 
     public override void Initialize()
     {
@@ -35,14 +31,37 @@ public sealed class JammerSystem : EntitySystem
     public override void Update(float frameTime)
     {
         var query = EntityQueryEnumerator<ActiveRadioJammerComponent, RadioJammerComponent>();
+
         while (query.MoveNext(out var uid, out var _, out var jam))
         {
-            if (_powerCell.TryGetBatteryFromSlot(uid, out var batteryUid, out var battery) &&
-                !_battery.TryUseCharge(batteryUid.Value, jam.Wattage * frameTime, battery))
+
+            if (_powerCell.TryGetBatteryFromSlot(uid, out var batteryUid, out var battery))
             {
-                RemComp<ActiveRadioJammerComponent>(uid);
-                RemComp<DeviceNetworkJammerComponent>(uid);
+                if (!_battery.TryUseCharge(batteryUid.Value, GetCurrentWattage(jam) * frameTime, battery))
+                {
+                    ChangeLEDState(false, uid);
+                    RemComp<ActiveRadioJammerComponent>(uid);
+                    RemComp<DeviceNetworkJammerComponent>(uid);
+                }
+                else
+                {
+                    var percentCharged = battery.CurrentCharge / battery.MaxCharge;
+                    if (percentCharged > .50)
+                    {
+                        ChangeChargeLevel(RadioJammerChargeLevel.High, uid);
+                    }
+                    else if (percentCharged < .15)
+                    {
+                        ChangeChargeLevel(RadioJammerChargeLevel.Low, uid);
+                    }
+                    else
+                    {
+                        ChangeChargeLevel(RadioJammerChargeLevel.Medium, uid);
+                    }
+                }
+
             }
+
         }
     }
 
@@ -50,40 +69,49 @@ public sealed class JammerSystem : EntitySystem
     {
         var activated = !HasComp<ActiveRadioJammerComponent>(uid) &&
             _powerCell.TryGetBatteryFromSlot(uid, out var battery) &&
-            battery.CurrentCharge > comp.Wattage;
+            battery.CurrentCharge > GetCurrentWattage(comp);
         if (activated)
         {
+            ChangeLEDState(true, uid);
             EnsureComp<ActiveRadioJammerComponent>(uid);
             EnsureComp<DeviceNetworkJammerComponent>(uid, out var jammingComp);
-            jammingComp.Range = comp.Range;
+            jammingComp.Range = GetCurrentRange(comp);
             jammingComp.JammableNetworks.Add(DeviceNetworkComponent.DeviceNetIdDefaults.Wireless.ToString());
             Dirty(uid, jammingComp);
         }
         else
         {
-            RemComp<ActiveRadioJammerComponent>(uid);
-            RemComp<DeviceNetworkJammerComponent>(uid);
+            ChangeLEDState(false, uid);
+            RemCompDeferred<ActiveRadioJammerComponent>(uid);
+            RemCompDeferred<DeviceNetworkJammerComponent>(uid);
         }
         var state = Loc.GetString(activated ? "radio-jammer-component-on-state" : "radio-jammer-component-off-state");
         var message = Loc.GetString("radio-jammer-component-on-use", ("state", state));
-        _popup.PopupEntity(message, args.User, args.User);
+        Popup.PopupEntity(message, args.User, args.User);
         args.Handled = true;
     }
 
     private void OnPowerCellChanged(EntityUid uid, ActiveRadioJammerComponent comp, PowerCellChangedEvent args)
     {
         if (args.Ejected)
-            RemComp<ActiveRadioJammerComponent>(uid);
+        {
+            ChangeLEDState(false, uid);
+            RemCompDeferred<ActiveRadioJammerComponent>(uid);
+        }
     }
 
     private void OnExamine(EntityUid uid, RadioJammerComponent comp, ExaminedEvent args)
     {
         if (args.IsInDetailsRange)
         {
-            var msg = HasComp<ActiveRadioJammerComponent>(uid)
+            var powerIndicator = HasComp<ActiveRadioJammerComponent>(uid)
                 ? Loc.GetString("radio-jammer-component-examine-on-state")
                 : Loc.GetString("radio-jammer-component-examine-off-state");
-            args.PushMarkup(msg);
+            args.PushMarkup(powerIndicator);
+
+            var powerLevel = Loc.GetString(comp.Settings[comp.SelectedPowerLevel].Name);
+            var switchIndicator = Loc.GetString("radio-jammer-component-switch-setting", ("powerLevel", powerLevel));
+            args.PushMarkup(switchIndicator);
         }
     }
 
@@ -102,7 +130,7 @@ public sealed class JammerSystem : EntitySystem
 
         while (query.MoveNext(out _, out _, out var jam, out var transform))
         {
-            if (source.InRange(EntityManager, _transform, transform.Coordinates, jam.Range))
+            if (source.InRange(EntityManager, _transform, transform.Coordinates, GetCurrentRange(jam)))
             {
                 return true;
             }
diff --git a/Content.Shared/Radio/Components/SharedRadioJammerComponent.cs b/Content.Shared/Radio/Components/SharedRadioJammerComponent.cs
new file mode 100644 (file)
index 0000000..e5e52a3
--- /dev/null
@@ -0,0 +1,74 @@
+using Robust.Shared.Serialization;
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.RadioJammer;
+
+/// <summary>
+/// When activated (<see cref="ActiveRadioJammerComponent"/>) prevents from sending messages in range
+/// Suit sensors will also stop working.
+/// </summary>
+[NetworkedComponent, RegisterComponent]
+public sealed partial class RadioJammerComponent : Component
+{
+    [DataDefinition]
+    public partial struct RadioJamSetting
+    {
+        /// <summary>
+        /// Power usage per second when enabled.
+        /// </summary>
+        [DataField(required: true)]
+        public float Wattage;
+
+        /// <summary>
+        /// Range of the jammer.
+        /// </summary>
+        [DataField(required: true)]
+        public float Range;
+
+        /// <summary>
+        /// The message that is displayed when switched 
+        /// to this setting.
+        /// </summary>
+        [DataField(required: true)]
+        public LocId Message = string.Empty;
+
+        /// <summary>
+        /// Name of the setting.
+        /// </summary>
+        [DataField(required: true)]
+        public LocId Name = string.Empty;
+    }
+
+    /// <summary>
+    /// List of all the settings for the radio jammer.
+    /// </summary>
+    [DataField(required: true), ViewVariables(VVAccess.ReadOnly)]
+    public RadioJamSetting[] Settings;
+
+    /// <summary>
+    /// Index of the currently selected setting.
+    /// </summary>
+    [DataField]
+    public int SelectedPowerLevel = 1;
+}
+
+[Serializable, NetSerializable]
+public enum RadioJammerChargeLevel : byte
+{
+    Low,
+    Medium,
+    High
+}
+
+[Serializable, NetSerializable]
+public enum RadioJammerLayers : byte
+{
+    LED
+}
+
+[Serializable, NetSerializable]
+public enum RadioJammerVisuals : byte
+{
+    ChargeLevel,
+    LEDOn
+}
diff --git a/Content.Shared/Radio/EntitySystems/SharedJammerSystem.cs b/Content.Shared/Radio/EntitySystems/SharedJammerSystem.cs
new file mode 100644 (file)
index 0000000..e1f6327
--- /dev/null
@@ -0,0 +1,78 @@
+using Content.Shared.Popups;
+using Content.Shared.DeviceNetwork.Components;
+using Content.Shared.Verbs;
+using Content.Shared.RadioJammer;
+
+namespace Content.Shared.Radio.EntitySystems;
+
+public abstract class SharedJammerSystem : EntitySystem
+{
+    [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
+    [Dependency] protected readonly SharedPopupSystem Popup = default!;
+
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        SubscribeLocalEvent<RadioJammerComponent, GetVerbsEvent<Verb>>(OnGetVerb);
+    }
+
+    private void OnGetVerb(Entity<RadioJammerComponent> entity, ref GetVerbsEvent<Verb> args)
+    {
+        if (!args.CanAccess || !args.CanInteract)
+            return;
+
+        var user = args.User;
+
+        byte index = 0;
+        foreach (var setting in entity.Comp.Settings)
+        {
+            // This is because Act wont work with index.
+            // Needs it to be saved in the loop.
+            var currIndex = index;
+            var verb = new Verb
+            {
+                Priority = currIndex,
+                Category = VerbCategory.PowerLevel,
+                Disabled = entity.Comp.SelectedPowerLevel == currIndex,
+                Act = () =>
+                {
+                    entity.Comp.SelectedPowerLevel = currIndex;
+                    if (TryComp<DeviceNetworkJammerComponent>(entity.Owner, out var jammerComp))
+                    {
+                        // This is a little sketcy but only way to do it.
+                        jammerComp.Range = GetCurrentRange(entity.Comp);
+                        Dirty(entity.Owner, jammerComp);
+                    }
+                    Popup.PopupPredicted(Loc.GetString(setting.Message), user, user);
+                },
+                Text = Loc.GetString(setting.Name),
+            };
+            args.Verbs.Add(verb);
+            index++;
+        }
+    }
+
+    public float GetCurrentWattage(RadioJammerComponent jammer)
+    {
+        return jammer.Settings[jammer.SelectedPowerLevel].Wattage;
+    }
+
+    public float GetCurrentRange(RadioJammerComponent jammer)
+    {
+        return jammer.Settings[jammer.SelectedPowerLevel].Range;
+    }
+
+    protected void ChangeLEDState(bool isLEDOn, EntityUid uid,
+        AppearanceComponent? appearance = null)
+    {
+        _appearance.SetData(uid, RadioJammerVisuals.LEDOn, isLEDOn, appearance);
+    }
+
+    protected void ChangeChargeLevel(RadioJammerChargeLevel chargeLevel, EntityUid uid,
+        AppearanceComponent? appearance = null)
+    {
+        _appearance.SetData(uid, RadioJammerVisuals.ChargeLevel, chargeLevel, appearance);
+    }
+
+}
index d22041396fa266bdaf0997de6693a32fe8242e4d..9b9197249a93ea258029a19302e47e4cd2fd3ff9 100644 (file)
@@ -83,5 +83,7 @@ namespace Content.Shared.Verbs
         public static readonly VerbCategory Lever = new("verb-categories-lever", null);
 
         public static readonly VerbCategory SelectType = new("verb-categories-select-type", null);
+
+        public static readonly VerbCategory PowerLevel = new("verb-categories-power-level", null);
     }
 }
index 68efbf8d4eef2e2794dd04dff6de3f305e060594..eb540ee971f093957ac65c0683d20b7a12e1107f 100644 (file)
@@ -4,3 +4,13 @@ radio-jammer-component-off-state = off
 
 radio-jammer-component-examine-on-state = The light is currently [color=darkgreen]on[/color].
 radio-jammer-component-examine-off-state = The light is currently [color=darkred]off[/color].
+
+radio-jammer-component-setting-high = High
+radio-jammer-component-setting-medium = Medium
+radio-jammer-component-setting-low = Low
+
+radio-jammer-component-set-message-high = The jammer is now operating at high power.
+radio-jammer-component-set-message-medium = The jammer is now operating at medium power.
+radio-jammer-component-set-message-low = The jammer is now operating at low power.
+
+radio-jammer-component-switch-setting = The power level switch is set to "[color=yellow]{$powerLevel}[/color]".
index 2bebddca6124c4ef87f6b900d61ab53d548ee02a..c626e41ce16c9a5805a3a2b0afcad3a4e2831133 100644 (file)
@@ -28,6 +28,7 @@ verb-categories-timer = Set Delay
 verb-categories-lever = Lever
 verb-categories-select-type = Select Type
 verb-categories-fax = Set Destination
+verb-categories-power-level = Power Level
 
 verb-common-toggle-light = Toggle light
 verb-common-close = Close
index beb369562752b103e2d05156d06e4a3151257672..b456a23f1f8f9e93614f4953a3f37f6ab79778f9 100644 (file)
@@ -6,8 +6,26 @@
   components:
   - type: Sprite
     sprite: Objects/Devices/jammer.rsi
-    state: jammer
+    layers:
+        - state: jammer
+        - state: jammer_high_charge
+          map: ["enum.RadioJammerLayers.LED"]
+          shader: unshaded
+          visible: false
   - type: RadioJammer
+    settings:
+    - wattage: 1
+      range: 2.5
+      message: radio-jammer-component-set-message-low
+      name: radio-jammer-component-setting-low
+    - wattage: 2
+      range: 6
+      message: radio-jammer-component-set-message-medium
+      name: radio-jammer-component-setting-medium
+    - wattage: 12
+      range: 12
+      message: radio-jammer-component-set-message-high
+      name: radio-jammer-component-setting-high
   - type: PowerCellSlot
     cellSlotId: cell_slot
   - type: ContainerContainer
       cell_slot:
         name: power-cell-slot-component-slot-name-default
         startingItem: PowerCellMedium
+  - type: Appearance
+  - type: GenericVisualizer
+    visuals:
+      enum.RadioJammerVisuals.LEDOn:
+        RadioJammerLayers.LED:
+          True: { visible: True }
+          False: { visible: False }
+      enum.RadioJammerVisuals.ChargeLevel:
+        RadioJammerLayers.LED:
+          Low: {state: jammer_low_charge}
+          Medium: {state: jammer_medium_charge}
+          High: {state: jammer_high_charge}
index 6de27ba924f109e4b6bcf08e517a0ec822575e90..e1db2d05b65b8ea456bd56b17f35d59002099610 100644 (file)
Binary files a/Resources/Textures/Objects/Devices/jammer.rsi/jammer.png and b/Resources/Textures/Objects/Devices/jammer.rsi/jammer.png differ
diff --git a/Resources/Textures/Objects/Devices/jammer.rsi/jammer_high_charge.png b/Resources/Textures/Objects/Devices/jammer.rsi/jammer_high_charge.png
new file mode 100644 (file)
index 0000000..e288427
Binary files /dev/null and b/Resources/Textures/Objects/Devices/jammer.rsi/jammer_high_charge.png differ
diff --git a/Resources/Textures/Objects/Devices/jammer.rsi/jammer_low_charge.png b/Resources/Textures/Objects/Devices/jammer.rsi/jammer_low_charge.png
new file mode 100644 (file)
index 0000000..0950a95
Binary files /dev/null and b/Resources/Textures/Objects/Devices/jammer.rsi/jammer_low_charge.png differ
diff --git a/Resources/Textures/Objects/Devices/jammer.rsi/jammer_medium_charge.png b/Resources/Textures/Objects/Devices/jammer.rsi/jammer_medium_charge.png
new file mode 100644 (file)
index 0000000..7c12da8
Binary files /dev/null and b/Resources/Textures/Objects/Devices/jammer.rsi/jammer_medium_charge.png differ
index 2923d9ac6368879d8f86cc92c4eb7c3fe0c8b6c7..d837374a87fe6dda3ad47fcb82c73f11b632c342 100644 (file)
@@ -1,7 +1,7 @@
 {
     "version": 1,
     "license": "CC-BY-SA-3.0",
-    "copyright": "Taken from https://github.com/tgstation/tgstation/commit/c65da5a49477413310c81c460ea4b243a9f864dd",
+    "copyright": "Taken from https://github.com/tgstation/tgstation/commit/c65da5a49477413310c81c460ea4b243a9f864dd with minor edits.",
     "size": {
         "x": 32,
         "y": 32
         {
             "name": "jammer",
             "directions": 1
+        },
+        {
+            "name": "jammer_high_charge",
+            "directions": 1
+        },
+        {
+            "name": "jammer_medium_charge",
+            "directions": 1
+        },
+        {
+            "name": "jammer_low_charge",
+            "directions": 1,
+        "delays": [
+            [
+            0.3,
+            0.3
+            ]
+        ]
         }
     ]
-}
\ No newline at end of file
+}