2021-06-21 02:13:54 +02:00
|
|
|
using System.Threading.Tasks;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Construction.Components;
|
2020-12-03 22:49:00 +01:00
|
|
|
using Content.Shared.Construction;
|
2021-10-01 15:27:42 +02:00
|
|
|
using Content.Shared.Examine;
|
2020-12-03 22:49:00 +01:00
|
|
|
using JetBrains.Annotations;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2020-12-03 22:49:00 +01:00
|
|
|
using Robust.Shared.Localization;
|
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;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.Construction.Conditions
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks that the entity has all parts needed in the machine frame component.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[UsedImplicitly]
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataDefinition]
|
2021-03-25 18:59:16 +01:00
|
|
|
public class MachineFrameComplete : IGraphCondition
|
2020-12-03 22:49:00 +01:00
|
|
|
{
|
|
|
|
|
public async Task<bool> Condition(IEntity entity)
|
|
|
|
|
{
|
|
|
|
|
if (entity.Deleted || !entity.TryGetComponent<MachineFrameComponent>(out var machineFrame))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return machineFrame.IsComplete;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-01 15:27:42 +02:00
|
|
|
public bool DoExamine(ExaminedEvent args)
|
2020-12-03 22:49:00 +01:00
|
|
|
{
|
2021-10-01 15:27:42 +02:00
|
|
|
var entity = args.Examined;
|
|
|
|
|
|
2020-12-03 22:49:00 +01:00
|
|
|
if (!entity.TryGetComponent<MachineFrameComponent>(out var machineFrame))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (!machineFrame.HasBoard)
|
|
|
|
|
{
|
2021-10-01 15:27:42 +02:00
|
|
|
args.PushMarkup(Loc.GetString("construction-condition-machine-frame-insert-circuit-board-message"));
|
2020-12-03 22:49:00 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (machineFrame.IsComplete) return false;
|
|
|
|
|
|
2021-10-01 15:27:42 +02:00
|
|
|
args.Message.AddMarkup(Loc.GetString("construction-condition-machine-frame-requirement-label") + "\n");
|
2020-12-03 22:49:00 +01:00
|
|
|
foreach (var (part, required) in machineFrame.Requirements)
|
|
|
|
|
{
|
|
|
|
|
var amount = required - machineFrame.Progress[part];
|
|
|
|
|
|
|
|
|
|
if(amount == 0) continue;
|
|
|
|
|
|
2021-10-01 15:27:42 +02:00
|
|
|
args.Message.AddMarkup(Loc.GetString("construction-condition-machine-frame-required-element-entry",
|
|
|
|
|
("amount", amount),
|
|
|
|
|
("elementName", Loc.GetString(part.ToString())))
|
|
|
|
|
+ "\n");
|
2020-12-03 22:49:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var (material, required) in machineFrame.MaterialRequirements)
|
|
|
|
|
{
|
|
|
|
|
var amount = required - machineFrame.MaterialProgress[material];
|
|
|
|
|
|
|
|
|
|
if(amount == 0) continue;
|
|
|
|
|
|
2021-10-01 15:27:42 +02:00
|
|
|
args.Message.AddMarkup(Loc.GetString("construction-condition-machine-frame-required-element-entry",
|
|
|
|
|
("amount", amount),
|
|
|
|
|
("elementName", Loc.GetString(material.ToString())))
|
|
|
|
|
+ "\n");
|
2020-12-03 22:49:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var (compName, info) in machineFrame.ComponentRequirements)
|
|
|
|
|
{
|
|
|
|
|
var amount = info.Amount - machineFrame.ComponentProgress[compName];
|
|
|
|
|
|
|
|
|
|
if(amount == 0) continue;
|
|
|
|
|
|
2021-10-01 15:27:42 +02:00
|
|
|
args.Message.AddMarkup(Loc.GetString("construction-condition-machine-frame-required-element-entry",
|
2021-06-21 02:13:54 +02:00
|
|
|
("amount", info.Amount),
|
|
|
|
|
("elementName", Loc.GetString(info.ExamineName)))
|
|
|
|
|
+ "\n");
|
2020-12-03 22:49:00 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-08 05:09:30 +01:00
|
|
|
foreach (var (tagName, info) in machineFrame.TagRequirements)
|
|
|
|
|
{
|
|
|
|
|
var amount = info.Amount - machineFrame.TagProgress[tagName];
|
|
|
|
|
|
|
|
|
|
if(amount == 0) continue;
|
|
|
|
|
|
2021-10-01 15:27:42 +02:00
|
|
|
args.Message.AddMarkup(Loc.GetString("construction-condition-machine-frame-required-element-entry",
|
|
|
|
|
("amount", info.Amount),
|
|
|
|
|
("elementName", Loc.GetString(info.ExamineName)))
|
|
|
|
|
+ "\n");
|
2021-03-08 05:09:30 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-03 22:49:00 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|