fix reflected projectiles dealing stamina damage (#17648)

This commit is contained in:
Slava0135
2023-08-06 16:44:41 +03:00
committed by GitHub
parent c6f80b2efb
commit b49f0df05e
5 changed files with 46 additions and 54 deletions

View File

@@ -7,13 +7,13 @@ using Content.Shared.Damage.Events;
using Content.Shared.Database;
using Content.Shared.IdentityManagement;
using Content.Shared.Popups;
using Content.Shared.Projectiles;
using Content.Shared.Rejuvenate;
using Content.Shared.Rounding;
using Content.Shared.Stunnable;
using Content.Shared.Weapons.Melee.Events;
using JetBrains.Annotations;
using Robust.Shared.GameStates;
using Robust.Shared.Physics.Events;
using Robust.Shared.Player;
using Robust.Shared.Random;
using Robust.Shared.Serialization;
@@ -31,8 +31,6 @@ public sealed partial class StaminaSystem : EntitySystem
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly SharedStunSystem _stunSystem = default!;
private const string CollideFixture = "projectile";
/// <summary>
/// How much of a buffer is there between the stun duration and when stuns can be re-applied.
/// </summary>
@@ -52,7 +50,7 @@ public sealed partial class StaminaSystem : EntitySystem
SubscribeLocalEvent<StaminaComponent, DisarmedEvent>(OnDisarmed);
SubscribeLocalEvent<StaminaComponent, RejuvenateEvent>(OnRejuvenate);
SubscribeLocalEvent<StaminaDamageOnCollideComponent, StartCollideEvent>(OnCollide);
SubscribeLocalEvent<StaminaDamageOnCollideComponent, ProjectileHitEvent>(OnCollide);
SubscribeLocalEvent<StaminaDamageOnHitComponent, MeleeHitEvent>(OnHit);
}
@@ -144,7 +142,7 @@ public sealed partial class StaminaSystem : EntitySystem
return;
var damage = args.PushProbability * component.CritThreshold;
TakeStaminaDamage(uid, damage, component, source:args.Source);
TakeStaminaDamage(uid, damage, component, source: args.Source);
// We need a better method of getting if the entity is going to resist stam damage, both this and the lines in the foreach at the end of OnHit() are awful
if (!component.Critical)
@@ -204,7 +202,7 @@ public sealed partial class StaminaSystem : EntitySystem
foreach (var (ent, comp) in toHit)
{
var oldDamage = comp.StaminaDamage;
TakeStaminaDamage(ent, damage / toHit.Count, comp, source:args.User, with:args.Weapon);
TakeStaminaDamage(ent, damage / toHit.Count, comp, source: args.User, with: args.Weapon);
if (comp.StaminaDamage.Equals(oldDamage))
{
_popup.PopupClient(Loc.GetString("stamina-resist"), ent, args.User);
@@ -212,11 +210,9 @@ public sealed partial class StaminaSystem : EntitySystem
}
}
private void OnCollide(EntityUid uid, StaminaDamageOnCollideComponent component, ref StartCollideEvent args)
private void OnCollide(EntityUid uid, StaminaDamageOnCollideComponent component, ref ProjectileHitEvent args)
{
if (!args.OurFixture.ID.Equals(CollideFixture)) return;
TakeStaminaDamage(args.OtherEntity, component.Damage, source:args.OurEntity);
TakeStaminaDamage(args.Target, component.Damage, source: uid);
}
private void SetStaminaAlert(EntityUid uid, StaminaComponent? component = null)
@@ -413,4 +409,4 @@ public sealed partial class StaminaSystem : EntitySystem
/// Raised before stamina damage is dealt to allow other systems to cancel it.
/// </summary>
[ByRefEvent]
public record struct BeforeStaminaDamageEvent(float Value, bool Cancelled=false);
public record struct BeforeStaminaDamageEvent(float Value, bool Cancelled = false);