MakeSentient.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using Content.Server.Ghost.Roles.Components;
  2. using Content.Server.Speech.Components;
  3. using Content.Shared.EntityEffects;
  4. using Content.Shared.Mind.Components;
  5. using Robust.Shared.Prototypes;
  6. namespace Content.Server.EntityEffects.Effects;
  7. public sealed partial class MakeSentient : EntityEffect
  8. {
  9. protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys)
  10. => Loc.GetString("reagent-effect-guidebook-make-sentient", ("chance", Probability));
  11. public override void Effect(EntityEffectBaseArgs args)
  12. {
  13. var entityManager = args.EntityManager;
  14. var uid = args.TargetEntity;
  15. // Let affected entities speak normally to make this effect different from, say, the "random sentience" event
  16. // This also works on entities that already have a mind
  17. // We call this before the mind check to allow things like player-controlled mice to be able to benefit from the effect
  18. entityManager.RemoveComponent<ReplacementAccentComponent>(uid);
  19. entityManager.RemoveComponent<MonkeyAccentComponent>(uid);
  20. // Stops from adding a ghost role to things like people who already have a mind
  21. if (entityManager.TryGetComponent<MindContainerComponent>(uid, out var mindContainer) && mindContainer.HasMind)
  22. {
  23. return;
  24. }
  25. // Don't add a ghost role to things that already have ghost roles
  26. if (entityManager.TryGetComponent(uid, out GhostRoleComponent? ghostRole))
  27. {
  28. return;
  29. }
  30. ghostRole = entityManager.AddComponent<GhostRoleComponent>(uid);
  31. entityManager.EnsureComponent<GhostTakeoverAvailableComponent>(uid);
  32. var entityData = entityManager.GetComponent<MetaDataComponent>(uid);
  33. ghostRole.RoleName = entityData.EntityName;
  34. ghostRole.RoleDescription = Loc.GetString("ghost-role-information-cognizine-description");
  35. }
  36. }