]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Log enrichment: Explosion damage to players (#29762)
authorTsjipTsjip <19798667+TsjipTsjip@users.noreply.github.com>
Fri, 9 Aug 2024 06:24:05 +0000 (08:24 +0200)
committerGitHub <noreply@github.com>
Fri, 9 Aug 2024 06:24:05 +0000 (16:24 +1000)
* 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>
Content.Server/Administration/Commands/ExplosionCommand.cs
Content.Server/Administration/Systems/AdminVerbSystem.Smites.cs
Content.Server/Explosion/EntitySystems/ExplosionSystem.Processing.cs
Content.Server/Explosion/EntitySystems/ExplosionSystem.cs
Content.Server/Lightning/LightningTargetSystem.cs
Content.Server/Storage/EntitySystems/BluespaceLockerSystem.cs
Content.Shared.Database/LogType.cs

index 81daca59c4853f4a4a0713a25021f77653ea0d32..c916a7cb5f35ddda5c9a632caa340b035a2149be 100644 (file)
@@ -132,6 +132,6 @@ public sealed class ExplosionCommand : IConsoleCommand
         }
 
         var sysMan = IoCManager.Resolve<IEntitySystemManager>();
-        sysMan.GetEntitySystem<ExplosionSystem>().QueueExplosion(coords, type.ID, intensity, slope, maxIntensity);
+        sysMan.GetEntitySystem<ExplosionSystem>().QueueExplosion(coords, type.ID, intensity, slope, maxIntensity, null);
     }
 }
index 1f5abf6726bab29f99d062f3ba9951ec5f0f574b..e4554d7d83e07c7512fa6e04341d99d77a1bd3c4 100644 (file)
@@ -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);
index 3cab1213b62405977374cb8e379baf6e84a75239..6d0cbcf2794c27357bf16b7c17c235963011ebcd 100644 (file)
@@ -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<EntityUid> 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<EntityUid> 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<ActorComponent>(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;
+
     /// <summary>
     ///     Initialize a new instance for processing
     /// </summary>
@@ -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.
 }
index 6de516ec0f378881af7eab4d492c22380283a87d..cd0ca1c22eb2faf1534dd188493e4ac556a16a46 100644 (file)
@@ -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)
index bc99def9742980de3f424977c00b71d894ad10b0..4a0ee23c5b70e50cd0f0967ca54f8821866e2970 100644 (file)
@@ -35,6 +35,7 @@ public sealed class LightningTargetSystem : EntitySystem
                 uid.Comp.ExplosionPrototype,
                 uid.Comp.TotalIntensity, uid.Comp.Dropoff,
                 uid.Comp.MaxTileIntensity,
+                uid,
                 canCreateVacuum: false);
         }
     }
index 3754919c689764036b210966e6fcd8a8a96543c1..191a0ac57c662b3a6f2e8e5aae662921fbfb2ec9 100644 (file)
@@ -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);
index 85cac5899d9c0b2b7617fb1d1deee4a5a6294f7b..5fedf3c7d4b90cead76ce670478c679802c7e999 100644 (file)
@@ -115,4 +115,10 @@ public enum LogType
     /// Storage & entity-storage related interactions
     /// </summary>
     Storage = 93,
+    
+    /// <summary>
+    /// A player got hit by an explosion and was dealt damage.
+    /// </summary>
+    ExplosionHit = 94,
+
 }