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;
|
2021-11-02 11:24:32 +01:00
|
|
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
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.
|
2021-11-02 11:24:32 +01:00
|
|
|
[DataField("material", required:true, customTypeSerializer:typeof(PrototypeIdSerializer<StackPrototype>))]
|
2023-08-22 18:14:33 -07:00
|
|
|
public string MaterialPrototypeId { get; private set; } = "Steel";
|
2021-03-05 01:08:38 +01:00
|
|
|
|
2023-08-22 18:14:33 -07:00
|
|
|
[DataField("amount")] 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
|
|
|
{
|
2021-11-02 11:24:32 +01:00
|
|
|
var material = IoCManager.Resolve<IPrototypeManager>().Index<StackPrototype>(MaterialPrototypeId);
|
|
|
|
|
|
2024-01-05 23:53:13 -07:00
|
|
|
examinedEvent.PushMarkup(Loc.GetString("construction-insert-material-entity", ("amount", Amount), ("materialName", material.Name)));
|
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()
|
|
|
|
|
{
|
|
|
|
|
var material = IoCManager.Resolve<IPrototypeManager>().Index<StackPrototype>(MaterialPrototypeId);
|
|
|
|
|
|
|
|
|
|
return new ConstructionGuideEntry()
|
|
|
|
|
{
|
|
|
|
|
Localization = "construction-presenter-material-step",
|
|
|
|
|
Arguments = new (string, object)[]{("amount", Amount), ("material", material.Name)},
|
|
|
|
|
Icon = material.Icon,
|
|
|
|
|
};
|
|
|
|
|
}
|
2020-10-08 17:41:23 +02:00
|
|
|
}
|
|
|
|
|
}
|