Machine construction can now use tags. (#3532)

* work on machine tags

* Makes protolathe board use tag requirements
This commit is contained in:
Vera Aguilera Puerto
2021-03-08 05:09:30 +01:00
committed by GitHub
parent 13e95ac9a8
commit f5396344ef
5 changed files with 95 additions and 15 deletions

View File

@@ -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))); 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; return true;
} }
} }

View File

@@ -28,9 +28,13 @@ namespace Content.Server.GameObjects.Components.Construction
[DataField("materialRequirements")] [DataField("materialRequirements")]
private Dictionary<string, int> _materialIdRequirements = new(); private Dictionary<string, int> _materialIdRequirements = new();
[ViewVariables]
[DataField("tagRequirements")]
private Dictionary<string, GenericPartInfo> _tagRequirements = new();
[ViewVariables] [ViewVariables]
[DataField("componentRequirements")] [DataField("componentRequirements")]
private Dictionary<string, ComponentPartInfo> _componentRequirements = new(); private Dictionary<string, GenericPartInfo> _componentRequirements = new();
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
[DataField("prototype")] [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) 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))); 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] [Serializable]
[DataDefinition] [DataDefinition]
public struct ComponentPartInfo public struct GenericPartInfo
{ {
[DataField("Amount")] [DataField("Amount")]
public int Amount; public int Amount;

View File

@@ -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"}"); 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() public void MapInit()

View File

@@ -3,6 +3,7 @@ using System.Threading.Tasks;
using Content.Server.Construction; using Content.Server.Construction;
using Content.Server.GameObjects.Components.Stack; using Content.Server.GameObjects.Components.Stack;
using Content.Shared.GameObjects.Components.Construction; using Content.Shared.GameObjects.Components.Construction;
using Content.Shared.GameObjects.Components.Tag;
using Content.Shared.Interfaces.GameObjects.Components; using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.Containers; using Robust.Shared.Containers;
@@ -48,6 +49,12 @@ namespace Content.Server.GameObjects.Components.Construction
return false; return false;
} }
foreach (var (tagName, info) in TagRequirements)
{
if (_tagProgress[tagName] < info.Amount)
return false;
}
return true; return true;
} }
} }
@@ -56,13 +63,16 @@ namespace Content.Server.GameObjects.Components.Construction
public bool HasBoard => _boardContainer?.ContainedEntities.Count != 0; public bool HasBoard => _boardContainer?.ContainedEntities.Count != 0;
[ViewVariables] [ViewVariables]
private Dictionary<MachinePart, int> _progress; private readonly Dictionary<MachinePart, int> _progress = new();
[ViewVariables] [ViewVariables]
private Dictionary<string, int> _materialProgress; private readonly Dictionary<string, int> _materialProgress = new();
[ViewVariables] [ViewVariables]
private Dictionary<string, int> _componentProgress; private readonly Dictionary<string, int> _componentProgress = new();
[ViewVariables]
private readonly Dictionary<string, int> _tagProgress = new();
[ViewVariables] [ViewVariables]
private Container _boardContainer; private Container _boardContainer;
@@ -77,11 +87,15 @@ namespace Content.Server.GameObjects.Components.Construction
public IReadOnlyDictionary<string, int> MaterialRequirements { get; private set; } public IReadOnlyDictionary<string, int> MaterialRequirements { get; private set; }
[ViewVariables] [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<MachinePart, int> Progress => _progress;
public IReadOnlyDictionary<string, int> MaterialProgress => _materialProgress; public IReadOnlyDictionary<string, int> MaterialProgress => _materialProgress;
public IReadOnlyDictionary<string, int> ComponentProgress => _componentProgress; public IReadOnlyDictionary<string, int> ComponentProgress => _componentProgress;
public IReadOnlyDictionary<string, int> TagProgress => _tagProgress;
public override void Initialize() public override void Initialize()
{ {
@@ -109,9 +123,12 @@ namespace Content.Server.GameObjects.Components.Construction
Requirements = machineBoard.Requirements; Requirements = machineBoard.Requirements;
MaterialRequirements = machineBoard.MaterialIdRequirements; MaterialRequirements = machineBoard.MaterialIdRequirements;
ComponentRequirements = machineBoard.ComponentRequirements; ComponentRequirements = machineBoard.ComponentRequirements;
_progress = new Dictionary<MachinePart, int>(); TagRequirements = machineBoard.TagRequirements;
_materialProgress = new Dictionary<string, int>();
_componentProgress = new Dictionary<string, int>(); _progress.Clear();
_materialProgress.Clear();
_componentProgress.Clear();
_tagProgress.Clear();
foreach (var (machinePart, _) in Requirements) foreach (var (machinePart, _) in Requirements)
{ {
@@ -127,6 +144,11 @@ namespace Content.Server.GameObjects.Components.Construction
{ {
_componentProgress[compName] = 0; _componentProgress[compName] = 0;
} }
foreach (var (compName, _) in TagRequirements)
{
_tagProgress[compName] = 0;
}
} }
public void RegenerateProgress() public void RegenerateProgress()
@@ -143,9 +165,11 @@ namespace Content.Server.GameObjects.Components.Construction
Requirements = null; Requirements = null;
MaterialRequirements = null; MaterialRequirements = null;
ComponentRequirements = null; ComponentRequirements = null;
_progress = null; TagRequirements = null;
_materialProgress = null; _progress.Clear();
_componentProgress = null; _materialProgress.Clear();
_componentProgress.Clear();
_tagProgress.Clear();
return; return;
} }
@@ -190,7 +214,7 @@ namespace Content.Server.GameObjects.Components.Construction
} }
// I have many regrets. // I have many regrets.
foreach (var (compName, amount) in ComponentRequirements) foreach (var (compName, _) in ComponentRequirements)
{ {
var registration = _componentFactory.GetRegistration(compName); var registration = _componentFactory.GetRegistration(compName);
@@ -202,6 +226,18 @@ namespace Content.Server.GameObjects.Components.Construction
else else
_componentProgress[compName]++; _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]++; _componentProgress[compName]++;
return true; 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; return false;

View File

@@ -23,7 +23,7 @@
requirements: requirements:
MatterBin: 2 MatterBin: 2
Manipulator: 2 Manipulator: 2
componentRequirements: tagRequirements:
GlassBeaker: GlassBeaker:
Amount: 2 Amount: 2
DefaultPrototype: Beaker DefaultPrototype: Beaker