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>
This commit is contained in:
TsjipTsjip
2024-08-09 08:24:05 +02:00
committed by GitHub
parent e05df5d3e2
commit 736325a31f
7 changed files with 55 additions and 17 deletions

View File

@@ -132,6 +132,6 @@ public sealed class ExplosionCommand : IConsoleCommand
} }
var sysMan = IoCManager.Resolve<IEntitySystemManager>(); 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);
} }
} }

View File

@@ -105,7 +105,7 @@ public sealed partial class AdminVerbSystem
var coords = _transformSystem.GetMapCoordinates(args.Target); var coords = _transformSystem.GetMapCoordinates(args.Target);
Timer.Spawn(_gameTiming.TickPeriod, Timer.Spawn(_gameTiming.TickPeriod,
() => _explosionSystem.QueueExplosion(coords, ExplosionSystem.DefaultExplosionPrototypeId, () => _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); CancellationToken.None);
_bodySystem.GibBody(args.Target); _bodySystem.GibBody(args.Target);

View File

@@ -1,7 +1,10 @@
using System.Linq;
using System.Numerics; using System.Numerics;
using Content.Server.Atmos.EntitySystems; using Content.Server.Atmos.EntitySystems;
using Content.Server.Explosion.Components;
using Content.Shared.CCVar; using Content.Shared.CCVar;
using Content.Shared.Damage; using Content.Shared.Damage;
using Content.Shared.Database;
using Content.Shared.Explosion; using Content.Shared.Explosion;
using Content.Shared.Explosion.Components; using Content.Shared.Explosion.Components;
using Content.Shared.Explosion.EntitySystems; using Content.Shared.Explosion.EntitySystems;
@@ -14,6 +17,7 @@ using Robust.Shared.Map.Components;
using Robust.Shared.Physics; using Robust.Shared.Physics;
using Robust.Shared.Physics.Components; using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Dynamics; using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Player;
using Robust.Shared.Random; using Robust.Shared.Random;
using Robust.Shared.Timing; using Robust.Shared.Timing;
using Robust.Shared.Utility; using Robust.Shared.Utility;
@@ -205,7 +209,8 @@ public sealed partial class ExplosionSystem : SharedExplosionSystem
MapCoordinates epicenter, MapCoordinates epicenter,
HashSet<EntityUid> processed, HashSet<EntityUid> processed,
string id, string id,
float? fireStacks) float? fireStacks,
EntityUid? cause)
{ {
var size = grid.Comp.TileSize; var size = grid.Comp.TileSize;
var gridBox = new Box2(tile * size, (tile + 1) * size); var gridBox = new Box2(tile * size, (tile + 1) * size);
@@ -224,7 +229,7 @@ public sealed partial class ExplosionSystem : SharedExplosionSystem
// process those entities // process those entities
foreach (var (uid, xform) in list) 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 // process anchored entities
@@ -234,7 +239,7 @@ public sealed partial class ExplosionSystem : SharedExplosionSystem
foreach (var entity in _anchored) foreach (var entity in _anchored)
{ {
processed.Add(entity); 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 // 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 // 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. // 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; return !tileBlocked;
@@ -306,7 +311,8 @@ public sealed partial class ExplosionSystem : SharedExplosionSystem
MapCoordinates epicenter, MapCoordinates epicenter,
HashSet<EntityUid> processed, HashSet<EntityUid> processed,
string id, string id,
float? fireStacks) float? fireStacks,
EntityUid? cause)
{ {
var gridBox = Box2.FromDimensions(tile * DefaultTileSize, new Vector2(DefaultTileSize, DefaultTileSize)); var gridBox = Box2.FromDimensions(tile * DefaultTileSize, new Vector2(DefaultTileSize, DefaultTileSize));
var worldBox = spaceMatrix.TransformBox(gridBox); var worldBox = spaceMatrix.TransformBox(gridBox);
@@ -322,7 +328,7 @@ public sealed partial class ExplosionSystem : SharedExplosionSystem
foreach (var (uid, xform) in state.Item1) foreach (var (uid, xform) in state.Item1)
{ {
processed.Add(uid); processed.Add(uid);
ProcessEntity(uid, epicenter, damage, throwForce, id, xform, fireStacks); ProcessEntity(uid, epicenter, damage, throwForce, id, xform, fireStacks, cause);
} }
if (throwForce <= 0) if (throwForce <= 0)
@@ -336,7 +342,7 @@ public sealed partial class ExplosionSystem : SharedExplosionSystem
foreach (var (uid, xform) in list) 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, float throwForce,
string id, string id,
TransformComponent? xform, TransformComponent? xform,
float? fireStacksOnIgnite) float? fireStacksOnIgnite,
EntityUid? cause)
{ {
if (originalDamage != null) if (originalDamage != null)
{ {
GetEntitiesToDamage(uid, originalDamage, id); GetEntitiesToDamage(uid, originalDamage, id);
foreach (var (entity, damage) in _toDamage) 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. // TODO EXPLOSIONS turn explosions into entities, and pass the the entity in as the damage origin.
_damageableSystem.TryChangeDamage(entity, damage, ignoreResistances: true); _damageableSystem.TryChangeDamage(entity, damage, ignoreResistances: true);
@@ -647,6 +668,8 @@ sealed class Explosion
public readonly EntityUid VisualEnt; public readonly EntityUid VisualEnt;
public readonly EntityUid? Cause;
/// <summary> /// <summary>
/// Initialize a new instance for processing /// Initialize a new instance for processing
/// </summary> /// </summary>
@@ -663,9 +686,11 @@ sealed class Explosion
bool canCreateVacuum, bool canCreateVacuum,
IEntityManager entMan, IEntityManager entMan,
IMapManager mapMan, IMapManager mapMan,
EntityUid visualEnt) EntityUid visualEnt,
EntityUid? cause)
{ {
VisualEnt = visualEnt; VisualEnt = visualEnt;
Cause = cause;
_system = system; _system = system;
ExplosionType = explosionType; ExplosionType = explosionType;
_tileSetIntensity = tileSetIntensity; _tileSetIntensity = tileSetIntensity;
@@ -829,7 +854,8 @@ sealed class Explosion
Epicenter, Epicenter,
ProcessedEntities, ProcessedEntities,
ExplosionType.ID, ExplosionType.ID,
ExplosionType.FireStacks); ExplosionType.FireStacks,
Cause);
// If the floor is not blocked by some dense object, damage the floor tiles. // If the floor is not blocked by some dense object, damage the floor tiles.
if (canDamageFloor) if (canDamageFloor)
@@ -847,7 +873,8 @@ sealed class Explosion
Epicenter, Epicenter,
ProcessedEntities, ProcessedEntities,
ExplosionType.ID, ExplosionType.ID,
ExplosionType.FireStacks); ExplosionType.FireStacks,
Cause);
} }
if (!MoveNext()) if (!MoveNext())
@@ -888,4 +915,5 @@ public sealed class QueuedExplosion
public float TotalIntensity, Slope, MaxTileIntensity, TileBreakScale; public float TotalIntensity, Slope, MaxTileIntensity, TileBreakScale;
public int MaxTileBreak; public int MaxTileBreak;
public bool CanCreateVacuum; public bool CanCreateVacuum;
public EntityUid? Cause; // The entity that exploded, for logging purposes.
} }

