1
0

StomachComponent.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using Content.Server.Body.Systems;
  2. using Content.Server.Nutrition.EntitySystems;
  3. using Content.Shared.Chemistry.Components;
  4. using Content.Shared.Chemistry.Reagent;
  5. using Content.Shared.Whitelist;
  6. using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
  7. namespace Content.Server.Body.Components
  8. {
  9. [RegisterComponent, Access(typeof(StomachSystem), typeof(FoodSystem))]
  10. public sealed partial class StomachComponent : Component
  11. {
  12. /// <summary>
  13. /// The next time that the stomach will try to digest its contents.
  14. /// </summary>
  15. [DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
  16. public TimeSpan NextUpdate;
  17. /// <summary>
  18. /// The interval at which this stomach digests its contents.
  19. /// </summary>
  20. [DataField]
  21. public TimeSpan UpdateInterval = TimeSpan.FromSeconds(1);
  22. /// <summary>
  23. /// The solution inside of this stomach this transfers reagents to the body.
  24. /// </summary>
  25. [ViewVariables]
  26. public Entity<SolutionComponent>? Solution;
  27. /// <summary>
  28. /// What solution should this stomach push reagents into, on the body?
  29. /// </summary>
  30. [DataField]
  31. public string BodySolutionName = BloodstreamComponent.DefaultChemicalsSolutionName;
  32. /// <summary>
  33. /// Time between reagents being ingested and them being
  34. /// transferred to <see cref="BloodstreamComponent"/>
  35. /// </summary>
  36. [DataField]
  37. public TimeSpan DigestionDelay = TimeSpan.FromSeconds(20);
  38. /// <summary>
  39. /// A whitelist for what special-digestible-required foods this stomach is capable of eating.
  40. /// </summary>
  41. [DataField]
  42. public EntityWhitelist? SpecialDigestible = null;
  43. /// <summary>
  44. /// Used to track how long each reagent has been in the stomach
  45. /// </summary>
  46. [ViewVariables]
  47. public readonly List<ReagentDelta> ReagentDeltas = new();
  48. /// <summary>
  49. /// Used to track quantity changes when ingesting & digesting reagents
  50. /// </summary>
  51. public sealed class ReagentDelta
  52. {
  53. public readonly ReagentQuantity ReagentQuantity;
  54. public TimeSpan Lifetime { get; private set; }
  55. public ReagentDelta(ReagentQuantity reagentQuantity)
  56. {
  57. ReagentQuantity = reagentQuantity;
  58. Lifetime = TimeSpan.Zero;
  59. }
  60. public void Increment(TimeSpan delta) => Lifetime += delta;
  61. }
  62. }
  63. }