HandEvents.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. using System.Numerics;
  2. using Content.Shared.Hands.Components;
  3. using JetBrains.Annotations;
  4. using Robust.Shared.Map;
  5. using Robust.Shared.Serialization;
  6. namespace Content.Shared.Hands
  7. {
  8. /// <summary>
  9. /// Raised directed on an entity when attempting to drop its hand items.
  10. /// </summary>
  11. public sealed class DropAttemptEvent : CancellableEntityEventArgs
  12. {
  13. public readonly EntityUid Uid;
  14. }
  15. /// <summary>
  16. /// Raised directed at an item that needs to update its in-hand sprites/layers.
  17. /// </summary>
  18. public sealed class GetInhandVisualsEvent : EntityEventArgs
  19. {
  20. /// <summary>
  21. /// Entity that owns the hand holding the item.
  22. /// </summary>
  23. public readonly EntityUid User;
  24. public readonly HandLocation Location;
  25. /// <summary>
  26. /// The layers that will be added to the entity that is holding this item.
  27. /// </summary>
  28. /// <remarks>
  29. /// Note that the actual ordering of the layers depends on the order in which they are added to this list;
  30. /// </remarks>
  31. public List<(string, PrototypeLayerData)> Layers = new();
  32. public GetInhandVisualsEvent(EntityUid user, HandLocation location)
  33. {
  34. User = user;
  35. Location = location;
  36. }
  37. }
  38. /// <summary>
  39. /// Raised directed at an item after its visuals have been updated.
  40. /// </summary>
  41. /// <remarks>
  42. /// Useful for systems/components that modify the visual layers that an item adds to a player. (e.g. RGB memes)
  43. /// </remarks>
  44. public sealed class HeldVisualsUpdatedEvent : EntityEventArgs
  45. {
  46. /// <summary>
  47. /// Entity that is holding the item.
  48. /// </summary>
  49. public readonly EntityUid User;
  50. /// <summary>
  51. /// The layers that this item is now revealing.
  52. /// </summary>
  53. public HashSet<string> RevealedLayers;
  54. public HeldVisualsUpdatedEvent(EntityUid user, HashSet<string> revealedLayers)
  55. {
  56. User = user;
  57. RevealedLayers = revealedLayers;
  58. }
  59. }
  60. /// <summary>
  61. /// Raised when an entity item in a hand is deselected.
  62. /// </summary>
  63. [PublicAPI]
  64. public sealed class HandDeselectedEvent : HandledEntityEventArgs
  65. {
  66. /// <summary>
  67. /// Entity that owns the deselected hand.
  68. /// </summary>
  69. public EntityUid User { get; }
  70. public HandDeselectedEvent(EntityUid user)
  71. {
  72. User = user;
  73. }
  74. }
  75. /// <summary>
  76. /// Raised when an item entity held by a hand is selected.
  77. /// </summary>
  78. [PublicAPI]
  79. public sealed class HandSelectedEvent : HandledEntityEventArgs
  80. {
  81. /// <summary>
  82. /// Entity that owns the selected hand.
  83. /// </summary>
  84. public EntityUid User { get; }
  85. public HandSelectedEvent(EntityUid user)
  86. {
  87. User = user;
  88. }
  89. }
  90. [Serializable, NetSerializable]
  91. public sealed class RequestSetHandEvent : EntityEventArgs
  92. {
  93. /// <summary>
  94. /// The hand to be swapped to.
  95. /// </summary>
  96. public string HandName { get; }
  97. public RequestSetHandEvent(string handName)
  98. {
  99. HandName = handName;
  100. }
  101. }
  102. /// <summary>
  103. /// Plays a clientside pickup animation by copying the specified entity.
  104. /// </summary>
  105. [Serializable, NetSerializable]
  106. public sealed class PickupAnimationEvent : EntityEventArgs
  107. {
  108. /// <summary>
  109. /// Entity to be copied for the clientside animation.
  110. /// </summary>
  111. public readonly NetEntity ItemUid;
  112. public readonly NetCoordinates InitialPosition;
  113. public readonly NetCoordinates FinalPosition;
  114. public readonly Angle InitialAngle;
  115. public PickupAnimationEvent(NetEntity itemUid,
  116. NetCoordinates initialPosition,
  117. NetCoordinates finalPosition,
  118. Angle initialAngle)
  119. {
  120. ItemUid = itemUid;
  121. FinalPosition = finalPosition;
  122. InitialPosition = initialPosition;
  123. InitialAngle = initialAngle;
  124. }
  125. }
  126. /// <summary>
  127. /// Raised directed on both the blocking entity and user when
  128. /// a virtual hand item is deleted.
  129. /// </summary>
  130. public sealed class VirtualItemDeletedEvent : EntityEventArgs
  131. {
  132. public EntityUid BlockingEntity;
  133. public EntityUid User;
  134. public VirtualItemDeletedEvent(EntityUid blockingEntity, EntityUid user)
  135. {
  136. BlockingEntity = blockingEntity;
  137. User = user;
  138. }
  139. }
  140. /// <summary>
  141. /// Raised when putting an entity into a hand slot
  142. /// </summary>
  143. [PublicAPI]
  144. public abstract class EquippedHandEvent : HandledEntityEventArgs
  145. {
  146. /// <summary>
  147. /// Entity that equipped the item.
  148. /// </summary>
  149. public EntityUid User { get; }
  150. /// <summary>
  151. /// Item that was equipped.
  152. /// </summary>
  153. public EntityUid Equipped { get; }
  154. /// <summary>
  155. /// Hand that the item was placed into.
  156. /// </summary>
  157. public Hand Hand { get; }
  158. public EquippedHandEvent(EntityUid user, EntityUid equipped, Hand hand)
  159. {
  160. User = user;
  161. Equipped = equipped;
  162. Hand = hand;
  163. }
  164. }
  165. /// <summary>
  166. /// Raised when removing an entity from an inventory slot.
  167. /// </summary>
  168. [PublicAPI]
  169. public abstract class UnequippedHandEvent : HandledEntityEventArgs
  170. {
  171. /// <summary>
  172. /// Entity that equipped the item.
  173. /// </summary>
  174. public EntityUid User { get; }
  175. /// <summary>
  176. /// Item that was unequipped.
  177. /// </summary>
  178. public EntityUid Unequipped { get; }
  179. /// <summary>
  180. /// Hand that the item is removed from.
  181. /// </summary>
  182. public Hand Hand { get; }
  183. public UnequippedHandEvent(EntityUid user, EntityUid unequipped, Hand hand)
  184. {
  185. User = user;
  186. Unequipped = unequipped;
  187. Hand = hand;
  188. }
  189. }
  190. /// <summary>
  191. /// Raised directed on an entity when it is equipped into hands.
  192. /// </summary>
  193. public sealed class GotEquippedHandEvent : EquippedHandEvent
  194. {
  195. public GotEquippedHandEvent(EntityUid user, EntityUid unequipped, Hand hand) : base(user, unequipped, hand) { }
  196. }
  197. /// <summary>
  198. /// Raised directed on an entity when it is unequipped from hands.
  199. /// </summary>
  200. public sealed class GotUnequippedHandEvent : UnequippedHandEvent
  201. {
  202. public GotUnequippedHandEvent(EntityUid user, EntityUid unequipped, Hand hand) : base(user, unequipped, hand) { }
  203. }
  204. /// <summary>
  205. /// Raised directed on a user when it picks something up.
  206. /// </summary>
  207. public sealed class DidEquipHandEvent : EquippedHandEvent
  208. {
  209. public DidEquipHandEvent(EntityUid user, EntityUid unequipped, Hand hand) : base(user, unequipped, hand) { }
  210. }
  211. /// <summary>
  212. /// Raised directed on a user when something leaves its hands.
  213. /// </summary>
  214. public sealed class DidUnequipHandEvent : UnequippedHandEvent
  215. {
  216. public DidUnequipHandEvent(EntityUid user, EntityUid unequipped, Hand hand) : base(user, unequipped, hand) { }
  217. }
  218. /// <summary>
  219. /// Event raised by a client when they want to use the item currently held in their hands.
  220. /// </summary>
  221. [Serializable, NetSerializable]
  222. public sealed class RequestUseInHandEvent : EntityEventArgs
  223. {
  224. }
  225. /// <summary>
  226. /// Event raised by a client when they want to activate the item currently in their hands.
  227. /// </summary>
  228. [Serializable, NetSerializable]
  229. public sealed class RequestActivateInHandEvent : EntityEventArgs
  230. {
  231. public string HandName { get; }
  232. public RequestActivateInHandEvent(string handName)
  233. {
  234. HandName = handName;
  235. }
  236. }
  237. /// <summary>
  238. /// Event raised by a client when they want to use the currently held item on some other held item
  239. /// </summary>
  240. [Serializable, NetSerializable]
  241. public sealed class RequestHandInteractUsingEvent : EntityEventArgs
  242. {
  243. public string HandName { get; }
  244. public RequestHandInteractUsingEvent(string handName)
  245. {
  246. HandName = handName;
  247. }
  248. }
  249. /// <summary>
  250. /// Event raised by a client when they want to move an item held in another hand to their currently active hand
  251. /// </summary>
  252. [Serializable, NetSerializable]
  253. public sealed class RequestMoveHandItemEvent : EntityEventArgs
  254. {
  255. public string HandName { get; }
  256. public RequestMoveHandItemEvent(string handName)
  257. {
  258. HandName = handName;
  259. }
  260. }
  261. /// <summary>
  262. /// Event raised by a client when they want to alt interact with the item currently in their hands.
  263. /// </summary>
  264. [Serializable, NetSerializable]
  265. public sealed class RequestHandAltInteractEvent : EntityEventArgs
  266. {
  267. public string HandName { get; }
  268. public RequestHandAltInteractEvent(string handName)
  269. {
  270. HandName = handName;
  271. }
  272. }
  273. public sealed class HandCountChangedEvent : EntityEventArgs
  274. {
  275. public HandCountChangedEvent(EntityUid sender)
  276. {
  277. Sender = sender;
  278. }
  279. public EntityUid Sender { get; }
  280. }
  281. [ByRefEvent]
  282. public sealed class HeldRelayedEvent<TEvent> : EntityEventArgs
  283. {
  284. public TEvent Args;
  285. public HeldRelayedEvent(TEvent args)
  286. {
  287. Args = args;
  288. }
  289. }
  290. }