Machine construction can now use tags. (#3532)
* work on machine tags * Makes protolathe board use tag requirements
This commit is contained in:
committed by
GitHub
parent
13e95ac9a8
commit
f5396344ef
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,9 +28,13 @@ namespace Content.Server.GameObjects.Components.Construction
|
||||
[DataField("materialRequirements")]
|
||||
private Dictionary<string, int> _materialIdRequirements = new();
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("tagRequirements")]
|
||||
private Dictionary<string, GenericPartInfo> _tagRequirements = new();
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("componentRequirements")]
|
||||
private Dictionary<string, ComponentPartInfo> _componentRequirements = new();
|
||||
private Dictionary<string, GenericPartInfo> _componentRequirements = new();
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("prototype")]
|
||||
@@ -52,7 +56,9 @@ namespace Content.Server.GameObjects.Components.Construction
|
||||
}
|
||||
}
|
||||
|
||||
public IReadOnlyDictionary<string, ComponentPartInfo> ComponentRequirements => _componentRequirements;
|
||||
public IReadOnlyDictionary<string, GenericPartInfo> ComponentRequirements => _componentRequirements;
|
||||
public IReadOnlyDictionary<string, GenericPartInfo> 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;
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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<MachinePart, int> _progress;
|
||||
private readonly Dictionary<MachinePart, int> _progress = new();
|
||||
|
||||
[ViewVariables]
|
||||
private Dictionary<string, int> _materialProgress;
|
||||
private readonly Dictionary<string, int> _materialProgress = new();
|
||||
|
||||
[ViewVariables]
|
||||
private Dictionary<string, int> _componentProgress;
|
||||
private readonly Dictionary<string, int> _componentProgress = new();
|
||||
|
||||
[ViewVariables]
|
||||
private readonly Dictionary<string, int> _tagProgress = new();
|
||||
|
||||
[ViewVariables]
|
||||
private Container _boardContainer;
|
||||
@@ -77,11 +87,15 @@ namespace Content.Server.GameObjects.Components.Construction
|
||||
public IReadOnlyDictionary<string, int> MaterialRequirements { get; private set; }
|
||||
|
||||
[ViewVariables]
|
||||
public IReadOnlyDictionary<string, ComponentPartInfo> ComponentRequirements { get; private set; }
|
||||
public IReadOnlyDictionary<string, GenericPartInfo> ComponentRequirements { get; private set; }
|
||||
|
||||
[ViewVariables]
|
||||
public IReadOnlyDictionary<string, GenericPartInfo> TagRequirements { get; private set; }
|
||||
|
||||
public IReadOnlyDictionary<MachinePart, int> Progress => _progress;
|
||||
public IReadOnlyDictionary<string, int> MaterialProgress => _materialProgress;
|
||||
public IReadOnlyDictionary<string, int> ComponentProgress => _componentProgress;
|
||||
public IReadOnlyDictionary<string, int> 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<MachinePart, int>();
|
||||
_materialProgress = new Dictionary<string, int>();
|
||||
_componentProgress = new Dictionary<string, int>();
|
||||
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;
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
requirements:
|
||||
MatterBin: 2
|
||||
Manipulator: 2
|
||||
componentRequirements:
|
||||
tagRequirements:
|
||||
GlassBeaker:
|
||||
Amount: 2
|
||||
DefaultPrototype: Beaker
|
||||
|
||||
Reference in New Issue
Block a user