MeleeHitEvent.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System.Numerics;
  2. using Content.Shared.Damage;
  3. using Content.Shared.FixedPoint;
  4. using Robust.Shared.Audio;
  5. namespace Content.Shared.Weapons.Melee.Events;
  6. /// <summary>
  7. /// Raised directed on the melee weapon entity used to attack something in combat mode,
  8. /// whether through a click attack or wide attack.
  9. /// </summary>
  10. public sealed class MeleeHitEvent : HandledEntityEventArgs
  11. {
  12. /// <summary>
  13. /// The base amount of damage dealt by the melee hit.
  14. /// </summary>
  15. public readonly DamageSpecifier BaseDamage;
  16. /// <summary>
  17. /// Modifier sets to apply to the hit event when it's all said and done.
  18. /// This should be modified by adding a new entry to the list.
  19. /// </summary>
  20. public List<DamageModifierSet> ModifiersList = new();
  21. /// <summary>
  22. /// Damage to add to the default melee weapon damage. Applied before modifiers.
  23. /// </summary>
  24. /// <remarks>
  25. /// This might be required as damage modifier sets cannot add a new damage type to a DamageSpecifier.
  26. /// </remarks>
  27. public DamageSpecifier BonusDamage = new();
  28. /// <summary>
  29. /// A list containing every hit entity. Can be zero.
  30. /// </summary>
  31. public IReadOnlyList<EntityUid> HitEntities;
  32. /// <summary>
  33. /// Used to define a new hit sound in case you want to override the default GenericHit.
  34. /// Also gets a pitch modifier added to it.
  35. /// </summary>
  36. public SoundSpecifier? HitSoundOverride;
  37. /// <summary>
  38. /// The user who attacked with the melee weapon.
  39. /// </summary>
  40. public readonly EntityUid User;
  41. /// <summary>
  42. /// The melee weapon used.
  43. /// </summary>
  44. public readonly EntityUid Weapon;
  45. /// <summary>
  46. /// The direction of the attack.
  47. /// If null, it was a click-attack.
  48. /// </summary>
  49. public readonly Vector2? Direction;
  50. /// <summary>
  51. /// Check if this is true before attempting to do something during a melee attack other than changing/adding bonus damage. <br/>
  52. /// For example, do not spend charges unless <see cref="IsHit"/> equals true.
  53. /// </summary>
  54. /// <remarks>
  55. /// Examining melee weapons calls this event, but with <see cref="IsHit"/> set to false.
  56. /// </remarks>
  57. public bool IsHit = true;
  58. public MeleeHitEvent(List<EntityUid> hitEntities, EntityUid user, EntityUid weapon, DamageSpecifier baseDamage, Vector2? direction)
  59. {
  60. HitEntities = hitEntities;
  61. User = user;
  62. Weapon = weapon;
  63. BaseDamage = baseDamage;
  64. Direction = direction;
  65. }
  66. }
  67. /// <summary>
  68. /// Raised on a melee weapon to calculate potential damage bonuses or decreases.
  69. /// </summary>
  70. [ByRefEvent]
  71. public record struct GetMeleeDamageEvent(EntityUid Weapon, DamageSpecifier Damage, List<DamageModifierSet> Modifiers, EntityUid User, bool ResistanceBypass = false);
  72. /// <summary>
  73. /// Raised on a melee weapon to calculate the attack rate.
  74. /// </summary>
  75. [ByRefEvent]
  76. public record struct GetMeleeAttackRateEvent(EntityUid Weapon, float Rate, float Multipliers, EntityUid User);
  77. /// <summary>
  78. /// Raised on a melee weapon to calculate the heavy damage modifier.
  79. /// </summary>
  80. [ByRefEvent]
  81. public record struct GetHeavyDamageModifierEvent(EntityUid Weapon, FixedPoint2 DamageModifier, float Multipliers, EntityUid User);