adds a source uid to most damage & mobstate events (#11559)

Co-authored-by: Flipp Syder <76629141+vulppine@users.noreply.github.com>
This commit is contained in:
Paul Ritter
2022-10-08 12:15:27 +02:00
committed by GitHub
parent 548cee77e2
commit 79854e59a4
24 changed files with 50 additions and 37 deletions

View File

@@ -58,7 +58,7 @@ public sealed class BlockingUserSystem : EntitySystem
{
if (args.DamageDelta != null && args.DamageIncreased)
{
_damageable.TryChangeDamage(component.BlockingItem, args.DamageDelta);
_damageable.TryChangeDamage(component.BlockingItem, args.DamageDelta, origin: args.Origin);
}
}

View File

@@ -113,7 +113,7 @@ namespace Content.Shared.Damage
/// The damage changed event is used by other systems, such as damage thresholds.
/// </remarks>
public void DamageChanged(DamageableComponent component, DamageSpecifier? damageDelta = null,
bool interruptsDoAfters = true)
bool interruptsDoAfters = true, EntityUid? origin = null)
{
component.DamagePerGroup = component.Damage.GetDamagePerGroup(_prototypeManager);
component.TotalDamage = component.Damage.Total;
@@ -124,7 +124,7 @@ namespace Content.Shared.Damage
var data = new DamageVisualizerGroupData(damageDelta.GetDamagePerGroup(_prototypeManager).Keys.ToList());
_appearance.SetData(component.Owner, DamageVisualizerKeys.DamageUpdateGroups, data, appearance);
}
RaiseLocalEvent(component.Owner, new DamageChangedEvent(component, damageDelta, interruptsDoAfters));
RaiseLocalEvent(component.Owner, new DamageChangedEvent(component, damageDelta, interruptsDoAfters, origin));
}
/// <summary>
@@ -140,7 +140,7 @@ namespace Content.Shared.Damage
/// null if the user had no applicable components that can take damage.
/// </returns>
public DamageSpecifier? TryChangeDamage(EntityUid? uid, DamageSpecifier damage, bool ignoreResistances = false,
bool interruptsDoAfters = true, DamageableComponent? damageable = null)
bool interruptsDoAfters = true, DamageableComponent? damageable = null, EntityUid? origin = null)
{
if (!uid.HasValue || !Resolve(uid.Value, ref damageable, false))
{
@@ -364,10 +364,16 @@ namespace Content.Shared.Damage
/// </summary>
public readonly bool InterruptsDoAfters = false;
public DamageChangedEvent(DamageableComponent damageable, DamageSpecifier? damageDelta, bool interruptsDoAfters)
/// <summary>
/// Contains the entity which caused the change in damage, if any was responsible.
/// </summary>
public readonly EntityUid? Origin;
public DamageChangedEvent(DamageableComponent damageable, DamageSpecifier? damageDelta, bool interruptsDoAfters, EntityUid? origin)
{
Damageable = damageable;
DamageDelta = damageDelta;
Origin = origin;
if (DamageDelta == null)
return;

View File

@@ -406,7 +406,7 @@ public abstract class SharedDoorSystem : EntitySystem
{
door.CurrentlyCrushing.Add(entity);
if (door.CrushDamage != null)
_damageableSystem.TryChangeDamage(entity, door.CrushDamage);
_damageableSystem.TryChangeDamage(entity, door.CrushDamage, origin: uid);
_stunSystem.TryParalyze(entity, stunTime, true);
}

View File

@@ -178,7 +178,7 @@ namespace Content.Shared.MobState.EntitySystems
public void UpdateState(EntityUid _, MobStateComponent component, DamageChangedEvent args)
{
UpdateState(component, args.Damageable.TotalDamage);
UpdateState(component, args.Damageable.TotalDamage, args.Origin);
}
private void OnMoveAttempt(EntityUid uid, MobStateComponent component, UpdateCanMoveEvent args)
@@ -275,20 +275,20 @@ namespace Content.Shared.MobState.EntitySystems
/// <summary>
/// Updates the mob state..
/// </summary>
public void UpdateState(MobStateComponent component, FixedPoint2 damage)
public void UpdateState(MobStateComponent component, FixedPoint2 damage, EntityUid? origin = null)
{
if (!TryGetState(component, damage, out var newState, out var threshold))
{
return;
}
SetMobState(component, component.CurrentState, (newState.Value, threshold));
SetMobState(component, component.CurrentState, (newState.Value, threshold), origin);
}
/// <summary>
/// Sets the mob state and marks the component as dirty.
/// </summary>
private void SetMobState(MobStateComponent component, DamageState? old, (DamageState state, FixedPoint2 threshold)? current)
private void SetMobState(MobStateComponent component, DamageState? old, (DamageState state, FixedPoint2 threshold)? current, EntityUid? origin = null)
{
if (!current.HasValue)
{
@@ -313,7 +313,7 @@ namespace Content.Shared.MobState.EntitySystems
EnterState(component, state);
UpdateState(component, state, threshold);
var message = new MobStateChangedEvent(component, old, state);
var message = new MobStateChangedEvent(component, old, state, origin);
RaiseLocalEvent(component.Owner, message, true);
Dirty(component);
}

View File

@@ -7,11 +7,13 @@ namespace Content.Shared.MobState
public MobStateChangedEvent(
MobStateComponent component,
DamageState? oldMobState,
DamageState currentMobState)
DamageState currentMobState,
EntityUid? origin)
{
Component = component;
OldMobState = oldMobState;
CurrentMobState = currentMobState;
Origin = origin;
}
public EntityUid Entity => Component.Owner;
@@ -21,6 +23,8 @@ namespace Content.Shared.MobState
public DamageState? OldMobState { get; }
public DamageState CurrentMobState { get; }
public EntityUid? Origin { get; }
}
public static class A