Гипоспрей борга теперь позволяет выбирать нужный реагент. (#676)
This commit is contained in:
parent
62854643f0
commit
82bb9039ea
6 changed files with 103 additions and 43 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<BorgSwitchableTypeComponent> ent, ProtoId<BorgTypePrototype> 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<JobPrototype>(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<StationRecordKeyStorageComponent>(uid, out var keyStorage)
|
||||
|| keyStorage.Key is not { } key
|
||||
|| !_record.TryGetRecord<GeneralStationRecord>(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<RadioChannelPrototype>(channelName);
|
||||
_radioSystem.SendRadioMessage(source, message, channel, source);
|
||||
}
|
||||
// Sunrise-End
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<ReagentQuantity> Options = default!;
|
||||
|
||||
[DataField("currentIndex"), ViewVariables(VVAccess.ReadWrite)]
|
||||
public int CurrentIndex = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Should the already generated solution be kept when switching?
|
||||
/// </summary>
|
||||
[DataField("keepSolution"), ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool KeepSolution = false;
|
||||
public bool KeepSolution;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<SolutionRegenerationSwitcherComponent, GetVerbsEvent<AlternativeVerb>>(AddSwitchVerb);
|
||||
SubscribeLocalEvent<SolutionRegenerationSwitcherComponent, GetVerbsEvent<Verb>>(AddSwitchVerb);
|
||||
}
|
||||
|
||||
private void AddSwitchVerb(EntityUid uid, SolutionRegenerationSwitcherComponent component, GetVerbsEvent<AlternativeVerb> args)
|
||||
private void AddSwitchVerb(EntityUid uid, SolutionRegenerationSwitcherComponent component, GetVerbsEvent<Verb> 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<SolutionRegenerationComponent>(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<SolutionRegenerationComponent>(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<SolutionRegenerationComponent>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,2 +0,0 @@
|
|||
autoregen-switched = Теперь производится { $reagent }.
|
||||
autoreagent-switch = Сменить реагент
|
||||
|
|
@ -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 = Переключает производство реагента.
|
||||
Loading…
Add table
Reference in a new issue