View File

@@ -253,7 +253,7 @@ public sealed partial class ExplosionSystem : SharedExplosionSystem
var posFound = _transformSystem.TryGetMapOrGridCoordinates(uid, out var gridPos, pos); 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) if (!addLog)
return; return;
@@ -281,6 +281,7 @@ public sealed partial class ExplosionSystem : SharedExplosionSystem
float totalIntensity, float totalIntensity,
float slope, float slope,
float maxTileIntensity, float maxTileIntensity,
EntityUid? cause,
float tileBreakScale = 1f, float tileBreakScale = 1f,
int maxTileBreak = int.MaxValue, int maxTileBreak = int.MaxValue,
bool canCreateVacuum = true, bool canCreateVacuum = true,
@@ -324,7 +325,8 @@ public sealed partial class ExplosionSystem : SharedExplosionSystem
MaxTileIntensity = maxTileIntensity, MaxTileIntensity = maxTileIntensity,
TileBreakScale = tileBreakScale, TileBreakScale = tileBreakScale,
MaxTileBreak = maxTileBreak, MaxTileBreak = maxTileBreak,
CanCreateVacuum = canCreateVacuum CanCreateVacuum = canCreateVacuum,
Cause = cause
}; };
_explosionQueue.Enqueue(boom); _explosionQueue.Enqueue(boom);
_queuedExplosions.Add(boom); _queuedExplosions.Add(boom);
@@ -393,7 +395,8 @@ public sealed partial class ExplosionSystem : SharedExplosionSystem
queued.CanCreateVacuum, queued.CanCreateVacuum,
EntityManager, EntityManager,
_mapManager, _mapManager,
visualEnt); visualEnt,
queued.Cause);
} }
private void CameraShake(float range, MapCoordinates epicenter, float totalIntensity) private void CameraShake(float range, MapCoordinates epicenter, float totalIntensity)

View File

@@ -35,6 +35,7 @@ public sealed class LightningTargetSystem : EntitySystem
uid.Comp.ExplosionPrototype, uid.Comp.ExplosionPrototype,
uid.Comp.TotalIntensity, uid.Comp.Dropoff, uid.Comp.TotalIntensity, uid.Comp.Dropoff,
uid.Comp.MaxTileIntensity, uid.Comp.MaxTileIntensity,
uid,
canCreateVacuum: false); canCreateVacuum: false);
} }
} }

View File

@@ -390,7 +390,7 @@ public sealed class BluespaceLockerSystem : EntitySystem
{ {
case BluespaceLockerDestroyType.Explode: case BluespaceLockerDestroyType.Explode:
_explosionSystem.QueueExplosion(uid.ToCoordinates().ToMap(EntityManager, _transformSystem), _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; goto case BluespaceLockerDestroyType.Delete;
case BluespaceLockerDestroyType.Delete: case BluespaceLockerDestroyType.Delete:
QueueDel(uid); QueueDel(uid);

View File

@@ -115,4 +115,10 @@ public enum LogType
/// Storage & entity-storage related interactions /// Storage & entity-storage related interactions
/// </summary> /// </summary>
Storage = 93, Storage = 93,
/// <summary>
/// A player got hit by an explosion and was dealt damage.
/// </summary>
ExplosionHit = 94,
} }