diff --git a/Content.Server/Construction/Conditions/MachineFrameComplete.cs b/Content.Server/Construction/Conditions/MachineFrameComplete.cs index 61a1984c30..42c5998a67 100644 --- a/Content.Server/Construction/Conditions/MachineFrameComplete.cs +++ b/Content.Server/Construction/Conditions/MachineFrameComplete.cs @@ -65,6 +65,15 @@ namespace Content.Server.Construction.Conditions message.AddMarkup(Loc.GetString("[color=yellow]{0}x[/color] [color=green]{1}[/color]\n", info.Amount, Loc.GetString(info.ExamineName))); } + foreach (var (tagName, info) in machineFrame.TagRequirements) + { + var amount = info.Amount - machineFrame.TagProgress[tagName]; + + if(amount == 0) continue; + + message.AddMarkup(Loc.GetString("[color=yellow]{0}x[/color] [color=green]{1}[/color]\n", info.Amount, Loc.GetString(info.ExamineName))); + } + return true; } } diff --git a/Content.Server/GameObjects/Components/Construction/MachineBoardComponent.cs b/Content.Server/GameObjects/Components/Construction/MachineBoardComponent.cs index 2ca8841006..98a3895950 100644 --- a/Content.Server/GameObjects/Components/Construction/MachineBoardComponent.cs +++ b/Content.Server/GameObjects/Components/Construction/MachineBoardComponent.cs @@ -28,9 +28,13 @@ namespace Content.Server.GameObjects.Components.Construction [DataField("materialRequirements")] private Dictionary _materialIdRequirements = new(); + [ViewVariables] + [DataField("tagRequirements")] + private Dictionary _tagRequirements = new(); + [ViewVariables] [DataField("componentRequirements")] - private Dictionary _componentRequirements = new(); + private Dictionary _componentRequirements = new(); [ViewVariables(VVAccess.ReadWrite)] [DataField("prototype")] @@ -52,7 +56,9 @@ namespace Content.Server.GameObjects.Components.Construction } } - public IReadOnlyDictionary ComponentRequirements => _componentRequirements; + public IReadOnlyDictionary ComponentRequirements => _componentRequirements; + public IReadOnlyDictionary TagRequirements => _tagRequirements; + public void Examine(FormattedMessage message, bool inDetailsRange) { @@ -71,12 +77,17 @@ namespace Content.Server.GameObjects.Components.Construction { message.AddMarkup(Loc.GetString("[color=yellow]{0}x[/color] [color=green]{1}[/color]\n", info.Amount, Loc.GetString(info.ExamineName))); } + + foreach (var (_, info) in TagRequirements) + { + message.AddMarkup(Loc.GetString("[color=yellow]{0}x[/color] [color=green]{1}[/color]\n", info.Amount, Loc.GetString(info.ExamineName))); + } } } [Serializable] [DataDefinition] - public struct ComponentPartInfo + public struct GenericPartInfo { [DataField("Amount")] public int Amount; diff --git a/Content.Server/GameObjects/Components/Construction/MachineComponent.cs b/Content.Server/GameObjects/Components/Construction/MachineComponent.cs index caa3a313cd..b7db9e9173 100644 --- a/Content.Server/GameObjects/Components/Construction/MachineComponent.cs +++ b/Content.Server/GameObjects/Components/Construction/MachineComponent.cs @@ -113,6 +113,17 @@ namespace Content.Server.GameObjects.Components.Construction throw new Exception($"Couldn't insert machine component part with default prototype '{compName}' to machine with prototype {Owner.Prototype?.ID ?? "N/A"}"); } } + + foreach (var (tagName, info) in machineBoard.TagRequirements) + { + for (var i = 0; i < info.Amount; i++) + { + var c = entityManager.SpawnEntity(info.DefaultPrototype, Owner.Transform.Coordinates); + + if(!partContainer.Insert(c)) + throw new Exception($"Couldn't insert machine component part with default prototype '{tagName}' to machine with prototype {Owner.Prototype?.ID ?? "N/A"}"); + } + } } public void MapInit() diff --git a/Content.Server/GameObjects/Components/Construction/MachineFrameComponent.cs b/Content.Server/GameObjects/Components/Construction/MachineFrameComponent.cs index 4517041af5..c7be531435 100644 --- a/Content.Server/GameObjects/Components/Construction/MachineFrameComponent.cs +++ b/Content.Server/GameObjects/Components/Construction/MachineFrameComponent.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using Content.Server.Construction; using Content.Server.GameObjects.Components.Stack; using Content.Shared.GameObjects.Components.Construction; +using Content.Shared.GameObjects.Components.Tag; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Server.GameObjects; using Robust.Shared.Containers; @@ -48,6 +49,12 @@ namespace Content.Server.GameObjects.Components.Construction return false; } + foreach (var (tagName, info) in TagRequirements) + { + if (_tagProgress[tagName] < info.Amount) + return false; + } + return true; } } @@ -56,13 +63,16 @@ namespace Content.Server.GameObjects.Components.Construction public bool HasBoard => _boardContainer?.ContainedEntities.Count != 0; [ViewVariables] - private Dictionary _progress; + private readonly Dictionary _progress = new(); [ViewVariables] - private Dictionary _materialProgress; + private readonly Dictionary _materialProgress = new(); [ViewVariables] - private Dictionary _componentProgress; + private readonly Dictionary _componentProgress = new(); + + [ViewVariables] + private readonly Dictionary _tagProgress = new(); [ViewVariables] private Container _boardContainer; @@ -77,11 +87,15 @@ namespace Content.Server.GameObjects.Components.Construction public IReadOnlyDictionary MaterialRequirements { get; private set; } [ViewVariables] - public IReadOnlyDictionary ComponentRequirements { get; private set; } + public IReadOnlyDictionary ComponentRequirements { get; private set; } + + [ViewVariables] + public IReadOnlyDictionary TagRequirements { get; private set; } public IReadOnlyDictionary Progress => _progress; public IReadOnlyDictionary MaterialProgress => _materialProgress; public IReadOnlyDictionary ComponentProgress => _componentProgress; + public IReadOnlyDictionary TagProgress => _tagProgress; public override void Initialize() { @@ -109,9 +123,12 @@ namespace Content.Server.GameObjects.Components.Construction Requirements = machineBoard.Requirements; MaterialRequirements = machineBoard.MaterialIdRequirements; ComponentRequirements = machineBoard.ComponentRequirements; - _progress = new Dictionary(); - _materialProgress = new Dictionary(); - _componentProgress = new Dictionary(); + TagRequirements = machineBoard.TagRequirements; + + _progress.Clear(); + _materialProgress.Clear(); + _componentProgress.Clear(); + _tagProgress.Clear(); foreach (var (machinePart, _) in Requirements) { @@ -127,6 +144,11 @@ namespace Content.Server.GameObjects.Components.Construction { _componentProgress[compName] = 0; } + + foreach (var (compName, _) in TagRequirements) + { + _tagProgress[compName] = 0; + } } public void RegenerateProgress() @@ -143,9 +165,11 @@ namespace Content.Server.GameObjects.Components.Construction Requirements = null; MaterialRequirements = null; ComponentRequirements = null; - _progress = null; - _materialProgress = null; - _componentProgress = null; + TagRequirements = null; + _progress.Clear(); + _materialProgress.Clear(); + _componentProgress.Clear(); + _tagProgress.Clear(); return; } @@ -190,7 +214,7 @@ namespace Content.Server.GameObjects.Components.Construction } // I have many regrets. - foreach (var (compName, amount) in ComponentRequirements) + foreach (var (compName, _) in ComponentRequirements) { var registration = _componentFactory.GetRegistration(compName); @@ -202,6 +226,18 @@ namespace Content.Server.GameObjects.Components.Construction else _componentProgress[compName]++; } + + // I have MANY regrets. + foreach (var (tagName, _) in TagRequirements) + { + if (!part.HasTag(tagName)) + continue; + + if (!_tagProgress.ContainsKey(tagName)) + _tagProgress[tagName] = 1; + else + _tagProgress[tagName]++; + } } } @@ -291,6 +327,19 @@ namespace Content.Server.GameObjects.Components.Construction _componentProgress[compName]++; return true; } + + foreach (var (tagName, info) in TagRequirements) + { + if (_tagProgress[tagName] >= info.Amount) + continue; + + if (!eventArgs.Using.HasTag(tagName)) + continue; + + if (!eventArgs.Using.TryRemoveFromContainer() || !_partContainer.Insert(eventArgs.Using)) continue; + _tagProgress[tagName]++; + return true; + } } return false; diff --git a/Resources/Prototypes/Entities/Objects/Devices/Circuitboards/Machine/production.yml b/Resources/Prototypes/Entities/Objects/Devices/Circuitboards/Machine/production.yml index 9119d6e902..26c589371b 100644 --- a/Resources/Prototypes/Entities/Objects/Devices/Circuitboards/Machine/production.yml +++ b/Resources/Prototypes/Entities/Objects/Devices/Circuitboards/Machine/production.yml @@ -23,7 +23,7 @@ requirements: MatterBin: 2 Manipulator: 2 - componentRequirements: + tagRequirements: GlassBeaker: Amount: 2 DefaultPrototype: Beaker