From 736325a31f90cb1ffde51f5114a166bf87b71c8c Mon Sep 17 00:00:00 2001 From: TsjipTsjip <19798667+TsjipTsjip@users.noreply.github.com> Date: Fri, 9 Aug 2024 08:24:05 +0200 Subject: [PATCH] Log enrichment: Explosion damage to players (#29762) * Log enrichment: Explosion damage to players * Update Content.Server/Explosion/EntitySystems/ExplosionSystem.Processing.cs Co-authored-by: Chief-Engineer <119664036+Chief-Engineer@users.noreply.github.com> * Revert to total damage variant only, currently serialised as string. * Make this its own log type. --------- Co-authored-by: Chief-Engineer <119664036+Chief-Engineer@users.noreply.github.com> --- .../Commands/ExplosionCommand.cs | 2 +- .../Systems/AdminVerbSystem.Smites.cs | 2 +- .../ExplosionSystem.Processing.cs | 50 +++++++++++++++---- .../EntitySystems/ExplosionSystem.cs | 9 ++-- .../Lightning/LightningTargetSystem.cs | 1 + .../EntitySystems/BluespaceLockerSystem.cs | 2 +- Content.Shared.Database/LogType.cs | 6 +++ 7 files changed, 55 insertions(+), 17 deletions(-) diff --git a/Content.Server/Administration/Commands/ExplosionCommand.cs b/Content.Server/Administration/Commands/ExplosionCommand.cs index 81daca59c4..c916a7cb5f 100644 --- a/Content.Server/Administration/Commands/ExplosionCommand.cs +++ b/Content.Server/Administration/Commands/ExplosionCommand.cs @@ -132,6 +132,6 @@ public sealed class ExplosionCommand : IConsoleCommand } var sysMan = IoCManager.Resolve(); - sysMan.GetEntitySystem().QueueExplosion(coords, type.ID, intensity, slope, maxIntensity); + sysMan.GetEntitySystem().QueueExplosion(coords, type.ID, intensity, slope, maxIntensity, null); } } diff --git a/Content.Server/Administration/Systems/AdminVerbSystem.Smites.cs b/Content.Server/Administration/Systems/AdminVerbSystem.Smites.cs index 1f5abf6726..e4554d7d83 100644 --- a/Content.Server/Administration/Systems/AdminVerbSystem.Smites.cs +++ b/Content.Server/Administration/Systems/AdminVerbSystem.Smites.cs @@ -105,7 +105,7 @@ public sealed partial class AdminVerbSystem var coords = _transformSystem.GetMapCoordinates(args.Target); Timer.Spawn(_gameTiming.TickPeriod, () => _explosionSystem.QueueExplosion(coords, ExplosionSystem.DefaultExplosionPrototypeId, - 4, 1, 2, maxTileBreak: 0), // it gibs, damage doesn't need to be high. + 4, 1, 2, args.Target, maxTileBreak: 0), // it gibs, damage doesn't need to be high. CancellationToken.None); _bodySystem.GibBody(args.Target); diff --git a/Content.Server/Explosion/EntitySystems/ExplosionSystem.Processing.cs b/Content.Server/Explosion/EntitySystems/ExplosionSystem.Processing.cs index 3cab1213b6..6d0cbcf279 100644 --- a/Content.Server/Explosion/EntitySystems/ExplosionSystem.Processing.cs +++ b/Content.Server/Explosion/EntitySystems/ExplosionSystem.Processing.cs @@ -1,7 +1,10 @@ +using System.Linq; using System.Numerics; using Content.Server.Atmos.EntitySystems; +using Content.Server.Explosion.Components; using Content.Shared.CCVar; using Content.Shared.Damage; +using Content.Shared.Database; using Content.Shared.Explosion; using Content.Shared.Explosion.Components; using Content.Shared.Explosion.EntitySystems; @@ -14,6 +17,7 @@ using Robust.Shared.Map.Components; using Robust.Shared.Physics; using Robust.Shared.Physics.Components; using Robust.Shared.Physics.Dynamics; +using Robust.Shared.Player; using Robust.Shared.Random; using Robust.Shared.Timing; using Robust.Shared.Utility; @@ -205,7 +209,8 @@ public sealed partial class ExplosionSystem : SharedExplosionSystem MapCoordinates epicenter, HashSet processed, string id, - float? fireStacks) + float? fireStacks, + EntityUid? cause) { var size = grid.Comp.TileSize; var gridBox = new Box2(tile * size, (tile + 1) * size); @@ -224,7 +229,7 @@ public sealed partial class ExplosionSystem : SharedExplosionSystem // process those entities foreach (var (uid, xform) in list) { - ProcessEntity(uid, epicenter, damage, throwForce, id, xform, fireStacks); + ProcessEntity(uid, epicenter, damage, throwForce, id, xform, fireStacks, cause); } // process anchored entities @@ -234,7 +239,7 @@ public sealed partial class ExplosionSystem : SharedExplosionSystem foreach (var entity in _anchored) { processed.Add(entity); - ProcessEntity(entity, epicenter, damage, throwForce, id, null, fireStacks); + ProcessEntity(entity, epicenter, damage, throwForce, id, null, fireStacks, cause); } // Walls and reinforced walls will break into girders. These girders will also be considered turf-blocking for @@ -270,7 +275,7 @@ public sealed partial class ExplosionSystem : SharedExplosionSystem { // Here we only throw, no dealing damage. Containers n such might drop their entities after being destroyed, but // they should handle their own damage pass-through, with their own damage reduction calculation. - ProcessEntity(uid, epicenter, null, throwForce, id, xform, null); + ProcessEntity(uid, epicenter, null, throwForce, id, xform, null, cause); } return !tileBlocked; @@ -306,7 +311,8 @@ public sealed partial class ExplosionSystem : SharedExplosionSystem MapCoordinates epicenter, HashSet processed, string id, - float? fireStacks) + float? fireStacks, + EntityUid? cause) { var gridBox = Box2.FromDimensions(tile * DefaultTileSize, new Vector2(DefaultTileSize, DefaultTileSize)); var worldBox = spaceMatrix.TransformBox(gridBox); @@ -322,7 +328,7 @@ public sealed partial class ExplosionSystem : SharedExplosionSystem foreach (var (uid, xform) in state.Item1) { processed.Add(uid); - ProcessEntity(uid, epicenter, damage, throwForce, id, xform, fireStacks); + ProcessEntity(uid, epicenter, damage, throwForce, id, xform, fireStacks, cause); } if (throwForce <= 0) @@ -336,7 +342,7 @@ public sealed partial class ExplosionSystem : SharedExplosionSystem foreach (var (uid, xform) in list) { - ProcessEntity(uid, epicenter, null, throwForce, id, xform, fireStacks); + ProcessEntity(uid, epicenter, null, throwForce, id, xform, fireStacks, cause); } } @@ -434,13 +440,28 @@ public sealed partial class ExplosionSystem : SharedExplosionSystem float throwForce, string id, TransformComponent? xform, - float? fireStacksOnIgnite) + float? fireStacksOnIgnite, + EntityUid? cause) { if (originalDamage != null) { GetEntitiesToDamage(uid, originalDamage, id); foreach (var (entity, damage) in _toDamage) { + if (damage.GetTotal() > 0 && TryComp(entity, out var actorComponent)) + { + // Log damage to player entities only, cause this will create a massive amount of log spam otherwise. + if (cause != null) + { + _adminLogger.Add(LogType.ExplosionHit, LogImpact.Medium, $"Explosion of {ToPrettyString(cause):actor} dealt {damage.GetTotal()} damage to {ToPrettyString(entity):subject}"); + } + else + { + _adminLogger.Add(LogType.ExplosionHit, LogImpact.Medium, $"Explosion at {epicenter:epicenter} dealt {damage.GetTotal()} damage to {ToPrettyString(entity):subject}"); + } + + } + // TODO EXPLOSIONS turn explosions into entities, and pass the the entity in as the damage origin. _damageableSystem.TryChangeDamage(entity, damage, ignoreResistances: true); @@ -647,6 +668,8 @@ sealed class Explosion public readonly EntityUid VisualEnt; + public readonly EntityUid? Cause; + /// /// Initialize a new instance for processing /// @@ -663,9 +686,11 @@ sealed class Explosion bool canCreateVacuum, IEntityManager entMan, IMapManager mapMan, - EntityUid visualEnt) + EntityUid visualEnt, + EntityUid? cause) { VisualEnt = visualEnt; + Cause = cause; _system = system; ExplosionType = explosionType; _tileSetIntensity = tileSetIntensity; @@ -829,7 +854,8 @@ sealed class Explosion Epicenter, ProcessedEntities, ExplosionType.ID, - ExplosionType.FireStacks); + ExplosionType.FireStacks, + Cause); // If the floor is not blocked by some dense object, damage the floor tiles. if (canDamageFloor) @@ -847,7 +873,8 @@ sealed class Explosion Epicenter, ProcessedEntities, ExplosionType.ID, - ExplosionType.FireStacks); + ExplosionType.FireStacks, + Cause); } if (!MoveNext()) @@ -888,4 +915,5 @@ public sealed class QueuedExplosion public float TotalIntensity, Slope, MaxTileIntensity, TileBreakScale; public int MaxTileBreak; public bool CanCreateVacuum; + public EntityUid? Cause; // The entity that exploded, for logging purposes. } diff --git a/Content.Server/Explosion/EntitySystems/ExplosionSystem.cs b/Content.Server/Explosion/EntitySystems/ExplosionSystem.cs index 6de516ec0f..cd0ca1c22e 100644 --- a/Content.Server/Explosion/EntitySystems/ExplosionSystem.cs +++ b/Content.Server/Explosion/EntitySystems/ExplosionSystem.cs @@ -253,7 +253,7 @@ public sealed partial class ExplosionSystem : SharedExplosionSystem var posFound = _transformSystem.TryGetMapOrGridCoordinates(uid, out var gridPos, pos); - QueueExplosion(mapPos, typeId, totalIntensity, slope, maxTileIntensity, tileBreakScale, maxTileBreak, canCreateVacuum, addLog: false); + QueueExplosion(mapPos, typeId, totalIntensity, slope, maxTileIntensity, uid, tileBreakScale, maxTileBreak, canCreateVacuum, addLog: false); if (!addLog) return; @@ -281,6 +281,7 @@ public sealed partial class ExplosionSystem : SharedExplosionSystem float totalIntensity, float slope, float maxTileIntensity, + EntityUid? cause, float tileBreakScale = 1f, int maxTileBreak = int.MaxValue, bool canCreateVacuum = true, @@ -324,7 +325,8 @@ public sealed partial class ExplosionSystem : SharedExplosionSystem MaxTileIntensity = maxTileIntensity, TileBreakScale = tileBreakScale, MaxTileBreak = maxTileBreak, - CanCreateVacuum = canCreateVacuum + CanCreateVacuum = canCreateVacuum, + Cause = cause }; _explosionQueue.Enqueue(boom); _queuedExplosions.Add(boom); @@ -393,7 +395,8 @@ public sealed partial class ExplosionSystem : SharedExplosionSystem queued.CanCreateVacuum, EntityManager, _mapManager, - visualEnt); + visualEnt, + queued.Cause); } private void CameraShake(float range, MapCoordinates epicenter, float totalIntensity) diff --git a/Content.Server/Lightning/LightningTargetSystem.cs b/Content.Server/Lightning/LightningTargetSystem.cs index bc99def974..4a0ee23c5b 100644 --- a/Content.Server/Lightning/LightningTargetSystem.cs +++ b/Content.Server/Lightning/LightningTargetSystem.cs @@ -35,6 +35,7 @@ public sealed class LightningTargetSystem : EntitySystem uid.Comp.ExplosionPrototype, uid.Comp.TotalIntensity, uid.Comp.Dropoff, uid.Comp.MaxTileIntensity, + uid, canCreateVacuum: false); } } diff --git a/Content.Server/Storage/EntitySystems/BluespaceLockerSystem.cs b/Content.Server/Storage/EntitySystems/BluespaceLockerSystem.cs index 3754919c68..191a0ac57c 100644 --- a/Content.Server/Storage/EntitySystems/BluespaceLockerSystem.cs +++ b/Content.Server/Storage/EntitySystems/BluespaceLockerSystem.cs @@ -390,7 +390,7 @@ public sealed class BluespaceLockerSystem : EntitySystem { case BluespaceLockerDestroyType.Explode: _explosionSystem.QueueExplosion(uid.ToCoordinates().ToMap(EntityManager, _transformSystem), - ExplosionSystem.DefaultExplosionPrototypeId, 4, 1, 2, maxTileBreak: 0); + ExplosionSystem.DefaultExplosionPrototypeId, 4, 1, 2, uid, maxTileBreak: 0); goto case BluespaceLockerDestroyType.Delete; case BluespaceLockerDestroyType.Delete: QueueDel(uid); diff --git a/Content.Shared.Database/LogType.cs b/Content.Shared.Database/LogType.cs index 85cac5899d..5fedf3c7d4 100644 --- a/Content.Shared.Database/LogType.cs +++ b/Content.Shared.Database/LogType.cs @@ -115,4 +115,10 @@ public enum LogType /// Storage & entity-storage related interactions /// Storage = 93, + + /// + /// A player got hit by an explosion and was dealt damage. + /// + ExplosionHit = 94, + }