1
0

MaterialConstructionGraphStep.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System.Diagnostics.CodeAnalysis;
  2. using Content.Shared.Examine;
  3. using Content.Shared.Stacks;
  4. using Robust.Shared.Prototypes;
  5. using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
  6. namespace Content.Shared.Construction.Steps
  7. {
  8. [DataDefinition]
  9. public sealed partial class MaterialConstructionGraphStep : EntityInsertConstructionGraphStep
  10. {
  11. // TODO: Make this use the material system.
  12. // TODO TODO: Make the material system not shit.
  13. [DataField("material", required:true, customTypeSerializer:typeof(PrototypeIdSerializer<StackPrototype>))]
  14. public string MaterialPrototypeId { get; private set; } = "Steel";
  15. [DataField("amount")] public int Amount { get; private set; } = 1;
  16. public override void DoExamine(ExaminedEvent examinedEvent)
  17. {
  18. var material = IoCManager.Resolve<IPrototypeManager>().Index<StackPrototype>(MaterialPrototypeId);
  19. examinedEvent.PushMarkup(Loc.GetString("construction-insert-material-entity", ("amount", Amount), ("materialName", material.Name)));
  20. }
  21. public override bool EntityValid(EntityUid uid, IEntityManager entityManager, IComponentFactory compFactory)
  22. {
  23. return entityManager.TryGetComponent(uid, out StackComponent? stack) && stack.StackTypeId == MaterialPrototypeId && stack.Count >= Amount;
  24. }
  25. public bool EntityValid(EntityUid entity, [NotNullWhen(true)] out StackComponent? stack)
  26. {
  27. if (IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out StackComponent? otherStack) && otherStack.StackTypeId == MaterialPrototypeId && otherStack.Count >= Amount)
  28. stack = otherStack;
  29. else
  30. stack = null;
  31. return stack != null;
  32. }
  33. public override ConstructionGuideEntry GenerateGuideEntry()
  34. {
  35. var material = IoCManager.Resolve<IPrototypeManager>().Index<StackPrototype>(MaterialPrototypeId);
  36. return new ConstructionGuideEntry()
  37. {
  38. Localization = "construction-presenter-material-step",
  39. Arguments = new (string, object)[]{("amount", Amount), ("material", material.Name)},
  40. Icon = material.Icon,
  41. };
  42. }
  43. }
  44. }