1
0

VerbEvents.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. using Content.Shared.ActionBlocker;
  2. using Content.Shared.Hands.Components;
  3. using Content.Shared.Interaction;
  4. using Robust.Shared.Containers;
  5. using Robust.Shared.Serialization;
  6. using Robust.Shared.Utility;
  7. namespace Content.Shared.Verbs
  8. {
  9. [Serializable, NetSerializable]
  10. public sealed class RequestServerVerbsEvent : EntityEventArgs
  11. {
  12. public readonly NetEntity EntityUid;
  13. public readonly List<string> VerbTypes = new();
  14. /// <summary>
  15. /// If the target item is inside of some storage (e.g., backpack), this is the entity that owns that item
  16. /// slot. Needed for validating that the user can access the target item.
  17. /// </summary>
  18. public readonly NetEntity? SlotOwner;
  19. public readonly bool AdminRequest;
  20. public RequestServerVerbsEvent(NetEntity entityUid, IEnumerable<Type> verbTypes, NetEntity? slotOwner = null, bool adminRequest = false)
  21. {
  22. EntityUid = entityUid;
  23. SlotOwner = slotOwner;
  24. AdminRequest = adminRequest;
  25. foreach (var type in verbTypes)
  26. {
  27. DebugTools.Assert(typeof(Verb).IsAssignableFrom(type));
  28. VerbTypes.Add(type.Name);
  29. }
  30. }
  31. }
  32. [Serializable, NetSerializable]
  33. public sealed class VerbsResponseEvent : EntityEventArgs
  34. {
  35. public readonly List<Verb>? Verbs;
  36. public readonly NetEntity Entity;
  37. public VerbsResponseEvent(NetEntity entity, SortedSet<Verb>? verbs)
  38. {
  39. Entity = entity;
  40. if (verbs == null)
  41. return;
  42. // Apparently SortedSet is not serializable, so we cast to List<Verb>.
  43. Verbs = new(verbs);
  44. }
  45. }
  46. [Serializable, NetSerializable]
  47. public sealed class ExecuteVerbEvent : EntityEventArgs
  48. {
  49. public readonly NetEntity Target;
  50. public readonly Verb RequestedVerb;
  51. public ExecuteVerbEvent(NetEntity target, Verb requestedVerb)
  52. {
  53. Target = target;
  54. RequestedVerb = requestedVerb;
  55. }
  56. }
  57. /// <summary>
  58. /// Directed event that requests verbs from any systems/components on a target entity.
  59. /// </summary>
  60. public sealed class GetVerbsEvent<TVerb> : EntityEventArgs where TVerb : Verb
  61. {
  62. /// <summary>
  63. /// Event output. Set of verbs that can be executed.
  64. /// </summary>
  65. public readonly SortedSet<TVerb> Verbs = new();
  66. /// <summary>
  67. /// Additional verb categories to show in the pop-up menu, even if there are no verbs currently associated
  68. /// with that category. This is mainly useful to prevent verb menu pop-in. E.g., admins will get admin/debug
  69. /// related verbs on entities, even though most of those verbs are all defined server-side.
  70. /// </summary>
  71. public readonly List<VerbCategory> ExtraCategories;
  72. /// <summary>
  73. /// Can the user physically access the target?
  74. /// </summary>
  75. /// <remarks>
  76. /// This is a combination of <see cref="ContainerHelpers.IsInSameOrParentContainer"/> and
  77. /// <see cref="SharedInteractionSystem.InRangeUnobstructed"/>.
  78. /// </remarks>
  79. public readonly bool CanAccess = false;
  80. /// <summary>
  81. /// The entity being targeted for the verb.
  82. /// </summary>
  83. public readonly EntityUid Target;
  84. /// <summary>
  85. /// The entity that will be "performing" the verb.
  86. /// </summary>
  87. public readonly EntityUid User;
  88. /// <summary>
  89. /// Can the user physically interact?
  90. /// </summary>
  91. /// <remarks>
  92. /// This is a just a cached <see cref="ActionBlockerSystem.CanInteract"/> result. Given that many verbs need
  93. /// to check this, it prevents it from having to be repeatedly called by each individual system that might
  94. /// contribute a verb.
  95. /// </remarks>
  96. public readonly bool CanInteract;
  97. /// <summary>
  98. /// Cached version of CanComplexInteract
  99. /// </summary>
  100. public readonly bool CanComplexInteract;
  101. /// <summary>
  102. /// The User's hand component.
  103. /// </summary>
  104. /// <remarks>
  105. /// This may be null if the user has no hands.
  106. /// </remarks>
  107. public readonly HandsComponent? Hands;
  108. /// <summary>
  109. /// The entity currently being held by the active hand.
  110. /// </summary>
  111. /// <remarks>
  112. /// This is only ever not null when <see cref="ActionBlockerSystem.CanUseHeldEntity(EntityUid)"/> is true and the user
  113. /// has hands.
  114. /// </remarks>
  115. public readonly EntityUid? Using;
  116. public GetVerbsEvent(EntityUid user, EntityUid target, EntityUid? @using, HandsComponent? hands, bool canInteract, bool canComplexInteract, bool canAccess, List<VerbCategory> extraCategories)
  117. {
  118. User = user;
  119. Target = target;
  120. Using = @using;
  121. Hands = hands;
  122. CanAccess = canAccess;
  123. CanComplexInteract = canComplexInteract;
  124. CanInteract = canInteract;
  125. ExtraCategories = extraCategories;
  126. }
  127. }
  128. }