Add chatty lathes (#34959)
This commit is contained in:
committed by
GitHub
parent
be5bbd4dc3
commit
5d38ae56de
17
Content.Server/Lathe/Components/LatheAnnouncingComponent.cs
Normal file
17
Content.Server/Lathe/Components/LatheAnnouncingComponent.cs
Normal file
@@ -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();
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -408,6 +408,8 @@
|
||||
- Sheet
|
||||
- RawMaterial
|
||||
- Ingot
|
||||
- type: LatheAnnouncing
|
||||
channels: [Security]
|
||||
|
||||
- type: entity
|
||||
id: AmmoTechFab
|
||||
@@ -478,6 +480,8 @@
|
||||
board: MedicalTechFabCircuitboard
|
||||
- type: StealTarget
|
||||
stealGroup: MedicalTechFabCircuitboard
|
||||
- type: LatheAnnouncing
|
||||
channels: [Medical]
|
||||
|
||||
- type: entity
|
||||
parent: BaseLathe
|
||||
|
||||
Reference in New Issue
Block a user