2021-06-21 02:13:54 +02:00
|
|
|
using System;
|
2020-12-03 22:49:00 +01:00
|
|
|
using System.Collections.Generic;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Examine;
|
2021-02-25 06:18:29 +01:00
|
|
|
using Content.Shared.Stacks;
|
2020-12-03 22:49:00 +01:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-02-25 06:18:29 +01:00
|
|
|
using Robust.Shared.IoC;
|
2020-12-03 22:49:00 +01:00
|
|
|
using Robust.Shared.Localization;
|
2021-02-25 06:18:29 +01:00
|
|
|
using Robust.Shared.Prototypes;
|
2021-03-05 01:08:38 +01:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2020-12-03 22:49:00 +01:00
|
|
|
using Robust.Shared.Utility;
|
|
|
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Construction.Components
|
2020-12-03 22:49:00 +01:00
|
|
|
{
|
|
|
|
|
[RegisterComponent]
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning disable 618
|
2020-12-03 22:49:00 +01:00
|
|
|
public class MachineBoardComponent : Component, IExamine
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning restore 618
|
2020-12-03 22:49:00 +01:00
|
|
|
{
|
2021-02-25 06:18:29 +01:00
|
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
|
|
|
|
2020-12-03 22:49:00 +01:00
|
|
|
[ViewVariables]
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("requirements")]
|
2021-03-16 15:50:20 +01:00
|
|
|
public readonly Dictionary<MachinePart, int> Requirements = new();
|
2020-12-03 22:49:00 +01:00
|
|
|
|
|
|
|
|
[ViewVariables]
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("materialRequirements")]
|
2021-03-16 15:50:20 +01:00
|
|
|
public readonly Dictionary<string, int> MaterialIdRequirements = new();
|
2020-12-03 22:49:00 +01:00
|
|
|
|
2021-03-08 05:09:30 +01:00
|
|
|
[ViewVariables]
|
|
|
|
|
[DataField("tagRequirements")]
|
2021-03-16 15:50:20 +01:00
|
|
|
public readonly Dictionary<string, GenericPartInfo> TagRequirements = new();
|
2021-03-08 05:09:30 +01:00
|
|
|
|
2020-12-03 22:49:00 +01:00
|
|
|
[ViewVariables]
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("componentRequirements")]
|
2021-03-16 15:50:20 +01:00
|
|
|
public readonly Dictionary<string, GenericPartInfo> ComponentRequirements = new();
|
2020-12-03 22:49:00 +01:00
|
|
|
|
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("prototype")]
|
2021-03-16 15:50:20 +01:00
|
|
|
public string? Prototype { get; private set; }
|
2021-02-25 06:18:29 +01:00
|
|
|
|
|
|
|
|
public IEnumerable<KeyValuePair<StackPrototype, int>> MaterialRequirements
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
foreach (var (materialId, amount) in MaterialIdRequirements)
|
|
|
|
|
{
|
|
|
|
|
var material = _prototypeManager.Index<StackPrototype>(materialId);
|
|
|
|
|
yield return new KeyValuePair<StackPrototype, int>(material, amount);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-20 12:42:42 +01:00
|
|
|
public void Examine(FormattedMessage message, bool inDetailsRange)
|
2020-12-03 22:49:00 +01:00
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
message.AddMarkup(Loc.GetString("machine-board-component-on-examine-label") + "\n");
|
2020-12-03 22:49:00 +01:00
|
|
|
foreach (var (part, amount) in Requirements)
|
|
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
message.AddMarkup(Loc.GetString("machine-board-component-required-element-entry-text",
|
|
|
|
|
("amount", amount),
|
|
|
|
|
("requiredElement", Loc.GetString(part.ToString())))
|
|
|
|
|
+ "\n");
|
2020-12-03 22:49:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var (material, amount) in MaterialRequirements)
|
|
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
message.AddMarkup(Loc.GetString("machine-board-component-required-element-entry-text",
|
|
|
|
|
("amount", amount),
|
|
|
|
|
("requiredElement", Loc.GetString(material.Name)))
|
|
|
|
|
+ "\n");
|
2020-12-03 22:49:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var (_, info) in ComponentRequirements)
|
|
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
message.AddMarkup(Loc.GetString("machine-board-component-required-element-entry-text",
|
|
|
|
|
("amount", info.Amount),
|
|
|
|
|
("requiredElement", Loc.GetString(info.ExamineName)))
|
|
|
|
|
+ "\n");
|
2020-12-03 22:49:00 +01:00
|
|
|
}
|
2021-03-08 05:09:30 +01:00
|
|
|
|
|
|
|
|
foreach (var (_, info) in TagRequirements)
|
|
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
message.AddMarkup(Loc.GetString("machine-board-component-required-element-entry-text",
|
|
|
|
|
("amount", info.Amount),
|
|
|
|
|
("requiredElement", Loc.GetString(info.ExamineName)))
|
|
|
|
|
+ "\n");
|
2021-03-08 05:09:30 +01:00
|
|
|
}
|
2020-12-03 22:49:00 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Serializable]
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataDefinition]
|
2021-03-08 05:09:30 +01:00
|
|
|
public struct GenericPartInfo
|
2020-12-03 22:49:00 +01:00
|
|
|
{
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("Amount")]
|
2020-12-03 22:49:00 +01:00
|
|
|
public int Amount;
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("ExamineName")]
|
2020-12-03 22:49:00 +01:00
|
|
|
public string ExamineName;
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("DefaultPrototype")]
|
2020-12-03 22:49:00 +01:00
|
|
|
public string DefaultPrototype;
|
|
|
|
|
}
|
|
|
|
|
}
|