diff --git a/Content.Server/Chemistry/Components/SolutionRegenerationComponent.cs b/Content.Server/Chemistry/Components/SolutionRegenerationComponent.cs index 6d284ab1869..d183e104e1c 100644 --- a/Content.Server/Chemistry/Components/SolutionRegenerationComponent.cs +++ b/Content.Server/Chemistry/Components/SolutionRegenerationComponent.cs @@ -1,5 +1,5 @@ +using Content.Server._Sunrise.SolutionRegenerationSwitcher; using Content.Server.Chemistry.EntitySystems; -using Content.Server.Sunrise.SolutionRegenerationSwitcher; using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Reagent; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom; diff --git a/Content.Server/Silicons/Borgs/BorgSwitchableTypeSystem.cs b/Content.Server/Silicons/Borgs/BorgSwitchableTypeSystem.cs index d1a32a6a5ba..3d6bcd680bf 100644 --- a/Content.Server/Silicons/Borgs/BorgSwitchableTypeSystem.cs +++ b/Content.Server/Silicons/Borgs/BorgSwitchableTypeSystem.cs @@ -1,8 +1,14 @@ using Content.Server.Inventory; using Content.Server.Radio.Components; +using Content.Server.Radio.EntitySystems; +using Content.Server.StationRecords.Systems; +using Content.Shared.Access; using Content.Shared.Inventory; +using Content.Shared.Radio; +using Content.Shared.Roles; using Content.Shared.Silicons.Borgs; using Content.Shared.Silicons.Borgs.Components; +using Content.Shared.StationRecords; using Robust.Shared.Prototypes; using Robust.Shared.Utility; @@ -15,6 +21,8 @@ public sealed class BorgSwitchableTypeSystem : SharedBorgSwitchableTypeSystem { [Dependency] private readonly BorgSystem _borgSystem = default!; [Dependency] private readonly ServerInventorySystem _inventorySystem = default!; + [Dependency] private readonly RadioSystem _radioSystem = default!; + [Dependency] private readonly StationRecordsSystem _record = default!; protected override void SelectBorgModule(Entity ent, ProtoId borgType) { @@ -77,6 +85,53 @@ protected override void SelectBorgModule(Entity ent _inventorySystem.SetTemplateId((ent.Owner, inventory), prototype.InventoryTemplateId); } + // Sunrise-Start + var borgName = MetaData(ent.Owner).EntityName; + if (Prototypes.TryIndex(prototype.Job, out var jobPrototype)) + { + UpdateStationRecord(ent.Owner, + jobPrototype.LocalizedName, + jobPrototype); + + foreach (var channel in ent.Comp.NotifyChannels) + { + Report(ent.Owner, + channel, + Loc.GetString("borg-switch-type-notify", + ("name", borgName), + ("type", jobPrototype.LocalizedName))); + } + } + // Sunrise-End + base.SelectBorgModule(ent, borgType); } + + // Sunrise-Start + public void UpdateStationRecord(EntityUid uid, string newJobTitle, JobPrototype? newJobProto) + { + if (!TryComp(uid, out var keyStorage) + || keyStorage.Key is not { } key + || !_record.TryGetRecord(key, out var record)) + { + return; + } + + record.JobTitle = newJobTitle; + + if (newJobProto != null) + { + record.JobPrototype = newJobProto.ID; + record.JobIcon = newJobProto.Icon; + } + + _record.Synchronize(key); + } + + private void Report(EntityUid source, string channelName, string message) + { + var channel = Prototypes.Index(channelName); + _radioSystem.SendRadioMessage(source, message, channel, source); + } + // Sunrise-End } diff --git a/Content.Server/_Sunrise/SolutionRegenerationSwitcher/SolutionRegenerationSwitcherComponent.cs b/Content.Server/_Sunrise/SolutionRegenerationSwitcher/SolutionRegenerationSwitcherComponent.cs index ff56218dacc..15c666b37a3 100644 --- a/Content.Server/_Sunrise/SolutionRegenerationSwitcher/SolutionRegenerationSwitcherComponent.cs +++ b/Content.Server/_Sunrise/SolutionRegenerationSwitcher/SolutionRegenerationSwitcherComponent.cs @@ -1,6 +1,6 @@ using Content.Shared.Chemistry.Reagent; -namespace Content.Server.Sunrise.SolutionRegenerationSwitcher +namespace Content.Server._Sunrise.SolutionRegenerationSwitcher { [RegisterComponent] public sealed partial class SolutionRegenerationSwitcherComponent : Component @@ -8,13 +8,7 @@ public sealed partial class SolutionRegenerationSwitcherComponent : Component [DataField("options", required: true), ViewVariables(VVAccess.ReadWrite)] public List Options = default!; - [DataField("currentIndex"), ViewVariables(VVAccess.ReadWrite)] - public int CurrentIndex = 0; - - /// - /// Should the already generated solution be kept when switching? - /// [DataField("keepSolution"), ViewVariables(VVAccess.ReadWrite)] - public bool KeepSolution = false; + public bool KeepSolution; } } diff --git a/Content.Server/_Sunrise/SolutionRegenerationSwitcher/SolutionRegenerationSwitcherSystem.cs b/Content.Server/_Sunrise/SolutionRegenerationSwitcher/SolutionRegenerationSwitcherSystem.cs index b35704c2113..3cdf4099fa1 100644 --- a/Content.Server/_Sunrise/SolutionRegenerationSwitcher/SolutionRegenerationSwitcherSystem.cs +++ b/Content.Server/_Sunrise/SolutionRegenerationSwitcher/SolutionRegenerationSwitcherSystem.cs @@ -1,16 +1,16 @@ using Content.Server.Chemistry.Components; -using Content.Server.Chemistry.Containers.EntitySystems; using Content.Server.Popups; +using Content.Shared.Chemistry.EntitySystems; using Content.Shared.Chemistry.Reagent; using Content.Shared.Verbs; using Robust.Shared.Prototypes; -namespace Content.Server.Sunrise.SolutionRegenerationSwitcher +namespace Content.Server._Sunrise.SolutionRegenerationSwitcher { public sealed class SolutionRegenerationSwitcherSystem : EntitySystem { [Dependency] private readonly IPrototypeManager _prototypeManager = default!; - [Dependency] private readonly SolutionContainerSystem _solutionSystem = default!; + [Dependency] private readonly SharedSolutionContainerSystem _solutionSystem = default!; [Dependency] private readonly PopupSystem _popups = default!; private ISawmill _sawmill = default!; @@ -21,30 +21,38 @@ public override void Initialize() _sawmill = Logger.GetSawmill("chemistry"); - SubscribeLocalEvent>(AddSwitchVerb); + SubscribeLocalEvent>(AddSwitchVerb); } - private void AddSwitchVerb(EntityUid uid, SolutionRegenerationSwitcherComponent component, GetVerbsEvent args) + private void AddSwitchVerb(EntityUid uid, SolutionRegenerationSwitcherComponent component, GetVerbsEvent args) { if (!args.CanInteract || !args.CanAccess) return; - if (component.Options.Count <= 1) - return; - - AlternativeVerb verb = new() + foreach (var componentOption in component.Options) { - Act = () => + if (!_prototypeManager.TryIndex(componentOption.Reagent.Prototype, out ReagentPrototype? proto)) { - SwitchReagent(uid, component, args.User); - }, - Text = Loc.GetString("autoreagent-switch"), - Priority = 2 - }; - args.Verbs.Add(verb); + _sawmill.Error($"Can't get get reagent prototype {componentOption.Reagent.Prototype} for {ToPrettyString(uid)}"); + return; + } + + Verb reagent = new() + { + Text = proto.LocalizedName, + Category = VerbCategory.ReagentSwitch, + Act = () => + { + SwitchReagent(uid, componentOption, component, args.User); + }, + Priority = 2, + Message = Loc.GetString("solution-regeneration-switcher-switch-verb-text"), + }; + args.Verbs.Add(reagent); + } } - private void SwitchReagent(EntityUid uid, SolutionRegenerationSwitcherComponent component, EntityUid user) + private void SwitchReagent(EntityUid uid, ReagentQuantity reagent, SolutionRegenerationSwitcherComponent component, EntityUid user) { if (!TryComp(uid, out var solutionRegenerationComponent)) { @@ -52,36 +60,37 @@ private void SwitchReagent(EntityUid uid, SolutionRegenerationSwitcherComponent return; } - if (component.CurrentIndex + 1 == component.Options.Count) - component.CurrentIndex = 0; - else - component.CurrentIndex++; - if (!_solutionSystem.TryGetSolution(uid, solutionRegenerationComponent.SolutionName, out var solution)) { _sawmill.Error($"Can't get SolutionRegeneration.Solution for {ToPrettyString(uid)}"); return; } + if (!TryComp(uid, out var solutionRegeneration)) + { + _sawmill.Error($"Entity {ToPrettyString(uid)} not have SolutionRegenerationComponent"); + return; + } + + if (solutionRegeneration.Generated.ContainsReagent(reagent.Reagent)) + { + _popups.PopupEntity(Loc.GetString("solution-regeneration-switcher-already-select"), user, user); + return; + } + // Empty out the current solution. if (!component.KeepSolution) _solutionSystem.RemoveAllSolution(solution.Value); - // Replace the generating solution with the newly selected solution. - var newReagent = component.Options[component.CurrentIndex]; - - if (TryComp(uid, out var solutionRegeneration)) - { - solutionRegeneration.ChangeGenerated(newReagent); - } + solutionRegeneration.ChangeGenerated(reagent); - if (!_prototypeManager.TryIndex(newReagent.Reagent.Prototype, out ReagentPrototype? proto)) + if (!_prototypeManager.TryIndex(reagent.Reagent.Prototype, out ReagentPrototype? proto)) { - _sawmill.Error($"Can't get get reagent prototype {newReagent.Reagent.Prototype} for {ToPrettyString(uid)}"); + _sawmill.Error($"Can't get get reagent prototype {reagent.Reagent.Prototype} for {ToPrettyString(uid)}"); return; } - _popups.PopupEntity(Loc.GetString("autoregen-switched", ("reagent", proto.LocalizedName)), user, user); + _popups.PopupEntity(Loc.GetString("solution-regeneration-switcher-switched", ("reagent", proto.LocalizedName)), user, user); } } } diff --git a/Resources/Locale/en-US/_strings/_sunrise/autoregen-switcher/autoregen-component.ftl b/Resources/Locale/en-US/_strings/_sunrise/autoregen-switcher/autoregen-component.ftl deleted file mode 100644 index 013fcdd79da..00000000000 --- a/Resources/Locale/en-US/_strings/_sunrise/autoregen-switcher/autoregen-component.ftl +++ /dev/null @@ -1,2 +0,0 @@ -autoregen-switched = Теперь производится { $reagent }. -autoreagent-switch = Сменить реагент diff --git a/Resources/Locale/en-US/_strings/_sunrise/autoregen-switcher/solution-regeneration-switcher.ftl b/Resources/Locale/en-US/_strings/_sunrise/autoregen-switcher/solution-regeneration-switcher.ftl new file mode 100644 index 00000000000..7cdfca68182 --- /dev/null +++ b/Resources/Locale/en-US/_strings/_sunrise/autoregen-switcher/solution-regeneration-switcher.ftl @@ -0,0 +1,4 @@ +solution-regeneration-switcher-switched = Теперь производится { $reagent } +solution-regeneration-switcher-switch-verb = Сменить реагент +solution-regeneration-switcher-already-select = Реагент уже выбран +solution-regeneration-switcher-switch-verb-text = Переключает производство реагента.