Skip to content

Commit

Permalink
Гипоспрей борга теперь позволяет выбирать нужный реагент.
Browse files Browse the repository at this point in the history
  • Loading branch information
VigersRay committed Nov 20, 2024
1 parent 6285464 commit 068a5d1
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
55 changes: 55 additions & 0 deletions Content.Server/Silicons/Borgs/BorgSwitchableTypeSystem.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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)
{
Expand Down Expand Up @@ -77,6 +85,53 @@ protected override void SelectBorgModule(Entity<BorgSwitchableTypeComponent> ent
_inventorySystem.SetTemplateId((ent.Owner, inventory), prototype.InventoryTemplateId);
}

// Sunrise-Start
var borgName = MetaData(ent.Owner).EntityName;
if (Prototypes.TryIndex<JobPrototype>(prototype.Job, out var jobPrototype))

Check failure on line 90 in Content.Server/Silicons/Borgs/BorgSwitchableTypeSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

'BorgTypePrototype' does not contain a definition for 'Job' and no accessible extension method 'Job' accepting a first argument of type 'BorgTypePrototype' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 90 in Content.Server/Silicons/Borgs/BorgSwitchableTypeSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

'BorgTypePrototype' does not contain a definition for 'Job' and no accessible extension method 'Job' accepting a first argument of type 'BorgTypePrototype' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 90 in Content.Server/Silicons/Borgs/BorgSwitchableTypeSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

'BorgTypePrototype' does not contain a definition for 'Job' and no accessible extension method 'Job' accepting a first argument of type 'BorgTypePrototype' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 90 in Content.Server/Silicons/Borgs/BorgSwitchableTypeSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

'BorgTypePrototype' does not contain a definition for 'Job' and no accessible extension method 'Job' accepting a first argument of type 'BorgTypePrototype' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 90 in Content.Server/Silicons/Borgs/BorgSwitchableTypeSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'BorgTypePrototype' does not contain a definition for 'Job' and no accessible extension method 'Job' accepting a first argument of type 'BorgTypePrototype' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 90 in Content.Server/Silicons/Borgs/BorgSwitchableTypeSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'BorgTypePrototype' does not contain a definition for 'Job' and no accessible extension method 'Job' accepting a first argument of type 'BorgTypePrototype' could be found (are you missing a using directive or an assembly reference?)
{
UpdateStationRecord(ent.Owner,
jobPrototype.LocalizedName,
jobPrototype);

foreach (var channel in ent.Comp.NotifyChannels)

Check failure on line 96 in Content.Server/Silicons/Borgs/BorgSwitchableTypeSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

'BorgSwitchableTypeComponent' does not contain a definition for 'NotifyChannels' and no accessible extension method 'NotifyChannels' accepting a first argument of type 'BorgSwitchableTypeComponent' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 96 in Content.Server/Silicons/Borgs/BorgSwitchableTypeSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

'BorgSwitchableTypeComponent' does not contain a definition for 'NotifyChannels' and no accessible extension method 'NotifyChannels' accepting a first argument of type 'BorgSwitchableTypeComponent' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 96 in Content.Server/Silicons/Borgs/BorgSwitchableTypeSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

'BorgSwitchableTypeComponent' does not contain a definition for 'NotifyChannels' and no accessible extension method 'NotifyChannels' accepting a first argument of type 'BorgSwitchableTypeComponent' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 96 in Content.Server/Silicons/Borgs/BorgSwitchableTypeSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

'BorgSwitchableTypeComponent' does not contain a definition for 'NotifyChannels' and no accessible extension method 'NotifyChannels' accepting a first argument of type 'BorgSwitchableTypeComponent' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 96 in Content.Server/Silicons/Borgs/BorgSwitchableTypeSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'BorgSwitchableTypeComponent' does not contain a definition for 'NotifyChannels' and no accessible extension method 'NotifyChannels' accepting a first argument of type 'BorgSwitchableTypeComponent' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 96 in Content.Server/Silicons/Borgs/BorgSwitchableTypeSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'BorgSwitchableTypeComponent' does not contain a definition for 'NotifyChannels' and no accessible extension method 'NotifyChannels' accepting a first argument of type 'BorgSwitchableTypeComponent' could be found (are you missing a using directive or an assembly reference?)
{
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
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
using Content.Shared.Chemistry.Reagent;

namespace Content.Server.Sunrise.SolutionRegenerationSwitcher
namespace Content.Server._Sunrise.SolutionRegenerationSwitcher
{
[RegisterComponent]
public sealed partial class SolutionRegenerationSwitcherComponent : Component
{
[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;
}
}
Original file line number Diff line number Diff line change
@@ -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!;
Expand All @@ -21,67 +21,76 @@ public override void Initialize()

_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,

Check failure on line 43 in Content.Server/_Sunrise/SolutionRegenerationSwitcher/SolutionRegenerationSwitcherSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

'VerbCategory' does not contain a definition for 'ReagentSwitch'

Check failure on line 43 in Content.Server/_Sunrise/SolutionRegenerationSwitcher/SolutionRegenerationSwitcherSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

'VerbCategory' does not contain a definition for 'ReagentSwitch'

Check failure on line 43 in Content.Server/_Sunrise/SolutionRegenerationSwitcher/SolutionRegenerationSwitcherSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

'VerbCategory' does not contain a definition for 'ReagentSwitch'

Check failure on line 43 in Content.Server/_Sunrise/SolutionRegenerationSwitcher/SolutionRegenerationSwitcherSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

'VerbCategory' does not contain a definition for 'ReagentSwitch'

Check failure on line 43 in Content.Server/_Sunrise/SolutionRegenerationSwitcher/SolutionRegenerationSwitcherSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'VerbCategory' does not contain a definition for 'ReagentSwitch'

Check failure on line 43 in Content.Server/_Sunrise/SolutionRegenerationSwitcher/SolutionRegenerationSwitcherSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'VerbCategory' does not contain a definition for '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))
{
_sawmill.Warning($"{ToPrettyString(uid)} has no SolutionRegenerationComponent.");
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];

if (TryComp<SolutionRegenerationComponent>(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);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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 = Переключает производство реагента.

0 comments on commit 068a5d1

Please sign in to comment.