From 82bb9039ea214818e8d57c338939f2829bacd763 Mon Sep 17 00:00:00 2001 From: Vigers Ray <60344369+VigersRay@users.noreply.github.com> Date: Wed, 20 Nov 2024 17:39:36 +0300 Subject: [PATCH] =?UTF-8?q?=D0=93=D0=B8=D0=BF=D0=BE=D1=81=D0=BF=D1=80?= =?UTF-8?q?=D0=B5=D0=B9=20=D0=B1=D0=BE=D1=80=D0=B3=D0=B0=20=D1=82=D0=B5?= =?UTF-8?q?=D0=BF=D0=B5=D1=80=D1=8C=20=D0=BF=D0=BE=D0=B7=D0=B2=D0=BE=D0=BB?= =?UTF-8?q?=D1=8F=D0=B5=D1=82=20=D0=B2=D1=8B=D0=B1=D0=B8=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D1=8C=20=D0=BD=D1=83=D0=B6=D0=BD=D1=8B=D0=B9=20=D1=80=D0=B5?= =?UTF-8?q?=D0=B0=D0=B3=D0=B5=D0=BD=D1=82.=20(#676)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SolutionRegenerationComponent.cs | 2 +- .../Borgs/BorgSwitchableTypeSystem.cs | 55 ++++++++++++++ .../SolutionRegenerationSwitcherComponent.cs | 10 +-- .../SolutionRegenerationSwitcherSystem.cs | 73 +++++++++++-------- .../autoregen-component.ftl | 2 - .../solution-regeneration-switcher.ftl | 4 + 6 files changed, 103 insertions(+), 43 deletions(-) delete mode 100644 Resources/Locale/en-US/_strings/_sunrise/autoregen-switcher/autoregen-component.ftl create mode 100644 Resources/Locale/en-US/_strings/_sunrise/autoregen-switcher/solution-regeneration-switcher.ftl diff --git a/Content.Server/Chemistry/Components/SolutionRegenerationComponent.cs b/Content.Server/Chemistry/Components/SolutionRegenerationComponent.cs index 6d284ab186..d183e104e1 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 d1a32a6a5b..3d6bcd680b 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 @@ public sealed class BorgSwitchableTypeSystem : SharedBorgSwitchableTypeSystem _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 ff56218dac..15c666b37a 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 @@ namespace Content.Server.Sunrise.SolutionRegenerationSwitcher [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 b35704c211..3cdf4099fa 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 @@ namespace Content.Server.Sunrise.SolutionRegenerationSwitcher _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 @@ namespace Content.Server.Sunrise.SolutionRegenerationSwitcher 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]; + solutionRegeneration.ChangeGenerated(reagent); - if (TryComp(uid, out var solutionRegeneration)) + if (!_prototypeManager.TryIndex(reagent.Reagent.Prototype, out ReagentPrototype? proto)) { - solutionRegeneration.ChangeGenerated(newReagent); - } - - if (!_prototypeManager.TryIndex(newReagent.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 013fcdd79d..0000000000 --- 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 0000000000..7cdfca6818 --- /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 = Переключает производство реагента.