DodgeWideswingSystem.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // SPDX-FileCopyrightText: 2025 Aiden <28298836+Aidenkrz@users.noreply.github.com>
  2. // SPDX-FileCopyrightText: 2025 Ilya246 <57039557+Ilya246@users.noreply.github.com>
  3. // SPDX-FileCopyrightText: 2025 Misandry <mary@thughunt.ing>
  4. // SPDX-FileCopyrightText: 2025 gus <august.eymann@gmail.com>
  5. //
  6. // SPDX-License-Identifier: AGPL-3.0-or-later
  7. using Content.Shared.Damage;
  8. using Content.Shared.Damage.Systems;
  9. using Content.Shared.Popups;
  10. using Content.Shared.Stunnable;
  11. using Robust.Shared.Random;
  12. namespace Content.Shared.Goobstation.Weapons.DodgeWideswing;
  13. public sealed class DodgeWideswingSystem : EntitySystem
  14. {
  15. [Dependency] private readonly SharedPopupSystem _popup = default!;
  16. [Dependency] private readonly IRobustRandom _random = default!;
  17. [Dependency] private readonly StaminaSystem _stamina = default!;
  18. /// <summary>
  19. /// Subscribes to damage change events for entities with the <see cref="DodgeWideswingComponent"/>.
  20. /// </summary>
  21. public override void Initialize()
  22. {
  23. base.Initialize();
  24. SubscribeLocalEvent<DodgeWideswingComponent, BeforeDamageChangedEvent>(OnDamageChanged);
  25. }
  26. /// <summary>
  27. /// Handles incoming heavy attack damage for entities with a DodgeWideswingComponent, potentially converting the damage into stamina loss and cancelling the original damage based on configured chance and conditions.
  28. /// </summary>
  29. /// <param name="uid">The entity receiving the damage.</param>
  30. /// <param name="component">The DodgeWideswingComponent associated with the entity.</param>
  31. /// <param name="args">The event data for the incoming damage, passed by reference.</param>
  32. private void OnDamageChanged(EntityUid uid, DodgeWideswingComponent component, ref BeforeDamageChangedEvent args)
  33. {
  34. if (args.HeavyAttack && (!HasComp<KnockedDownComponent>(uid) || component.WhenKnockedDown) && _random.Prob(component.Chance))
  35. {
  36. _stamina.TakeStaminaDamage(uid, args.Damage.GetTotal().Float() * component.StaminaRatio, source: args.Origin, immediate: false);
  37. if (component.PopupId != null)
  38. _popup.PopupPredicted(Loc.GetString(component.PopupId, ("target", uid)), uid, args.Origin);
  39. args.Cancelled = true;
  40. }
  41. }
  42. }