2020-10-08 17:41:23 +02:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2021-09-15 16:36:43 +02:00
|
|
|
using Content.Shared.Examine;
|
2021-02-25 06:18:29 +01:00
|
|
|
using Content.Shared.Stacks;
|
|
|
|
|
using Robust.Shared.Prototypes;
|
2020-10-08 17:41:23 +02:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Shared.Construction.Steps
|
2020-10-08 17:41:23 +02:00
|
|
|
{
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataDefinition]
|
2023-08-22 18:14:33 -07:00
|
|
|
public sealed partial class MaterialConstructionGraphStep : EntityInsertConstructionGraphStep
|
2020-10-08 17:41:23 +02:00
|
|
|
{
|
|
|
|
|
// TODO: Make this use the material system.
|
|
|
|
|
// TODO TODO: Make the material system not shit.
|
2025-05-01 17:21:16 +03:00
|
|
|
[DataField("material", required:true)]
|
|
|
|
|
public ProtoId<StackPrototype> MaterialPrototypeId { get; private set; }
|
2021-03-05 01:08:38 +01:00
|
|
|
|
2025-05-01 17:21:16 +03:00
|
|
|
[DataField] public int Amount { get; private set; } = 1;
|
2021-02-25 06:18:29 +01:00
|
|
|
|
2021-09-15 16:36:43 +02:00
|
|
|
public override void DoExamine(ExaminedEvent examinedEvent)
|
2020-10-08 17:41:23 +02:00
|
|
|
{
|
2025-05-01 17:21:16 +03:00
|
|
|
var material = IoCManager.Resolve<IPrototypeManager>().Index(MaterialPrototypeId);
|
|
|
|
|
var materialName = Loc.GetString(material.Name, ("amount", Amount));
|
2021-11-02 11:24:32 +01:00
|
|
|
|
2025-05-01 17:21:16 +03:00
|
|
|
examinedEvent.PushMarkup(Loc.GetString("construction-insert-material-entity", ("amount", Amount), ("materialName", materialName)));
|
2020-10-08 17:41:23 +02:00
|
|
|
}
|
|
|
|
|
|
2023-01-19 13:57:18 +11:00
|
|
|
public override bool EntityValid(EntityUid uid, IEntityManager entityManager, IComponentFactory compFactory)
|
2020-10-08 17:41:23 +02:00
|
|
|
{
|
2022-12-24 23:28:21 -05:00
|
|
|
return entityManager.TryGetComponent(uid, out StackComponent? stack) && stack.StackTypeId == MaterialPrototypeId && stack.Count >= Amount;
|
2020-10-08 17:41:23 +02:00
|
|
|
}
|
|
|
|
|
|
2022-12-24 23:28:21 -05:00
|
|
|
public bool EntityValid(EntityUid entity, [NotNullWhen(true)] out StackComponent? stack)
|
2020-10-08 17:41:23 +02:00
|
|
|
{
|
2022-12-24 23:28:21 -05:00
|
|
|
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out StackComponent? otherStack) && otherStack.StackTypeId == MaterialPrototypeId && otherStack.Count >= Amount)
|
2020-10-08 17:41:23 +02:00
|
|
|
stack = otherStack;
|
|
|
|
|
else
|
|
|
|
|
stack = null;
|
|
|
|
|
|
|
|
|
|
return stack != null;
|
|
|
|
|
}
|
2021-11-02 11:24:32 +01:00
|
|
|
|
|
|
|
|
public override ConstructionGuideEntry GenerateGuideEntry()
|
|
|
|
|
{
|
2025-05-01 17:21:16 +03:00
|
|
|
var material = IoCManager.Resolve<IPrototypeManager>().Index(MaterialPrototypeId);
|
|
|
|
|
var materialName = Loc.GetString(material.Name, ("amount", Amount));
|
2021-11-02 11:24:32 +01:00
|
|
|
|
|
|
|
|
return new ConstructionGuideEntry()
|
|
|
|
|
{
|
|
|
|
|
Localization = "construction-presenter-material-step",
|
2025-05-01 17:21:16 +03:00
|
|
|
Arguments = new (string, object)[]{("amount", Amount), ("material", materialName)},
|
2021-11-02 11:24:32 +01:00
|
|
|
Icon = material.Icon,
|
|
|
|
|
};
|
|
|
|
|
}
|
2020-10-08 17:41:23 +02:00
|
|
|
}
|
|
|
|
|
}
|