ReagentEntry.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System.Linq;
  2. using System.Text.Json.Serialization;
  3. using Content.Server.Body.Components;
  4. using Content.Shared.Body.Prototypes;
  5. using Content.Shared.Chemistry.Reaction;
  6. using Content.Shared.Chemistry.Reagent;
  7. using Content.Shared.EntityEffects;
  8. using Robust.Shared.Prototypes;
  9. namespace Content.Server.GuideGenerator;
  10. public sealed class ReagentEntry
  11. {
  12. [JsonPropertyName("id")]
  13. public string Id { get; }
  14. [JsonPropertyName("name")]
  15. public string Name { get; }
  16. [JsonPropertyName("group")]
  17. public string Group { get; }
  18. [JsonPropertyName("desc")]
  19. public string Description { get; }
  20. [JsonPropertyName("physicalDesc")]
  21. public string PhysicalDescription { get; }
  22. [JsonPropertyName("color")]
  23. public string SubstanceColor { get; }
  24. [JsonPropertyName("recipes")]
  25. public List<string> Recipes { get; } = new();
  26. [JsonPropertyName("metabolisms")]
  27. public Dictionary<string, ReagentEffectsEntry>? Metabolisms { get; }
  28. public ReagentEntry(ReagentPrototype proto)
  29. {
  30. Id = proto.ID;
  31. Name = proto.LocalizedName;
  32. Group = proto.Group;
  33. Description = proto.LocalizedDescription;
  34. PhysicalDescription = proto.LocalizedPhysicalDescription;
  35. SubstanceColor = proto.SubstanceColor.ToHex();
  36. Metabolisms = proto.Metabolisms?.ToDictionary(x => x.Key.Id, x => x.Value);
  37. }
  38. }
  39. public sealed class ReactionEntry
  40. {
  41. [JsonPropertyName("id")]
  42. public string Id { get; }
  43. [JsonPropertyName("name")]
  44. public string Name { get; }
  45. [JsonPropertyName("reactants")]
  46. public Dictionary<string, ReactantEntry> Reactants { get; }
  47. [JsonPropertyName("products")]
  48. public Dictionary<string, float> Products { get; }
  49. [JsonPropertyName("effects")]
  50. public List<EntityEffect> Effects { get; }
  51. public ReactionEntry(ReactionPrototype proto)
  52. {
  53. Id = proto.ID;
  54. Name = proto.Name;
  55. Reactants =
  56. proto.Reactants
  57. .Select(x => KeyValuePair.Create(x.Key, new ReactantEntry(x.Value.Amount.Float(), x.Value.Catalyst)))
  58. .ToDictionary(x => x.Key, x => x.Value);
  59. Products =
  60. proto.Products
  61. .Select(x => KeyValuePair.Create(x.Key, x.Value.Float()))
  62. .ToDictionary(x => x.Key, x => x.Value);
  63. Effects = proto.Effects;
  64. }
  65. }
  66. public sealed class ReactantEntry
  67. {
  68. [JsonPropertyName("amount")]
  69. public float Amount { get; }
  70. [JsonPropertyName("catalyst")]
  71. public bool Catalyst { get; }
  72. public ReactantEntry(float amnt, bool cata)
  73. {
  74. Amount = amnt;
  75. Catalyst = cata;
  76. }
  77. }