DamageOnInteractSystem.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. // SPDX-FileCopyrightText: 2024 Aiden <aiden@djkraz.com>
  2. // SPDX-FileCopyrightText: 2024 Alzore <140123969+Blackern5000@users.noreply.github.com>
  3. // SPDX-FileCopyrightText: 2024 Brandon Hu <103440971+Brandon-Huu@users.noreply.github.com>
  4. // SPDX-FileCopyrightText: 2024 CaasGit <87243814+CaasGit@users.noreply.github.com>
  5. // SPDX-FileCopyrightText: 2024 Chief-Engineer <119664036+Chief-Engineer@users.noreply.github.com>
  6. // SPDX-FileCopyrightText: 2024 Cojoke <83733158+Cojoke-dot@users.noreply.github.com>
  7. // SPDX-FileCopyrightText: 2024 DrSmugleaf <10968691+DrSmugleaf@users.noreply.github.com>
  8. // SPDX-FileCopyrightText: 2024 DrSmugleaf <DrSmugleaf@users.noreply.github.com>
  9. // SPDX-FileCopyrightText: 2024 Ed <96445749+TheShuEd@users.noreply.github.com>
  10. // SPDX-FileCopyrightText: 2024 Emisse <99158783+Emisse@users.noreply.github.com>
  11. // SPDX-FileCopyrightText: 2024 EmoGarbage404 <retron404@gmail.com>
  12. // SPDX-FileCopyrightText: 2024 Eoin Mcloughlin <helloworld@eoinrul.es>
  13. // SPDX-FileCopyrightText: 2024 Errant <35878406+Errant-4@users.noreply.github.com>
  14. // SPDX-FileCopyrightText: 2024 Flareguy <78941145+Flareguy@users.noreply.github.com>
  15. // SPDX-FileCopyrightText: 2024 Hrosts <35345601+Hrosts@users.noreply.github.com>
  16. // SPDX-FileCopyrightText: 2024 IProduceWidgets <107586145+IProduceWidgets@users.noreply.github.com>
  17. // SPDX-FileCopyrightText: 2024 Ian <ignaz.k@live.de>
  18. // SPDX-FileCopyrightText: 2024 Ilya246 <57039557+Ilya246@users.noreply.github.com>
  19. // SPDX-FileCopyrightText: 2024 Joel Zimmerman <JoelZimmerman@users.noreply.github.com>
  20. // SPDX-FileCopyrightText: 2024 JustCone <141039037+JustCone14@users.noreply.github.com>
  21. // SPDX-FileCopyrightText: 2024 Killerqu00 <47712032+Killerqu00@users.noreply.github.com>
  22. // SPDX-FileCopyrightText: 2024 Ko4ergaPunk <62609550+Ko4ergaPunk@users.noreply.github.com>
  23. // SPDX-FileCopyrightText: 2024 Kukutis96513 <146854220+Kukutis96513@users.noreply.github.com>
  24. // SPDX-FileCopyrightText: 2024 Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>
  25. // SPDX-FileCopyrightText: 2024 Lye <128915833+Lyroth001@users.noreply.github.com>
  26. // SPDX-FileCopyrightText: 2024 MerrytheManokit <167581110+MerrytheManokit@users.noreply.github.com>
  27. // SPDX-FileCopyrightText: 2024 Mervill <mervills.email@gmail.com>
  28. // SPDX-FileCopyrightText: 2024 Mr. 27 <45323883+Dutch-VanDerLinde@users.noreply.github.com>
  29. // SPDX-FileCopyrightText: 2024 MureixloI <132683811+MureixloI@users.noreply.github.com>
  30. // SPDX-FileCopyrightText: 2024 NakataRin <45946146+NakataRin@users.noreply.github.com>
  31. // SPDX-FileCopyrightText: 2024 Nemanja <98561806+EmoGarbage404@users.noreply.github.com>
  32. // SPDX-FileCopyrightText: 2024 OrangeMoronage9622 <whyteterry0092@gmail.com>
  33. // SPDX-FileCopyrightText: 2024 PJBot <pieterjan.briers+bot@gmail.com>
  34. // SPDX-FileCopyrightText: 2024 Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
  35. // SPDX-FileCopyrightText: 2024 Piras314 <p1r4s@proton.me>
  36. // SPDX-FileCopyrightText: 2024 Plykiya <58439124+Plykiya@users.noreply.github.com>
  37. // SPDX-FileCopyrightText: 2024 Preston Smith <92108534+thetolbean@users.noreply.github.com>
  38. // SPDX-FileCopyrightText: 2024 Psychpsyo <60073468+Psychpsyo@users.noreply.github.com>
  39. // SPDX-FileCopyrightText: 2024 Repo <47093363+Titian3@users.noreply.github.com>
  40. // SPDX-FileCopyrightText: 2024 RiceMar1244 <138547931+RiceMar1244@users.noreply.github.com>
  41. // SPDX-FileCopyrightText: 2024 ShadowCommander <10494922+ShadowCommander@users.noreply.github.com>
  42. // SPDX-FileCopyrightText: 2024 Simon <63975668+Simyon264@users.noreply.github.com>
  43. // SPDX-FileCopyrightText: 2024 SlamBamActionman <83650252+SlamBamActionman@users.noreply.github.com>
  44. // SPDX-FileCopyrightText: 2024 Stalen <33173619+stalengd@users.noreply.github.com>
  45. // SPDX-FileCopyrightText: 2024 TakoDragon <69509841+BackeTako@users.noreply.github.com>
  46. // SPDX-FileCopyrightText: 2024 Thomas <87614336+Aeshus@users.noreply.github.com>
  47. // SPDX-FileCopyrightText: 2024 TsjipTsjip <19798667+TsjipTsjip@users.noreply.github.com>
  48. // SPDX-FileCopyrightText: 2024 Ubaser <134914314+UbaserB@users.noreply.github.com>
  49. // SPDX-FileCopyrightText: 2024 Unkn0wn_Gh0st <shadowstalkermll@gmail.com>
  50. // SPDX-FileCopyrightText: 2024 Vasilis <vasilis@pikachu.systems>
  51. // SPDX-FileCopyrightText: 2024 Vigers Ray <60344369+VigersRay@users.noreply.github.com>
  52. // SPDX-FileCopyrightText: 2024 beck-thompson <107373427+beck-thompson@users.noreply.github.com>
  53. // SPDX-FileCopyrightText: 2024 deathride58 <deathride58@users.noreply.github.com>
  54. // SPDX-FileCopyrightText: 2024 deltanedas <39013340+deltanedas@users.noreply.github.com>
  55. // SPDX-FileCopyrightText: 2024 deltanedas <@deltanedas:kde.org>
  56. // SPDX-FileCopyrightText: 2024 dffdff2423 <dffdff2423@gmail.com>
  57. // SPDX-FileCopyrightText: 2024 eoineoineoin <github@eoinrul.es>
  58. // SPDX-FileCopyrightText: 2024 foboscheshir <156405958+foboscheshir@users.noreply.github.com>
  59. // SPDX-FileCopyrightText: 2024 github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  60. // SPDX-FileCopyrightText: 2024 gluesniffler <159397573+gluesniffler@users.noreply.github.com>
  61. // SPDX-FileCopyrightText: 2024 lzk <124214523+lzk228@users.noreply.github.com>
  62. // SPDX-FileCopyrightText: 2024 metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
  63. // SPDX-FileCopyrightText: 2024 metalgearsloth <comedian_vs_clown@hotmail.com>
  64. // SPDX-FileCopyrightText: 2024 nikthechampiongr <32041239+nikthechampiongr@users.noreply.github.com>
  65. // SPDX-FileCopyrightText: 2024 plykiya <plykiya@protonmail.com>
  66. // SPDX-FileCopyrightText: 2024 saintmuntzer <47153094+saintmuntzer@users.noreply.github.com>
  67. // SPDX-FileCopyrightText: 2024 shamp <140359015+shampunj@users.noreply.github.com>
  68. // SPDX-FileCopyrightText: 2024 slarticodefast <161409025+slarticodefast@users.noreply.github.com>
  69. // SPDX-FileCopyrightText: 2024 strO0pwafel <153459934+strO0pwafel@users.noreply.github.com>
  70. // SPDX-FileCopyrightText: 2024 stroopwafel <j.o.luijkx@student.tudelft.nl>
  71. // SPDX-FileCopyrightText: 2024 themias <89101928+themias@users.noreply.github.com>
  72. // SPDX-FileCopyrightText: 2024 to4no_fix <156101927+chavonadelal@users.noreply.github.com>
  73. // SPDX-FileCopyrightText: 2024 voidnull000 <18663194+voidnull000@users.noreply.github.com>
  74. // SPDX-FileCopyrightText: 2025 Aiden <28298836+Aidenkrz@users.noreply.github.com>
  75. //
  76. // SPDX-License-Identifier: AGPL-3.0-or-later
  77. using Content.Shared.Administration.Logs;
  78. using Content.Shared.Damage.Components;
  79. using Content.Shared.Database;
  80. using Content.Shared.Interaction;
  81. using Content.Shared.Inventory;
  82. using Content.Shared.Popups;
  83. using Robust.Shared.Audio.Systems;
  84. using Content.Shared._Shitmed.Targeting; // Shitmed Change
  85. using Content.Shared.Hands.Components; // Shitmed Change
  86. namespace Content.Shared.Damage.Systems;
  87. public sealed class DamageOnInteractSystem : EntitySystem
  88. {
  89. [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
  90. [Dependency] private readonly DamageableSystem _damageableSystem = default!;
  91. [Dependency] private readonly SharedAudioSystem _audioSystem = default!;
  92. [Dependency] private readonly SharedPopupSystem _popupSystem = default!;
  93. [Dependency] private readonly InventorySystem _inventorySystem = default!;
  94. public override void Initialize()
  95. {
  96. base.Initialize();
  97. SubscribeLocalEvent<DamageOnInteractComponent, InteractHandEvent>(OnHandInteract);
  98. }
  99. /// <summary>
  100. /// Damages the user that interacts with the entity with an empty hand and
  101. /// plays a sound or pops up text in response. If the user does not have
  102. /// proper protection, the user will only be damaged and other interactions
  103. /// will be cancelled.
  104. /// </summary>
  105. /// <param name="entity">The entity being interacted with</param>
  106. /// <param name="args">Contains the user that interacted with the entity</param>
  107. private void OnHandInteract(Entity<DamageOnInteractComponent> entity, ref InteractHandEvent args)
  108. {
  109. if (!entity.Comp.IsDamageActive)
  110. return;
  111. var totalDamage = entity.Comp.Damage;
  112. if (!entity.Comp.IgnoreResistances)
  113. {
  114. // try to get damage on interact protection from either the inventory slots of the entity
  115. _inventorySystem.TryGetInventoryEntity<DamageOnInteractProtectionComponent>(args.User, out var protectiveEntity);
  116. // or checking the entity for the comp itself if the inventory didn't work
  117. if (protectiveEntity.Comp == null && TryComp<DamageOnInteractProtectionComponent>(args.User, out var protectiveComp))
  118. {
  119. protectiveEntity = (args.User, protectiveComp);
  120. }
  121. // if protectiveComp isn't null after all that, it means the user has protection,
  122. // so let's calculate how much they resist
  123. if (protectiveEntity.Comp != null)
  124. {
  125. totalDamage = DamageSpecifier.ApplyModifierSet(totalDamage, protectiveEntity.Comp.DamageProtection);
  126. }
  127. }
  128. // Shitmed Change Start
  129. TargetBodyPart? targetPart = null;
  130. var hands = CompOrNull<HandsComponent>(args.User);
  131. if (hands is { ActiveHand: not null })
  132. {
  133. targetPart = hands.ActiveHand.Location switch
  134. {
  135. HandLocation.Left => TargetBodyPart.LeftHand,
  136. HandLocation.Right => TargetBodyPart.RightHand,
  137. _ => null
  138. };
  139. }
  140. totalDamage = _damageableSystem.TryChangeDamage(args.User, totalDamage, origin: args.Target, targetPart: targetPart);
  141. // Shitmed Change End
  142. if (totalDamage != null && totalDamage.AnyPositive())
  143. {
  144. args.Handled = true;
  145. _adminLogger.Add(LogType.Damaged, $"{ToPrettyString(args.User):user} injured their hand by interacting with {ToPrettyString(args.Target):target} and received {totalDamage.GetTotal():damage} damage");
  146. _audioSystem.PlayPredicted(entity.Comp.InteractSound, args.Target, args.User);
  147. if (entity.Comp.PopupText != null)
  148. _popupSystem.PopupClient(Loc.GetString(entity.Comp.PopupText), args.User, args.User);
  149. }
  150. }
  151. public void SetIsDamageActiveTo(Entity<DamageOnInteractComponent> entity, bool mode)
  152. {
  153. if (entity.Comp.IsDamageActive == mode)
  154. return;
  155. entity.Comp.IsDamageActive = mode;
  156. Dirty(entity);
  157. }
  158. }