]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add chatty lathes (#34959)
authorpathetic meowmeow <uhhadd@gmail.com>
Wed, 16 Apr 2025 19:29:25 +0000 (15:29 -0400)
committerGitHub <noreply@github.com>
Wed, 16 Apr 2025 19:29:25 +0000 (21:29 +0200)
Content.Server/Lathe/Components/LatheAnnouncingComponent.cs [new file with mode: 0644]
Content.Server/Lathe/LatheSystem.cs
Content.Server/Research/Systems/ResearchSystem.Technology.cs
Content.Shared/Research/Components/TechnologyDatabaseComponent.cs
Content.Shared/Research/Systems/BlueprintSystem.cs
Content.Shared/Research/Systems/SharedResearchSystem.cs
Resources/Locale/en-US/lathe/lathesystem.ftl
Resources/Prototypes/Entities/Structures/Machines/lathe.yml

diff --git a/Content.Server/Lathe/Components/LatheAnnouncingComponent.cs b/Content.Server/Lathe/Components/LatheAnnouncingComponent.cs
new file mode 100644 (file)
index 0000000..16c30d9
--- /dev/null
@@ -0,0 +1,17 @@
+using Content.Shared.Radio;
+using Robust.Shared.Prototypes;
+
+namespace Content.Server.Lathe.Components;
+
+/// <summary>
+/// Causes this entity to announce onto the provided channels when it receives new recipes from its server
+/// </summary>
+[RegisterComponent]
+public sealed partial class LatheAnnouncingComponent : Component
+{
+    /// <summary>
+    /// Radio channels to broadcast to when a new set of recipes is received
+    /// </summary>
+    [DataField(required: true)]
+    public List<ProtoId<RadioChannelPrototype>> Channels = new();
+}
index 68a5228bdfccb4ea1f209e165a5c0f2869ea0d55..4851f6b63dcad45709cc78580aeff963a20e9d58 100644 (file)
@@ -8,6 +8,7 @@ using Content.Server.Materials;
 using Content.Server.Popups;
 using Content.Server.Power.Components;
 using Content.Server.Power.EntitySystems;
+using Content.Server.Radio.EntitySystems;
 using Content.Server.Stack;
 using Content.Shared.Atmos;
 using Content.Shared.Chemistry.Components;
@@ -20,6 +21,7 @@ using Content.Shared.Emag.Systems;
 using Content.Shared.Examine;
 using Content.Shared.Lathe;
 using Content.Shared.Lathe.Prototypes;
+using Content.Shared.Localizations;
 using Content.Shared.Materials;
 using Content.Shared.Power;
 using Content.Shared.ReagentSpeed;
@@ -53,6 +55,7 @@ namespace Content.Server.Lathe
         [Dependency] private readonly SharedSolutionContainerSystem _solution = default!;
         [Dependency] private readonly StackSystem _stack = default!;
         [Dependency] private readonly TransformSystem _transform = default!;
+        [Dependency] private readonly RadioSystem _radio = default!;
 
         /// <summary>
         /// Per-tick cache
@@ -67,6 +70,7 @@ namespace Content.Server.Lathe
             SubscribeLocalEvent<LatheComponent, MapInitEvent>(OnMapInit);
             SubscribeLocalEvent<LatheComponent, PowerChangedEvent>(OnPowerChanged);
             SubscribeLocalEvent<LatheComponent, TechnologyDatabaseModifiedEvent>(OnDatabaseModified);
+            SubscribeLocalEvent<LatheAnnouncingComponent, TechnologyDatabaseModifiedEvent>(OnTechnologyDatabaseModified);
             SubscribeLocalEvent<LatheComponent, ResearchRegistrationChangedEvent>(OnResearchRegistrationChanged);
 
             SubscribeLocalEvent<LatheComponent, LatheQueueRecipeMessage>(OnLatheQueueRecipeMessage);
@@ -364,6 +368,41 @@ namespace Content.Server.Lathe
             UpdateUserInterfaceState(uid, component);
         }
 
