PlantMutateChemicals.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using Content.Server.Botany;
  2. using Content.Server.Botany.Components;
  3. using Content.Shared.EntityEffects;
  4. using Content.Shared.Random;
  5. using Robust.Shared.Prototypes;
  6. using Robust.Shared.Random;
  7. namespace Content.Server.EntityEffects.Effects;
  8. /// <summary>
  9. /// changes the chemicals available in a plant's produce
  10. /// </summary>
  11. public sealed partial class PlantMutateChemicals : EntityEffect
  12. {
  13. public override void Effect(EntityEffectBaseArgs args)
  14. {
  15. var plantholder = args.EntityManager.GetComponent<PlantHolderComponent>(args.TargetEntity);
  16. if (plantholder.Seed == null)
  17. return;
  18. var random = IoCManager.Resolve<IRobustRandom>();
  19. var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
  20. var chemicals = plantholder.Seed.Chemicals;
  21. var randomChems = prototypeManager.Index<WeightedRandomFillSolutionPrototype>("RandomPickBotanyReagent").Fills;
  22. // Add a random amount of a random chemical to this set of chemicals
  23. if (randomChems != null)
  24. {
  25. var pick = random.Pick<RandomFillSolution>(randomChems);
  26. var chemicalId = random.Pick(pick.Reagents);
  27. var amount = random.Next(1, (int)pick.Quantity);
  28. var seedChemQuantity = new SeedChemQuantity();
  29. if (chemicals.ContainsKey(chemicalId))
  30. {
  31. seedChemQuantity.Min = chemicals[chemicalId].Min;
  32. seedChemQuantity.Max = chemicals[chemicalId].Max + amount;
  33. }
  34. else
  35. {
  36. seedChemQuantity.Min = 1;
  37. seedChemQuantity.Max = 1 + amount;
  38. seedChemQuantity.Inherent = false;
  39. }
  40. var potencyDivisor = (int)Math.Ceiling(100.0f / seedChemQuantity.Max);
  41. seedChemQuantity.PotencyDivisor = potencyDivisor;
  42. chemicals[chemicalId] = seedChemQuantity;
  43. }
  44. }
  45. protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys)
  46. {
  47. return "TODO";
  48. }
  49. }