PlantAdjustAttribute.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using Content.Server.Botany.Components;
  2. using Content.Shared.EntityEffects;
  3. using Robust.Shared.Prototypes;
  4. using Robust.Shared.Random;
  5. using System.Diagnostics.CodeAnalysis;
  6. namespace Content.Server.EntityEffects.Effects.PlantMetabolism;
  7. [ImplicitDataDefinitionForInheritors]
  8. public abstract partial class PlantAdjustAttribute : EntityEffect
  9. {
  10. [DataField]
  11. public float Amount { get; protected set; } = 1;
  12. /// <summary>
  13. /// Localisation key for the name of the adjusted attribute. Used for guidebook descriptions.
  14. /// </summary>
  15. [DataField]
  16. public abstract string GuidebookAttributeName { get; set; }
  17. /// <summary>
  18. /// Whether the attribute in question is a good thing. Used for guidebook descriptions to determine the color of the number.
  19. /// </summary>
  20. [DataField]
  21. public virtual bool GuidebookIsAttributePositive { get; protected set; } = true;
  22. /// <summary>
  23. /// Checks if the plant holder can metabolize the reagent or not. Checks if it has an alive plant by default.
  24. /// </summary>
  25. /// <param name="plantHolder">The entity holding the plant</param>
  26. /// <param name="plantHolderComponent">The plant holder component</param>
  27. /// <param name="entityManager">The entity manager</param>
  28. /// <param name="mustHaveAlivePlant">Whether to check if it has an alive plant or not</param>
  29. /// <returns></returns>
  30. public bool CanMetabolize(EntityUid plantHolder, [NotNullWhen(true)] out PlantHolderComponent? plantHolderComponent,
  31. IEntityManager entityManager,
  32. bool mustHaveAlivePlant = true)
  33. {
  34. plantHolderComponent = null;
  35. if (!entityManager.TryGetComponent(plantHolder, out plantHolderComponent)
  36. || mustHaveAlivePlant && (plantHolderComponent.Seed == null || plantHolderComponent.Dead))
  37. return false;
  38. return true;
  39. }
  40. protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys)
  41. {
  42. string color;
  43. if (GuidebookIsAttributePositive ^ Amount < 0.0)
  44. {
  45. color = "green";
  46. }
  47. else
  48. {
  49. color = "red";
  50. }
  51. return Loc.GetString("reagent-effect-guidebook-plant-attribute", ("attribute", Loc.GetString(GuidebookAttributeName)), ("amount", Amount.ToString("0.00")), ("colorName", color), ("chance", Probability));
  52. }
  53. }