+        private void OnTechnologyDatabaseModified(Entity<LatheAnnouncingComponent> ent, ref TechnologyDatabaseModifiedEvent args)
+        {
+            if (args.NewlyUnlockedRecipes is null)
+                return;
+
+            if (!TryGetAvailableRecipes(ent.Owner, out var potentialRecipes))
+                return;
+
+            var recipeNames = new List<string>();
+            foreach (var recipeId in args.NewlyUnlockedRecipes)
+            {
+                if (!potentialRecipes.Contains(new(recipeId)))
+                    continue;
+
+                if (!_proto.TryIndex(recipeId, out LatheRecipePrototype? recipe))
+                    continue;
+
+                var itemName = GetRecipeName(recipe!);
+                recipeNames.Add(Loc.GetString("lathe-unlock-recipe-radio-broadcast-item", ("item", itemName)));
+            }
+
+            if (recipeNames.Count == 0)
+                return;
+
+            var message = Loc.GetString(
+                "lathe-unlock-recipe-radio-broadcast",
+                ("items", ContentLocalizationManager.FormatList(recipeNames))
+            );
+
+            foreach (var channel in ent.Comp.Channels)
+            {
+                _radio.SendRadioMessage(ent.Owner, message, channel, ent.Owner, escapeMarkup: false);
+            }
+        }
+
         private void OnResearchRegistrationChanged(EntityUid uid, LatheComponent component, ref ResearchRegistrationChangedEvent args)
         {
             UpdateUserInterfaceState(uid, component);
index 360985b4b6371aa487719ce8df1d0f7463805269..0237c8712a31713a762ca53c7e69d0045bdf5922 100644 (file)
@@ -119,15 +119,17 @@ public sealed partial class ResearchSystem
         }
 
         component.UnlockedTechnologies.Add(technology.ID);
+        var addedRecipes = new List<string>();
         foreach (var unlock in technology.RecipeUnlocks)
         {
             if (component.UnlockedRecipes.Contains(unlock))
                 continue;
             component.UnlockedRecipes.Add(unlock);
+            addedRecipes.Add(unlock);
         }
         Dirty(uid, component);
 
-        var ev = new TechnologyDatabaseModifiedEvent();
+        var ev = new TechnologyDatabaseModifiedEvent(addedRecipes);
         RaiseLocalEvent(uid, ref ev);
     }
 
index 4f976869f76b8ce3395e878e8727e5d1ede0c929..a69e4ee9dd709484b01c76e8c4115cb37bff280f 100644 (file)
@@ -54,7 +54,7 @@ public sealed partial class TechnologyDatabaseComponent : Component
 /// server to all of it's clients.
 /// </remarks>
 [ByRefEvent]
-public readonly record struct TechnologyDatabaseModifiedEvent;
+public readonly record struct TechnologyDatabaseModifiedEvent(List<string>? NewlyUnlockedRecipes);
 
 /// <summary>
 /// Event raised on a database after being synchronized
index 237ff70300255d8a5224285cb34bcab1165bae4a..903e52908933f15ee3e661d811e2721c2db0c2ca 100644 (file)
@@ -7,6 +7,7 @@ using Content.Shared.Research.Prototypes;
 using Content.Shared.Whitelist;
 using Robust.Shared.Containers;
 using Robust.Shared.Prototypes;
+using System.Linq;
 
 namespace Content.Shared.Research.Systems;
 
@@ -64,7 +65,7 @@ public sealed class BlueprintSystem : EntitySystem
 
         _container.Insert(blueprint.Owner, _container.GetContainer(ent, ent.Comp.ContainerId));
 
-        var ev = new TechnologyDatabaseModifiedEvent();
+        var ev = new TechnologyDatabaseModifiedEvent(blueprint.Comp.ProvidedRecipes.Select(it => it.Id).ToList());
         RaiseLocalEvent(ent, ref ev);
         return true;
     }
index bca1ae4888f37c9b14c2dea0e394ea6427bd4e3f..7ed33f72043581f5aca554db88bcad9cb4be8f63 100644 (file)
@@ -301,7 +301,7 @@ public abstract class SharedResearchSystem : EntitySystem
         component.UnlockedRecipes.Add(recipe);
         Dirty(uid, component);
 
-        var ev = new TechnologyDatabaseModifiedEvent();
+        var ev = new TechnologyDatabaseModifiedEvent(new List<string> { recipe });
         RaiseLocalEvent(uid, ref ev);
     }
 }
index 9fa62e0c1e05e094893b938bcae24f9bb63e9ba2..93e0107f6816d0efd27a1036a10eb97c5da425da 100644 (file)
@@ -1 +1,3 @@
 lathe-popup-material-not-used = This material is not used in this machine.
+lathe-unlock-recipe-radio-broadcast = This lathe is now capable of producing the following recipes: {$items}
+lathe-unlock-recipe-radio-broadcast-item = [bold]{$item}[/bold]
index cf3bcac302e6292c1ae3500b07e86ba8dfc0685b..0d008ed1e175bb3b8f9294585c8982bca6c9f66f 100644 (file)
         - Sheet
         - RawMaterial
         - Ingot
+  - type: LatheAnnouncing
+    channels: [Security]
 
 - type: entity
   id: AmmoTechFab
     board: MedicalTechFabCircuitboard
   - type: StealTarget
     stealGroup: MedicalTechFabCircuitboard
+  - type: LatheAnnouncing
+    channels: [Medical]
 
 - type: entity
   parent: BaseLathe