VoteOptions.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using Content.Server.Voting.Managers;
  2. using Robust.Shared.Player;
  3. namespace Content.Server.Voting
  4. {
  5. /// <summary>
  6. /// Options for creating a vote.
  7. /// </summary>
  8. public sealed class VoteOptions
  9. {
  10. /// <summary>
  11. /// The text that is shown for "who called the vote".
  12. /// </summary>
  13. public string InitiatorText { get; set; } = "<placeholder>";
  14. /// <summary>
  15. /// The player that started the vote. Used to keep track of player cooldowns to avoid vote spam.
  16. /// </summary>
  17. public ICommonSession? InitiatorPlayer { get; set; }
  18. /// <summary>
  19. /// The shown title of the vote.
  20. /// </summary>
  21. public string Title { get; set; } = "<somebody forgot to fill this in lol>";
  22. /// <summary>
  23. /// How long the vote lasts.
  24. /// </summary>
  25. public TimeSpan Duration { get; set; } = TimeSpan.FromMinutes(1);
  26. /// <summary>
  27. /// How long the initiator should be timed out from calling votes. Defaults to duration * 2;
  28. /// </summary>
  29. public TimeSpan? InitiatorTimeout { get; set; }
  30. /// <summary>
  31. /// The options of the vote. Each entry is a tuple of the player-shown text,
  32. /// and a data object that can be used to keep track of options later.
  33. /// </summary>
  34. public List<(string text, object data)> Options { get; set; } = new();
  35. /// <summary>
  36. /// Which sessions may send a vote. Used when only a subset of players should be able to vote. Defaults to all.
  37. /// </summary>
  38. public VoteManager.VoterEligibility VoterEligibility = VoteManager.VoterEligibility.All;
  39. /// <summary>
  40. /// Whether the vote should send and display the number of votes to the clients. Being an admin defaults this option to true for your client.
  41. /// </summary>
  42. public bool DisplayVotes = true;
  43. /// <summary>
  44. /// Whether the vote should have an entity attached to it, to be used for things like letting ghosts follow it.
  45. /// </summary>
  46. public NetEntity? TargetEntity = null;
  47. /// <summary>
  48. /// Sets <see cref="InitiatorPlayer"/> and <see cref="InitiatorText"/>
  49. /// by setting the latter to the player's name.
  50. /// </summary>
  51. public void SetInitiator(ICommonSession player)
  52. {
  53. InitiatorPlayer = player;
  54. InitiatorText = player.Name;
  55. }
  56. public void SetInitiatorOrServer(ICommonSession? player)
  57. {
  58. if (player != null)
  59. {
  60. SetInitiator(player);
  61. }
  62. else
  63. {
  64. InitiatorText = Loc.GetString("vote-options-server-initiator-text");
  65. }
  66. }
  67. }
  68. }