PlantSpeciesChange.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using Content.Server.Botany;
  2. using Content.Server.Botany.Components;
  3. using Content.Shared.EntityEffects;
  4. using Robust.Shared.Prototypes;
  5. using Robust.Shared.Random;
  6. using Serilog;
  7. namespace Content.Server.EntityEffects.Effects;
  8. /// <summary>
  9. /// Changes a plant into one of the species its able to mutate into.
  10. /// </summary>
  11. public sealed partial class PlantSpeciesChange : EntityEffect
  12. {
  13. public override void Effect(EntityEffectBaseArgs args)
  14. {
  15. var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
  16. var plantholder = args.EntityManager.GetComponent<PlantHolderComponent>(args.TargetEntity);
  17. if (plantholder.Seed == null)
  18. return;
  19. if (plantholder.Seed.MutationPrototypes.Count == 0)
  20. return;
  21. var random = IoCManager.Resolve<IRobustRandom>();
  22. var targetProto = random.Pick(plantholder.Seed.MutationPrototypes);
  23. prototypeManager.TryIndex(targetProto, out SeedPrototype? protoSeed);
  24. if (protoSeed == null)
  25. {
  26. Log.Error($"Seed prototype could not be found: {targetProto}!");
  27. return;
  28. }
  29. plantholder.Seed = plantholder.Seed.SpeciesChange(protoSeed);
  30. }
  31. protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys)
  32. {
  33. return "TODO";
  34. }
  35. }