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

@@ -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;