RobustHarvest.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using Content.Server.Botany.Components;
  2. using Content.Server.Botany.Systems;
  3. using Content.Shared.EntityEffects;
  4. using JetBrains.Annotations;
  5. using Robust.Shared.Prototypes;
  6. using Robust.Shared.Random;
  7. namespace Content.Server.EntityEffects.Effects.PlantMetabolism;
  8. [UsedImplicitly]
  9. [DataDefinition]
  10. public sealed partial class RobustHarvest : EntityEffect
  11. {
  12. [DataField]
  13. public int PotencyLimit = 50;
  14. [DataField]
  15. public int PotencyIncrease = 3;
  16. [DataField]
  17. public int PotencySeedlessThreshold = 30;
  18. public override void Effect(EntityEffectBaseArgs args)
  19. {
  20. if (!args.EntityManager.TryGetComponent(args.TargetEntity, out PlantHolderComponent? plantHolderComp)
  21. || plantHolderComp.Seed == null || plantHolderComp.Dead ||
  22. plantHolderComp.Seed.Immutable)
  23. return;
  24. var plantHolder = args.EntityManager.System<PlantHolderSystem>();
  25. var random = IoCManager.Resolve<IRobustRandom>();
  26. if (plantHolderComp.Seed.Potency < PotencyLimit)
  27. {
  28. plantHolder.EnsureUniqueSeed(args.TargetEntity, plantHolderComp);
  29. plantHolderComp.Seed.Potency = Math.Min(plantHolderComp.Seed.Potency + PotencyIncrease, PotencyLimit);
  30. if (plantHolderComp.Seed.Potency > PotencySeedlessThreshold)
  31. {
  32. plantHolderComp.Seed.Seedless = true;
  33. }
  34. }
  35. else if (plantHolderComp.Seed.Yield > 1 && random.Prob(0.1f))
  36. {
  37. // Too much of a good thing reduces yield
  38. plantHolder.EnsureUniqueSeed(args.TargetEntity, plantHolderComp);
  39. plantHolderComp.Seed.Yield--;
  40. }
  41. }
  42. protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys) => Loc.GetString("reagent-effect-guidebook-plant-robust-harvest", ("seedlesstreshold", PotencySeedlessThreshold), ("limit", PotencyLimit), ("increase", PotencyIncrease), ("chance", Probability));
  43. }