StaminaDamageOnTriggerComponent (#39607)
* InflictStaminaOnTriggerSystem Surprised this wasn't done alongside the damage one. * Correct docstring * Moar docstring changes!!! * Resolve PR comment * a * Update Content.Shared/Trigger/Systems/StaminaDamageOnTriggerSystem.cs --------- Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
99ad34ed06
commit
2cb4e01019
@@ -0,0 +1,42 @@
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Damage.Systems;
|
||||
using Content.Shared.Trigger.Components.Effects;
|
||||
|
||||
namespace Content.Shared.Trigger.Systems;
|
||||
|
||||
public sealed class StaminaDamageOnTriggerSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedStaminaSystem _stamina = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<StaminaDamageOnTriggerComponent, TriggerEvent>(OnTrigger);
|
||||
}
|
||||
|
||||
private void OnTrigger(Entity<StaminaDamageOnTriggerComponent> ent, ref TriggerEvent args)
|
||||
{
|
||||
if (args.Key != null && !ent.Comp.KeysIn.Contains(args.Key))
|
||||
return;
|
||||
|
||||
var target = ent.Comp.TargetUser ? args.User : ent.Owner;
|
||||
|
||||
if (target == null)
|
||||
return;
|
||||
|
||||
var ev = new BeforeStaminaDamageOnTriggerEvent(ent.Comp.Stamina, target.Value);
|
||||
RaiseLocalEvent(ent.Owner, ref ev);
|
||||
|
||||
_stamina.TakeStaminaDamage(target.Value, ev.Stamina, source: args.User, with: ent.Owner, ignoreResist: ent.Comp.IgnoreResistances);
|
||||
|
||||
args.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised on an entity before it inflicts stamina due to StaminaDamageOnTriggerComponent.
|
||||
/// Used to modify the stamina that will be inflicted.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public record struct BeforeStaminaDamageOnTriggerEvent(float Stamina, EntityUid Tripper);
|
||||
Reference in New Issue
Block a user